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

Unified 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: Created 4 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/broadcastchannel/basics.html
diff --git a/third_party/WebKit/LayoutTests/broadcastchannel/basics.html b/third_party/WebKit/LayoutTests/broadcastchannel/basics.html
new file mode 100644
index 0000000000000000000000000000000000000000..3ce6237902e5ecd7e92aea3ffb6e0822f9e38257
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/broadcastchannel/basics.html
@@ -0,0 +1,73 @@
+<!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('eventType');
+ let c2 = new BroadcastChannel('eventType');
+
+ c2.onmessage = t.step_func(e => {
+ console.log(e.source);
+ console.log(e.origin);
+ assert_true(e instanceof MessageEvent);
+ assert_equals(e.target, c2);
+ assert_equals(e.type, 'message');
+ assert_equals(e.origin, location.origin, 'origin');
+ assert_equals(e.data, 'hello world');
+ assert_equals(e.source, null, 'source');
+ t.done();
+ });
+ c1.postMessage('hello world');
+ }, 'postMessage results in correct event');
+
+async_test(t => {
+ let c1 = new BroadcastChannel('order');
+ let c2 = new BroadcastChannel('order');
+ let c3 = new BroadcastChannel('order');
+
+ let events = [];
+ let doneCount = 0;
+ let handler = t.step_func(e => {
+ events.push(e);
+ if (e.data == 'done') {
+ doneCount++;
+ if (doneCount == 2) {
+ assert_equals(events.length, 6);
+ assert_equals(events[0].target, c2, 'target for event 0');
+ assert_equals(events[0].data, 'from c1');
+ assert_equals(events[1].target, c3, 'target for event 1');
+ assert_equals(events[1].data, 'from c1');
+ assert_equals(events[2].target, c1, 'target for event 2');
+ assert_equals(events[2].data, 'from c3');
+ assert_equals(events[3].target, c2, 'target for event 3');
+ assert_equals(events[3].data, 'from c3');
+ assert_equals(events[4].target, c1, 'target for event 4');
+ assert_equals(events[4].data, 'done');
+ assert_equals(events[5].target, c3, 'target for event 5');
+ assert_equals(events[5].data, 'done');
+ t.done();
+ }
+ }
+ });
+ c1.onmessage = handler;
+ c2.onmessage = handler;
+ c3.onmessage = handler;
+
+ c1.postMessage('from c1');
+ c3.postMessage('from c3');
+ c2.postMessage('done');
+ }, 'messages are delivered in port creation order');
+
+async_test(t => {
+ let c1 = new BroadcastChannel('closed');
+ let c2 = new BroadcastChannel('closed');
+ let c3 = new BroadcastChannel('closed');
+
+ c2.onmessage = t.unreached_func();
+ c2.close();
+ c3.onmessage = t.step_func(() => t.done());
+ c1.postMessage('test');
+ }, 'messages aren\'t delivered to a closed port');
+</script>

Powered by Google App Engine
This is Rietveld 408576698