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..12def1dc75d2667715257ad94a5b004b17b01a1f |
| --- /dev/null |
| +++ b/LayoutTests/http/tests/serviceworker/claim-not-using-registration.html |
| @@ -0,0 +1,79 @@ |
| +<!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) |
| + .then(function(registration) { |
| + return wait_for_state(t, registration.installing, 'activated'); |
| + }) |
| + .then(function() { |
|
jsbell
2015/01/24 01:09:38
How about replacing lines 20...31 with:
.then(fun
xiang
2015/01/26 07:19:16
Done. This looks better!
|
| + var wait_frame1 = with_iframe(frame1_url) |
| + .then(function(f) { |
| + frame1 = f; |
| + }); |
| + var wait_frame2 = with_iframe(frame2_url) |
| + .then(function(f) { |
| + frame2 = f; |
| + }); |
| + return Promise.all([wait_frame1, wait_frame2]); |
| + }) |
| + .then(function() { |
| + 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) { |
|
jsbell
2015/01/24 01:09:38
Not necessarily for this CL but: we should really
xiang
2015/01/26 07:19:16
I can work on this later, thanks for the suggestio
|
| + 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'); |
|
jsbell
2015/01/24 01:09:38
Can you add a message to this assertion? e.g. 'Wor
xiang
2015/01/26 07:19:16
Done.
|
| + 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> |