OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>Service Worker: Clients.matchAll</title> | 2 <title>Service Worker: Clients.matchAll</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.js"></script> | 5 <script src="resources/test-helpers.js"></script> |
6 <script> | 6 <script> |
7 var scope = 'resources/blank.html?clients-matchAll'; | 7 var scope = 'resources/blank.html?clients-matchAll'; |
8 var t = async_test('Test Clients.matchAll()'); | 8 var expectedFirst = [ |
| 9 /* visibilityState, focused, url, frameType */ |
| 10 ['visible', true, new URL(scope + '#1', location).toString(), 'nested'], |
| 11 ['visible', false, new URL(scope + '#2', location).toString(), 'nested'] |
| 12 ]; |
| 13 var expectedSecond = [ |
| 14 /* visibilityState, focused, url, frameType */ |
| 15 ['visible', true, new URL(scope + '#2', location).toString(), 'nested'], |
| 16 ['visible', false, new URL(scope + '#1', location).toString(), 'nested'] |
| 17 ]; |
| 18 |
9 var frame1, frame2; | 19 var frame1, frame2; |
10 t.step(function() { | 20 var worker; |
11 service_worker_unregister_and_register( | 21 promise_test(function(t) { |
| 22 return service_worker_unregister_and_register( |
12 t, 'resources/clients-matchall-worker.js', scope) | 23 t, 'resources/clients-matchall-worker.js', scope) |
13 .then(function(registration) { | 24 .then(function(registration) { |
14 return wait_for_state(t, registration.installing, 'activated'); | 25 worker = registration.installing; |
| 26 return wait_for_state(t, worker, 'activated'); |
15 }) | 27 }) |
16 .then(function() { return with_iframe(scope + '#1'); }) | 28 .then(function() { return with_iframe(scope + '#1'); }) |
17 .then(function(f) { | 29 .then(function(f) { |
18 frame1 = f; | 30 frame1 = f; |
19 f.focus(); | |
20 return with_iframe(scope + '#2'); | 31 return with_iframe(scope + '#2'); |
21 }) | 32 }) |
22 .then(function(f) { | 33 .then(function(f) { |
23 frame2 = f; | 34 frame2 = f; |
24 var channel = new MessageChannel(); | 35 return new Promise(function(resolve) { |
25 channel.port1.onmessage = t.step_func(onMessage); | 36 frame1.focus(); |
26 f.contentWindow.navigator.serviceWorker.controller.postMessage( | 37 var channel = new MessageChannel(); |
27 {port:channel.port2}, [channel.port2]); | 38 channel.port1.onmessage = resolve; |
| 39 worker.postMessage({port:channel.port2}, [channel.port2]); |
| 40 }); |
28 }) | 41 }) |
29 .catch(unreached_rejection(t)); | 42 .then(function(message) { |
30 }); | 43 assert_equals(message.data.length, 2); |
31 | 44 assert_array_equals(message.data[0], expectedFirst[0]); |
32 var expected = [ | 45 assert_array_equals(message.data[1], expectedFirst[1]); |
33 /* visibilityState, focused, url, frameType */ | 46 return new Promise(function(resolve) { |
34 ['visible', true, new URL(scope + '#1', location).toString(), 'nested'], | 47 frame2.focus(); |
35 ['visible', false, new URL(scope + '#2', location).toString(), 'nested'] | 48 var channel = new MessageChannel(); |
36 ]; | 49 channel.port1.onmessage = resolve; |
37 | 50 worker.postMessage({port:channel.port2}, [channel.port2]); |
38 function onMessage(e) { | 51 }); |
39 assert_equals(e.data.length, 2); | 52 }) |
40 assert_array_equals(e.data[0], expected[0]); | 53 .then(function(message) { |
41 assert_array_equals(e.data[1], expected[1]); | 54 assert_equals(message.data.length, 2); |
42 frame1.remove(); | 55 assert_array_equals(message.data[0], expectedSecond[0]); |
43 frame2.remove(); | 56 assert_array_equals(message.data[1], expectedSecond[1]); |
44 service_worker_unregister_and_done(t, scope); | 57 frame1.remove(); |
45 } | 58 frame2.remove(); |
| 59 return service_worker_unregister_and_done(t, scope); |
| 60 }) |
| 61 }, 'Test Clients.matchAll()'); |
46 </script> | 62 </script> |
OLD | NEW |