OLD | NEW |
1 if (window.testRunner) { | 1 if (window.testRunner) { |
2 testRunner.dumpAsText(); | 2 testRunner.dumpAsText(); |
3 testRunner.waitUntilDone(); | 3 testRunner.waitUntilDone(); |
4 } | 4 } |
5 | 5 |
6 description("This test checks the various use cases around sending multiple port
s through MessagePort.postMessage"); | 6 description("This test checks the various use cases around sending multiple port
s through MessagePort.postMessage"); |
7 | 7 |
8 var channel = new MessageChannel(); | 8 var channel = new MessageChannel(); |
9 var channel2 = new MessageChannel(); | 9 var channel2 = new MessageChannel(); |
10 var channel3 = new MessageChannel(); | 10 var channel3 = new MessageChannel(); |
11 var channel4 = new MessageChannel(); | 11 var channel4 = new MessageChannel(); |
12 | 12 |
13 channel.port1.postMessage("noport"); | 13 channel.port1.postMessage("noport"); |
14 channel.port1.postMessage("zero ports", []); | 14 channel.port1.postMessage("zero ports", []); |
15 channel.port1.postMessage("two ports", [channel2.port1, channel2.port2]); | 15 channel.port1.postMessage("two ports", [channel2.port1, channel2.port2]); |
16 | 16 |
17 // Now test various failure cases | 17 // Now test various failure cases |
18 shouldThrow('channel.port1.postMessage("same port", [channel.port1])', '"DataClo
neError: Failed to execute \'postMessage\' on \'MessagePort\': Item #0 in the ar
ray of ports contains the source port."'); | 18 shouldThrow('channel.port1.postMessage("same port", [channel.port1])', '"DataClo
neError: Failed to execute \'postMessage\' on \'MessagePort\': Item #0 in the ar
ray of ports contains the source port."'); |
19 shouldThrow('channel.port1.postMessage("entangled port", [channel.port2])', '"Da
taCloneError: Failed to execute \'postMessage\' on \'MessagePort\': Item #0 in t
he array of ports contains the target port."'); | 19 shouldThrow('channel.port1.postMessage("entangled port", [channel.port2])', '"Da
taCloneError: Failed to execute \'postMessage\' on \'MessagePort\': Item #0 in t
he array of ports contains the target port."'); |
20 shouldThrow('channel.port1.postMessage("null port", [channel3.port1, null, chann
el3.port2])', "'DataCloneError: An object could not be cloned.'"); | 20 shouldThrow('channel.port1.postMessage("null port", [channel3.port1, null, chann
el3.port2])', "'DataCloneError: An object could not be cloned.'"); |
21 shouldThrow('channel.port1.postMessage("notAPort", [channel3.port1, {}, channel3
.port2])', "'DataCloneError: An object could not be cloned.'"); | 21 shouldThrow('channel.port1.postMessage("notAPort", [channel3.port1, {}, channel3
.port2])', "'DataCloneError: An object could not be cloned.'"); |
22 shouldThrow('channel.port1.postMessage("duplicate port", [channel3.port1, channe
l3.port1])', "'DataCloneError: An object could not be cloned.'"); | 22 shouldThrow('channel.port1.postMessage("duplicate port", [channel3.port1, channe
l3.port1])', "'DataCloneError: An object could not be cloned.'"); |
23 // Should be OK to send channel3.port1 (should not have been disentangled by the
previous failed calls). | 23 // Should be OK to send channel3.port1 (should not have been disentangled by the
previous failed calls). |
24 channel.port1.postMessage("entangled ports", [channel3.port1, channel3.port2]); | 24 channel.port1.postMessage("entangled ports", [channel3.port1, channel3.port2]); |
25 | 25 |
26 shouldThrow('channel.port1.postMessage("notAnArray", channel3.port1)', "'TypeErr
or: Type error'") | 26 shouldThrow('channel.port1.postMessage("notAnArray", channel3.port1)', '"TypeErr
or: Failed to execute \'postMessage\' on \'MessagePort\': Second argument is nei
ther an array, nor does it have indexed properties."'); |
27 shouldThrow('channel.port1.postMessage("notASequence", [{length: 3}])', "'DataCl
oneError: An object could not be cloned.'"); | 27 shouldThrow('channel.port1.postMessage("notASequence", [{length: 3}])', "'DataCl
oneError: An object could not be cloned.'"); |
28 | 28 |
29 // Should not crash (we should figure out that the array contains undefined | 29 // Should not crash (we should figure out that the array contains undefined |
30 // entries). | 30 // entries). |
31 var largePortArray = []; | 31 var largePortArray = []; |
32 largePortArray[1234567890] = channel4.port1; | 32 largePortArray[1234567890] = channel4.port1; |
33 shouldThrow('channel.port1.postMessage("largeSequence", largePortArray)', "'Data
CloneError: An object could not be cloned.'"); | 33 shouldThrow('channel.port1.postMessage("largeSequence", largePortArray)', "'Data
CloneError: An object could not be cloned.'"); |
34 | 34 |
35 channel.port1.postMessage("done"); | 35 channel.port1.postMessage("done"); |
36 | 36 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 else | 82 else |
83 testPassed("Sending Error object should throw a DataCloneError, got: "
+ e); | 83 testPassed("Sending Error object should throw a DataCloneError, got: "
+ e); |
84 } | 84 } |
85 c4.port1.postMessage("Should succeed"); | 85 c4.port1.postMessage("Should succeed"); |
86 channel0.port1.postMessage({id:"done"}); | 86 channel0.port1.postMessage({id:"done"}); |
87 | 87 |
88 channel0.port2.onmessage = function(event) { | 88 channel0.port2.onmessage = function(event) { |
89 if (event.data.id == "send-port") { | 89 if (event.data.id == "send-port") { |
90 if (event.ports && event.ports.length > 0 && event.ports[0] === even
t.data.port) | 90 if (event.ports && event.ports.length > 0 && event.ports[0] === even
t.data.port) |
91 testPassed("send-port: transferred one port"); | 91 testPassed("send-port: transferred one port"); |
92 else | 92 else |
93 testFailed("send-port: port transfer failed"); | 93 testFailed("send-port: port transfer failed"); |
94 } else if (event.data.id == "send-port-twice") { | 94 } else if (event.data.id == "send-port-twice") { |
95 if (event.ports && event.ports.length == 1 && | 95 if (event.ports && event.ports.length == 1 && |
96 event.ports[0] === event.data.port0 && event.ports[0] === even
t.data.port1) | 96 event.ports[0] === event.data.port0 && event.ports[0] === even
t.data.port1) |
97 testPassed("send-port-twice: transferred one port twice"); | 97 testPassed("send-port-twice: transferred one port twice"); |
98 else | 98 else |
99 testFailed("send-port-twice: failed to transfer one port twice")
; | 99 testFailed("send-port-twice: failed to transfer one port twice")
; |
100 } else if (event.data.id == "send-two-ports") { | 100 } else if (event.data.id == "send-two-ports") { |
101 if (event.ports && event.ports.length == 2 && | 101 if (event.ports && event.ports.length == 2 && |
102 event.ports[0] === event.data.port0 && event.ports[1] === even
t.data.port1) | 102 event.ports[0] === event.data.port0 && event.ports[1] === even
t.data.port1) |
103 testPassed("send-two-ports: transferred two ports"); | 103 testPassed("send-two-ports: transferred two ports"); |
104 else | 104 else |
105 testFailed("send-two-ports: failed to transfer two ports"); | 105 testFailed("send-two-ports: failed to transfer two ports"); |
106 } else if (event.data.id == "done") { | 106 } else if (event.data.id == "done") { |
107 debug('<br><span class="pass">TEST COMPLETE</span>'); | 107 debug('<br><span class="pass">TEST COMPLETE</span>'); |
108 if (window.testRunner) | 108 if (window.testRunner) |
109 testRunner.notifyDone(); | 109 testRunner.notifyDone(); |
110 } else { | 110 } else { |
111 testFailed("Unexpected message " + event.data); | 111 testFailed("Unexpected message " + event.data); |
112 } | 112 } |
(...skipping 25 matching lines...) Expand all Loading... |
138 if (event.ports.length == 2) | 138 if (event.ports.length == 2) |
139 testPassed("event.ports contains two ports when two ports re-sent af
ter error"); | 139 testPassed("event.ports contains two ports when two ports re-sent af
ter error"); |
140 else | 140 else |
141 testFailed("event.ports contained " + event.ports.length + " when tw
o ports re-sent after error"); | 141 testFailed("event.ports contained " + event.ports.length + " when tw
o ports re-sent after error"); |
142 } else if (event.data == "done") { | 142 } else if (event.data == "done") { |
143 testTransfers(); | 143 testTransfers(); |
144 } else | 144 } else |
145 testFailed("Received unexpected message: " + event.data); | 145 testFailed("Received unexpected message: " + event.data); |
146 } | 146 } |
147 | 147 |
OLD | NEW |