OLD | NEW |
1 <html> | 1 <html> |
2 <head> | 2 <head> |
3 <script src="../../resources/js-test.js"></script> | 3 <script src="../../resources/js-test.js"></script> |
4 </head> | 4 </head> |
5 <body> | 5 <body> |
6 <script> | 6 <script> |
7 description("Tests various use cases when cloning MessagePorts."); | 7 description("Tests various use cases when cloning MessagePorts."); |
8 window.jsTestIsAsync = true; | 8 window.jsTestIsAsync = true; |
9 | 9 |
10 var channel = new MessageChannel; | 10 var channel = new MessageChannel; |
11 channel.port1.onmessage = channel.port2.onmessage = function(evt) { | 11 channel.port1.onmessage = channel.port2.onmessage = function(evt) { |
12 testFailed("Should not have received message: " + evt.data); | 12 testFailed("Should not have received message: " + evt.data); |
13 } | 13 } |
14 | 14 |
15 // Posting port to itself should throw an exception. | 15 // Posting port to itself should throw an exception. |
16 shouldThrow("channel.port1.postMessage('msg', [channel.port1])", '"DataCloneErro
r: Failed to execute \'postMessage\' on \'MessagePort\': Item #0 in the array of
ports contains the source port."'); | 16 shouldThrow("channel.port1.postMessage('msg', [channel.port1])", '"DataCloneErro
r: Failed to execute \'postMessage\' on \'MessagePort\': Port at index 0 contain
s the source port."'); |
17 | 17 |
18 debug("Posting port to entangled pair neuters the port and does nothing else:"); | 18 debug("Posting port to entangled pair neuters the port and does nothing else:"); |
19 channel = new MessageChannel; | 19 channel = new MessageChannel; |
20 var channel2 = new MessageChannel; | 20 var channel2 = new MessageChannel; |
21 channel.port1.postMessage("msg", [channel.port2]); | 21 channel.port1.postMessage("msg", [channel.port2]); |
22 shouldThrow("channel2.port1.postMessage('msg', [channel.port2])", '"DataCloneErr
or: Failed to execute \'postMessage\' on \'MessagePort\': Item #0 in the array o
f ports is already neutered."'); | 22 shouldThrow("channel2.port1.postMessage('msg', [channel.port2])", '"DataCloneErr
or: Failed to execute \'postMessage\' on \'MessagePort\': Port at index 0 is alr
eady neutered."'); |
23 | 23 |
24 channel = new MessageChannel; | 24 channel = new MessageChannel; |
25 channel2 = new MessageChannel | 25 channel2 = new MessageChannel |
26 channel.port1.postMessage("msg", [channel2.port1]); | 26 channel.port1.postMessage("msg", [channel2.port1]); |
27 | 27 |
| 28 debug("Posting a neutered ArrayBuffer should throw."); |
| 29 channel = new MessageChannel; |
| 30 var arrayBuffer = new ArrayBuffer(2); |
| 31 |
| 32 channel.port1.postMessage("msg", [arrayBuffer]); |
| 33 shouldThrow("channel.port1.postMessage(arrayBuffer, [])", '"DataCloneError: Fail
ed to execute \'postMessage\' on \'MessagePort\': An ArrayBuffer is neutered and
could not be cloned."'); |
| 34 |
| 35 debug("Posting a neutered ArrayBufferView should throw."); |
| 36 channel = new MessageChannel; |
| 37 var uint16Array = new Uint16Array(10); |
| 38 |
| 39 shouldThrow("channel.port1.postMessage('msg', [uint16Array])", '"DataCloneError:
Failed to execute \'postMessage\' on \'MessagePort\': Value at index 0 does not
have a transferable type."'); |
| 40 |
| 41 channel.port1.postMessage("msg", [uint16Array.buffer]); |
| 42 shouldThrow("channel.port1.postMessage(uint16Array, [])", '"DataCloneError: Fail
ed to execute \'postMessage\' on \'MessagePort\': An ArrayBuffer is neutered and
could not be cloned."'); |
| 43 |
28 // Should not be able to post a cloned port. | 44 // Should not be able to post a cloned port. |
29 shouldThrow("channel.port1.postMessage('msg', [channel2.port1])", '"DataCloneErr
or: Failed to execute \'postMessage\' on \'MessagePort\': Item #0 in the array o
f ports is already neutered."'); | 45 shouldThrow("channel.port1.postMessage('msg', [channel2.port1])", '"DataCloneErr
or: Failed to execute \'postMessage\' on \'MessagePort\': Port at index 0 is alr
eady neutered."'); |
30 | 46 |
31 // Test posting messages to a port in cloned state. | 47 // Test posting messages to a port in cloned state. |
32 | 48 |
33 var channel = new MessageChannel; | 49 var channel = new MessageChannel; |
34 var channel2 = new MessageChannel; | 50 var channel2 = new MessageChannel; |
35 | 51 |
36 // Post messages before and after clone to make sure ordering is preserved and a
ll messages are received. | 52 // Post messages before and after clone to make sure ordering is preserved and a
ll messages are received. |
37 channel2.port2.postMessage("1"); | 53 channel2.port2.postMessage("1"); |
38 channel.port1.postMessage("msg", [channel2.port1]); | 54 channel.port1.postMessage("msg", [channel2.port1]); |
39 channel2.port2.postMessage("2"); | 55 channel2.port2.postMessage("2"); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 channel.port1.postMessage("closed", [channel2.port2]); | 99 channel.port1.postMessage("closed", [channel2.port2]); |
84 channel.port2.onmessage = function(evt) { | 100 channel.port2.onmessage = function(evt) { |
85 testEvent = evt; | 101 testEvent = evt; |
86 shouldNotBe("testEvent.ports", "null"); | 102 shouldNotBe("testEvent.ports", "null"); |
87 shouldBe("testEvent.ports.length", "1"); | 103 shouldBe("testEvent.ports.length", "1"); |
88 shouldBe("testEvent.data", "'closed'"); | 104 shouldBe("testEvent.data", "'closed'"); |
89 | 105 |
90 finishJSTest(); | 106 finishJSTest(); |
91 } | 107 } |
92 } | 108 } |
| 109 |
93 </script> | 110 </script> |
94 </body> | 111 </body> |
95 </html> | 112 </html> |
OLD | NEW |