Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / Window / anonymous-slot-with-changes.html
blob0db595d5e00e3e17ea3079697078c3599bcde513
1 <html>
2 <head></head>
3 <body>
4 <div id="description"></div>
5 <div id="console"></div>
6 <input type="file" id="fileInput"></input>
7 <script>
8 if (window.testRunner) {
9 testRunner.dumpAsText();
10 testRunner.waitUntilDone();
13 var console = document.getElementById("console");
15 var messages = [];
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 var keys = Object.keys(actual);
44 if (!equal(keys, Object.keys(expected)))
45 return false;
46 for (var i = 0; i < keys.length; i++) {
47 if (!equal(actual[keys[i]], expected[keys[i]]))
48 return false;
50 return true;
53 function safeToString(o) {
54 if (o instanceof Date)
55 return o.toISOString();
56 if (typeof o !== "object" || !o)
57 return o;
58 try {
59 return o.toString();
60 } catch (e) {
61 return Object.prototype.toString.call(o) + "(default toString threw "+e+")";
65 function shouldBe(actual, expected)
67 var actualValue = eval(actual);
68 var expectedValue = eval(expected);
69 if (equal(actualValue, expectedValue))
70 console.innerHTML += "PASS: " + actual + " is " + safeToString(expectedValue) + " of type " + typeof actualValue + "<br>";
71 else
72 console.innerHTML += "FAIL: " + actual + " is " + actualValue + " should be " + expectedValue + " of type " + typeof expectedValue + "<br>";
75 function onmessage(evt) {
76 evt.foo = "bar"; // add a property.
77 eventData = evt.data;
78 shouldBe("eventData", messages[0]);
79 evt.func = function(){}; // add a function property.
80 eventData = evt.data;
81 shouldBe("eventData", messages[0]);
82 evt.func = ""; // despecialise a function property.
83 eventData = evt.data;
84 shouldBe("eventData", messages[0]);
85 for (var i = 0; i < 1000; i++) // To dictionary transition
86 evt[i] = i;
87 eventData = evt.data;
88 shouldBe("eventData", messages[0]);
89 delete evt.foo; // To uncachable dictionary
90 eventData = evt.data;
91 shouldBe("eventData", messages[0]);
92 messages.shift();
93 if (safeToString(evt.data) == 'done' && window.testRunner)
94 testRunner.notifyDone();
97 window.addEventListener('message', onmessage, false);
99 function tryPostMessage(message, shouldThrow, expected) {
100 try {
101 var value = eval(message);
102 postMessage(value, "*");
103 if (shouldThrow)
104 console.innerHTML += "FAIL: 'postMessage("+message+")' should throw but didn't<br>";
105 messages.push(expected || message);
106 } catch(e) {
107 if (shouldThrow)
108 console.innerHTML += "PASS: 'postMessage("+message+")' threw " + e + "<br>";
109 else
110 console.innerHTML += "FAIL: 'postMessage("+message+")' should not throw but threw " + e + "<br>";
114 document.getElementById("description").innerHTML = "Tests that we clone object hierarchies";
116 tryPostMessage('null');
117 tryPostMessage('undefined');
118 tryPostMessage('1');
119 tryPostMessage('true');
120 tryPostMessage('"1"');
121 tryPostMessage('({})');
122 tryPostMessage('({a:1})');
123 tryPostMessage('[]');
124 tryPostMessage('[1,2,3]');
125 tryPostMessage('[,,1]');
126 tryPostMessage('(function(){})', true);
127 tryPostMessage('new Date(1234567890000)');
128 tryPostMessage('"done"');
129 </script>
130 </body>
131 </html>