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

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

Issue 2810543002: [tests] Convert a detached typed array to a null string (Closed)
Patch Set: clean up Created 3 years, 8 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
OLDNEW
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 // Represent detached TypedArrays as ""
adamk 2017/04/11 15:13:33 This comment doesn't match what the code does.
Choongwoo Han 2017/04/11 15:16:15 Done.
30 if (obj instanceof Int8Array && obj.byteLength === 0)
31 return "[detached TypedArray]";
32 return obj;
33 }
34
35 function convertArrayDetached(obj) {
36 if (obj instanceof Array)
37 return obj.map(convertDetached)
38 return obj;
39 }
40
28 function tryPostMessageFunction(postMessageFunction, first, second, third, shoul dFail) { 41 function tryPostMessageFunction(postMessageFunction, first, second, third, shoul dFail) {
29 var pass, reason; 42 var pass, reason;
30 try { 43 try {
31 postMessageFunction(first, second, third); 44 postMessageFunction(first, second, third);
32 pass = !shouldFail; 45 pass = !shouldFail;
33 reason = " did not throw an exception"; 46 reason = " did not throw an exception";
34 } catch (e) { 47 } catch (e) {
35 pass = shouldFail; 48 pass = shouldFail;
36 reason = ": threw exception " + e; 49 reason = ": threw exception " + e;
37 } 50 }
38 if (pass) 51 if (pass)
39 testPassed("Posting message ('" + first + "', " + third + ")" + reason); 52 testPassed("Posting message ('" + convertDetached(first) + "', " + conve rtArrayDetached(third) + ")" + reason);
40 else 53 else
41 testFailed("Posting message ('" + first + "', " + third + ")" + reason); 54 testFailed("Posting message ('" + convertDetached(first) + "', " + conve rtArrayDetached(third) + ")" + reason);
42 } 55 }
43 56
44 function tryPostMessage(first, second, third, shouldFail) { 57 function tryPostMessage(first, second, third, shouldFail) {
45 tryPostMessageFunction(window.postMessage, first, second, third, shouldFail) ; 58 tryPostMessageFunction(window.postMessage, first, second, third, shouldFail) ;
46 } 59 }
47 60
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>"; 61 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 62
50 tryPostMessage('1', '*', 1, true); 63 tryPostMessage('1', '*', 1, true);
51 tryPostMessage('2', '*', 'c', true); 64 tryPostMessage('2', '*', 'c', true);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 tryPostMessageFunction(window.postMessage, 'data', '*', [1,,2], true); 105 tryPostMessageFunction(window.postMessage, 'data', '*', [1,,2], true);
93 tryPostMessageFunction(window.postMessage, 'data', '*', [null, window.postMessag e], true); 106 tryPostMessageFunction(window.postMessage, 'data', '*', [null, window.postMessag e], true);
94 107
95 shouldThrow("window.postMessage()"); 108 shouldThrow("window.postMessage()");
96 shouldThrow("window.postMessage('a')"); 109 shouldThrow("window.postMessage('a')");
97 110
98 tryPostMessageFunction(window.postMessage, 'done', '*'); 111 tryPostMessageFunction(window.postMessage, 'done', '*');
99 </script> 112 </script>
100 </body> 113 </body>
101 </html> 114 </html>
OLDNEW
« no previous file with comments | « AUTHORS ('k') | third_party/WebKit/LayoutTests/fast/dom/Window/window-postmessage-args-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698