Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Side by Side Diff: LayoutTests/fast/dom/Window/window-postmessage-args.html

Issue 1025203002: Have postMessage()s throw TypeError on failed arity checks. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: tidy up incorrect postMessage() usage Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | LayoutTests/fast/dom/Window/window-postmessage-args-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <html> 1 <html>
2 <head></head> 2 <head>
3 <script src="../../../resources/js-test.js"></script>
4 </head>
3 <body> 5 <body>
4 <div id="description"></div>
5 <div id="console"></div>
6 <script> 6 <script>
7 description("Test window.postMessage() argument handling.");
8
9 self.jsTestIsAsync = true;
10
7 if (window.testRunner) { 11 if (window.testRunner) {
8 testRunner.dumpAsText(); 12 testRunner.dumpAsText();
9 testRunner.waitUntilDone(); 13 testRunner.waitUntilDone();
10 } 14 }
11 15
12 var console = document.getElementById("console");
13
14 function onmessage(evt) { 16 function onmessage(evt) {
15 if (evt.ports) 17 if (evt.ports)
16 console.innerHTML += "Received message '" + evt.data + "' with " + evt.p orts.length + " ports.<br>"; 18 debug("Received message '" + evt.data + "' with " + evt.ports.length + " ports.");
17 else 19 else
18 console.innerHTML += "Received message '" + evt.data + "'<br>"; 20 debug("Received message '" + evt.data);
19 21
20 if (evt.data == 'done' && window.testRunner) 22 if (evt.data == 'done')
21 testRunner.notifyDone(); 23 finishJSTest();
22 } 24 }
23 25
24 window.addEventListener('message', onmessage, false); 26 window.addEventListener('message', onmessage, false);
25 27
26 function tryPostMessageFunction(postMessageFunction, first, second, third, shoul dFail) { 28 function tryPostMessageFunction(postMessageFunction, first, second, third, shoul dFail) {
27 var pass, reason; 29 var pass, reason;
28 try { 30 try {
29 postMessageFunction(first, second, third); 31 postMessageFunction(first, second, third);
30 pass = !shouldFail; 32 pass = !shouldFail;
31 reason = " did not throw an exception"; 33 reason = " did not throw an exception";
32 } catch (e) { 34 } catch (e) {
33 pass = shouldFail; 35 pass = shouldFail;
34 reason = ": threw exception " + e; 36 reason = ": threw exception " + e;
35 } 37 }
36 console.innerHTML += (pass ? "PASS" : "FAIL") + ": Posting message ('" + fir st + "', " + third + ")" + reason + "<br>"; 38 if (pass)
39 testPassed("Posting message ('" + first + "', " + third + ")" + reason);
40 else
41 testFailed("Posting message ('" + first + "', " + third + ")" + reason);
37 } 42 }
38 43
39 function tryPostMessage(first, second, third, shouldFail) { 44 function tryPostMessage(first, second, third, shouldFail) {
40 tryPostMessageFunction(window.postMessage, first, second, third, shouldFail) ; 45 tryPostMessageFunction(window.postMessage, first, second, third, shouldFail) ;
41 } 46 }
42 47
43 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>"; 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>";
44 49
45 tryPostMessage('1', '*', 1, true); 50 tryPostMessage('1', '*', 1, true);
46 tryPostMessage('2', '*', 'c', true); // Legacy overload resolution will consider 3rd argument to be the (string) origin. 51 tryPostMessage('2', '*', 'c', true); // Legacy overload resolution will consider 3rd argument to be the (string) origin.
(...skipping 15 matching lines...) Expand all
62 var channel4 = new MessageChannel; 67 var channel4 = new MessageChannel;
63 tryPostMessageFunction(window.postMessage, channel4.port1, '*', [channel4.port1, channel4.port2]); 68 tryPostMessageFunction(window.postMessage, channel4.port1, '*', [channel4.port1, channel4.port2]);
64 var channel5 = new MessageChannel; 69 var channel5 = new MessageChannel;
65 tryPostMessageFunction(window.postMessage, [channel5.port1, channel5.port2], '*' , [channel5.port1, channel5.port2]); 70 tryPostMessageFunction(window.postMessage, [channel5.port1, channel5.port2], '*' , [channel5.port1, channel5.port2]);
66 tryPostMessageFunction(window.postMessage, 'data', '*', [channel5.port1, channel 5.port2], true); 71 tryPostMessageFunction(window.postMessage, 'data', '*', [channel5.port1, channel 5.port2], true);
67 tryPostMessageFunction(window.postMessage, [channel5.port1, channel5.port2], '*' , [], true); 72 tryPostMessageFunction(window.postMessage, [channel5.port1, channel5.port2], '*' , [], true);
68 73
69 var arrayBuffer = new ArrayBuffer(30); 74 var arrayBuffer = new ArrayBuffer(30);
70 var int8View = new Int8Array(arrayBuffer, 2, 10); 75 var int8View = new Int8Array(arrayBuffer, 2, 10);
71 tryPostMessageFunction(window.postMessage, arrayBuffer, '*', [arrayBuffer]); 76 tryPostMessageFunction(window.postMessage, arrayBuffer, '*', [arrayBuffer]);
72 if (!(arrayBuffer.byteLength === 0)) { 77 if (!(arrayBuffer.byteLength === 0))
73 console.innerHTML += "FAIL: arrayBuffer not neutered; byteLength = " + array Buffer.byteLength + "<br>"; 78 testFailed("arrayBuffer not neutered; byteLength = " + arrayBuffer.byteLengt h);
74 } 79 else
75 else { 80 testPassed("arrayBuffer neutered");
76 console.innerHTML += "PASS: arrayBuffer neutered<br>";
77 }
78 81
79 if (!(int8View.length == 0)) { 82 if (!(int8View.length == 0))
80 console.innerHTML += "FAIL: view was not neutered; length = " + int8View.len gth + "<br>"; 83 testFailed("view was not neutered; length = " + int8View.length);
81 } 84 else
82 else { 85 testPassed("view neutered");
83 console.innerHTML += "PASS: view neutered<br>" 86
84 }
85 tryPostMessageFunction(window.postMessage, arrayBuffer, '*', [], true); 87 tryPostMessageFunction(window.postMessage, arrayBuffer, '*', [], true);
86 tryPostMessageFunction(window.postMessage, 'data', '*', [arrayBuffer], true); 88 tryPostMessageFunction(window.postMessage, 'data', '*', [arrayBuffer], true);
87 89
88 tryPostMessageFunction(window.postMessage, int8View, '*', [], true); 90 tryPostMessageFunction(window.postMessage, int8View, '*', [], true);
89 tryPostMessageFunction(window.postMessage, 'data', '*', [int8View], true); 91 tryPostMessageFunction(window.postMessage, 'data', '*', [int8View], true);
90 92
91 tryPostMessageFunction(window.postMessage, 'data', '*', {length:1}, true); 93 tryPostMessageFunction(window.postMessage, 'data', '*', {length:1}, true);
92 tryPostMessageFunction(window.postMessage, 'data', '*', [1,,2], true); 94 tryPostMessageFunction(window.postMessage, 'data', '*', [1,,2], true);
93 tryPostMessageFunction(window.postMessage, 'data', '*', [null, window.postMessag e], true); 95 tryPostMessageFunction(window.postMessage, 'data', '*', [null, window.postMessag e], true);
94 96
97 shouldThrow("window.postMessage()");
98 shouldThrow("window.postMessage('a')");
99
95 tryPostMessageFunction(window.postMessage, 'done', '*'); 100 tryPostMessageFunction(window.postMessage, 'done', '*');
96 </script> 101 </script>
97 </body> 102 </body>
98 </html> 103 </html>
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/fast/dom/Window/window-postmessage-args-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698