mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-22 17:55:50 +00:00
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:
parent
7bcbe18938
commit
43be510baf
@ -1,5 +0,0 @@
|
|||||||
[update.https.html]
|
|
||||||
type: testharness
|
|
||||||
[Update a registration]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
@ -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())
|
||||||
|
|
@ -9,7 +9,6 @@ promise_test(function(t) {
|
|||||||
var worker_url = 'resources/update-worker.py';
|
var worker_url = 'resources/update-worker.py';
|
||||||
var expected_url = normalizeURL(worker_url);
|
var expected_url = normalizeURL(worker_url);
|
||||||
var registration;
|
var registration;
|
||||||
|
|
||||||
return service_worker_unregister_and_register(t, worker_url, scope)
|
return service_worker_unregister_and_register(t, worker_url, scope)
|
||||||
.then(function(r) {
|
.then(function(r) {
|
||||||
registration = r;
|
registration = r;
|
||||||
@ -17,42 +16,60 @@ promise_test(function(t) {
|
|||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
assert_equals(registration.installing, null,
|
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,
|
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,
|
assert_equals(registration.active.scriptURL, expected_url,
|
||||||
'active should exist in the initial state');
|
'active should exist in the initial state.');
|
||||||
|
// A new worker (generated by update-worker.py) should be found.
|
||||||
// A new worker should be found.
|
// The returned promise should resolve when a new worker script is
|
||||||
registration.update();
|
// fetched and starts installing.
|
||||||
return wait_for_update(t, registration);
|
return Promise.all([registration.update(),
|
||||||
|
wait_for_update(t, registration)]);
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
assert_equals(registration.installing.scriptURL, expected_url,
|
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,
|
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,
|
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');
|
return wait_for_state(t, registration.installing, 'installed');
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
assert_equals(registration.installing, null,
|
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,
|
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,
|
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');
|
return wait_for_state(t, registration.waiting, 'activated');
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
assert_equals(registration.installing, null,
|
assert_equals(registration.installing, null,
|
||||||
'installing should be null after activated');
|
'installing should be null after activated.');
|
||||||
assert_equals(registration.waiting, null,
|
assert_equals(registration.waiting, null,
|
||||||
'waiting should be null after activated');
|
'waiting should be null after activated.');
|
||||||
assert_equals(registration.active.scriptURL, expected_url,
|
assert_equals(registration.active.scriptURL, expected_url,
|
||||||
'new worker should be promoted to active');
|
'new worker should be promoted to active.');
|
||||||
return service_worker_unregister_and_done(t, scope);
|
|
||||||
})
|
})
|
||||||
}, '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>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user