Bug 1180754 - Get serviceworkerobject-scripturl test passing. r?bkelly draft
authorNikhil Marathe <nsm.nikhil@gmail.com>
Mon, 31 Aug 2015 17:52:52 -0700
changeset 289352 b31759e989a120015ce6a6a48d11914d04790b62
parent 289319 cafb1c90f794a73100a8f0afb9fe3301df0f2bde
child 508889 a139e2bf03af96d259b578417d14aae0a8754a86
push id4973
push usernsm.nikhil@gmail.com
push dateTue, 01 Sep 2015 00:53:04 +0000
reviewersbkelly
bugs1180754
milestone43.0a1
Bug 1180754 - Get serviceworkerobject-scripturl test passing. r?bkelly This commit does several things: 1. Change to https so the test does not fail due to security exceptions. 2. Add a function service_worker_unregister_exact to get around the "getRegistration() matches most specific registration" issue. 3. Uses the URL object for the "absolute" test instead of relying on server substitution since it achieves the same thing. 4. Allows fragments in the scriptURL since I cannot find anything in the spec preventing this. I have filed https://github.com/slightlyoff/ServiceWorker/issues/742 to resolve this. Update web-platform-tests expected data
testing/web-platform/mozilla/meta/MANIFEST.json
testing/web-platform/mozilla/meta/service-workers/service-worker/serviceworkerobject-scripturl.sub.html.ini
testing/web-platform/mozilla/tests/service-workers/service-worker/resources/test-helpers.sub.js
testing/web-platform/mozilla/tests/service-workers/service-worker/serviceworkerobject-scripturl.https.html
testing/web-platform/mozilla/tests/service-workers/service-worker/serviceworkerobject-scripturl.sub.html
--- a/testing/web-platform/mozilla/meta/MANIFEST.json
+++ b/testing/web-platform/mozilla/meta/MANIFEST.json
@@ -425,20 +425,20 @@
           }
         ],
         "service-workers/service-worker/service-worker-csp-script.https.html": [
           {
             "path": "service-workers/service-worker/service-worker-csp-script.https.html",
             "url": "/_mozilla/service-workers/service-worker/service-worker-csp-script.https.html"
           }
         ],
-        "service-workers/service-worker/serviceworkerobject-scripturl.sub.html": [
+        "service-workers/service-worker/serviceworkerobject-scripturl.https.html": [
           {
-            "path": "service-workers/service-worker/serviceworkerobject-scripturl.sub.html",
-            "url": "/_mozilla/service-workers/service-worker/serviceworkerobject-scripturl.sub.html"
+            "path": "service-workers/service-worker/serviceworkerobject-scripturl.https.html",
+            "url": "/_mozilla/service-workers/service-worker/serviceworkerobject-scripturl.https.html"
           }
         ],
         "service-workers/service-worker/shared-worker-controlled.https.html": [
           {
             "path": "service-workers/service-worker/shared-worker-controlled.https.html",
             "url": "/_mozilla/service-workers/service-worker/shared-worker-controlled.https.html"
           }
         ],
@@ -541,9 +541,9 @@
       }
     },
     "reftest_nodes": {}
   },
   "reftest_nodes": {},
   "rev": null,
   "url_base": "/_mozilla/",
   "version": 2
-}
\ No newline at end of file
+}
deleted file mode 100644
--- a/testing/web-platform/mozilla/meta/service-workers/service-worker/serviceworkerobject-scripturl.sub.html.ini
+++ /dev/null
@@ -1,11 +0,0 @@
-[serviceworkerobject-scripturl.sub.html]
-  type: testharness
-  [Verify the scriptURL property: relative]
-    expected: FAIL
-
-  [Verify the scriptURL property: with-fragment]
-    expected: FAIL
-
-  [Verify the scriptURL property: absolute]
-    expected: FAIL
-
--- a/testing/web-platform/mozilla/tests/service-workers/service-worker/resources/test-helpers.sub.js
+++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/resources/test-helpers.sub.js
@@ -1,32 +1,45 @@
 // Adapter for testharness.js-style tests with Service Workers
 
 function service_worker_unregister_and_register(test, url, scope) {
   if (!scope || scope.length == 0)
     return Promise.reject(new Error('tests must define a scope'));
 
   var options = { scope: scope };
-  return service_worker_unregister(test, scope)
+  return service_worker_unregister_exact(test, scope)
     .then(function() {
         return navigator.serviceWorker.register(url, options);
       })
     .catch(unreached_rejection(test,
                                'unregister and register should not fail'));
 }
 
+// This unregisters by using getRegistration() on documentUrl, which will
+// unregister the most specific matching registration!
 function service_worker_unregister(test, documentUrl) {
   return navigator.serviceWorker.getRegistration(documentUrl)
     .then(function(registration) {
         if (registration)
           return registration.unregister();
       })
     .catch(unreached_rejection(test, 'unregister should not fail'));
 }
 
+// This unregisters the registration that precisely matches scope. Use this
+// when unregistering by scope. If no registration is found, it just resolves.
+function service_worker_unregister_exact(test, scope) {
+  return navigator.serviceWorker.getRegistration(scope)
+    .then(function(registration) {
+        if (registration && registration.scope === scope)
+          return registration.unregister();
+      })
+    .catch(unreached_rejection(test, 'unregister should not fail'));
+}
+
 function service_worker_unregister_and_done(test, scope) {
   return service_worker_unregister(test, scope)
     .then(test.done.bind(test));
 }
 
 function unreached_fulfillment(test, prefix) {
   return test.step_func(function(result) {
       var error_prefix = prefix || 'unexpected fulfillment';
rename from testing/web-platform/mozilla/tests/service-workers/service-worker/serviceworkerobject-scripturl.sub.html
rename to testing/web-platform/mozilla/tests/service-workers/service-worker/serviceworkerobject-scripturl.https.html
--- a/testing/web-platform/mozilla/tests/service-workers/service-worker/serviceworkerobject-scripturl.sub.html
+++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/serviceworkerobject-scripturl.https.html
@@ -3,26 +3,25 @@
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <script src="resources/test-helpers.sub.js"></script>
 <script>
 
 function url_test(name, url) {
   var scope = 'resources/scope/' + name;
   async_test(function(t) {
-    var expectedURL = normalizeURL(url);
+    var expectedURL = (new URL(url, window.location)).toString();
     service_worker_unregister_and_register(t, url, scope)
       .then(function(registration) {
           var worker = registration.installing;
           assert_equals(worker.scriptURL, expectedURL,
                         'Returned ServiceWorker object should have scriptURL');
           service_worker_unregister_and_done(t, scope);
         })
       .catch(unreached_rejection(t));
   }, 'Verify the scriptURL property: ' + name);
 }
 
 url_test('relative', 'resources/empty-worker.js');
 url_test('with-fragment', 'resources/empty-worker.js#ref');
-url_test('absolute',
-         'http://{{domains[www]}}:{{ports[http][0]}}/service-worker/resources/empty-worker.js');
+url_test('absolute', (new URL('./resources/empty-worker.js', window.location)).href);
 
 </script>