Commit 553e0c3c authored by dominicc@chromium.org's avatar dominicc@chromium.org

Add tests for navigator.serviceWorker.waiting.

BUG=379012

Review URL: https://codereview.chromium.org/324893002

git-svn-id: svn://svn.chromium.org/blink/trunk@176157 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 0d30851a
...@@ -34,7 +34,7 @@ function service_worker_unregister_and_register(test, url, scope, onregister) { ...@@ -34,7 +34,7 @@ function service_worker_unregister_and_register(test, url, scope, onregister) {
} }
function service_worker_unregister_and_done(test, scope) { function service_worker_unregister_and_done(test, scope) {
navigator.serviceWorker.unregister(scope).then( return navigator.serviceWorker.unregister(scope).then(
test.done.bind(test), test.done.bind(test),
unreached_rejection(test, 'Unregister should not fail')); unreached_rejection(test, 'Unregister should not fail'));
} }
...@@ -48,12 +48,17 @@ function unreached_rejection(test, prefix) { ...@@ -48,12 +48,17 @@ function unreached_rejection(test, prefix) {
// FIXME: Clean up the iframe when the test completes. // FIXME: Clean up the iframe when the test completes.
function with_iframe(url, f) { function with_iframe(url, f) {
var frame = document.createElement('iframe'); return new Promise(function(resolve, reject) {
frame.src = url; var frame = document.createElement('iframe');
frame.onload = function() { frame.src = url;
f(frame); frame.onload = function() {
}; if (f) {
document.body.appendChild(frame); f(frame);
}
resolve(frame);
};
document.body.appendChild(frame);
});
} }
function normalizeURL(url) { function normalizeURL(url) {
......
This is a testharness.js-based test.
FAIL waiting is set assert_unreached: Unregister should not fail: NotSupportedError Reached unreachable code
Harness: the test ran to completion.
<!DOCTYPE html>
<title>ServiceWorker: navigator.serviceWorker.waiting</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/test-helpers.js"></script>
<body>
<script>
// "waiting" is set
async_test(function(t) {
var step = t.step_func.bind(t);
var url = 'resources/worker-no-op.js';
var scope = 'resources/blank.html';
var frame;
navigator.serviceWorker.unregister(scope)
.then(step(function() { return with_iframe(scope); }),
unreached_rejection(t, 'Unregister should not fail'))
.then(step(function(f) {
frame = f;
return navigator.serviceWorker.register(url, {scope: scope});
}))
.then(step(function(serviceWorker) {
// FIXME: Replace this with .ready when that supports the in-waiting
// Service Worker.
return new Promise(step(function(resolve, reject) {
serviceWorker.onstatechange = step(function() {
if (serviceWorker.state == 'installed') {
resolve();
}
});
}));
}), unreached_rejection(t, 'Registration should not fail'))
.then(step(function() {
var container = frame.contentWindow.navigator.serviceWorker;
assert_equals(container.controller, null);
assert_equals(container.waiting.url, normalizeURL(url));
// FIXME: Add a test for a frame created after installation.
// Should the existing frame ("frame") block activation?
}))
.then(step(function() {
frame.remove();
return service_worker_unregister_and_done(t, scope);
}));
}, 'waiting is set');
</script>
This is a testharness.js-based test.
PASS waiting is set
Harness: the test ran to completion.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment