OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <title>Service Worker: claim client not using registration</title> | |
3 <script src="../resources/testharness.js"></script> | |
4 <script src="../resources/testharness-helpers.js"></script> | |
5 <script src="../resources/testharnessreport.js"></script> | |
6 <script src="resources/test-helpers.js"></script> | |
7 <script> | |
8 | |
9 promise_test(function(t) { | |
10 var frame1_url = 'resources/blank.html'; | |
11 var frame2_url = 'resources/other.html'; | |
12 var claim_scope = 'resources/'; | |
13 var url1 = 'resources/empty.js'; | |
14 var url2 = 'resources/claim-worker.js'; | |
15 var claim_worker, claim_registration, frame1, frame2; | |
16 return service_worker_unregister_and_register(t, url1, frame2_url) | |
17 .then(function(registration) { | |
18 return wait_for_state(t, registration.installing, 'activated'); | |
19 }) | |
20 .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!
| |
21 var wait_frame1 = with_iframe(frame1_url) | |
22 .then(function(f) { | |
23 frame1 = f; | |
24 }); | |
25 var wait_frame2 = with_iframe(frame2_url) | |
26 .then(function(f) { | |
27 frame2 = f; | |
28 }); | |
29 return Promise.all([wait_frame1, wait_frame2]); | |
30 }) | |
31 .then(function() { | |
32 assert_equals( | |
33 frame1.contentWindow.navigator.serviceWorker.controller, null, | |
34 'Frame1 controller should be null'); | |
35 assert_equals( | |
36 frame2.contentWindow.navigator.serviceWorker.controller.scriptURL, | |
37 normalizeURL(url1), | |
38 'Frame2 controller scriptURL should be url1'); | |
39 return navigator.serviceWorker.register(url2, {scope: claim_scope}); | |
40 }) | |
41 .then(function(registration) { | |
42 claim_worker = registration.installing; | |
43 claim_registration = registration; | |
44 return wait_for_state(t, registration.installing, 'activated'); | |
45 }) | |
46 .then(function() { | |
47 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
| |
48 frame1.contentWindow.navigator.serviceWorker.oncontrollerchange = | |
49 function() { resolve(); } | |
50 }); | |
51 var channel = new MessageChannel(); | |
52 var saw_message = new Promise(function(resolve) { | |
53 channel.port1.onmessage = t.step_func(function(e) { | |
54 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.
| |
55 resolve(); | |
56 }); | |
57 }); | |
58 claim_worker.postMessage({port: channel.port2}, [channel.port2]); | |
59 return Promise.all([saw_controllerchanged, saw_message]); | |
60 }) | |
61 .then(function() { | |
62 assert_equals( | |
63 frame1.contentWindow.navigator.serviceWorker.controller.scriptURL, | |
64 normalizeURL(url2), | |
65 'Frame1 should be controlled by the new registration'); | |
66 assert_equals( | |
67 frame2.contentWindow.navigator.serviceWorker.controller.scriptURL, | |
68 normalizeURL(url1), | |
69 'Frame2 should not be influenced'); | |
70 frame1.remove(); | |
71 frame2.remove(); | |
72 return claim_registration.unregister(); | |
73 }) | |
74 .then(function() { | |
75 return service_worker_unregister_and_done(t, frame2_url); | |
76 }); | |
77 }, 'Test claim client which is not using registration'); | |
78 | |
79 </script> | |
OLD | NEW |