Bug 1180737 - Add update-test.py and update test to latest version. r=bkelly.
authorNikhil Marathe <nsm.nikhil@gmail.com>
Mon, 31 Aug 2015 18:56:21 -0700
changeset 260603 40e6330dd773b563b20c9eee992eefc92f172270
parent 260602 17a5de3b6eaa023d7bbec275eebb57d9f38fd598
child 260604 50fd13696678be08cc9fdd953905fffc72b6aa48
push id29318
push usercbook@mozilla.com
push dateThu, 03 Sep 2015 11:15:07 +0000
treeherdermozilla-central@74fbd245369c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1180737
milestone43.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 1180737 - Add update-test.py and update test to latest version. r=bkelly. Added update-test.py which is a conversion of Blink update-test.php to deliver workers with different mime types. Updated test file to latest version to check for SecurityError. Dealt with the usual waiting/active issue. Update web-platform-tests expected data
testing/web-platform/mozilla/meta/service-workers/service-worker/update.https.html.ini
testing/web-platform/mozilla/tests/service-workers/service-worker/resources/update-worker.py
testing/web-platform/mozilla/tests/service-workers/service-worker/update.https.html
deleted file mode 100644
--- a/testing/web-platform/mozilla/meta/service-workers/service-worker/update.https.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[update.https.html]
-  type: testharness
-  [Update a registration]
-    expected: FAIL
-
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/resources/update-worker.py
@@ -0,0 +1,34 @@
+import time
+
+def main(request, response):
+    # Set mode to 'init' for initial fetch.
+    mode = 'init'
+    if 'mode' in request.cookies:
+        mode = request.cookies['mode'].value
+
+    # 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')]
+
+    content_type = ''
+
+    if mode == 'init':
+        # Set a normal mimetype.
+        # Set cookie value to 'normal' so the next fetch will work in 'normal' mode.
+        content_type = 'application/javascript'
+        response.set_cookie('mode', 'normal')
+    elif mode == 'normal':
+        # Set a normal mimetype.
+        # Set cookie value to 'error' so the next fetch will work in 'error' mode.
+        content_type = 'application/javascript'
+        response.set_cookie('mode', 'error');
+    elif mode == 'error':
+        # Set a disallowed mimetype.
+        # Unset and delete cookie to clean up the test setting.
+        content_type = 'text/html'
+        response.delete_cookie('mode')
+
+    headers.append(('Content-Type', content_type))
+    # Return a different script for each access.
+    return headers, '// %s' % (time.time())
+
--- a/testing/web-platform/mozilla/tests/service-workers/service-worker/update.https.html
+++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/update.https.html
@@ -4,55 +4,72 @@
 <script src="/resources/testharnessreport.js"></script>
 <script src="resources/test-helpers.sub.js"></script>
 <script>
 promise_test(function(t) {
     var scope = 'resources/scope/update';
     var worker_url = 'resources/update-worker.py';
     var expected_url = normalizeURL(worker_url);
     var registration;
-
     return service_worker_unregister_and_register(t, worker_url, scope)
       .then(function(r) {
           registration = r;
           return wait_for_state(t, registration.installing, 'activated');
         })
       .then(function() {
           assert_equals(registration.installing, null,
-                        'installing should be null in the initial state');
+                        'installing should be null in the initial state.');
           assert_equals(registration.waiting, null,
-                        'waiting should be null in the initial state');
+                        'waiting should be null in the initial state.');
           assert_equals(registration.active.scriptURL, expected_url,
-                        'active should exist in the initial state');
-
-          // A new worker should be found.
-          registration.update();
-          return wait_for_update(t, registration);
+                        'active should exist in the initial state.');
+          // A new worker (generated by update-worker.py) should be found.
+          // The returned promise should resolve when a new worker script is
+          // fetched and starts installing.
+          return Promise.all([registration.update(),
+                              wait_for_update(t, registration)]);
         })
       .then(function() {
           assert_equals(registration.installing.scriptURL, expected_url,
-                        'new installing should be set after updatefound');
+                        'new installing should be set after update resolves.');
           assert_equals(registration.waiting, null,
-                        'waiting should still be null after updatefound');
+                        'waiting should still be null after update resolves.');
           assert_equals(registration.active.scriptURL, expected_url,
-                        'active should still exist after update found');
+                        'active should still exist after update found.');
           return wait_for_state(t, registration.installing, 'installed');
         })
       .then(function() {
           assert_equals(registration.installing, null,
-                        'installing should be null after installing');
-          assert_equals(registration.waiting.scriptURL, expected_url,
-                        'waiting should be set after installing');
-          assert_equals(registration.active.scriptURL, expected_url,
-                        'active should still exist after installing');
-          return wait_for_state(t, registration.waiting, 'activated');
+                        'installing should be null after installing.');
+          if (registration.waiting) {
+            assert_equals(registration.waiting.scriptURL, expected_url,
+                          'waiting should be set after installing.');
+            assert_equals(registration.active.scriptURL, expected_url,
+                          'active should still exist after installing.');
+            return wait_for_state(t, registration.waiting, 'activated');
+          }
         })
       .then(function() {
           assert_equals(registration.installing, null,
-                        'installing should be null after activated');
+                        'installing should be null after activated.');
           assert_equals(registration.waiting, null,
-                        'waiting should be null after activated');
+                        'waiting should be null after activated.');
           assert_equals(registration.active.scriptURL, expected_url,
-                        'new worker should be promoted to active');
-          return service_worker_unregister_and_done(t, scope);
+                        'new worker should be promoted to active.');
+        })
+      .then(function() {
+          // A new worker(generated by update-worker.py) should be found.
+          // The returned promise should reject as update-worker.py sets the
+          // mimetype to a disallowed value for this attempt.
+          return registration.update();
         })
-  }, 'Update a registration');
+      .then(
+        function() { assert_unreached("update() should reject."); },
+        function(e) {
+          assert_throws('SecurityError', function() { throw e; },
+                        'Using a disallowed mimetype should make update() ' +
+                        'promise reject with a SecurityError.');
+          assert_equals(registration.active.scriptURL, expected_url,
+                        'active should still exist after update failure.');
+          return service_worker_unregister_and_done(t, scope);
+        });
+  }, 'Update a registration.');
 </script>