Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!-- | 1 <!-- |
| 2 Copyright (C) 2012 Samsung Electronics. All rights reserved. | 2 Copyright (C) 2012 Samsung Electronics. All rights reserved. |
| 3 | 3 |
| 4 Redistribution and use in source and binary forms, with or without | 4 Redistribution and use in source and binary forms, with or without |
| 5 modification, are permitted provided that the following conditions | 5 modification, are permitted provided that the following conditions |
| 6 are met: | 6 are met: |
| 7 | 7 |
| 8 1. Redistributions of source code must retain the above copyright | 8 1. Redistributions of source code must retain the above copyright |
| 9 notice, this list of conditions and the following disclaimer. | 9 notice, this list of conditions and the following disclaimer. |
| 10 2. Redistributions in binary form must reproduce the above copyright | 10 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 * Evaluates string in page. | 242 * Evaluates string in page. |
| 243 * @param {string} message | 243 * @param {string} message |
| 244 * @param {!function} callback | 244 * @param {!function} callback |
| 245 */ | 245 */ |
| 246 InspectorTest.evaluateInPage = function(string, callback) | 246 InspectorTest.evaluateInPage = function(string, callback) |
| 247 { | 247 { |
| 248 this.sendCommand("Runtime.evaluate", { "expression": string }, function(mess age) { | 248 this.sendCommand("Runtime.evaluate", { "expression": string }, function(mess age) { |
| 249 if (message.error) | 249 if (message.error) |
| 250 InspectorTest.log("Error while executing '" + string + "': " + messa ge.error.message); | 250 InspectorTest.log("Error while executing '" + string + "': " + messa ge.error.message); |
| 251 else if (callback) | 251 else if (callback) |
| 252 callback(); | 252 callback(message.result.result.value); |
| 253 }); | 253 }); |
| 254 }; | 254 }; |
| 255 | 255 |
| 256 InspectorTest.completeTestIfError = function(messageObject) | 256 InspectorTest.completeTestIfError = function(messageObject) |
| 257 { | 257 { |
| 258 if (messageObject.error) { | 258 if (messageObject.error) { |
| 259 InspectorTest.log(messageObject.error.message); | 259 InspectorTest.log(messageObject.error.message); |
| 260 InspectorTest.completeTest(); | 260 InspectorTest.completeTest(); |
| 261 return true; | 261 return true; |
| 262 } | 262 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 281 * @param {string} scriptName | 281 * @param {string} scriptName |
| 282 */ | 282 */ |
| 283 InspectorTest.importScript = function(scriptName) | 283 InspectorTest.importScript = function(scriptName) |
| 284 { | 284 { |
| 285 var xhr = new XMLHttpRequest(); | 285 var xhr = new XMLHttpRequest(); |
| 286 xhr.open("GET", scriptName, false); | 286 xhr.open("GET", scriptName, false); |
| 287 xhr.send(null); | 287 xhr.send(null); |
| 288 window.eval(xhr.responseText + "\n//@ sourceURL=" + scriptName); | 288 window.eval(xhr.responseText + "\n//@ sourceURL=" + scriptName); |
| 289 } | 289 } |
| 290 | 290 |
| 291 InspectorTest.safeWrap = function(func, onexception) | |
| 292 { | |
| 293 function result() | |
| 294 { | |
| 295 if (!func) | |
| 296 return; | |
| 297 var wrapThis = this; | |
| 298 try { | |
| 299 return func.apply(wrapThis, arguments); | |
| 300 } catch(e) { | |
| 301 InspectorTest.log("Exception while running: " + func + "\n" + (e.sta ck || e)); | |
| 302 if (onexception) | |
| 303 InspectorTest.safeWrap(onexception)(); | |
| 304 else | |
| 305 InspectorTest.completeTest(); | |
| 306 } | |
| 307 } | |
| 308 return result; | |
| 309 } | |
| 310 | |
| 311 var lastPromiseEvalId = 0; | |
| 312 var pendingPromiseEvalRequests = {}; | |
| 313 | |
| 314 /** | |
| 315 * The given function should take two callback paraters before the arguments: | |
| 316 * * resolve - called when successful (with optional result) | |
| 317 * * reject - called when there was a failure (with optional error) | |
| 318 */ | |
| 319 InspectorTest.invokePageFunctionPromise = function(functionName, parameters) | |
| 320 { | |
| 321 return new Promise(function(resolve, reject) { | |
| 322 var id = ++lastPromiseEvalId; | |
| 323 pendingPromiseEvalRequests[id] = { resolve: InspectorTest.safeWrap(resol ve), reject: InspectorTest.safeWrap(reject) }; | |
| 324 | |
| 325 var jsonParameters = []; | |
| 326 for (var i = 0; i < parameters.length; ++i) | |
| 327 jsonParameters.push(JSON.stringify(parameters[i])); | |
| 328 var asyncEvalWrapper = function(callId, functionName, argumentsArray) | |
| 329 { | |
| 330 function evalCallbackResolve(result) | |
| 331 { | |
| 332 testRunner.evaluateInWebInspector(2, "InspectorTest.didInvokePag eFunctionPromise(" + callId + ", " + JSON.stringify(result) + ", true);"); | |
|
samli
2015/10/26 21:30:23
2 was evalCallbackCallId in inspector-test.js, but
pfeldman
2015/10/26 21:35:48
I don't think this number matters at all.
| |
| 333 } | |
| 334 | |
| 335 function evalCallbackReject(result) | |
| 336 { | |
| 337 testRunner.evaluateInWebInspector(2, "InspectorTest.didInvokePag eFunctionPromise(" + callId + ", " + JSON.stringify(result) + ", false);"); | |
| 338 } | |
| 339 | |
| 340 var args = [evalCallbackResolve, evalCallbackReject].concat(argument sArray.map(JSON.stringify)); | |
| 341 var functionCall = functionName + ".call(null, " + args.join(", ") + ")"; | |
| 342 try { | |
| 343 eval(functionCall); | |
| 344 } catch(e) { | |
| 345 InspectorTest.log("Error: " + e); | |
| 346 evalCallbackReject(e); | |
| 347 } | |
| 348 } | |
| 349 var pageRequest = "(" + asyncEvalWrapper.toString() + ")(" + id + ", une scape('" + escape(functionName) + "'), [" + jsonParameters.join(", ") + "])"; | |
| 350 InspectorTest.evaluateInPage(pageRequest); | |
| 351 }); | |
| 352 } | |
| 353 | |
| 354 InspectorTest.didInvokePageFunctionPromise = function(callId, value, didResolve) | |
| 355 { | |
| 356 var callbacks = pendingPromiseEvalRequests[callId]; | |
| 357 if (!callbacks) { | |
| 358 InspectorTest.log("Missing callback for async eval " + callId + ", perha ps callback invoked twice?"); | |
| 359 return; | |
| 360 } | |
| 361 var callback = didResolve ? callbacks.resolve : callbacks.reject; | |
| 362 delete pendingPromiseEvalRequests[callId]; | |
| 363 callback(value); | |
| 364 } | |
| 291 | 365 |
| 292 InspectorTest.eventHandler["Inspector.evaluateForTestInFrontend"] = function(mes sage) | 366 InspectorTest.eventHandler["Inspector.evaluateForTestInFrontend"] = function(mes sage) |
| 293 { | 367 { |
| 294 try { | 368 try { |
| 295 eval(message.params.script); | 369 eval(message.params.script); |
| 296 } catch (e) { | 370 } catch (e) { |
| 297 InspectorTest.log("FAIL: exception in evaluateForTestInFrontend: " + e); | 371 InspectorTest.log("FAIL: exception in evaluateForTestInFrontend: " + e); |
| 298 InspectorTest.completeTest(); | 372 InspectorTest.completeTest(); |
| 299 } | 373 } |
| 300 }; | 374 }; |
| 301 | 375 |
| 302 function enableInspectorAgent() | 376 function enableInspectorAgent() |
| 303 { | 377 { |
| 304 InspectorTest.sendCommand("Inspector.enable", { }); | 378 InspectorTest.sendCommand("Inspector.enable", { }); |
| 305 } | 379 } |
| 306 | 380 |
| 307 window.addEventListener("load", enableInspectorAgent, false); | 381 window.addEventListener("load", enableInspectorAgent, false); |
| 308 | 382 |
| 309 </script> | 383 </script> |
| 310 </head> | 384 </head> |
| 311 </html> | 385 </html> |
| OLD | NEW |