Chromium Code Reviews| 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 t = async_test('Test Clients.matchAll()'); |
| 9 var frame1, frame2; | 9 var frame1, frame2; |
| 10 t.step(function() { | 10 t.step(function() { |
|
nhiroki
2015/08/19 08:01:13
Can you make this promise_test?
jeremyarcher
2015/08/19 08:36:52
Done.
| |
| 11 service_worker_unregister_and_register( | 11 service_worker_unregister_and_register( |
| 12 t, 'resources/clients-matchall-worker.js', scope) | 12 t, 'resources/clients-matchall-worker.js', scope) |
| 13 .then(function(registration) { | 13 .then(function(registration) { |
| 14 return wait_for_state(t, registration.installing, 'activated'); | 14 return wait_for_state(t, registration.installing, 'activated'); |
| 15 }) | 15 }) |
| 16 .then(function() { return with_iframe(scope + '#1'); }) | 16 .then(function() { return with_iframe(scope + '#1'); }) |
| 17 .then(function(f) { | 17 .then(function(f) { |
| 18 frame1 = f; | 18 frame1 = f; |
| 19 f.focus(); | |
| 20 return with_iframe(scope + '#2'); | 19 return with_iframe(scope + '#2'); |
| 21 }) | 20 }) |
| 22 .then(function(f) { | 21 .then(function(f) { |
| 23 frame2 = f; | 22 return new Promise(function(resolve) { |
| 24 var channel = new MessageChannel(); | 23 frame2 = f; |
| 25 channel.port1.onmessage = t.step_func(onMessage); | 24 frame1.focus(); |
| 26 f.contentWindow.navigator.serviceWorker.controller.postMessage( | 25 var channel = new MessageChannel(); |
| 27 {port:channel.port2}, [channel.port2]); | 26 channel.port1.onmessage = t.step_func(resolve); |
| 27 f.contentWindow.navigator.serviceWorker.controller.postMessage( | |
|
nhiroki
2015/08/19 08:01:13
For cleanup, you can retain |registration.installi
jeremyarcher
2015/08/19 08:36:52
Done.
| |
| 28 {port:channel.port2}, [channel.port2]); | |
| 29 }); | |
| 30 }) | |
| 31 .then(function(message) { | |
| 32 return new Promise(function(resolve) { | |
| 33 assert_equals(message.data.length, 2); | |
| 34 assert_array_equals(message.data[0], expectedFirst[0]); | |
| 35 assert_array_equals(message.data[1], expectedFirst[1]); | |
| 36 frame1.focus(); | |
|
nhiroki
2015/08/19 08:01:13
This makes the same result with the first trial. f
jeremyarcher
2015/08/19 08:36:52
Oh dear- copy paste strikes again. PTAL
| |
| 37 var channel = new MessageChannel(); | |
| 38 channel.port1.onmessage = t.step_func(resolve); | |
| 39 frame1.contentWindow.navigator.serviceWorker.controller. | |
|
nhiroki
2015/08/19 08:01:13
ditto (reg.installing)
jeremyarcher
2015/08/19 08:36:52
Done.
| |
| 40 postMessage({port:channel.port2}, [channel.port2]); | |
| 41 }); | |
| 42 }) | |
| 43 .then(function(message) { | |
| 44 assert_equals(message.data.length, 2); | |
| 45 assert_array_equals(message.data[0], expectedSecond[0]); | |
| 46 assert_array_equals(message.data[1], expectedSecond[1]); | |
| 47 frame1.remove(); | |
| 48 frame2.remove(); | |
| 49 return service_worker_unregister_and_done(t, scope); | |
| 28 }) | 50 }) |
| 29 .catch(unreached_rejection(t)); | 51 .catch(unreached_rejection(t)); |
| 30 }); | 52 }); |
| 31 | 53 |
| 32 var expected = [ | 54 var expectedFirst = [ |
| 33 /* visibilityState, focused, url, frameType */ | 55 /* visibilityState, focused, url, frameType */ |
| 34 ['visible', true, new URL(scope + '#1', location).toString(), 'nested'], | 56 ['visible', true, new URL(scope + '#1', location).toString(), 'nested'], |
| 35 ['visible', false, new URL(scope + '#2', location).toString(), 'nested'] | 57 ['visible', false, new URL(scope + '#2', location).toString(), 'nested'] |
| 36 ]; | 58 ]; |
| 37 | 59 |
| 38 function onMessage(e) { | 60 var expectedSecond = [ |
| 39 assert_equals(e.data.length, 2); | 61 /* visibilityState, focused, url, frameType */ |
| 40 assert_array_equals(e.data[0], expected[0]); | 62 ['visible', true, new URL(scope + '#1', location).toString(), 'nested'], |
| 41 assert_array_equals(e.data[1], expected[1]); | 63 ['visible', false, new URL(scope + '#2', location).toString(), 'nested'] |
| 42 frame1.remove(); | 64 ]; |
| 43 frame2.remove(); | |
| 44 service_worker_unregister_and_done(t, scope); | |
| 45 } | |
| 46 </script> | 65 </script> |
| OLD | NEW |