Chromium Code Reviews| Index: LayoutTests/http/tests/serviceworker/claim-not-using-registration.html |
| diff --git a/LayoutTests/http/tests/serviceworker/claim-not-using-registration.html b/LayoutTests/http/tests/serviceworker/claim-not-using-registration.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4ed4b9f05ef401d7ac6b31164183fe709896141b |
| --- /dev/null |
| +++ b/LayoutTests/http/tests/serviceworker/claim-not-using-registration.html |
| @@ -0,0 +1,74 @@ |
| +<!DOCTYPE html> |
| +<title>Service Worker: claim client not using registration</title> |
| +<script src="../resources/testharness.js"></script> |
| +<script src="../resources/testharness-helpers.js"></script> |
| +<script src="../resources/testharnessreport.js"></script> |
| +<script src="resources/test-helpers.js"></script> |
| +<script> |
| + |
| +promise_test(function(t) { |
| + var frame1_url = 'resources/blank.html'; |
| + var frame2_url = 'resources/other.html'; |
| + var claim_scope = 'resources/'; |
| + var url1 = 'resources/empty.js'; |
| + var url2 = 'resources/claim-worker.js'; |
| + var claim_worker, claim_registration, frame1, frame2; |
| + return service_worker_unregister_and_register(t, url1, frame2_url) |
|
falken
2015/01/27 03:25:54
nit: "url1" and "url2" doesn't really speak to me,
xiang
2015/01/28 07:36:43
Done.
|
| + .then(function(registration) { |
| + return wait_for_state(t, registration.installing, 'activated'); |
| + }) |
| + .then(function() { |
| + return Promise.all([with_iframe(frame1_url), with_iframe(frame2_url)]); |
| + }) |
| + .then(function(frames) { |
| + frame1 = frames[0]; |
| + frame2 = frames[1]; |
| + assert_equals( |
| + frame1.contentWindow.navigator.serviceWorker.controller, null, |
| + 'Frame1 controller should be null'); |
| + assert_equals( |
| + frame2.contentWindow.navigator.serviceWorker.controller.scriptURL, |
| + normalizeURL(url1), |
| + 'Frame2 controller scriptURL should be url1'); |
| + return navigator.serviceWorker.register(url2, {scope: claim_scope}); |
| + }) |
| + .then(function(registration) { |
| + claim_worker = registration.installing; |
| + claim_registration = registration; |
| + return wait_for_state(t, registration.installing, 'activated'); |
| + }) |
| + .then(function() { |
| + var saw_controllerchanged = new Promise(function(resolve) { |
| + frame1.contentWindow.navigator.serviceWorker.oncontrollerchange = |
| + function() { resolve(); } |
| + }); |
| + var channel = new MessageChannel(); |
| + var saw_message = new Promise(function(resolve) { |
| + channel.port1.onmessage = t.step_func(function(e) { |
| + assert_equals(e.data, 'PASS', |
| + 'Worker call to claim() should fulfill.'); |
| + resolve(); |
| + }); |
| + }); |
| + claim_worker.postMessage({port: channel.port2}, [channel.port2]); |
| + return Promise.all([saw_controllerchanged, saw_message]); |
| + }) |
| + .then(function() { |
| + assert_equals( |
| + frame1.contentWindow.navigator.serviceWorker.controller.scriptURL, |
| + normalizeURL(url2), |
| + 'Frame1 should be controlled by the new registration'); |
| + assert_equals( |
| + frame2.contentWindow.navigator.serviceWorker.controller.scriptURL, |
| + normalizeURL(url1), |
| + 'Frame2 should not be influenced'); |
| + frame1.remove(); |
| + frame2.remove(); |
| + return claim_registration.unregister(); |
| + }) |
| + .then(function() { |
| + return service_worker_unregister_and_done(t, frame2_url); |
| + }); |
| + }, 'Test claim client which is not using registration'); |
| + |
| +</script> |