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

Side by Side Diff: third_party/WebKit/LayoutTests/broadcastchannel/basics.html

Issue 2004643002: Implement BroadcastChannel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address dcheng's comments Created 4 years, 5 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 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharnessreport.js"></script>
5 <script>
6
7 async_test(t => {
8 let c1 = new BroadcastChannel('eventType');
9 let c2 = new BroadcastChannel('eventType');
10
11 c2.onmessage = t.step_func(e => {
12 assert_true(e instanceof MessageEvent);
13 assert_equals(e.target, c2);
14 assert_equals(e.type, 'message');
15 assert_equals(e.origin, location.origin, 'origin');
16 assert_equals(e.data, 'hello world');
17 assert_equals(e.source, null, 'source');
18 t.done();
19 });
20 c1.postMessage('hello world');
21 }, 'postMessage results in correct event');
22
23 async_test(t => {
24 let c1 = new BroadcastChannel('order');
25 let c2 = new BroadcastChannel('order');
26 let c3 = new BroadcastChannel('order');
27
28 let events = [];
29 let doneCount = 0;
30 let handler = t.step_func(e => {
31 events.push(e);
32 if (e.data == 'done') {
33 doneCount++;
34 if (doneCount == 2) {
35 assert_equals(events.length, 6);
36 assert_equals(events[0].target, c2, 'target for event 0');
37 assert_equals(events[0].data, 'from c1');
38 assert_equals(events[1].target, c3, 'target for event 1');
39 assert_equals(events[1].data, 'from c1');
40 assert_equals(events[2].target, c1, 'target for event 2');
41 assert_equals(events[2].data, 'from c3');
42 assert_equals(events[3].target, c2, 'target for event 3');
43 assert_equals(events[3].data, 'from c3');
44 assert_equals(events[4].target, c1, 'target for event 4');
45 assert_equals(events[4].data, 'done');
46 assert_equals(events[5].target, c3, 'target for event 5');
47 assert_equals(events[5].data, 'done');
48 t.done();
49 }
50 }
51 });
52 c1.onmessage = handler;
53 c2.onmessage = handler;
54 c3.onmessage = handler;
55
56 c1.postMessage('from c1');
57 c3.postMessage('from c3');
58 c2.postMessage('done');
59 }, 'messages are delivered in port creation order');
60
61 async_test(t => {
62 let c1 = new BroadcastChannel('closed');
63 let c2 = new BroadcastChannel('closed');
64 let c3 = new BroadcastChannel('closed');
65
66 c2.onmessage = t.unreached_func();
67 c2.close();
68 c3.onmessage = t.step_func(() => t.done());
69 c1.postMessage('test');
70 }, 'messages aren\'t delivered to a closed port');
71
72 async_test(t => {
73 let c1 = new BroadcastChannel('create-in-onmessage');
74 let c2 = new BroadcastChannel('create-in-onmessage');
75
76 c2.onmessage = t.step_func(e => {
77 assert_equals(e.data, 'first');
78 c2.close();
79 let c3 = new BroadcastChannel('create-in-onmessage');
80 c3.onmessage = t.step_func(event => {
81 assert_equals(event.data, 'done');
82 t.done();
83 });
84 c1.postMessage('done');
85 });
86 c1.postMessage('first');
87 c2.postMessage('second');
88 }, 'closing and creating channels during message delivery works correctly');
89
90 // TODO(mek): Depending on https://github.com/whatwg/html/issues/1371 adjust
91 // this test to match the correct behavior.
92 async_test(t => {
93 let c1 = new BroadcastChannel('close-in-onmessage');
94 let c2 = new BroadcastChannel('close-in-onmessage');
95 let c3 = new BroadcastChannel('close-in-onmessage');
96 let events = [];
97 c1.onmessage = e => events.push('c1: ' + e.data);
98 c2.onmessage = e => events.push('c2: ' + e.data);
99 c3.onmessage = e => events.push('c3: ' + e.data);
100
101 // c2 closes itself when it receives the first message
102 c2.addEventListener('message', e => {
103 c2.close();
104 });
105
106 c3.addEventListener('message', t.step_func(e => {
107 if (e.data == 'done') {
108 assert_array_equals(events, [
109 'c2: first',
110 'c3: first',
111 'c2: done',
112 'c3: done']);
113 t.done();
114 }
115 }));
116 c1.postMessage('first');
117 c1.postMessage('done');
118 }, 'Closing a channel in onmessage doesn\'t cancel already queued events');
119
120 </script>
OLDNEW
« no previous file with comments | « content/content_browser.gypi ('k') | third_party/WebKit/LayoutTests/broadcastchannel/blobs.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698