From 6c56c9b9be1b529020653da2bd25dde18a762ed6 Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Thu, 3 Mar 2016 19:37:59 -0500 Subject: [PATCH] Bug 1252055 P2 Update tests to verify ServiceWorker object equality. r=ehsan --- .../serviceworkers/test_claim_oninstall.html | 18 ++++++++--------- .../controller-on-load.https.html | 20 ++++++++++++++++--- .../controller-on-reload.https.html | 19 ++++++++++++++---- 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/dom/workers/test/serviceworkers/test_claim_oninstall.html b/dom/workers/test/serviceworkers/test_claim_oninstall.html index 2779231bad09..4605cfb76f64 100644 --- a/dom/workers/test/serviceworkers/test_claim_oninstall.html +++ b/dom/workers/test/serviceworkers/test_claim_oninstall.html @@ -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; } }); diff --git a/testing/web-platform/mozilla/tests/service-workers/service-worker/controller-on-load.https.html b/testing/web-platform/mozilla/tests/service-workers/service-worker/controller-on-load.https.html index e09a90152ba2..ff3b7ce04f40 100644 --- a/testing/web-platform/mozilla/tests/service-workers/service-worker/controller-on-load.https.html +++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/controller-on-load.https.html @@ -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); })) diff --git a/testing/web-platform/mozilla/tests/service-workers/service-worker/controller-on-reload.https.html b/testing/web-platform/mozilla/tests/service-workers/service-worker/controller-on-reload.https.html index 9223b2ff8c35..4490c707963b 100644 --- a/testing/web-platform/mozilla/tests/service-workers/service-worker/controller-on-reload.https.html +++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/controller-on-reload.https.html @@ -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); });