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
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,35 @@
+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
+ print 'NSM mode is now', mode
+
+ # 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 200, 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>