Bug 1207727 - Add WPT tests for service worker update algorithm. r=bkelly
authordimi <dlee@mozilla.com>
Mon, 26 Oct 2015 11:03:47 +0800
changeset 304652 fcde5d56c92665f3e8b68a14543f21ceeb8de22d
parent 304651 9214ef441dabc11baef57ca294de2797c36158ed
child 304653 7c109c8df8ebb616592f30af939a2790a679267c
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1207727
milestone44.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 1207727 - Add WPT tests for service worker update algorithm. r=bkelly
dom/workers/test/serviceworkers/mochitest.ini
modules/libpref/init/all.js
testing/web-platform/mozilla/meta/MANIFEST.json
testing/web-platform/mozilla/meta/service-workers/service-worker/update-after-oneday.https.html.ini
testing/web-platform/mozilla/tests/service-workers/service-worker/resources/update-nocookie-worker.py
testing/web-platform/mozilla/tests/service-workers/service-worker/resources/update/update-after-oneday.https.html
testing/web-platform/mozilla/tests/service-workers/service-worker/update-after-navigation-fetch-event.https.html
testing/web-platform/mozilla/tests/service-workers/service-worker/update-after-oneday.https.html
--- a/dom/workers/test/serviceworkers/mochitest.ini
+++ b/dom/workers/test/serviceworkers/mochitest.ini
@@ -215,18 +215,16 @@ skip-if = release_build
 [test_match_all_advanced.html]
 [test_match_all_client_id.html]
 [test_match_all_client_properties.html]
 [test_navigator.html]
 [test_origin_after_redirect.html]
 [test_origin_after_redirect_cached.html]
 [test_origin_after_redirect_to_https.html]
 [test_origin_after_redirect_to_https_cached.html]
-[test_periodic_https_update.html]
-[test_periodic_update.html]
 [test_post_message.html]
 [test_post_message_advanced.html]
 [test_post_message_source.html]
 [test_register_base.html]
 [test_register_https_in_http.html]
 [test_request_context_audio.html]
 [test_request_context_beacon.html]
 [test_request_context_cache.html]
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -155,16 +155,19 @@ pref("dom.serviceWorkers.interception.en
 pref("dom.serviceWorkers.interception.opaque.enabled", false);
 
 // The amount of time (milliseconds) service workers keep running after each event.
 pref("dom.serviceWorkers.idle_timeout", 30000);
 
 // The amount of time (milliseconds) service workers can be kept running using waitUntil promises.
 pref("dom.serviceWorkers.idle_extended_timeout", 300000);
 
+// Enable test for 24 hours update, service workers will always treat last update check time is over 24 hours
+pref("dom.serviceWorkers.testUpdateOverOneDay", false);
+
 // Whether nonzero values can be returned from performance.timing.*
 pref("dom.enable_performance", true);
 
 // Whether resource timing will be gathered and returned by performance.GetEntries*
 pref("dom.enable_resource_timing", true);
 
 // Enable high-resolution timing markers for users
 pref("dom.enable_user_timing", true);
--- a/testing/web-platform/mozilla/meta/MANIFEST.json
+++ b/testing/web-platform/mozilla/meta/MANIFEST.json
@@ -500,16 +500,28 @@
           }
         ],
         "service-workers/service-worker/update.https.html": [
           {
             "path": "service-workers/service-worker/update.https.html",
             "url": "/_mozilla/service-workers/service-worker/update.https.html"
           }
         ],
+        "service-workers/service-worker/update-after-navigation-fetch-event.https.html": [
+          {
+            "path": "service-workers/service-worker//update-after-navigation-fetch-event.https.html",
+            "url": "/_mozilla/service-workers/service-worker//update-after-navigation-fetch-event.https.html"
+          }
+        ],
+        "service-workers/service-worker/update-after-oneday.https.html": [
+          {
+            "path": "service-workers/service-worker//update-after-oneday.https.html",
+            "url": "/_mozilla/service-workers/service-worker//update-after-oneday.https.html"
+          }
+        ],
         "service-workers/service-worker/waiting.https.html": [
           {
             "path": "service-workers/service-worker/waiting.https.html",
             "url": "/_mozilla/service-workers/service-worker/waiting.https.html"
           }
         ],
         "service-workers/service-worker/worker-interception.https.html": [
           {
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/mozilla/meta/service-workers/service-worker/update-after-oneday.https.html.ini
@@ -0,0 +1,2 @@
+[update-after-oneday.https.html]
+  prefs: [dom.serviceWorkers.testUpdateOverOneDay: true]
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/resources/update-nocookie-worker.py
@@ -0,0 +1,14 @@
+import time
+
+def main(request, response):
+    # no-cache itself to ensure the user agent finds a new version for each update.
+    headers = [('Cache-Control', 'no-cache, must-revalidate'),
+               ('Pragma', 'no-cache')]
+
+    # Set a normal mimetype.
+    content_type = 'application/javascript'
+
+    headers.append(('Content-Type', content_type))
+    # Return a different script for each access.
+    return headers, '// %s' % (time.time())
+
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/resources/update/update-after-oneday.https.html
@@ -0,0 +1,8 @@
+<body>
+<script>
+function load_image(url) {
+  var img = document.createElement('img');
+  img.src = url;
+}
+</script>
+</body>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/update-after-navigation-fetch-event.https.html
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<title>Service Worker: Update should be triggered after a navigation fetch event.</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/test-helpers.sub.js"></script>
+<script>
+
+promise_test(function(t) {
+    var script = 'resources/update-nocookie-worker.py';
+    var scope = 'resources/scope/update';
+    var parsed_url = normalizeURL(script);
+    var registration;
+
+    return service_worker_unregister_and_register(t, parsed_url, scope)
+      .then(function(r) {
+          registration = r;
+          return wait_for_state(t, registration.installing, 'activated');
+        })
+      .then(function() {
+          // Navigation to the iframe.
+          return with_iframe(scope);
+        })
+      .then(function(f) {
+          // Navigation fetch event should trigger update.
+          return wait_for_update(t, registration);
+       })
+       .then(function() {
+          return service_worker_unregister_and_done(t, scope);
+       })
+  }, 'Update should be triggered after a navigation fetch event.');
+</script>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/update-after-oneday.https.html
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<!-- This test requires browser to treat all registrations are older than 24 hours.
+     Preference 'dom.serviceWorkers.testUpdateOverOneDay' should be enabled during
+     the execution of the test -->
+<title>Service Worker: Functional events should trigger update if last update time is over 24 hours</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/test-helpers.sub.js"></script>
+<script>
+
+promise_test(function(t) {
+    var script = 'resources/update-nocookie-worker.py';
+    var scope = 'resources/update/update-after-oneday.https.html';
+    var parsed_url = normalizeURL(script);
+    var registration;
+    var frame;
+
+    return service_worker_unregister_and_register(t, parsed_url, scope)
+      .then(function(r) {
+          registration = r;
+          return wait_for_state(t, registration.installing, 'activated');
+        })
+      .then(function() { return with_iframe(scope); })
+      .then(function(f) {
+          frame = f;
+          return wait_for_update(t, registration);
+       })
+       .then(function() {
+          // Trigger a non-navigation fetch event
+          frame.contentWindow.load_image(normalizeURL('resources/update/dummy'));
+          return wait_for_update(t, registration);
+       })
+       .then(function() {
+          return service_worker_unregister_and_done(t, scope);
+       })
+  }, 'Update should be triggered after a functional event when last update time is over 24 hours');
+
+</script>
+
+