• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1test(() => assert_throws_js(TypeError, () => new BroadcastChannel()),
2  'Should throw if no name is provided');
3
4test(() => {
5    let c = new BroadcastChannel(null);
6    assert_equals(c.name, 'null');
7  }, 'Null name should not throw');
8
9test(() => {
10    let c = new BroadcastChannel(undefined);
11    assert_equals(c.name, 'undefined');
12  }, 'Undefined name should not throw');
13
14test(() => {
15    let c = new BroadcastChannel('fooBar');
16    assert_equals(c.name, 'fooBar');
17  }, 'Non-empty name should not throw');
18
19test(() => {
20    let c = new BroadcastChannel(123);
21    assert_equals(c.name, '123');
22  }, 'Non-string name should not throw');
23
24test(() => {
25    let c = new BroadcastChannel('');
26    assert_throws_js(TypeError, () => c.postMessage());
27  }, 'postMessage without parameters should throw');
28
29test(() => {
30    let c = new BroadcastChannel('');
31    c.postMessage(null);
32  }, 'postMessage with null should not throw');
33
34test(() => {
35    let c = new BroadcastChannel('');
36    c.close();
37  }, 'close should not throw');
38
39test(() => {
40    let c = new BroadcastChannel('');
41    c.close();
42    c.close();
43  }, 'close should not throw when called multiple times');
44
45test(() => {
46    let c = new BroadcastChannel('');
47    c.close();
48    assert_throws_dom('InvalidStateError', () => c.postMessage(''));
49  }, 'postMessage after close should throw');
50
51test(() => {
52    let c = new BroadcastChannel('');
53    assert_not_equals(c.onmessage, undefined);
54  }, 'BroadcastChannel should have an onmessage event');
55
56test(() => {
57    let c = new BroadcastChannel('');
58    assert_throws_dom('DataCloneError', () => c.postMessage(Symbol()));
59  }, 'postMessage should throw with uncloneable data');
60
61test(() => {
62    let c = new BroadcastChannel('');
63    c.close();
64    assert_throws_dom('InvalidStateError', () => c.postMessage(Symbol()));
65  }, 'postMessage should throw InvalidStateError after close, even with uncloneable data');
66