summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/workers/Worker-multi-port.html
blob: 587176e9fc101e950b8f941d96f1f170356ea51e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<!DOCTYPE html>
<title>Test sending multiple ports through Worker.postMessage.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
async_test(function(t) {
  var worker = new Worker("support/Worker-thread-multi-port.js");
  worker.onmessage = t.step_func_done(function(evt) {
    assert_true(evt.data.startsWith('PASS'));
  });
  worker.postMessage("noport");
}, 'Test postMessage with no port.');

async_test(function(t) {
  var worker = new Worker("support/Worker-thread-multi-port.js");
  worker.onmessage = t.step_func_done(function(evt) {
    assert_true(evt.data.startsWith('PASS'));
  });
  worker.postMessage("noargs");
}, 'Test postMessage with no arguments.');

async_test(function(t) {
  var worker = new Worker("support/Worker-thread-multi-port.js");
  worker.onmessage = t.step_func_done(function(evt) {
    assert_true(evt.data.startsWith('PASS'));
  });
  worker.postMessage("zero ports", []);
}, 'Test postMessage with no ports and empty array.');

async_test(function(t) {
  var worker = new Worker("support/Worker-thread-multi-port.js");
  var channel = new MessageChannel();
  worker.onmessage = t.step_func_done(function(evt) {
    assert_true(evt.data.startsWith('PASS'));
  });
  worker.postMessage("two ports", [channel.port1, channel.port2]);
}, 'Test postMessage with two ports.');

test(() => {
  var worker = new Worker("support/Worker-thread-multi-port.js");
  assert_throws_js(TypeError,
                   function() { worker.postMessage(); },
                   'Empty postMessage should throw exception.');
}, 'Test empty postMessage throws exception.');

test(() => {
  var worker = new Worker("support/Worker-thread-multi-port.js");
  var channel = new MessageChannel();
  assert_throws_js(TypeError,
                   function() { worker.postMessage("null port",
                                                   [channel.port1, null,
                                                    channel.port2]); },
                   'postMessage with null ports should throw exception.');
}, 'Test postMessage with null ports throws exception.');

test(() => {
  var worker = new Worker("support/Worker-thread-multi-port.js")
  var channel = new MessageChannel();
  assert_throws_dom('DataCloneError',
                    function() { worker.postMessage("notAPort",
                                                    [channel.port1, {},
                                                     channel.port2]); },
                    'postMessage with incorrect ports should throw exception.');
}, 'Test postMessage with incorrect ports throws exception');

test(() => {
  var worker = new Worker("support/Worker-thread-multi-port.js");
  assert_throws_dom('DataCloneError',
                    function() { worker.postMessage("notASequence", [{length: 3}]) },
                    'postMessage without sequence should throw exception.');
}, 'Test postMessage without sequence throws exception');

async_test(function(t) {
  var worker = new Worker("support/Worker-thread-multi-port.js");
  var channel = new MessageChannel();
  assert_throws_dom('DataCloneError',
                    function() { worker.postMessage("notAPort",
                                                    [channel.port1, {},
                                                     channel.port2]); },
                    'postMessage with incorrect ports should throw exception.');
  worker.onmessage = t.step_func_done(function(evt) {
    assert_true(evt.data.startsWith('PASS'));
  });
  worker.postMessage("failed ports", [channel.port1, channel.port2]);
}, 'Test postMessage on channel with previous failed postMessage calls.');
</script>