OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>Service Worker: Clients.get with window and worker clients</title> | 2 <title>Service Worker: Clients.get with window and worker clients</title> |
3 <script src="/resources/testharness.js"></script> | 3 <script src="/resources/testharness.js"></script> |
4 <script src="/resources/testharnessreport.js"></script> | 4 <script src="/resources/testharnessreport.js"></script> |
5 <script src="resources/test-helpers.sub.js"></script> | 5 <script src="resources/test-helpers.sub.js"></script> |
6 <script> | 6 <script> |
7 var scope = 'resources/clients-get-client-types'; | 7 var scope = 'resources/clients-get-client-types'; |
8 var frame_url = scope + '-frame.html'; | 8 var frame_url = scope + '-frame.html'; |
9 var shared_worker_url = scope + '-shared-worker.js'; | 9 var shared_worker_url = scope + '-shared-worker.js'; |
10 var worker_url = scope + '-worker.js'; | |
10 var client_ids = []; | 11 var client_ids = []; |
11 var frame; | 12 var frame; |
12 promise_test(function(t) { | 13 promise_test(function(t) { |
13 return service_worker_unregister_and_register( | 14 return service_worker_unregister_and_register( |
14 t, 'resources/clients-get-worker.js', scope) | 15 t, 'resources/clients-get-worker.js', scope) |
15 .then(function(registration) { | 16 .then(function(registration) { |
16 add_completion_callback(function() { registration.unregister(); }); | 17 add_completion_callback(function() { registration.unregister(); }); |
17 return wait_for_state(t, registration.installing, 'activated'); | 18 return wait_for_state(t, registration.installing, 'activated'); |
18 }) | 19 }) |
19 .then(function() { | 20 .then(function() { |
(...skipping 10 matching lines...) Expand all Loading... | |
30 return new Promise(function(resolve) { | 31 return new Promise(function(resolve) { |
31 var w = new SharedWorker(shared_worker_url); | 32 var w = new SharedWorker(shared_worker_url); |
32 w.port.onmessage = function(e) { | 33 w.port.onmessage = function(e) { |
33 resolve(e.data.clientId); | 34 resolve(e.data.clientId); |
34 }; | 35 }; |
35 }); | 36 }); |
36 }) | 37 }) |
37 .then(function(client_id) { | 38 .then(function(client_id) { |
38 client_ids.push(client_id); | 39 client_ids.push(client_id); |
39 var channel = new MessageChannel(); | 40 var channel = new MessageChannel(); |
41 var w = new Worker(worker_url); | |
42 w.postMessage({cmd:'GetClientId', port:channel.port2}, | |
43 [channel.port2]); | |
44 return new Promise(function(resolve) { | |
45 channel.port1.onmessage = function(e) { | |
46 resolve(e.data.clientId); | |
47 }; | |
48 }); | |
49 }) | |
50 .then(function(client_id) { | |
51 client_ids.push(client_id); | |
52 var channel = new MessageChannel(); | |
53 frame.contentWindow.postMessage('StartWorker', '*', [channel.port2]); | |
54 return new Promise(function(resolve) { | |
55 channel.port1.onmessage = function(e) { | |
56 resolve(e.data.clientId); | |
57 }; | |
58 }); | |
59 }) | |
60 .then(function(client_id) { | |
61 client_ids.push(client_id); | |
62 var channel = new MessageChannel(); | |
40 var saw_message = new Promise(function(resolve) { | 63 var saw_message = new Promise(function(resolve) { |
41 channel.port1.onmessage = resolve; | 64 channel.port1.onmessage = resolve; |
42 }); | 65 }); |
43 frame.contentWindow.navigator.serviceWorker.controller.postMessage( | 66 frame.contentWindow.navigator.serviceWorker.controller.postMessage( |
44 {port: channel.port2, clientIds: client_ids}, [channel.port2]); | 67 {port: channel.port2, clientIds: client_ids}, [channel.port2]); |
45 return saw_message; | 68 return saw_message; |
46 }) | 69 }) |
47 .then(function(e) { | 70 .then(function(e) { |
48 assert_equals(e.data.length, 2); | 71 assert_equals(e.data.length, expected.length); |
72 assert_not_equals(e.data[0], undefined, | |
73 'Window client is undefined'); | |
falken
2017/05/26 01:49:25
These assert_not_equals undefined seem redundant w
leonhsl(Using Gerrit)
2017/05/26 03:44:17
Adding assert_not_equals undefined here is because
falken
2017/05/26 04:24:57
That error actually seems pretty useful: it basica
leonhsl(Using Gerrit)
2017/05/26 05:27:32
I see, Thanks a lot for kindly explanations. Remov
| |
49 assert_array_equals(e.data[0], expected[0]); | 74 assert_array_equals(e.data[0], expected[0]); |
75 assert_not_equals(e.data[1], undefined, | |
76 'Shared worker client is undefined'); | |
50 assert_array_equals(e.data[1], expected[1]); | 77 assert_array_equals(e.data[1], expected[1]); |
78 assert_not_equals(e.data[2], undefined, | |
79 'Worker(Started by main frame) client is undefined'); | |
80 assert_array_equals(e.data[2], expected[2]); | |
81 assert_not_equals(e.data[3], undefined, | |
82 'Worker(Started by sub frame) client is undefined'); | |
83 assert_array_equals(e.data[3], expected[3]); | |
51 }); | 84 }); |
52 }, 'Test Clients.get() with window and worker clients'); | 85 }, 'Test Clients.get() with window and worker clients'); |
53 | 86 |
54 function wait_for_clientId() { | 87 function wait_for_clientId() { |
55 return new Promise(function(resolve) { | 88 return new Promise(function(resolve) { |
56 function get_client_id(e) { | 89 function get_client_id(e) { |
57 window.removeEventListener('message', get_client_id); | 90 window.removeEventListener('message', get_client_id); |
58 resolve(e.data.clientId); | 91 resolve(e.data.clientId); |
59 } | 92 } |
60 window.addEventListener('message', get_client_id, false); | 93 window.addEventListener('message', get_client_id, false); |
61 }); | 94 }); |
62 } | 95 } |
63 | 96 |
64 var expected = [ | 97 var expected = [ |
65 // visibilityState, focused, url, type, frameType | 98 // visibilityState, focused, url, type, frameType |
66 ['visible', true, normalizeURL(scope) + '-frame.html', 'window', 'nested'], | 99 ['visible', true, normalizeURL(scope) + '-frame.html', 'window', 'nested'], |
67 [undefined, undefined, normalizeURL(scope) + '-shared-worker.js', 'sharedwor ker', 'none'] | 100 [undefined, undefined, normalizeURL(scope) + '-shared-worker.js', 'sharedwor ker', 'none'], |
101 [undefined, undefined, normalizeURL(scope) + '-worker.js', 'worker', 'none'] , | |
102 [undefined, undefined, normalizeURL(scope) + '-frame-worker.js', 'worker', ' none'] | |
68 ]; | 103 ]; |
69 </script> | 104 </script> |
OLD | NEW |