| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <!-- This is in chromium/ because the equivalent version available in Web | |
| 3 Platform Tests also asserts the presence of the Client's `type` attribute. | |
| 4 This less precise version (and its resources) should be maintained only to | |
| 5 preserve test coverage until the attribute is implemented. See | |
| 6 https://crbug.com/705685 --> | |
| 7 <title>Service Worker: Clients.matchAll with includeUncontrolled</title> | |
| 8 <script src="../../resources/testharness.js"></script> | |
| 9 <script src="../../resources/testharnessreport.js"></script> | |
| 10 <script src="../resources/test-helpers.js"></script> | |
| 11 <script> | |
| 12 var base_url = 'resources/blank.html'; // This is out-of-scope. | |
| 13 var scope = base_url + '?clients-matchAll-includeUncontrolled'; | |
| 14 | |
| 15 // Creates 3 iframes, 2 for in-scope and 1 for out-of-scope. | |
| 16 // The frame opened for scope + '#2' is returned via a promise. | |
| 17 // FIXME: remove iframes when the test finishes. | |
| 18 function create_iframes(scope) { | |
| 19 return with_iframe(base_url) | |
| 20 .then(function(frame0) { | |
| 21 return with_iframe(scope + '#1'); | |
| 22 }) | |
| 23 .then(function(frame1) { | |
| 24 return with_iframe(scope + '#2'); | |
| 25 }); | |
| 26 } | |
| 27 | |
| 28 var expected_without_include_uncontrolled = [ | |
| 29 /* visibilityState, focused, url, frameType */ | |
| 30 ['visible', false, new URL(scope + '#1', location).toString(), 'nested'], | |
| 31 ['visible', true, new URL(scope + '#2', location).toString(), 'nested'] | |
| 32 ]; | |
| 33 | |
| 34 var expected_with_include_uncontrolled = [ | |
| 35 /* visibilityState, focused, url, frameType */ | |
| 36 ['visible', false, new URL(scope + '#1', location).toString(), 'nested'], | |
| 37 ['visible', true, new URL(scope + '#2', location).toString(), 'nested'], | |
| 38 ['visible', false, new URL(base_url, location).toString(), 'nested'], | |
| 39 ['visible', true, location.href, 'top-level'] | |
| 40 ]; | |
| 41 | |
| 42 function test_matchall(frame, expected, query_options) { | |
| 43 // Make sure we have focus for '#2' frame and its parent window. | |
| 44 frame.focus(); | |
| 45 frame.contentWindow.focus(); | |
| 46 expected.sort(function(a, b) { return a[2] > b[2] ? 1 : -1; }); | |
| 47 return new Promise(function(resolve, reject) { | |
| 48 var channel = new MessageChannel(); | |
| 49 channel.port1.onmessage = function(e) { | |
| 50 e.data.sort(function(a, b) { return a[2] > b[2] ? 1 : -1; }); | |
| 51 assert_equals(e.data.length, expected.length); | |
| 52 for (var i = 0; i < e.data.length; i++) | |
| 53 assert_array_equals(e.data[i], expected[i]); | |
| 54 resolve(frame); | |
| 55 }; | |
| 56 frame.contentWindow.navigator.serviceWorker.controller.postMessage( | |
| 57 {port:channel.port2, options:query_options}, | |
| 58 [channel.port2]); | |
| 59 }); | |
| 60 } | |
| 61 | |
| 62 // Run clients.matchAll without and with includeUncontrolled=true. | |
| 63 // (We want to run the two tests sequentially in the same async_test | |
| 64 // so that we can use the same set of iframes without intefering each other. | |
| 65 async_test(function(t) { | |
| 66 service_worker_unregister_and_register( | |
| 67 t, 'resources/clients-matchall-worker.js', scope) | |
| 68 .then(function(registration) { | |
| 69 return wait_for_state(t, registration.installing, 'activated'); | |
| 70 }) | |
| 71 .then(function() { return create_iframes(scope); }) | |
| 72 .then(function(frame) { | |
| 73 return test_matchall(frame, expected_without_include_uncontrolled); | |
| 74 }) | |
| 75 .then(function(frame) { | |
| 76 return test_matchall(frame, expected_with_include_uncontrolled, | |
| 77 {includeUncontrolled:true}); | |
| 78 }) | |
| 79 .then(function() { | |
| 80 service_worker_unregister_and_done(t, scope); | |
| 81 }) | |
| 82 .catch(unreached_rejection(t)); | |
| 83 }, 'Verify matchAll() respect includeUncontrolled'); | |
| 84 | |
| 85 </script> | |
| OLD | NEW |