4 <div id=
"description"></div>
5 <input type=
"file" id=
"fileInput">
6 <div id=
"console"></div>
8 if (window
.testRunner
) {
9 testRunner
.dumpAsText();
10 testRunner
.waitUntilDone();
13 var console
= document
.getElementById("console");
17 function equal(actual
, expected
)
19 if (typeof actual
!== typeof expected
)
21 if (actual
=== expected
)
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();
28 if (Array
.isArray(actual
) || Array
.isArray(expected
)) {
29 if (!Array
.isArray(actual
) || !Array
.isArray(expected
))
31 if (actual
.length
!= expected
.length
)
33 for (var i
= 0; i
< actual
.length
; i
++) {
34 if ((i
in actual
) ^ (i
in expected
))
36 if (!equal(actual
[i
], expected
[i
]))
41 if (actual
.constructor !== expected
.constructor)
43 if ("object" != typeof actual
)
45 var keys
= Object
.keys(actual
);
46 if (!equal(keys
, Object
.keys(expected
)))
48 for (var i
= 0; i
< keys
.length
; i
++) {
49 if (!equal(actual
[keys
[i
]], expected
[keys
[i
]]))
55 function safeToString(o
) {
56 if (o
instanceof Date
)
57 return o
.toISOString();
58 if (typeof o
!== "object" || !o
)
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>";
74 console
.innerHTML
+= "FAIL: " + actual
+ " is " + actualValue
+ " should be " + expectedValue
+ " of type " + typeof expectedValue
+ "<br>";
77 window
.onmessage = function(evt
) {
78 if (safeToString(frames
[0].tests
[i
].eventData
) == 'done') {
79 if (window
.testRunner
)
80 testRunner
.notifyDone();
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");
89 function tryPostMessage(message
, constructor) {
91 var value
= eval(message
);
92 frames
[0].postMessage(value
, "*");
93 tests
.push({constructor: constructor});
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"');
119 <iframe src=
"resources/window-postmessage-clone-frames-frame.html" onload=
"startTest()"></iframe>