Bug 1465594 - Ensure proper order of XHRs; r=jryans draft
authorJan Odvarko <odvarko@gmail.com>
Thu, 07 Jun 2018 14:51:40 +0200
changeset 805188 74b95c1c10f027a44fc80db18118f455f11b46c5
parent 805066 f7fd9b08c0156be5b5cd99de5ed0ed0b98d93051
push id112590
push userjodvarko@mozilla.com
push dateThu, 07 Jun 2018 13:05:58 +0000
reviewersjryans
bugs1465594
milestone62.0a1
Bug 1465594 - Ensure proper order of XHRs; r=jryans MozReview-Commit-ID: BdieFClyunE
devtools/client/netmonitor/test/html_params-test-page.html
--- a/devtools/client/netmonitor/test/html_params-test-page.html
+++ b/devtools/client/netmonitor/test/html_params-test-page.html
@@ -13,60 +13,49 @@
 
   <body>
     <p>Request params type test</p>
 
     <script type="text/javascript">
       /* exported performRequests */
       "use strict";
 
-      function get(address, query) {
-        const xhr = new XMLHttpRequest();
-        xhr.open("GET", address + query, true);
-        xhr.send();
-      }
-
-      function post(address, query, contentType, postBody) {
-        const xhr = new XMLHttpRequest();
-        xhr.open("POST", address + query, true);
-        xhr.setRequestHeader("content-type", contentType);
-        xhr.send(postBody);
+      async function get(address, query) {
+        return new Promise(resolve => {
+          const xhr = new XMLHttpRequest();
+          xhr.open("GET", address + query, true);
+          xhr.onreadystatechange = function() {
+            if (this.readyState == this.DONE) {
+              resolve();
+            }
+          };
+          xhr.send();
+        });
       }
 
-      function performRequests() {
-        const urlencoded = "application/x-www-form-urlencoded";
-
-        /* eslint-disable max-nested-callbacks */
-        setTimeout(function() {
-          post("baz", "?a", urlencoded, '{ "foo": "bar" }');
-
-          setTimeout(function() {
-            post("baz", "?a=b", urlencoded, '{ "foo": "bar" }');
-
-            setTimeout(function() {
-              post("baz", "?a=b", urlencoded, "?foo=bar");
-
-              setTimeout(function() {
-                post("baz", "?a", undefined, '{ "foo": "bar" }');
+      async function post(address, query, contentType, postBody) {
+        return new Promise(resolve => {
+          const xhr = new XMLHttpRequest();
+          xhr.open("POST", address + query, true);
+          xhr.setRequestHeader("content-type", contentType);
+          xhr.onreadystatechange = function() {
+            if (this.readyState == this.DONE) {
+              resolve();
+            }
+          };
+          xhr.send(postBody);
+        });
+      }
 
-                setTimeout(function() {
-                  post("baz", "?a=b", undefined, '{ "foo": "bar" }');
-
-                  setTimeout(function() {
-                    post("baz", "?a=b", undefined, "?foo=bar");
-
-                    setTimeout(function() {
-                      get("baz", "");
-
-                      // Done.
-                    }, 10);
-                  }, 10);
-                }, 10);
-              }, 10);
-            }, 10);
-          }, 10);
-        }, 10);
-        /* eslint-enable max-nested-callbacks */
+      async function performRequests() {
+        const urlencoded = "application/x-www-form-urlencoded";
+        await post("baz", "?a", urlencoded, '{ "foo": "bar" }');
+        await post("baz", "?a=b", urlencoded, '{ "foo": "bar" }');
+        await post("baz", "?a=b", urlencoded, "?foo=bar");
+        await post("baz", "?a", undefined, '{ "foo": "bar" }');
+        await post("baz", "?a=b", undefined, '{ "foo": "bar" }');
+        await post("baz", "?a=b", undefined, "?foo=bar");
+        await get("baz", "");
       }
     </script>
   </body>
 
 </html>