Bug 1230164 P1 Ensure all service worker WPT tests remove controlled frames before completion. r=ehsan

This commit is contained in:
Ben Kelly 2015-12-04 13:32:36 -08:00
parent 0b049e8333
commit 24e4271227
22 changed files with 66 additions and 20 deletions

View File

@ -13,6 +13,8 @@ var SERVICE_WORKER_SCRIPT = "resources/empty-worker.js";
var resolve_install_appcache = undefined;
var reject_install_appcache = undefined;
var frames = [];
// Called by the INSTALL_APPCACHE_URL child frame.
function notify_appcache_installed(success) {
if (success)
@ -24,6 +26,7 @@ function notify_appcache_installed(success) {
function install_appcache() {
return new Promise(function(resolve, reject) {
var frame = document.createElement('iframe');
frames.push(frame);
frame.src = INSTALL_APPCACHE_URL;
document.body.appendChild(frame);
resolve_install_appcache = function() {
@ -47,6 +50,7 @@ function notify_is_appcached(is) {
function is_appcached() {
return new Promise(function(resolve) {
var frame = document.createElement('iframe');
frames.push(frame);
frame.src = IS_APPCACHED_URL;
document.body.appendChild(frame);
resolve_is_appcached = function(is) {
@ -77,6 +81,7 @@ async_test(function(t) {
})
.then(function(result) {
assert_false(result, 'but serviceworkers should take priority');
frames.forEach(function(f) { f.remove(); });
service_worker_unregister_and_done(t, SERVICE_WORKER_SCOPE);
})
.catch(unreached_rejection(t));

View File

@ -6,18 +6,24 @@
<script>
var base_url = 'resources/blank.html'; // This is out-of-scope.
var scope = base_url + '?clients-matchAll-includeUncontrolled';
var frames = [];
// Creates 3 iframes, 2 for in-scope and 1 for out-of-scope.
// The frame opened for scope + '#2' is returned via a promise.
// FIXME: remove iframes when the test finishes.
function create_iframes(scope) {
return with_iframe(base_url)
.then(function(frame0) {
frames.push(frame0);
return with_iframe(scope + '#1');
})
.then(function(frame1) {
frames.push(frame1);
return with_iframe(scope + '#2');
});
})
.then(function(frame2) {
frames.push(frame2);
return frame2;
})
}
var expected_without_include_uncontrolled = [
@ -75,6 +81,7 @@ async_test(function(t) {
{includeUncontrolled:true});
})
.then(function() {
frames.forEach(function(f) { f.remove() });
service_worker_unregister_and_done(t, scope);
})
.catch(unreached_rejection(t));

View File

@ -6,6 +6,7 @@
<script>
var scope = 'resources/blank.html?clients-matchAll';
var t = async_test('Test Clients.matchAll()');
var frames = [];
t.step(function() {
service_worker_unregister_and_register(
t, 'resources/clients-matchall-worker.js', scope)
@ -14,10 +15,12 @@ t.step(function() {
})
.then(function() { return with_iframe(scope + '#1'); })
.then(function(frame1) {
frames.push(frame1);
frame1.focus();
return with_iframe(scope + '#2');
})
.then(function(frame2) {
frames.push(frame2);
var channel = new MessageChannel();
channel.port1.onmessage = t.step_func(onMessage);
frame2.contentWindow.navigator.serviceWorker.controller.postMessage(
@ -36,6 +39,7 @@ function onMessage(e) {
assert_equals(e.data.length, 2);
assert_array_equals(e.data[0], expected[0]);
assert_array_equals(e.data[1], expected[1]);
frames.forEach(function(f) { f.remove(); });
service_worker_unregister_and_done(t, scope);
}
</script>

View File

@ -22,6 +22,7 @@ t.step(function() {
assert_true(controller instanceof w.ServiceWorker,
'controller should be a ServiceWorker object');
assert_equals(controller.scriptURL, normalizeURL(url));
frame.remove();
service_worker_unregister_and_done(t, scope);
}))
.catch(unreached_rejection(t));

View File

@ -19,6 +19,7 @@ async_test(function(t) {
var channel = new MessageChannel();
channel.port1.onmessage = t.step_func(function(e) {
assert_equals(e.data.results, 'finish');
frame.remove();
service_worker_unregister_and_done(t, SCOPE);
});
frame.contentWindow.postMessage({},

View File

@ -52,14 +52,12 @@ function redirect_fetch_test(t, test) {
var p = new Promise(function(resolve, reject) {
var channel = new MessageChannel();
channel.port1.onmessage = function(e) {
frame.remove();
if (e.data.result === 'reject') {
frame.remove();
reject(e.data.detail);
} else if (e.data.result === 'success') {
frame.remove();
resolve(e.data.result);
} else {
frame.remove();
resolve(e.data.detail);
}
};

View File

@ -192,7 +192,7 @@ async_test(function(t) {
assert_equals(frame.contentDocument.body.textContent,
'POST:application/x-www-form-urlencoded:' +
'testName1=testValue1&testName2=testValue2');
document.body.removeChild(frame);
frame.remove();
return service_worker_unregister_and_done(t, scope);
})
.catch(unreached_rejection(t));

View File

@ -73,12 +73,13 @@ function getLoadedWindowAsObject(win) {
async_test(function(t) {
var scope = 'resources/fetch-frame-resource/frame-basic';
var frame;
service_worker_unregister_and_register(t, worker, scope)
.then(function(reg) {
return wait_for_state(t, reg.installing, 'activated');
})
.then(function() {
var frame = document.createElement('iframe');
frame = document.createElement('iframe');
frame.src =
scope + '?url=' +
encodeURIComponent(host_info['HTTPS_ORIGIN'] + path);
@ -90,6 +91,7 @@ async_test(function(t) {
result.jsonpResult,
'success',
'Basic type response could be loaded in the iframe.');
frame.remove();
return service_worker_unregister_and_done(t, scope);
})
.catch(unreached_rejection(t));
@ -97,12 +99,13 @@ async_test(function(t) {
async_test(function(t) {
var scope = 'resources/fetch-frame-resource/frame-cors';
var frame;
service_worker_unregister_and_register(t, worker, scope)
.then(function(reg) {
return wait_for_state(t, reg.installing, 'activated');
})
.then(function() {
var frame = document.createElement('iframe');
frame = document.createElement('iframe');
frame.src =
scope + '?mode=cors&url=' +
encodeURIComponent(host_info['HTTPS_REMOTE_ORIGIN'] + path +
@ -115,6 +118,7 @@ async_test(function(t) {
result.jsonpResult,
'success',
'CORS type response could be loaded in the iframe.');
frame.remove();
return service_worker_unregister_and_done(t, scope);
})
.catch(unreached_rejection(t));
@ -122,12 +126,13 @@ async_test(function(t) {
async_test(function(t) {
var scope = 'resources/fetch-frame-resource/frame-opaque';
var frame;
service_worker_unregister_and_register(t, worker, scope)
.then(function(reg) {
return wait_for_state(t, reg.installing, 'activated');
})
.then(function() {
var frame = document.createElement('iframe');
frame = document.createElement('iframe');
frame.src =
scope + '?mode=no-cors&url=' +
encodeURIComponent(host_info['HTTPS_REMOTE_ORIGIN'] + path);
@ -139,6 +144,7 @@ async_test(function(t) {
result,
null,
'Opaque type response could not be loaded in the iframe.');
frame.remove();
return service_worker_unregister_and_done(t, scope);
})
.catch(unreached_rejection(t));

View File

@ -9,6 +9,7 @@
var worker = 'resources/fetch-rewrite-worker.js';
var path = base_path() + 'resources/fetch-access-control.py';
var host_info = get_host_info();
var frame;
async_test(function(t) {
var scope = 'resources/fetch-header-visibility-iframe.html';
@ -17,7 +18,7 @@
return wait_for_state(t, reg.installing, 'activated');
})
.then(function() {
var frame = document.createElement('iframe');
frame = document.createElement('iframe');
frame.src = scope;
document.body.appendChild(frame);
@ -42,6 +43,7 @@
});
})
.then(function(result) {
frame.remove();
return service_worker_unregister_and_done(t, scope);
})
.catch(unreached_rejection(t));

View File

@ -54,6 +54,7 @@ async_test(function(t) {
expected_url, 'frame should now be loaded and controlled');
assert_equals(registration.active.state, 'activated',
'active worker should be in activated state');
frame.remove();
return service_worker_unregister_and_done(t, scope);
}).catch(unreached_rejection(t));
}, 'Fetch events should wait for the activate event to complete.');

View File

@ -4,6 +4,7 @@
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script>
var frame;
var t = async_test('postMessage MessagePorts from ServiceWorker to Client');
t.step(function() {
var scope = 'resources/blank.html'
@ -13,7 +14,8 @@ t.step(function() {
return wait_for_state(t, registration.installing, 'activated');
})
.then(function() { return with_iframe(scope); })
.then(function(frame) {
.then(function(f) {
frame = f;
var w = frame.contentWindow;
w.navigator.serviceWorker.onmessage = t.step_func(onMessage);
w.navigator.serviceWorker.controller.postMessage('ping');
@ -39,6 +41,7 @@ t.step(function() {
assert_array_equals(
result, expected,
'Worker should post back expected values via MessagePort.');
frame.remove();
service_worker_unregister_and_done(t, scope);
} else {
assert_unreached('Got unexpected message from ServiceWorker');

View File

@ -4,6 +4,7 @@
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script>
var frame;
var t = async_test('postMessage from ServiceWorker to Client');
t.step(function() {
var scope = 'resources/blank.html';
@ -14,7 +15,8 @@ t.step(function() {
return wait_for_state(t, registration.installing, 'activated');
})
.then(function() { return with_iframe(scope); })
.then(function(frame) {
.then(function(f) {
frame = f;
sw = frame.contentWindow.navigator.serviceWorker;
sw.onmessage = t.step_func(onMessage);
sw.controller.postMessage('ping');
@ -34,6 +36,7 @@ t.step(function() {
if (message === 'quit') {
assert_array_equals(result, expected,
'Worker should post back expected messages.');
frame.remove();
service_worker_unregister_and_done(t, scope);
} else {
result.push(message);

View File

@ -8,6 +8,7 @@ var t = async_test('Request: end-to-end');
t.step(function() {
var url = 'resources/request-end-to-end-worker.js';
var scope = 'resources/blank.html';
var frames = [];
service_worker_unregister_and_register(t, url, scope)
.then(onRegister)
@ -33,7 +34,7 @@ t.step(function() {
}
function onActive() {
with_iframe(scope);
with_iframe(scope).then(function(f) { frames.push(f); });
}
function onMessage(event) {
@ -51,6 +52,7 @@ t.step(function() {
assert_equals(event.data.errorNameWhileAppendingHeader, 'TypeError',
'Appending a new header to the request must throw a ' +
'TypeError.')
frames.forEach(function(f) { f.remove(); });
service_worker_unregister_and_done(t, scope);
}
});

View File

@ -45,14 +45,12 @@ promise_test(function(t) {
.then(function(registration) {
sw_registration = registration;
add_completion_callback(function() {
frame.remove();
registration.unregister();
});
return saw_controllerchanged;
})
.then(function() {
// XXXcatalinb: Removing the iframe here would terminate the worker
// discarding inflight events.
// frame.remove();
assert_not_equals(sw_registration.active, null,
'Registration active worker should not be null');
fetch_tests_from_worker(sw_registration.active);

View File

@ -25,6 +25,7 @@ promise_test(function(t) {
.then(function(registration) {
sw_registration = registration;
add_completion_callback(function() {
frame.remove();
registration.unregister();
});
return wait_for_state(t, registration.installing, 'activated');
@ -35,7 +36,6 @@ promise_test(function(t) {
assert_not_equals(sw_registration.active, null,
'Registration active worker should not be null');
fetch_tests_from_worker(sw_registration.active);
frame.remove();
});
}, 'Test skipWaiting while a client is not being controlled');

View File

@ -46,6 +46,7 @@ promise_test(function(t) {
'Worker with url2 should be redundant');
assert_equals(sw_registration.active.scriptURL, normalizeURL(url3),
'Worker with url3 should be activated');
frame.remove();
return service_worker_unregister_and_done(t, scope);
});
}, 'Test skipWaiting with both active and waiting workers');

View File

@ -11,6 +11,7 @@ async_test(function(t) {
var frame_window;
var controller;
var registration;
var frame;
service_worker_unregister_and_register(t, worker_url, scope)
.then(function(r) {
@ -20,7 +21,8 @@ async_test(function(t) {
.then(function() {
return with_iframe(scope);
})
.then(function(frame) {
.then(function(f) {
frame = f;
frame_window = frame.contentWindow;
controller = frame_window.navigator.serviceWorker.controller;
assert_true(controller instanceof frame_window.ServiceWorker,
@ -36,6 +38,7 @@ async_test(function(t) {
.then(function(response) {
assert_equals(response, 'intercepted by service worker',
'controller should intercept requests');
frame.remove();
t.done();
})
.catch(unreached_rejection(t));
@ -45,6 +48,7 @@ async_test(function(t) {
var scope =
'resources/unregister-controller-page.html?load-after-unregister';
var registration;
var frame;
service_worker_unregister_and_register(t, worker_url, scope)
.then(function(r) {
@ -57,7 +61,8 @@ async_test(function(t) {
.then(function() {
return with_iframe(scope);
})
.then(function(frame) {
.then(function(f) {
frame = f;
var frame_window = frame.contentWindow;
assert_equals(frame_window.navigator.serviceWorker.controller, null,
'document should not have a controller');
@ -66,6 +71,7 @@ async_test(function(t) {
.then(function(response) {
assert_equals(response, 'a simple text file\n',
'requests should not be intercepted');
frame.remove();
t.done();
})
.catch(unreached_rejection(t));
@ -94,6 +100,7 @@ async_test(function(t) {
assert_equals(frame.contentWindow.navigator.serviceWorker.controller,
null,
'document should not have a controller');
frame.remove();
t.done();
})
.catch(unreached_rejection(t));

View File

@ -7,7 +7,6 @@ var worker_url = 'resources/empty-worker.js';
async_test(function(t) {
var scope = 'resources/scope/re-register-resolves-to-new-value';
var iframe;
var registration;
service_worker_unregister_and_register(t, worker_url, scope)
@ -86,6 +85,7 @@ async_test(function(t) {
iframe.contentWindow.navigator.serviceWorker.controller,
controller,
'the worker from the first registration is the controller');
iframe.remove();
service_worker_unregister_and_done(t, scope);
})
.catch(unreached_rejection(t));
@ -121,6 +121,7 @@ async_test(function(t) {
assert_not_equals(
frame.contentWindow.navigator.serviceWorker.controller, null,
'document should have a controller');
frame.remove();
service_worker_unregister_and_done(t, scope);
})
.catch(unreached_rejection(t));

View File

@ -10,6 +10,7 @@ promise_test(function(t) {
var scope = 'resources/scope/update';
var parsed_url = normalizeURL(script);
var registration;
var frame;
return service_worker_unregister_and_register(t, parsed_url, scope)
.then(function(r) {
@ -21,10 +22,12 @@ promise_test(function(t) {
return with_iframe(scope);
})
.then(function(f) {
frame = f;
// Navigation fetch event should trigger update.
return wait_for_update(t, registration);
})
.then(function() {
frame.remove();
return service_worker_unregister_and_done(t, scope);
})
}, 'Update should be triggered after a navigation fetch event.');

View File

@ -40,6 +40,7 @@ promise_test(function(t) {
return wait_for_update(t, registration);
})
.then(function() {
frame.remove();
return service_worker_unregister_and_done(t, scope);
})
}, 'Update should be triggered after a functional event when last update time is over 24 hours');

View File

@ -138,6 +138,7 @@ promise_test(function(t) {
return new Promise(function(resolve, reject) {
var channel = new MessageChannel();
channel.port1.onmessage = function(e) {
frame.remove();
resolve(e.data);
}

View File

@ -22,6 +22,7 @@ async_test(function(t) {
return new Promise(function(resolve, reject) {
function onMessage(e) {
assert_false(e.data.xhr);
frame.remove();
service_worker_unregister_and_done(t, scope);
}
var channel = new MessageChannel();