Bug 1207727 - Add WPT tests for service worker update algorithm. r=bkelly

This commit is contained in:
dimi 2015-10-26 11:03:47 +08:00
parent 0a7f5412e3
commit 975b82b179
8 changed files with 110 additions and 2 deletions

View File

@ -220,8 +220,6 @@ skip-if = release_build
[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]

View File

@ -160,6 +160,9 @@ 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);

View File

@ -505,6 +505,18 @@
"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",

View File

@ -0,0 +1,2 @@
[update-after-oneday.https.html]
prefs: [dom.serviceWorkers.testUpdateOverOneDay: true]

View File

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

View File

@ -0,0 +1,8 @@
<body>
<script>
function load_image(url) {
var img = document.createElement('img');
img.src = url;
}
</script>
</body>

View File

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

View File

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