Bug 1252055 P2 Update tests to verify ServiceWorker object equality. r=ehsan

This commit is contained in:
Ben Kelly 2016-03-03 19:37:59 -05:00
parent a7b1943700
commit b1344ecea0
3 changed files with 41 additions and 16 deletions

View File

@ -37,19 +37,19 @@
}
var p = new Promise(function(res, rej) {
registration.installing.onstatechange = function(e) {
ok(registration.waiting, "Worker should be in waitinging state");
// The worker will become active only if claim will reject inside the
// install handler.
registration.waiting.onstatechange = function(e) {
ok(registration.active, "Claim should reject if the worker is not active");
var worker = registration.installing;
worker.onstatechange = function(e) {
if (worker.state === 'installed') {
is(worker, registration.waiting, "Worker should be in waiting state");
} else if (worker.state === 'activated') {
// The worker will become active only if claim will reject inside the
// install handler.
is(worker, registration.active,
"Claim should reject if the worker is not active");
ok(navigator.serviceWorker.controller === null, "Client is not controlled.");
e.target.onstatechange = null;
res();
}
e.target.onstatechange = null;
}
});

View File

@ -9,19 +9,33 @@ var t = async_test('controller is set for a controlled document');
t.step(function() {
var url = 'resources/empty-worker.js';
var scope = 'resources/blank.html';
var registration;
var controller;
var frame;
service_worker_unregister_and_register(t, url, scope)
.then(t.step_func(function(registration) {
.then(t.step_func(function(swr) {
registration = swr;
return wait_for_state(t, registration.installing, 'activated');
}))
.then(t.step_func(function() {
return with_iframe(scope)
}))
.then(t.step_func(function(frame) {
.then(t.step_func(function(f) {
frame = f;
var w = frame.contentWindow;
var controller = w.navigator.serviceWorker.controller;
controller = w.navigator.serviceWorker.controller;
assert_true(controller instanceof w.ServiceWorker,
'controller should be a ServiceWorker object');
assert_equals(controller.scriptURL, normalizeURL(url));
// objects from different windows should not be equal
assert_not_equals(controller, registration.active);
return w.navigator.serviceWorker.getRegistration();
}))
.then(t.step_func(function(frameRegistration) {
// SW objects from same window should be equal
assert_equals(frameRegistration.active, controller);
frame.remove();
service_worker_unregister_and_done(t, scope);
}))

View File

@ -8,6 +8,8 @@
promise_test(function(t) {
var scope = 'resources/blank.html';
var frame;
var registration;
var controller;
return service_worker_unregister(t, scope)
.then(function() {
return with_iframe(scope);
@ -17,7 +19,8 @@ promise_test(function(t) {
return frame.contentWindow.navigator.serviceWorker.register(
'resources/empty-worker.js', {scope: scope});
})
.then(function(registration) {
.then(function(swr) {
registration = swr;
return wait_for_state(t, registration.installing, 'activated');
})
.then(function() {
@ -32,9 +35,17 @@ promise_test(function(t) {
})
.then(function() {
var w = frame.contentWindow;
assert_true(
w.navigator.serviceWorker.controller instanceof w.ServiceWorker,
'controller should be a ServiceWorker object upon reload');
controller = w.navigator.serviceWorker.controller;
assert_true(controller instanceof w.ServiceWorker,
'controller should be a ServiceWorker object upon reload');
// objects from separate windows should not be equal
assert_not_equals(controller, registration.active);
return w.navigator.serviceWorker.getRegistration();
})
.then(function(frameRegistration) {
assert_equals(frameRegistration.active, controller);
frame.remove();
service_worker_unregister_and_done(t, scope);
});