OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
nhiroki
2016/02/18 01:40:27
This tests only the case where there are window cl
nhiroki
2016/02/18 02:18:09
FYI: I think it's ok to ship this feature (to make
jungkees
2016/02/18 15:02:20
Okay. I'll do that in a separate CL.
jungkees
2016/02/18 15:02:20
I will do so.
| |
2 <title>Service Worker: Clients.get</title> | |
3 <script src="../resources/testharness.js"></script> | |
4 <script src="../resources/testharnessreport.js"></script> | |
5 <script src="../resources/get-host-info.js"></script> | |
6 <script src="resources/test-helpers.js"></script> | |
7 <script> | |
8 var scope = 'resources/clients-get-frame.html'; | |
9 var t = async_test('Test Clients.get()'); | |
10 var clientIds = []; | |
nhiroki
2016/02/17 02:40:28
"Write variable identifiers and function names in
jungkees
2016/02/17 14:01:12
Sorry for having missed them. Thanks for the point
| |
11 var frame; | |
12 t.step(function() { | |
13 service_worker_unregister_and_register( | |
14 t, 'resources/clients-get-worker.js', scope) | |
15 .then(function(registration) { | |
16 add_completion_callback(function() { registration.unregister(); }); | |
17 return wait_for_state(t, registration.installing, 'activated'); | |
18 }) | |
19 .then(function() { | |
20 return with_iframe(scope + '#1'); | |
21 }) | |
22 .then(function(frame1) { | |
23 add_completion_callback(function() { frame1.remove(); }); | |
24 frame1.focus(); | |
25 return wait_for_clientId(); | |
26 }) | |
27 .then(function(clientId) { | |
nhiroki
2016/02/17 02:40:28
client_id
jungkees
2016/02/17 14:01:12
Done.
| |
28 clientIds.push(clientId); | |
29 return with_iframe(scope + '#2'); | |
30 }) | |
31 .then(function(frame2) { | |
32 frame = frame2; | |
33 add_completion_callback(function() { frame2.remove(); }); | |
34 return wait_for_clientId(); | |
35 }) | |
36 .then(function(clientId) { | |
nhiroki
2016/02/17 02:40:28
ditto.
jungkees
2016/02/17 14:01:12
Done.
| |
37 clientIds.push(clientId, 'invalid-id'); | |
38 var channel = new MessageChannel(); | |
39 channel.port1.onmessage = t.step_func(on_message); | |
40 frame.contentWindow.navigator.serviceWorker.controller.postMessage( | |
41 {port:channel.port2, clientIds:clientIds}, [channel.port2]); | |
42 }) | |
43 .catch(unreached_rejection(t)); | |
44 }); | |
45 | |
46 function wait_for_clientId() { | |
47 return new Promise(function(resolve, reject) { | |
48 function get_client_id(e) { | |
49 window.removeEventListener('message', get_client_id); | |
50 resolve(e.data.clientId); | |
51 } | |
52 window.addEventListener('message', get_client_id, false); | |
53 }); | |
54 } | |
55 | |
56 var expected = [ | |
57 /* visibilityState, focused, url, frameType */ | |
58 ['visible', true, new URL(scope + '#1', location).toString(), 'nested'], | |
nhiroki
2016/02/17 02:40:28
"normalizeURL(scope) + '#1'" might work?
jungkees
2016/02/17 14:01:12
Yes, that works. Addressed.
| |
59 ['visible', false, new URL(scope + '#2', location).toString(), 'nested'], | |
60 undefined | |
61 ]; | |
62 | |
63 function on_message(e) { | |
64 assert_equals(e.data.length, 3); | |
65 assert_array_equals(e.data[0], expected[0]); | |
66 assert_array_equals(e.data[1], expected[1]); | |
67 assert_equals(e.data[2], expected[2]); | |
68 service_worker_unregister_and_done(t, scope); | |
nhiroki
2016/02/17 02:40:28
You don't have to explicitly run 'unregister' here
jungkees
2016/02/17 14:01:12
Without this line, it ends up being a timeout erro
zino
2016/02/17 18:38:13
I think you can use the "promise_test" instead of
nhiroki
2016/02/18 01:40:27
Did you call "t.done()"?
jungkees
2016/02/18 15:02:20
Correct it by using "promise_test".
| |
69 } | |
70 </script> | |
OLD | NEW |