OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Samsung Electronics. All rights reserved. | 2 * Copyright (C) 2012 Samsung Electronics. All rights reserved. |
3 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
11 * 2. Redistributions in binary form must reproduce the above copyright | 11 * 2. Redistributions in binary form must reproduce the above copyright |
12 * notice, this list of conditions and the following disclaimer in the | 12 * notice, this list of conditions and the following disclaimer in the |
13 * documentation and/or other materials provided with the distribution. | 13 * documentation and/or other materials provided with the distribution. |
14 * | 14 * |
15 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | 15 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
18 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | 18 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 */ | 25 */ |
| 26 |
| 27 var initialize_InspectorTest = function() { |
| 28 |
26 InspectorFrontendAPI = {}; | 29 InspectorFrontendAPI = {}; |
27 | 30 |
28 InspectorTest = {}; | 31 InspectorTest = {}; |
29 InspectorTest._dispatchTable = []; | 32 InspectorTest._dispatchTable = []; |
30 InspectorTest._requestId = -1; | 33 InspectorTest._requestId = -1; |
31 InspectorTest.eventHandler = {}; | 34 InspectorTest.eventHandler = {}; |
32 | 35 |
33 /** | 36 /** |
34 * @param {string} method | 37 * @param {string} method |
35 * @param {object} params | 38 * @param {object} params |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 dumpValue(object[i], " " + prefix, " " + prefix + "[" + i + "]
: "); | 161 dumpValue(object[i], " " + prefix, " " + prefix + "[" + i + "]
: "); |
159 lines.push(prefix + "]"); | 162 lines.push(prefix + "]"); |
160 } | 163 } |
161 | 164 |
162 dumpValue(object, "", title); | 165 dumpValue(object, "", title); |
163 InspectorTest.log(lines.join("\n")); | 166 InspectorTest.log(lines.join("\n")); |
164 } | 167 } |
165 | 168 |
166 /** | 169 /** |
167 * Logs message directly to process stdout via alert function (hopefully followed
by flush call). | 170 * Logs message directly to process stdout via alert function (hopefully followed
by flush call). |
168 * This message should survive process crash or kill by timeout. | 171 * This message should survive process crash or kill by timeout. |
169 * @param {string} message | 172 * @param {string} message |
170 */ | 173 */ |
171 InspectorTest.debugLog = function(message) | 174 InspectorTest.debugLog = function(message) |
172 { | 175 { |
173 this.sendCommand("Runtime.evaluate", { "expression": "debugLog(" + JSON.stri
ngify(message) + ")" } ); | 176 this.sendCommand("Runtime.evaluate", { "expression": "debugLog(" + JSON.stri
ngify(message) + ")" } ); |
174 } | 177 } |
175 | 178 |
176 InspectorTest.completeTest = function() | 179 InspectorTest.completeTest = function() |
177 { | 180 { |
178 this.sendCommand("Runtime.evaluate", { "expression": "closeTest();"} ); | 181 this.sendCommand("Runtime.evaluate", { "expression": "closeTest();"} ); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 * @param {string} scriptName | 224 * @param {string} scriptName |
222 */ | 225 */ |
223 InspectorTest.importScript = function(scriptName) | 226 InspectorTest.importScript = function(scriptName) |
224 { | 227 { |
225 var xhr = new XMLHttpRequest(); | 228 var xhr = new XMLHttpRequest(); |
226 xhr.open("GET", scriptName, false); | 229 xhr.open("GET", scriptName, false); |
227 xhr.send(null); | 230 xhr.send(null); |
228 window.eval(xhr.responseText + "\n//@ sourceURL=" + scriptName); | 231 window.eval(xhr.responseText + "\n//@ sourceURL=" + scriptName); |
229 } | 232 } |
230 | 233 |
231 window.addEventListener("message", function(event) { | 234 }; |
232 try { | 235 |
233 eval(event.data); | 236 var outputElement; |
234 } catch (e) { | 237 |
235 alert(e.stack); | 238 /** |
236 InspectorTest.completeTest(); | 239 * Logs message to process stdout via alert (hopefully implemented with immediat
e flush). |
237 throw e; | 240 * @param {string} text |
| 241 */ |
| 242 function debugLog(text) |
| 243 { |
| 244 alert(text); |
| 245 } |
| 246 |
| 247 /** |
| 248 * @param {string} text |
| 249 */ |
| 250 function log(text) |
| 251 { |
| 252 if (!outputElement) { |
| 253 var intermediate = document.createElement("div"); |
| 254 document.body.appendChild(intermediate); |
| 255 |
| 256 var intermediate2 = document.createElement("div"); |
| 257 intermediate.appendChild(intermediate2); |
| 258 |
| 259 outputElement = document.createElement("div"); |
| 260 outputElement.className = "output"; |
| 261 outputElement.id = "output"; |
| 262 outputElement.style.whiteSpace = "pre"; |
| 263 intermediate2.appendChild(outputElement); |
238 } | 264 } |
239 }); | 265 outputElement.appendChild(document.createTextNode(text)); |
| 266 outputElement.appendChild(document.createElement("br")); |
| 267 } |
| 268 |
| 269 function closeTest() |
| 270 { |
| 271 closeInspector(); |
| 272 testRunner.notifyDone(); |
| 273 } |
| 274 |
| 275 function runTest() |
| 276 { |
| 277 if (!window.testRunner) { |
| 278 console.error("This test requires DumpRenderTree"); |
| 279 return; |
| 280 } |
| 281 testRunner.dumpAsText(); |
| 282 testRunner.waitUntilDone(); |
| 283 testRunner.setCanOpenWindows(true); |
| 284 |
| 285 openInspector(); |
| 286 } |
| 287 |
| 288 function closeInspector() |
| 289 { |
| 290 window.internals.closeDummyInspectorFrontend(); |
| 291 } |
| 292 |
| 293 function openInspector() |
| 294 { |
| 295 var scriptTags = document.getElementsByTagName("script"); |
| 296 var scriptUrlBasePath = ""; |
| 297 for (var i = 0; i < scriptTags.length; ++i) { |
| 298 var index = scriptTags[i].src.lastIndexOf("/inspector-protocol-test.js")
; |
| 299 if (index > -1 ) { |
| 300 scriptUrlBasePath = scriptTags[i].src.slice(0, index); |
| 301 break; |
| 302 } |
| 303 } |
| 304 |
| 305 var dummyFrontendURL = scriptUrlBasePath + "/resources/protocol-test.html"; |
| 306 var inspectorFrontend = window.internals.openDummyInspectorFrontend(dummyFro
ntendURL); |
| 307 inspectorFrontend.addEventListener("load", function(event) { |
| 308 // FIXME: rename this 'test' global field across all tests. |
| 309 var testFunction = window.test; |
| 310 if (typeof testFunction === "function") { |
| 311 var initializers = ""; |
| 312 for (var symbol in window) { |
| 313 if (!/^initialize_/.test(symbol) || typeof window[symbol] !== "f
unction") |
| 314 continue; |
| 315 initializers += "(" + window[symbol].toString() + ")();\n"; |
| 316 } |
| 317 inspectorFrontend.postMessage(initializers + "(" + testFunction.toSt
ring() +")();", "*"); |
| 318 return; |
| 319 } |
| 320 // Kill waiting process if failed to send. |
| 321 alert("Failed to send test function"); |
| 322 testRunner.notifyDone(); |
| 323 }); |
| 324 } |
OLD | NEW |