Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(546)

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/clients-get.https.html

Issue 2778903002: Upstream service worker `client` tests to WPT (Closed)
Patch Set: Remove unnecessary branch Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <title>Service Worker: Clients.get</title> 2 <title>Service Worker: Clients.get</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="/common/get-host-info.sub.js"></script>
6 <script src="resources/test-helpers.sub.js"></script> 5 <script src="resources/test-helpers.sub.js"></script>
7 <script> 6 <script>
8 var host_info = get_host_info();
9
10 var scope = 'resources/clients-get-frame.html'; 7 var scope = 'resources/clients-get-frame.html';
11 var t = async_test('Test Clients.get()'); 8 var client_ids = [];
12 var clientIds = [];
13 var frame; 9 var frame;
14 t.step(function() { 10 promise_test(function(t) {
15 service_worker_unregister_and_register( 11 return service_worker_unregister_and_register(
16 t, 'resources/clients-get-worker.js', scope) 12 t, 'resources/clients-get-worker.js', scope)
17 .then(function(registration) { 13 .then(function(registration) {
14 add_completion_callback(function() { registration.unregister(); });
18 return wait_for_state(t, registration.installing, 'activated'); 15 return wait_for_state(t, registration.installing, 'activated');
19 }) 16 })
20 .then(function() { 17 .then(function() {
21 return with_iframe(scope + '#1'); 18 return with_iframe(scope + '#1');
22 }) 19 })
23 .then(function(frame1) { 20 .then(function(frame1) {
21 add_completion_callback(function() { frame1.remove(); });
24 frame1.focus(); 22 frame1.focus();
25 return wait_for_clientId(); 23 return wait_for_clientId();
26 }) 24 })
27 .then(function(clientId) { 25 .then(function(client_id) {
28 clientIds.push(clientId); 26 client_ids.push(client_id);
29 return with_iframe(scope + '#2'); 27 return with_iframe(scope + '#2');
30 }) 28 })
31 .then(function(frame2) { 29 .then(function(frame2) {
32 frame = frame2; 30 frame = frame2;
31 add_completion_callback(function() { frame2.remove(); });
33 return wait_for_clientId(); 32 return wait_for_clientId();
34 }) 33 })
35 .then(function(clientId) { 34 .then(function(client_id) {
36 clientIds.push(clientId); 35 client_ids.push(client_id, 'invalid-id');
37 var channel = new MessageChannel(); 36 var channel = new MessageChannel();
38 channel.port1.onmessage = t.step_func(on_message); 37 var saw_message = new Promise(function(resolve) {
38 channel.port1.onmessage = resolve;
39 });
39 frame.contentWindow.navigator.serviceWorker.controller.postMessage( 40 frame.contentWindow.navigator.serviceWorker.controller.postMessage(
40 {port:channel.port2, clientIds:clientIds, 41 {port: channel.port2, clientIds: client_ids}, [channel.port2]);
41 message: 'get_client_ids'}, [channel.port2]); 42 return saw_message;
42 }) 43 })
43 .catch(unreached_rejection(t)); 44 .then(function(e) {
44 }); 45 assert_equals(e.data.length, 3);
46 assert_array_equals(e.data[0], expected[0]);
47 assert_array_equals(e.data[1], expected[1]);
48 assert_equals(e.data[2], expected[2]);
49 });
50 }, 'Test Clients.get()');
45 51
46 function wait_for_clientId() { 52 function wait_for_clientId() {
47 return new Promise(function(resolve, reject) { 53 return new Promise(function(resolve, reject) {
48 function get_client_id(e) { 54 function get_client_id(e) {
49 window.removeEventListener("message", get_client_id); 55 window.removeEventListener('message', get_client_id);
50 resolve(e.data.clientId); 56 resolve(e.data.clientId);
51 } 57 }
52 window.addEventListener("message", get_client_id, false); 58 window.addEventListener('message', get_client_id, false);
53 }); 59 });
54 } 60 }
55 61
56 var expected = [ 62 var expected = [
57 /* visibilityState, focused, url, frameType */ 63 /* visibilityState, focused, url, frameType */
58 ['visible', true, new URL(scope + '#1', location).toString(), 'nested'], 64 ['visible', true, normalizeURL(scope) + '#1', 'nested'],
59 ['visible', false, new URL(scope + '#2', location).toString(), 'nested'], 65 ['visible', false, normalizeURL(scope) + '#2', 'nested'],
60 undefined 66 undefined
61 ]; 67 ];
62
63 function on_message(e) {
64 assert_equals(e.data.length, 3);
65 assert_array_equals(e.data[0], expected[0]);
66 assert_array_equals(e.data[1], expected[1]);
67 assert_equals(e.data[2], expected[2]);
68 service_worker_unregister_and_done(t, scope);
69 }
70 </script> 68 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698