Bug 1490310: Fix cleanup code in claim-worker-fetch.https.html r=asuth,perry
authorYaron Tausky <ytausky@mozilla.com>
Mon, 01 Oct 2018 18:35:36 +0000
changeset 494771 677786af21883f02d5eb6ba33505c52ea4daf11c
parent 494770 0d3748a0ad24606a4debc37726b0743ab4676734
child 494772 7783682f8ba7753ad6bdccd716edf37cb53ebc22
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth, perry
bugs1490310
milestone64.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 1490310: Fix cleanup code in claim-worker-fetch.https.html r=asuth,perry This test tried to clean up after itself, but didn't do a very good job at it. I didn't analyze it fully, but I suspect that the ordering of the microtasks in the test depended on a race condition that caused it to fail from time to time. This commit moves cleanup code to the test harness, which does a better job at ensuring that things happen in order. Differential Revision: https://phabricator.services.mozilla.com/D7278
testing/web-platform/meta/service-workers/service-worker/claim-worker-fetch.https.html.ini
testing/web-platform/tests/service-workers/service-worker/claim-worker-fetch.https.html
deleted file mode 100644
--- a/testing/web-platform/meta/service-workers/service-worker/claim-worker-fetch.https.html.ini
+++ /dev/null
@@ -1,4 +0,0 @@
-[claim-worker-fetch.https.html]
-  [fetch() in nested Worker should be intercepted after the client is claimed.]
-    expected: FAIL
-
--- a/testing/web-platform/tests/service-workers/service-worker/claim-worker-fetch.https.html
+++ b/testing/web-platform/tests/service-workers/service-worker/claim-worker-fetch.https.html
@@ -10,42 +10,47 @@
 promise_test(function(t) {
   return runTest(t, 'resources/claim-worker-fetch-iframe.html');
 }, 'fetch() in Worker should be intercepted after the client is claimed.');
 
 promise_test(function(t) {
   return runTest(t, 'resources/claim-nested-worker-fetch-iframe.html');
 }, 'fetch() in nested Worker should be intercepted after the client is claimed.');
 
-var frame;
-var registration;
-
 function runTest(t, iframe_url) {
   var resource = 'simple.txt';
 
+  var frame;
+  var registration;
   var worker;
   var scope = 'resources/';
   var script = 'resources/claim-worker.js';
 
-  const test_result = Promise.resolve()
+  return Promise.resolve()
     // Create the test iframe with a dedicated worker.
     .then(() => with_iframe(iframe_url))
-    .then(f => frame = f)
+    .then(f => {
+      t.add_cleanup(() => f.remove());
+      frame = f;
+    })
 
     // Check the controller and test with fetch in the worker.
     .then(() => assert_equals(frame.contentWindow.navigator.controller,
                               undefined,
                               'Should have no controller.'))
     .then(() => frame.contentWindow.fetch_in_worker(resource))
     .then(response_text => assert_equals(response_text,
                                          'a simple text file\n',
                                          'fetch() should not be intercepted.'))
     // Register a service worker.
     .then(() => service_worker_unregister_and_register(t, script, scope))
-    .then(r => worker = r.installing)
+    .then(r => {
+      t.add_cleanup(() => r.unregister());
+      worker = r.installing;
+    })
     .then(() => wait_for_state(t, worker, 'activated'))
 
     // Let the service worker claim the iframe and the worker.
     .then(() => {
       var channel = new MessageChannel();
       var saw_message = new Promise(function(resolve) {
         channel.port1.onmessage = t.step_func(function(e) {
           assert_equals(e.data, 'PASS',
@@ -64,24 +69,12 @@ function runTest(t, iframe_url) {
                              registration.active,
                              'Test iframe should be claimed.'))
     // TODO(horo): Check the worker's navigator.seviceWorker.controller.
     .then(() => frame.contentWindow.fetch_in_worker(resource))
     .then(response_text =>
           assert_equals(response_text,
                         'Intercepted!',
                         'fetch() in the worker should be intercepted.'));
-
-    // Cleanup this testcase.
-    return Promise.resolve()
-        .then(cleanup, cleanup)
-        .then(() => { return test_result; });
-}
-
-const cleanup = async () => {
-  if (registration)
-    await registration.unregister();
-  if (frame)
-    frame.remove();
 }
 
 </script>
 </body>