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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/webmessaging/message-channels/close.html

Issue 2558423002: Import wpt/webmessaging tests (Closed)
Patch Set: rebase again Created 3 years, 11 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
(Empty)
1 <!DOCTYPE html>
2 <meta charset=utf-8>
3 <link rel="help" href="https://html.spec.whatwg.org/multipage/comms.html#dom-mes sageport-close">
4 <script src="/resources/testharness.js"></script>
5 <script src="/resources/testharnessreport.js"></script>
6 <script>
7 // How long (in ms) these tests should wait before deciding no further messages
8 // will be received.
9 const time_to_wait_for_messages = 100;
10
11 async_test(t => {
12 const c = new MessageChannel();
13 c.port1.onmessage = t.unreached_func('Should not have delivered message');
14 c.port1.close();
15 c.port2.postMessage('TEST');
16 setTimeout(t.step_func_done(), time_to_wait_for_messages);
17 }, 'Message sent to closed port should not arrive.');
18
19 async_test(t => {
20 const c = new MessageChannel();
21 c.port1.onmessage = t.unreached_func('Should not have delivered message');
22 c.port2.close();
23 c.port2.postMessage('TEST');
24 setTimeout(t.step_func_done(), time_to_wait_for_messages);
25 }, 'Message sent from closed port should not arrive.');
26
27 async_test(t => {
28 const c = new MessageChannel();
29 c.port1.onmessage = t.unreached_func('Should not have delivered message');
30 c.port1.close();
31 const c2 = new MessageChannel();
32 c2.port1.onmessage = t.step_func(e => {
33 e.ports[0].postMessage('TESTMSG');
34 setTimeout(t.step_func_done(), time_to_wait_for_messages);
35 });
36 c2.port2.postMessage('TEST', [c.port2]);
37 }, 'Message sent to closed port from transferred port should not arrive.');
38
39 async_test(t => {
40 const c = new MessageChannel();
41 c.port1.onmessage = t.unreached_func('Should not have delivered message');
42 c.port2.close();
43 const c2 = new MessageChannel();
44 c2.port1.onmessage = t.step_func(e => {
45 e.ports[0].postMessage('TESTMSG');
46 setTimeout(t.step_func_done(), time_to_wait_for_messages);
47 });
48 c2.port2.postMessage('TEST', [c.port2]);
49 }, 'Message sent from transferred closed port should not arrive.');
50
51 async_test(t => {
52 const c = new MessageChannel();
53 let isClosed = false;
54 c.port1.onmessage = t.step_func_done(e => {
55 assert_true(isClosed);
56 assert_equals(e.data, 'TEST');
57 });
58 c.port2.postMessage('TEST');
59 c.port2.close();
60 isClosed = true;
61 }, 'Inflight messages should be delivered even when sending port is closed aft erwards.');
62
63 async_test(t => {
64 const c = new MessageChannel();
65 c.port1.onmessage = t.step_func_done(e => {
66 if (e.data == 'DONE') t.done();
67 assert_equals(e.data, 'TEST');
68 c.port1.close();
69 });
70 c.port2.postMessage('TEST');
71 c.port2.postMessage('DONE');
72 }, 'Close in onmessage should not cancel inflight messages.');
73
74 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698