diff --git a/test/fixtures/wpt/webmessaging/broadcastchannel/basics.any.js b/test/fixtures/wpt/webmessaging/broadcastchannel/basics.any.js new file mode 100644 index 00000000000000..68b4706028f5aa --- /dev/null +++ b/test/fixtures/wpt/webmessaging/broadcastchannel/basics.any.js @@ -0,0 +1,120 @@ +async_test(t => { + let c1 = new BroadcastChannel('eventType'); + let c2 = new BroadcastChannel('eventType'); + + c2.onmessage = t.step_func(e => { + 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'); + + async_test(t => { + let c1 = new BroadcastChannel('closed'); + let c2 = new BroadcastChannel('closed'); + let c3 = new BroadcastChannel('closed'); + + c2.onmessage = t.unreached_func(); + c3.onmessage = t.step_func(() => t.done()); + c1.postMessage('test'); + c2.close(); +}, 'messages aren\'t delivered to a port closed after calling postMessage.'); + +async_test(t => { + let c1 = new BroadcastChannel('create-in-onmessage'); + let c2 = new BroadcastChannel('create-in-onmessage'); + + c2.onmessage = t.step_func(e => { + assert_equals(e.data, 'first'); + c2.close(); + let c3 = new BroadcastChannel('create-in-onmessage'); + c3.onmessage = t.step_func(event => { + assert_equals(event.data, 'done'); + t.done(); + }); + c1.postMessage('done'); + }); + c1.postMessage('first'); + c2.postMessage('second'); + }, 'closing and creating channels during message delivery works correctly'); + +async_test(t => { + let c1 = new BroadcastChannel('close-in-onmessage'); + let c2 = new BroadcastChannel('close-in-onmessage'); + let c3 = new BroadcastChannel('close-in-onmessage'); + let events = []; + c1.onmessage = e => events.push('c1: ' + e.data); + c2.onmessage = e => events.push('c2: ' + e.data); + c3.onmessage = e => events.push('c3: ' + e.data); + + // c2 closes itself when it receives the first message + c2.addEventListener('message', e => { + c2.close(); + }); + + c3.addEventListener('message', t.step_func(e => { + if (e.data == 'done') { + assert_array_equals(events, [ + 'c2: first', + 'c3: first', + 'c3: done']); + t.done(); + } + })); + c1.postMessage('first'); + c1.postMessage('done'); + }, 'Closing a channel in onmessage prevents already queued tasks from firing onmessage events'); diff --git a/test/fixtures/wpt/webmessaging/broadcastchannel/blobs.html b/test/fixtures/wpt/webmessaging/broadcastchannel/blobs.html new file mode 100644 index 00000000000000..1f0e2f1f1d6050 --- /dev/null +++ b/test/fixtures/wpt/webmessaging/broadcastchannel/blobs.html @@ -0,0 +1,83 @@ + + + + + diff --git a/test/fixtures/wpt/webmessaging/broadcastchannel/cross-origin.html b/test/fixtures/wpt/webmessaging/broadcastchannel/cross-origin.html new file mode 100644 index 00000000000000..ee4b2f21c8e3fe --- /dev/null +++ b/test/fixtures/wpt/webmessaging/broadcastchannel/cross-origin.html @@ -0,0 +1,38 @@ + + + + + + + +
+ + diff --git a/test/fixtures/wpt/webmessaging/broadcastchannel/cross-partition.https.tentative.html b/test/fixtures/wpt/webmessaging/broadcastchannel/cross-partition.https.tentative.html new file mode 100644 index 00000000000000..163e6c00a93a95 --- /dev/null +++ b/test/fixtures/wpt/webmessaging/broadcastchannel/cross-partition.https.tentative.html @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + diff --git a/test/fixtures/wpt/webmessaging/broadcastchannel/detached-iframe.html b/test/fixtures/wpt/webmessaging/broadcastchannel/detached-iframe.html new file mode 100644 index 00000000000000..b9b06c3a46463b --- /dev/null +++ b/test/fixtures/wpt/webmessaging/broadcastchannel/detached-iframe.html @@ -0,0 +1,174 @@ + + + + + + + + + + diff --git a/test/fixtures/wpt/webmessaging/broadcastchannel/interface.any.js b/test/fixtures/wpt/webmessaging/broadcastchannel/interface.any.js new file mode 100644 index 00000000000000..35e09d34b418d3 --- /dev/null +++ b/test/fixtures/wpt/webmessaging/broadcastchannel/interface.any.js @@ -0,0 +1,65 @@ +test(() => assert_throws_js(TypeError, () => new BroadcastChannel()), + 'Should throw if no name is provided'); + +test(() => { + let c = new BroadcastChannel(null); + assert_equals(c.name, 'null'); + }, 'Null name should not throw'); + +test(() => { + let c = new BroadcastChannel(undefined); + assert_equals(c.name, 'undefined'); + }, 'Undefined name should not throw'); + +test(() => { + let c = new BroadcastChannel('fooBar'); + assert_equals(c.name, 'fooBar'); + }, 'Non-empty name should not throw'); + +test(() => { + let c = new BroadcastChannel(123); + assert_equals(c.name, '123'); + }, 'Non-string name should not throw'); + +test(() => { + let c = new BroadcastChannel(''); + assert_throws_js(TypeError, () => c.postMessage()); + }, 'postMessage without parameters should throw'); + +test(() => { + let c = new BroadcastChannel(''); + c.postMessage(null); + }, 'postMessage with null should not throw'); + +test(() => { + let c = new BroadcastChannel(''); + c.close(); + }, 'close should not throw'); + +test(() => { + let c = new BroadcastChannel(''); + c.close(); + c.close(); + }, 'close should not throw when called multiple times'); + +test(() => { + let c = new BroadcastChannel(''); + c.close(); + assert_throws_dom('InvalidStateError', () => c.postMessage('')); + }, 'postMessage after close should throw'); + +test(() => { + let c = new BroadcastChannel(''); + assert_not_equals(c.onmessage, undefined); + }, 'BroadcastChannel should have an onmessage event'); + +test(() => { + let c = new BroadcastChannel(''); + assert_throws_dom('DataCloneError', () => c.postMessage(Symbol())); + }, 'postMessage should throw with uncloneable data'); + +test(() => { + let c = new BroadcastChannel(''); + c.close(); + assert_throws_dom('InvalidStateError', () => c.postMessage(Symbol())); + }, 'postMessage should throw InvalidStateError after close, even with uncloneable data'); diff --git a/test/fixtures/wpt/webmessaging/broadcastchannel/opaque-origin.html b/test/fixtures/wpt/webmessaging/broadcastchannel/opaque-origin.html new file mode 100644 index 00000000000000..c10e0cb22256a0 --- /dev/null +++ b/test/fixtures/wpt/webmessaging/broadcastchannel/opaque-origin.html @@ -0,0 +1,35 @@ + + + + +