| OLD | NEW |
| (Empty) |
| 1 if (window.testRunner) { | |
| 2 testRunner.dumpAsText(); | |
| 3 testRunner.waitUntilDone(); | |
| 4 } | |
| 5 | |
| 6 var console = document.getElementById("console"); | |
| 7 | |
| 8 var messages = []; | |
| 9 var evalThunks = []; | |
| 10 | |
| 11 function equal(actual, expected) | |
| 12 { | |
| 13 if (actual === expected) | |
| 14 return true; | |
| 15 if (typeof actual !== typeof expected) | |
| 16 return false; | |
| 17 if ((actual instanceof Date) || (expected instanceof Date)) { | |
| 18 if ((actual instanceof Date) && (expected instanceof Date)) | |
| 19 return (expected instanceof Date) && actual.getTime() == expected.ge
tTime(); | |
| 20 return false; | |
| 21 } | |
| 22 if ((actual instanceof Number) || (expected instanceof Number)) { | |
| 23 return (actual instanceof Number) && (expected instanceof Number) && | |
| 24 (expected.valueOf() == actual.valueOf()); | |
| 25 } | |
| 26 if ((actual instanceof Boolean) || (expected instanceof Boolean)) { | |
| 27 return (actual instanceof Boolean) && (expected instanceof Boolean) && | |
| 28 (expected.valueOf() == actual.valueOf()); | |
| 29 } | |
| 30 if ((actual instanceof String) || (expected instanceof String)) { | |
| 31 return (actual instanceof String) && (expected instanceof String) && | |
| 32 (expected.valueOf() == actual.valueOf()); | |
| 33 } | |
| 34 if (Array.isArray(actual) || Array.isArray(expected)) { | |
| 35 if (!Array.isArray(actual) || !Array.isArray(expected)) | |
| 36 return false; | |
| 37 if (actual.length != expected.length) | |
| 38 return false; | |
| 39 for (var i = 0; i < actual.length; i++) { | |
| 40 if ((i in actual) ^ (i in expected)) | |
| 41 return false; | |
| 42 if (!equal(actual[i], expected[i])) | |
| 43 return false; | |
| 44 } | |
| 45 return true; | |
| 46 } | |
| 47 if (actual.constructor !== expected.constructor) | |
| 48 return false; | |
| 49 try { | |
| 50 var keys = Object.keys(actual); | |
| 51 } catch(e) { | |
| 52 return false; | |
| 53 } | |
| 54 try { | |
| 55 if (!equal(keys, Object.keys(expected))) | |
| 56 return false; | |
| 57 } catch(e) { | |
| 58 return false; | |
| 59 } | |
| 60 for (var i = 0; i < keys.length; i++) { | |
| 61 if (!equal(actual[keys[i]], expected[keys[i]])) | |
| 62 return false; | |
| 63 } | |
| 64 return true; | |
| 65 } | |
| 66 | |
| 67 function safeToString(o) { | |
| 68 if (o instanceof Date) | |
| 69 return o.toISOString(); | |
| 70 if (typeof o !== "object" || !o) | |
| 71 return o; | |
| 72 try { | |
| 73 return o.toString(); | |
| 74 } catch (e) { | |
| 75 return Object.prototype.toString.call(o) + "(default toString threw "+e+
")"; | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 function escapeHTML(text) { | |
| 80 // Coerce to string, then replace characters that need HTML escaping. | |
| 81 return (text+'').replace(/&/g, "&").replace(/</g, "<").replace(/>/g,
">"); | |
| 82 } | |
| 83 | |
| 84 function shouldBe(actual, expected) | |
| 85 { | |
| 86 var actualValue = eval(actual); | |
| 87 var expectedValue = eval(expected); | |
| 88 if (equal(actualValue, expectedValue)) | |
| 89 console.innerHTML += "PASS: " + actual + " is " + safeToString(expectedV
alue) + " of type " + typeof actualValue + "<br>"; | |
| 90 else | |
| 91 console.innerHTML += "FAIL: " + actual + " is " + actualValue + " should
be " + expectedValue + " of type " + typeof expectedValue + "<br>"; | |
| 92 } | |
| 93 | |
| 94 function shouldBeIdentical(actual, expected) | |
| 95 { | |
| 96 var actualValue = eval(actual); | |
| 97 var expectedValue = eval(expected); | |
| 98 if (actualValue === expectedValue) | |
| 99 console.innerHTML += "PASS: " + actual + " is === to " + expected + "<br
>"; | |
| 100 else | |
| 101 console.innerHTML += "FAIL: " + actual + " is not === to " + expected +
"<br>"; | |
| 102 } | |
| 103 | |
| 104 function doPass(msg) { | |
| 105 console.innerHTML += "PASS: " + msg + "<br>"; | |
| 106 } | |
| 107 | |
| 108 function doFail(msg) { | |
| 109 console.innerHTML += "FAIL: " + msg + "<br>"; | |
| 110 } | |
| 111 | |
| 112 window.doPassFail = function(result, msg) { | |
| 113 console.innerHTML += (result ? "PASS: " : "FAIL: ") + msg + "<br>"; | |
| 114 } | |
| 115 | |
| 116 function onmessage(evt) { | |
| 117 eventData = evt.data; | |
| 118 if (evt.data !== evt.data) | |
| 119 console.innerHTML += "MessageEvent.data does not produce the same value
on multiple queries. " + evt.data + ", " + evt.data + "<br>"; | |
| 120 var message = messages.shift(); | |
| 121 switch (message) { | |
| 122 case "cyclicObject": | |
| 123 shouldBeIdentical("eventData", "eventData.self"); | |
| 124 break; | |
| 125 case "cyclicArray": | |
| 126 shouldBeIdentical("eventData", "eventData[0]"); | |
| 127 break; | |
| 128 case "objectGraph": | |
| 129 shouldBeIdentical("eventData.graph1", "eventData.graph2"); | |
| 130 break; | |
| 131 case "arrayGraph": | |
| 132 shouldBeIdentical("eventData[0]", "eventData[1]"); | |
| 133 break; | |
| 134 case "evalThunk": | |
| 135 var thunk = evalThunks.shift(); | |
| 136 try { | |
| 137 thunk(eventData); | |
| 138 } catch(e) { | |
| 139 doFail("threw exception: " + e); | |
| 140 throw e; | |
| 141 } | |
| 142 break; | |
| 143 default: | |
| 144 shouldBe("eventData", message); | |
| 145 } | |
| 146 | |
| 147 if (safeToString(evt.data) == 'done' && window.testRunner) | |
| 148 testRunner.notifyDone(); | |
| 149 } | |
| 150 | |
| 151 window.addEventListener('message', onmessage, false); | |
| 152 | |
| 153 function ConstructorWithPrototype(s) { | |
| 154 this.field = s; | |
| 155 } | |
| 156 | |
| 157 ConstructorWithPrototype.prototype = { | |
| 158 protoProperty: 2010 | |
| 159 }; | |
| 160 | |
| 161 window.tryPostMessage = function(message, shouldThrow, expected, expectedExcepti
onOrEvalThunk, transferables) { | |
| 162 if (expected == "evalThunk") { | |
| 163 var evalThunk = expectedExceptionOrEvalThunk; | |
| 164 } else { | |
| 165 var expectedException = expectedExceptionOrEvalThunk; | |
| 166 } | |
| 167 try { | |
| 168 var value = eval(message); | |
| 169 postMessage(value, "*", transferables); | |
| 170 if (shouldThrow) | |
| 171 console.innerHTML += "FAIL: 'postMessage("+message+")' should throw
but didn't<br>"; | |
| 172 messages.push(expected || message); | |
| 173 if (expected == "evalThunk") { | |
| 174 evalThunks.push(evalThunk); | |
| 175 } | |
| 176 } catch(e) { | |
| 177 if (shouldThrow) { | |
| 178 if (expectedException === undefined || expectedException == e.code |
| expectedException == e || e instanceof expectedException) { | |
| 179 console.innerHTML += "PASS: 'postMessage("+message+")' threw " +
escapeHTML(e) + "<br>"; | |
| 180 } else { | |
| 181 console.innerHTML += "FAIL: 'postMessage("+message+")' threw " +
escapeHTML(e) + ", was expecting " + escapeHTML(expectedException) + "<br>"; | |
| 182 } | |
| 183 } else | |
| 184 console.innerHTML += "FAIL: 'postMessage("+message+")' should not th
row but threw " + e + "<br>"; | |
| 185 } | |
| 186 } | |
| OLD | NEW |