Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / Window / window-postmessage-clone-frames.html
blob648eea245aba96806fd9751dcb71ed933b841574
1 <html>
2 <head></head>
3 <body>
4 <div id="description"></div>
5 <input type="file" id="fileInput">
6 <div id="console"></div>
7 <script>
8 if (window.testRunner) {
9 testRunner.dumpAsText();
10 testRunner.waitUntilDone();
13 var console = document.getElementById("console");
15 var tests = [];
17 function equal(actual, expected)
19 if (typeof actual !== typeof expected)
20 return false;
21 if (actual === expected)
22 return true;
23 if ((actual instanceof Date) || (expected instanceof Date)) {
24 if ((actual instanceof Date) && (expected instanceof Date))
25 return (expected instanceof Date) && actual.getTime() == expected.getTime();
26 return false;
28 if (Array.isArray(actual) || Array.isArray(expected)) {
29 if (!Array.isArray(actual) || !Array.isArray(expected))
30 return false;
31 if (actual.length != expected.length)
32 return false;
33 for (var i = 0; i < actual.length; i++) {
34 if ((i in actual) ^ (i in expected))
35 return false;
36 if (!equal(actual[i], expected[i]))
37 return false;
39 return true;
41 if (actual.constructor !== expected.constructor)
42 return false;
43 if ("object" != typeof actual)
44 return false;
45 var keys = Object.keys(actual);
46 if (!equal(keys, Object.keys(expected)))
47 return false;
48 for (var i = 0; i < keys.length; i++) {
49 if (!equal(actual[keys[i]], expected[keys[i]]))
50 return false;
52 return true;
55 function safeToString(o) {
56 if (o instanceof Date)
57 return o.toISOString();
58 if (typeof o !== "object" || !o)
59 return o;
60 try {
61 return o.toString();
62 } catch (e) {
63 return Object.prototype.toString.call(o) + "(default toString threw "+e+")";
67 function shouldBe(actual, expected)
69 var actualValue = eval(actual);
70 var expectedValue = eval(expected);
71 if (equal(actualValue, expectedValue))
72 console.innerHTML += "PASS: " + actual + " is " + safeToString(expectedValue) + " of type " + typeof actualValue + "<br>";
73 else
74 console.innerHTML += "FAIL: " + actual + " is " + actualValue + " should be " + expectedValue + " of type " + typeof expectedValue + "<br>";
76 var i = 0;
77 window.onmessage = function(evt) {
78 if (safeToString(frames[0].tests[i].eventData) == 'done') {
79 if (window.testRunner)
80 testRunner.notifyDone();
81 return;
84 shouldBe("(frames[0].tests["+i+"]).eventData instanceof (frames[0])."+tests[i].constructor, "true");
85 shouldBe("(frames[0].tests["+i+"]).event.data instanceof (frames[0])."+tests[i].constructor, "true");
86 i++;
89 function tryPostMessage(message, constructor) {
90 try {
91 var value = eval(message);
92 frames[0].postMessage(value, "*");
93 tests.push({constructor: constructor});
94 } catch(e) {
95 console.innerHTML += "FAIL: 'postMessage("+message+")' should not throw but threw " + e + "<br>";
99 document.getElementById("description").innerHTML = "Tests that we clone object hierarchies";
101 function startTest() {
102 tryPostMessage('({})', "Object");
103 tryPostMessage('[]', "Array");
104 tryPostMessage('new Date', "Date");
105 var fileInput = document.getElementById("fileInput");
106 var fileRect = fileInput.getClientRects()[0];
107 var targetX = fileRect.left + fileRect.width / 2;
108 var targetY = fileRect.top + fileRect.height / 2;
109 if (window.eventSender) {
110 eventSender.beginDragWithFiles(['get-file-upload.html']);
111 eventSender.mouseMoveTo(targetX, targetY);
112 eventSender.mouseUp();
113 tryPostMessage('fileInput.files[0]', "File");
114 tryPostMessage('fileInput.files', "FileList");
116 tryPostMessage('"done"');
118 </script>
119 <iframe src="resources/window-postmessage-clone-frames-frame.html" onload="startTest()"></iframe>
120 </body>
121 </html>