OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>Service Worker: Clients.matchAll with includeUncontrolled</title> | 2 <title>Service Worker: Clients.matchAll with includeUncontrolled</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.sub.js"></script> |
6 <script> | 6 <script> |
7 var base_url = 'resources/blank.html'; // This is out-of-scope. | 7 var base_url = 'resources/blank.html'; // This is out-of-scope. |
8 var scope = base_url + '?clients-matchAll-includeUncontrolled'; | 8 var scope = base_url + '?clients-matchAll-includeUncontrolled'; |
| 9 var frames = []; |
9 | 10 |
10 // Creates 3 iframes, 2 for in-scope and 1 for out-of-scope. | 11 // Creates 3 iframes, 2 for in-scope and 1 for out-of-scope. |
11 // The frame opened for scope + '#2' is returned via a promise. | 12 // The frame opened for scope + '#2' is returned via a promise. |
12 // FIXME: remove iframes when the test finishes. | |
13 function create_iframes(scope) { | 13 function create_iframes(scope) { |
14 return with_iframe(base_url) | 14 return with_iframe(base_url) |
15 .then(function(frame0) { | 15 .then(function(frame0) { |
| 16 frames.push(frame0); |
16 return with_iframe(scope + '#1'); | 17 return with_iframe(scope + '#1'); |
17 }) | 18 }) |
18 .then(function(frame1) { | 19 .then(function(frame1) { |
| 20 frames.push(frame1); |
19 return with_iframe(scope + '#2'); | 21 return with_iframe(scope + '#2'); |
20 }); | 22 }) |
| 23 .then(function(frame2) { |
| 24 frames.push(frame2); |
| 25 return frame2; |
| 26 }) |
21 } | 27 } |
22 | 28 |
23 var expected_without_include_uncontrolled = [ | 29 var expected_without_include_uncontrolled = [ |
24 /* visibilityState, focused, url, frameType */ | 30 /* visibilityState, focused, url, frameType */ |
25 ['visible', false, new URL(scope + '#1', location).toString(), 'nested'], | 31 ['visible', false, new URL(scope + '#1', location).toString(), 'nested'], |
26 ['visible', true, new URL(scope + '#2', location).toString(), 'nested'] | 32 ['visible', true, new URL(scope + '#2', location).toString(), 'nested'] |
27 ]; | 33 ]; |
28 | 34 |
29 var expected_with_include_uncontrolled = [ | 35 var expected_with_include_uncontrolled = [ |
30 /* visibilityState, focused, url, frameType */ | 36 /* visibilityState, focused, url, frameType */ |
| 37 ['visible', true, location.href, 'top-level'], |
31 ['visible', false, new URL(scope + '#1', location).toString(), 'nested'], | 38 ['visible', false, new URL(scope + '#1', location).toString(), 'nested'], |
32 ['visible', true, new URL(scope + '#2', location).toString(), 'nested'], | 39 ['visible', true, new URL(scope + '#2', location).toString(), 'nested'], |
33 ['visible', false, new URL(base_url, location).toString(), 'nested'], | 40 ['visible', false, new URL(base_url, location).toString(), 'nested'] |
34 ['visible', true, location.href, 'top-level'] | |
35 ]; | 41 ]; |
36 | 42 |
37 function test_matchall(frame, expected, query_options) { | 43 function test_matchall(frame, expected, query_options) { |
38 // Make sure we have focus for '#2' frame and its parent window. | 44 // Make sure we have focus for '#2' frame and its parent window. |
39 frame.focus(); | 45 frame.focus(); |
40 frame.contentWindow.focus(); | 46 frame.contentWindow.focus(); |
41 expected.sort(function(a, b) { return a[2] > b[2] ? 1 : -1; }); | 47 expected.sort(function(a, b) { return a[2] > b[2] ? 1 : -1; }); |
42 return new Promise(function(resolve, reject) { | 48 return new Promise(function(resolve, reject) { |
43 var channel = new MessageChannel(); | 49 var channel = new MessageChannel(); |
44 channel.port1.onmessage = function(e) { | 50 channel.port1.onmessage = function(e) { |
45 e.data.sort(function(a, b) { return a[2] > b[2] ? 1 : -1; }); | 51 // Ignore hidden clients which may be coming from background tabs, or |
46 assert_equals(e.data.length, expected.length); | 52 // clients unrelated to this test. |
47 for (var i = 0; i < e.data.length; i++) | 53 var data = e.data.filter(function(info) { |
48 assert_array_equals(e.data[i], expected[i]); | 54 return info[0] == 'visible' && |
| 55 info[2].indexOf('service-worker') > -1; |
| 56 }); |
| 57 data.sort(function(a, b) { return a[2] > b[2] ? 1 : -1; }); |
| 58 assert_equals(data.length, expected.length); |
| 59 for (var i = 0; i < data.length; i++) |
| 60 assert_array_equals(data[i], expected[i]); |
49 resolve(frame); | 61 resolve(frame); |
50 }; | 62 }; |
51 frame.contentWindow.navigator.serviceWorker.controller.postMessage( | 63 frame.contentWindow.navigator.serviceWorker.controller.postMessage( |
52 {port:channel.port2, options:query_options}, | 64 {port:channel.port2, options:query_options}, |
53 [channel.port2]); | 65 [channel.port2]); |
54 }); | 66 }); |
55 } | 67 } |
56 | 68 |
57 // Run clients.matchAll without and with includeUncontrolled=true. | 69 // Run clients.matchAll without and with includeUncontrolled=true. |
58 // (We want to run the two tests sequentially in the same async_test | 70 // (We want to run the two tests sequentially in the same async_test |
59 // so that we can use the same set of iframes without intefering each other. | 71 // so that we can use the same set of iframes without intefering each other. |
60 async_test(function(t) { | 72 async_test(function(t) { |
61 service_worker_unregister_and_register( | 73 service_worker_unregister_and_register( |
62 t, 'resources/clients-matchall-worker.js', scope) | 74 t, 'resources/clients-matchall-worker.js', scope) |
63 .then(function(registration) { | 75 .then(function(registration) { |
64 return wait_for_state(t, registration.installing, 'activated'); | 76 return wait_for_state(t, registration.installing, 'activated'); |
65 }) | 77 }) |
66 .then(function() { return create_iframes(scope); }) | 78 .then(function() { return create_iframes(scope); }) |
67 .then(function(frame) { | 79 .then(function(frame) { |
68 return test_matchall(frame, expected_without_include_uncontrolled); | 80 return test_matchall(frame, expected_without_include_uncontrolled); |
69 }) | 81 }) |
70 .then(function(frame) { | 82 .then(function(frame) { |
71 return test_matchall(frame, expected_with_include_uncontrolled, | 83 return test_matchall(frame, expected_with_include_uncontrolled, |
72 {includeUncontrolled:true}); | 84 {includeUncontrolled:true}); |
73 }) | 85 }) |
74 .then(function() { | 86 .then(function() { |
| 87 frames.forEach(function(f) { f.remove() }); |
75 service_worker_unregister_and_done(t, scope); | 88 service_worker_unregister_and_done(t, scope); |
76 }) | 89 }) |
77 .catch(unreached_rejection(t)); | 90 .catch(unreached_rejection(t)); |
78 }, 'Verify matchAll() respect includeUncontrolled'); | 91 }, 'Verify matchAll() respect includeUncontrolled'); |
79 | 92 |
80 </script> | 93 </script> |
OLD | NEW |