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

--HG--
extra : commitid : 9XzorHqlWDi
extra : rebase_source : a02d66beb08f4eee83f27c21a6fee1178aeea71e
This commit is contained in:
Nikhil Marathe 2015-08-31 18:56:21 -07:00
parent 7bcbe18938
commit 43be510baf
3 changed files with 73 additions and 27 deletions

View File

@ -1,5 +0,0 @@
[update.https.html]
type: testharness
[Update a registration]
expected: FAIL

View File

@ -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())

View File

@ -9,7 +9,6 @@ promise_test(function(t) {
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;
@ -17,42 +16,60 @@ promise_test(function(t) {
})
.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');
'installing should be null after installing.');
if (registration.waiting) {
assert_equals(registration.waiting.scriptURL, expected_url,
'waiting should be set after installing');
'waiting should be set after installing.');
assert_equals(registration.active.scriptURL, expected_url,
'active should still exist after installing');
'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.');
})
}, 'Update a registration');
.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();
})
.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>