Bug 1444132 - Fix the order of requests done by html_cause-test-page.html test. r=jdescottes
authorAlexandre Poirot <poirot.alex@gmail.com>
Tue, 31 Jul 2018 07:33:04 -0700
changeset 826069 3baa0a93d12d224aa844d7116d53f64bc66ad004
parent 826068 3ba0fd5c1def88163a1b2feb73e8db88e701ae2f
child 826070 8b61609228c997c521223f9b6ea5ded55d31676f
push id118238
push userbmo:mh+mozilla@glandium.org
push dateThu, 02 Aug 2018 22:02:22 +0000
reviewersjdescottes
bugs1444132
milestone63.0a1
Bug 1444132 - Fix the order of requests done by html_cause-test-page.html test. r=jdescottes MozReview-Commit-ID: IY8TLzqjrnT
devtools/client/netmonitor/test/browser_net_cause.js
devtools/client/netmonitor/test/html_cause-test-page.html
--- a/devtools/client/netmonitor/test/browser_net_cause.js
+++ b/devtools/client/netmonitor/test/browser_net_cause.js
@@ -33,52 +33,53 @@ const EXPECTED_REQUESTS = [
     causeUri: CAUSE_URL,
     stack: false
   },
   {
     method: "GET",
     url: EXAMPLE_URL + "xhr_request",
     causeType: "xhr",
     causeUri: CAUSE_URL,
-    stack: [{ fn: "performXhrRequest", file: CAUSE_FILE_NAME, line: 24 }]
+    stack: [{ fn: "performXhrRequestCallback", file: CAUSE_FILE_NAME, line: 26 }]
   },
   {
     method: "GET",
     url: EXAMPLE_URL + "fetch_request",
     causeType: "fetch",
     causeUri: CAUSE_URL,
-    stack: [{ fn: "performFetchRequest", file: CAUSE_FILE_NAME, line: 28 }]
+    stack: [{ fn: "performFetchRequest", file: CAUSE_FILE_NAME, line: 31 }]
   },
   {
     method: "GET",
     url: EXAMPLE_URL + "promise_fetch_request",
     causeType: "fetch",
     causeUri: CAUSE_URL,
     stack: [
-      { fn: "performPromiseFetchRequest", file: CAUSE_FILE_NAME, line: 40 },
-      { fn: null, file: CAUSE_FILE_NAME, line: 39, asyncCause: "promise callback" },
+      { fn: "performPromiseFetchRequestCallback", file: CAUSE_FILE_NAME, line: 37 },
+      { fn: "performPromiseFetchRequest", file: CAUSE_FILE_NAME, line: 36,
+        asyncCause: "promise callback" },
     ]
   },
   {
     method: "GET",
     url: EXAMPLE_URL + "timeout_fetch_request",
     causeType: "fetch",
     causeUri: CAUSE_URL,
     stack: [
-      { fn: "performTimeoutFetchRequest", file: CAUSE_FILE_NAME, line: 42 },
-      { fn: "performPromiseFetchRequest", file: CAUSE_FILE_NAME, line: 41,
+      { fn: "performTimeoutFetchRequestCallback2", file: CAUSE_FILE_NAME, line: 44 },
+      { fn: "performTimeoutFetchRequestCallback1", file: CAUSE_FILE_NAME, line: 43,
         asyncCause: "setTimeout handler" },
     ]
   },
   {
     method: "POST",
     url: EXAMPLE_URL + "beacon_request",
     causeType: "beacon",
     causeUri: CAUSE_URL,
-    stack: [{ fn: "performBeaconRequest", file: CAUSE_FILE_NAME, line: 32 }]
+    stack: [{ fn: "performBeaconRequest", file: CAUSE_FILE_NAME, line: 50 }]
   },
 ];
 
 add_task(async function() {
   // Async stacks aren't on by default in all builds
   await SpecialPowers.pushPrefEnv({ set: [["javascript.options.asyncstack", true]] });
 
   // the initNetMonitor function clears the network request list after the
--- a/devtools/client/netmonitor/test/html_cause-test-page.html
+++ b/devtools/client/netmonitor/test/html_cause-test-page.html
@@ -12,39 +12,53 @@
     <link rel="stylesheet" type="text/css" href="stylesheet_request" />
   </head>
 
   <body>
     <p>Request cause test</p>
     <img src="img_request" />
     <script type="text/javascript">
       "use strict";
-
+      
       function performXhrRequest() {
         const xhr = new XMLHttpRequest();
         xhr.open("GET", "xhr_request", true);
-        xhr.send();
+        return new Promise(function performXhrRequestCallback(resolve) {
+          xhr.onload = resolve;
+          xhr.send();
+        });
       }
 
       function performFetchRequest() {
-        fetch("fetch_request");
+        return fetch("fetch_request");
+      }
+
+      // Perform some requests with async stacks
+      function performPromiseFetchRequest() {
+        return Promise.resolve().then(function performPromiseFetchRequestCallback() {
+          return fetch("promise_fetch_request");
+        });
+      }
+
+      function performTimeoutFetchRequest() {
+        return new Promise(function performTimeoutFetchRequestCallback1(resolve) {
+          setTimeout(function performTimeoutFetchRequestCallback2() {
+            resolve(fetch("timeout_fetch_request"));
+          }, 0);
+        });
       }
 
       function performBeaconRequest() {
         navigator.sendBeacon("beacon_request");
       }
 
-      performXhrRequest();
-      performFetchRequest();
+      (async function() {
+        await performXhrRequest();
+        await performFetchRequest();
+        await performPromiseFetchRequest();
+        await performTimeoutFetchRequest();
 
-      // Perform some requests with async stacks
-      Promise.resolve().then(function performPromiseFetchRequest() {
-        fetch("promise_fetch_request");
-        setTimeout(function performTimeoutFetchRequest() {
-          fetch("timeout_fetch_request");
-
-          // Finally, send a beacon request
-          performBeaconRequest();
-        }, 0);
-      });
+        // Finally, send a beacon request
+        performBeaconRequest();
+      })();
     </script>
   </body>
 </html>