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

Unified Diff: third_party/WebKit/LayoutTests/broadcastchannel/workers.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, 6 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/broadcastchannel/workers.html
diff --git a/third_party/WebKit/LayoutTests/broadcastchannel/workers.html b/third_party/WebKit/LayoutTests/broadcastchannel/workers.html
new file mode 100644
index 0000000000000000000000000000000000000000..55e427ad264756d2292b15b2aeaaca7c0efbcbb9
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/broadcastchannel/workers.html
@@ -0,0 +1,108 @@
+<!DOCTYPE html>
+<meta charset=utf-8>
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+<script>
+
+async_test(t => {
+ let c1 = new BroadcastChannel('worker');
+ let c2 = new BroadcastChannel('worker');
+ let events = [];
+
+ c1.onmessage = e => events.push(e);
+ c2.onmessage = e => events.push(e);
+
+ let doneCount = 0;
+ c2.addEventListener('message', t.step_func(e => {
+ if (e.data == 'from worker') {
+ c2.postMessage('from c2');
+ c1.postMessage('done');
+ } else if (e.data == 'done') {
+ assert_equals(events.length, 4);
+ assert_equals(events[0].data, 'from worker');
+ assert_equals(events[0].target, c1);
+ assert_equals(events[1].data, 'from worker');
+ assert_equals(events[1].target, c2);
+ assert_equals(events[2].data, 'from c2');
+ assert_equals(events[3].data, 'done');
+ if (++doneCount == 2) t.done();
+ }
+ }));
+
+ let worker = new Worker('resources/worker.js');
+ worker.onmessage = t.step_func(e => {
+ assert_array_equals(e.data, ['from c2', 'done']);
+ if (++doneCount == 2) t.done();
+ });
+ worker.postMessage({channel: 'worker'});
+
+ }, 'BroadcastChannel works in workers');
+
+async_test(t => {
+ let c1 = new BroadcastChannel('shared worker');
+ let c2 = new BroadcastChannel('shared worker');
+ let events = [];
+
+ c1.onmessage = e => events.push(e);
+ c2.onmessage = e => events.push(e);
+
+ let doneCount = 0;
+ c2.addEventListener('message', t.step_func(e => {
+ if (e.data == 'from worker') {
+ c2.postMessage('from c2');
+ c1.postMessage('done');
+ } else if (e.data == 'done') {
+ assert_equals(events.length, 4);
+ assert_equals(events[0].data, 'from worker');
+ assert_equals(events[0].target, c1);
+ assert_equals(events[1].data, 'from worker');
+ assert_equals(events[1].target, c2);
+ assert_equals(events[2].data, 'from c2');
+ assert_equals(events[3].data, 'done');
+ if (++doneCount == 2) t.done();
+ }
+ }));
+
+ let worker = new SharedWorker('resources/worker.js');
+ worker.port.onmessage = t.step_func(e => {
+ assert_array_equals(e.data, ['from c2', 'done']);
+ if (++doneCount == 2) t.done();
+ });
+ worker.port.postMessage({channel: 'shared worker'});
+
+ }, 'BroadcastChannel works in shared workers');
+
+async_test(t => {
+ let c = new BroadcastChannel('worker-close');
+ let events = [];
+
+ c.onmessage = e => events.push('c1: ' + e.data);
+
+ let worker = new Worker('resources/worker.js');
+ worker.onmessage = t.step_func(e => {
+ assert_array_equals(events, ['c1: from worker', 'c2: echo'],
+ 'messages in document');
+ assert_array_equals(e.data, ['done'], 'messages in worker');
+ t.done();
+ });
+
+ c.addEventListener('message', e => {
+ if (e.data == 'from worker') {
+ c.close();
+ if (self.gc) self.gc();
+ window.setTimeout(() => {
+ let c2 = new BroadcastChannel('worker-close');
+ c2.onmessage = e => {
+ events.push('c2: ' + e.data);
+ c2.postMessage('done');
+ };
+ worker.postMessage({ping: 'echo'});
+ }, 1);
+ }
+ });
+
+ worker.postMessage({channel: 'worker-close'});
+
+ }, 'Closing and re-opening a channel works.');
+
+</script>

Powered by Google App Engine
This is Rietveld 408576698