Bug 1356014 - Wait for appearance of the desired channel to do the related checks. r=bkelly
authorHo-Pang Hsu <hopang.hsu@gmail.com>
Fri, 28 Jul 2017 15:06:34 +0800
changeset 420414 ac9dcc2cad707b4d16e0b7059510b79b1470cec3
parent 420413 dca733c0467ff3133c5862728d4a0a5d9e03ee3c
child 420415 dc9de4bcb156a32bb9a342b79f4b6c4be2eb22b5
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1356014
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1356014 - Wait for appearance of the desired channel to do the related checks. r=bkelly
dom/workers/test/serviceworkers/test_devtools_serviceworker_interception.html
--- a/dom/workers/test/serviceworkers/test_devtools_serviceworker_interception.html
+++ b/dom/workers/test/serviceworkers/test_devtools_serviceworker_interception.html
@@ -86,17 +86,23 @@ function fetchAndCheckTimedChannel(aWind
   var resolveFunction;
   var promise = new Promise(aResolve => resolveFunction = aResolve);
 
   var topic = aFetch ? "http-on-examine-response"
                      : "service-worker-synthesized-response";
 
   function observer(aSubject) {
     var channel = aSubject.QueryInterface(Ci.nsIChannel);
-    ok(channel.URI.spec.endsWith(aURL));
+
+    // Since we cannot make sure that the network event triggered by the fetch()
+    // in this testcase is the very next event processed by ObserverService, we
+    // have to wait until we catch the one we want.
+    if (!channel.URI.spec.endsWith(aURL)) {
+      return;
+    }
 
     var tc = aSubject.QueryInterface(Ci.nsITimedChannel);
 
     // Check service worker related timings.
     var serviceWorkerTimings = [{start: tc.launchServiceWorkerStartTime,
                                  end:   tc.launchServiceWorkerEndTime},
                                 {start: tc.dispatchFetchEventStartTime,
                                  end:   tc.dispatchFetchEventEndTime},
@@ -109,36 +115,37 @@ function fetchAndCheckTimedChannel(aWind
         ok(aPreviousTimings.end <= aCurrentTimings.end,
            "End time order check.");
         ok(aCurrentTimings.start <= aCurrentTimings.end,
            "Start time should be smaller than end time.");
         return aCurrentTimings;
       });
     } else {
       serviceWorkerTimings.forEach(aTimings => {
-        is(aTimings.start, 0);
-        is(aTimings.end, 0);
+        is(aTimings.start, 0, "SW timings should be 0.");
+        is(aTimings.end, 0, "SW timings should be 0.");
       });
     }
 
     // Check network related timings.
     var networkTimings = [tc.domainLookupStartTime,
                           tc.domainLookupEndTime,
                           tc.connectStartTime,
                           tc.connectEndTime,
                           tc.requestStartTime,
                           tc.responseStartTime,
                           tc.responseEndTime];
     if (aFetch) {
       networkTimings.reduce((aPreviousTiming, aCurrentTiming) => {
-        ok(aPreviousTiming <= aCurrentTiming);
+        ok(aPreviousTiming <= aCurrentTiming, "Checking network timings");
         return aCurrentTiming;
       });
     } else {
-      networkTimings.forEach(aTiming => is(aTiming, 0));
+      networkTimings.forEach(aTiming => is(aTiming, 0,
+                                           "Network timings should be 0."));
     }
 
     SpecialPowers.removeObserver(observer, topic);
     resolveFunction();
   }
 
   SpecialPowers.addObserver(observer, topic);