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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/postmessage-to-client.https.html

Issue 2875383002: Upstream service worker `postMessage` tests to WPT (Closed)
Patch Set: Created 3 years, 7 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: postMessage to Client</title> 2 <title>Service Worker: postMessage to Client</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> 5 <script src="/common/get-host-info.sub.js"></script>
6 <script src="resources/test-helpers.sub.js"></script> 6 <script src="resources/test-helpers.sub.js"></script>
7 <script> 7 <script>
8 var frame; 8 promise_test(t => {
9 var t = async_test('postMessage from ServiceWorker to Client'); 9 var script = 'resources/postmessage-to-client-worker.js';
10 t.step(function() {
11 var scope = 'resources/blank.html'; 10 var scope = 'resources/blank.html';
12 var host_info = get_host_info(); 11 var w;
13 var sw; 12
14 service_worker_unregister_and_register( 13 return service_worker_unregister_and_register(t, script, scope)
15 t, 'resources/postmessage-to-client-worker.js', scope) 14 .then(registration => {
16 .then(function(registration) { 15 add_completion_callback(() => registration.unregister());
falken 2017/05/15 05:10:33 t.add_cleanup() ?
mike3 2017/05/15 20:07:45 They are functionally equivalent today, though `t.
17 return wait_for_state(t, registration.installing, 'activated'); 16 return wait_for_state(t, registration.installing, 'activated');
18 }) 17 })
19 .then(function() { return with_iframe(scope); }) 18 .then(() => with_iframe(scope))
20 .then(function(f) { 19 .then(frame => {
21 frame = f; 20 t.add_cleanup(() => frame.remove());
22 sw = frame.contentWindow.navigator.serviceWorker; 21
23 sw.onmessage = t.step_func(onMessage); 22 return new Promise(resolve => {
24 sw.controller.postMessage('ping'); 23 w = frame.contentWindow;
24 w.navigator.serviceWorker.onmessage = resolve;
25 w.navigator.serviceWorker.controller.postMessage('ping');
26 });
25 }) 27 })
26 .catch(unreached_rejection(t)); 28 .then(e => {
27 29 var message = e.data;
28 var result = []; 30 assert_equals(e.constructor, w.MessageEvent,
29 var expected = ['Sending message via clients']; 31 'message events should use MessageEvent interface.');
30 32 assert_equals(e.type, 'message', 'type should be "message".');
31 function onMessage(e) { 33 assert_equals(e.bubbles, false, 'message events should not bubble.');
32 assert_equals(e.constructor, frame.contentWindow.MessageEvent, 34 assert_equals(e.cancelable, false,
33 'message events should use MessageEvent interface.'); 35 'message events should not be cancelable.');
34 assert_equals(e.bubbles, false, 'message events should not bubble.'); 36 assert_equals(
35 assert_equals(e.cancelable, false, 37 e.origin, location.origin,
36 'message events should not be cancelable.'); 38 'origin of message should be origin of Service Worker.');
37 assert_equals(e.origin, host_info['HTTPS_ORIGIN'], 39 assert_equals(e.lastEventId, '',
38 'message event\'s origin should be set correctly.'); 40 'lastEventId should be an empty string.');
39 assert_equals(e.source, sw.controller, 'source should be ServiceWorker.'); 41 assert_equals(e.source.constructor, w.ServiceWorker,
40 42 'source should use ServiceWorker interface.');
41 var message = e.data; 43 assert_equals(
42 if (message === 'quit') { 44 e.source, w.navigator.serviceWorker.controller,
43 assert_array_equals(result, expected, 45 'source should be the service worker that sent the message.');
44 'Worker should post back expected messages.'); 46 assert_equals(e.ports.length, 0, 'ports should be an empty array.');
45 frame.remove(); 47 assert_equals(message, 'Sending message via clients');
46 service_worker_unregister_and_done(t, scope); 48 return new Promise(resolve => {
47 } else { 49 w.navigator.serviceWorker.onmessage = resolve;
48 result.push(message); 50 });
49 } 51 })
50 } 52 .then(e => { assert_equals(e.data, 'quit'); });
51 }); 53 }, 'postMessage from ServiceWorker to Client.');
52 </script> 54 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698