| 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("Test window.postMessage() argument handling."); | 7 description("Test window.postMessage() argument handling."); |
| 8 | 8 |
| 9 self.jsTestIsAsync = true; | 9 self.jsTestIsAsync = true; |
| 10 | 10 |
| 11 if (window.testRunner) { | 11 if (window.testRunner) { |
| 12 testRunner.dumpAsText(); | 12 testRunner.dumpAsText(); |
| 13 testRunner.waitUntilDone(); | 13 testRunner.waitUntilDone(); |
| 14 } | 14 } |
| 15 | 15 |
| 16 function onmessage(evt) { | 16 function onmessage(evt) { |
| 17 if (evt.ports) | 17 if (evt.ports) |
| 18 debug("Received message '" + evt.data + "' with " + evt.ports.length + "
ports."); | 18 debug("Received message '" + evt.data + "' with " + evt.ports.length + "
ports."); |
| 19 else | 19 else |
| 20 debug("Received message '" + evt.data); | 20 debug("Received message '" + evt.data); |
| 21 | 21 |
| 22 if (evt.data == 'done') | 22 if (evt.data == 'done') |
| 23 finishJSTest(); | 23 finishJSTest(); |
| 24 } | 24 } |
| 25 | 25 |
| 26 window.addEventListener('message', onmessage, false); | 26 window.addEventListener('message', onmessage, false); |
| 27 | 27 |
| 28 function convertDetached(obj) { |
| 29 if (obj instanceof Int8Array && obj.byteLength === 0) |
| 30 return "[detached TypedArray]"; |
| 31 return obj; |
| 32 } |
| 33 |
| 34 function convertArrayDetached(obj) { |
| 35 if (obj instanceof Array) |
| 36 return obj.map(convertDetached) |
| 37 return obj; |
| 38 } |
| 39 |
| 28 function tryPostMessageFunction(postMessageFunction, first, second, third, shoul
dFail) { | 40 function tryPostMessageFunction(postMessageFunction, first, second, third, shoul
dFail) { |
| 29 var pass, reason; | 41 var pass, reason; |
| 30 try { | 42 try { |
| 31 postMessageFunction(first, second, third); | 43 postMessageFunction(first, second, third); |
| 32 pass = !shouldFail; | 44 pass = !shouldFail; |
| 33 reason = " did not throw an exception"; | 45 reason = " did not throw an exception"; |
| 34 } catch (e) { | 46 } catch (e) { |
| 35 pass = shouldFail; | 47 pass = shouldFail; |
| 36 reason = ": threw exception " + e; | 48 reason = ": threw exception " + e; |
| 37 } | 49 } |
| 38 if (pass) | 50 if (pass) |
| 39 testPassed("Posting message ('" + first + "', " + third + ")" + reason); | 51 testPassed("Posting message ('" + convertDetached(first) + "', " + conve
rtArrayDetached(third) + ")" + reason); |
| 40 else | 52 else |
| 41 testFailed("Posting message ('" + first + "', " + third + ")" + reason); | 53 testFailed("Posting message ('" + convertDetached(first) + "', " + conve
rtArrayDetached(third) + ")" + reason); |
| 42 } | 54 } |
| 43 | 55 |
| 44 function tryPostMessage(first, second, third, shouldFail) { | 56 function tryPostMessage(first, second, third, shouldFail) { |
| 45 tryPostMessageFunction(window.postMessage, first, second, third, shouldFail)
; | 57 tryPostMessageFunction(window.postMessage, first, second, third, shouldFail)
; |
| 46 } | 58 } |
| 47 | 59 |
| 48 document.getElementById("description").innerHTML = "Test that the second argumen
t of window.postMessage is ignored or triggers an error if it is not a message p
ort. You should see PASS message '1' through '7', followed by 'done', with messa
ges 4-7 received below.<br><br>"; | 60 document.getElementById("description").innerHTML = "Test that the second argumen
t of window.postMessage is ignored or triggers an error if it is not a message p
ort. You should see PASS message '1' through '7', followed by 'done', with messa
ges 4-7 received below.<br><br>"; |
| 49 | 61 |
| 50 tryPostMessage('1', '*', 1, true); | 62 tryPostMessage('1', '*', 1, true); |
| 51 tryPostMessage('2', '*', 'c', true); | 63 tryPostMessage('2', '*', 'c', true); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 tryPostMessageFunction(window.postMessage, 'data', '*', [1,,2], true); | 104 tryPostMessageFunction(window.postMessage, 'data', '*', [1,,2], true); |
| 93 tryPostMessageFunction(window.postMessage, 'data', '*', [null, window.postMessag
e], true); | 105 tryPostMessageFunction(window.postMessage, 'data', '*', [null, window.postMessag
e], true); |
| 94 | 106 |
| 95 shouldThrow("window.postMessage()"); | 107 shouldThrow("window.postMessage()"); |
| 96 shouldThrow("window.postMessage('a')"); | 108 shouldThrow("window.postMessage('a')"); |
| 97 | 109 |
| 98 tryPostMessageFunction(window.postMessage, 'done', '*'); | 110 tryPostMessageFunction(window.postMessage, 'done', '*'); |
| 99 </script> | 111 </script> |
| 100 </body> | 112 </body> |
| 101 </html> | 113 </html> |
| OLD | NEW |