Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 if (window.GCController) | 1 if (window.GCController) |
| 2 GCController.collectAll(); | 2 GCController.collectAll(); |
| 3 var initialize_InspectorTest = function() { | 3 var initialize_InspectorTest = function() { |
| 4 | 4 |
| 5 var results = []; | 5 var results = []; |
| 6 | 6 |
| 7 function consoleOutputHook(messageType) | 7 function consoleOutputHook(messageType) |
| 8 { | 8 { |
| 9 InspectorTest.addResult(messageType + ": " + Array.prototype.slice.call(argu ments, 1)); | 9 InspectorTest.addResult(messageType + ": " + Array.prototype.slice.call(argu ments, 1)); |
| 10 } | 10 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 callback(InspectorTest.runtimeModel.createRemoteObject(result), wasT hrown); | 49 callback(InspectorTest.runtimeModel.createRemoteObject(result), wasT hrown); |
| 50 } | 50 } |
| 51 InspectorTest.RuntimeAgent.evaluate(code, "console", false, mycallback); | 51 InspectorTest.RuntimeAgent.evaluate(code, "console", false, mycallback); |
| 52 } | 52 } |
| 53 | 53 |
| 54 InspectorTest.evaluateInPagePromise = function(code) | 54 InspectorTest.evaluateInPagePromise = function(code) |
| 55 { | 55 { |
| 56 return new Promise(succ => InspectorTest.evaluateInPage(code, succ)); | 56 return new Promise(succ => InspectorTest.evaluateInPage(code, succ)); |
| 57 } | 57 } |
| 58 | 58 |
| 59 InspectorTest.evaluateInPageAsync = function(code) | |
| 60 { | |
| 61 var callback; | |
| 62 var promise = new Promise((fulfill) => callback = fulfill); | |
| 63 InspectorTest.RuntimeAgent.evaluate(code, | |
| 64 "console", | |
| 65 /* includeCommandLineAPI */ false, | |
| 66 /* doNotPauseOnExceptionsAndMuteConsole */ undefined, | |
| 67 /* contextId */ undefined, | |
| 68 /* returnByValue */ undefined, | |
| 69 /* generatePreview */ undefined, | |
| 70 /* userGesture */ undefined, | |
| 71 /* awaitPromise */ true, | |
| 72 mycallback); | |
| 73 | |
| 74 function mycallback(error, result, wasThrown) | |
| 75 { | |
| 76 if (!error) | |
|
dgozman
2016/08/03 22:46:58
Let's log something and completeTest otherwise, or
kozy
2016/08/03 23:48:39
Done.
| |
| 77 callback(InspectorTest.runtimeModel.createRemoteObject(result), wasT hrown); | |
|
dgozman
2016/08/03 22:46:58
There is no way to pass two arguments to a promise
kozy
2016/08/03 23:48:39
Done.
| |
| 78 } | |
| 79 return promise; | |
| 80 } | |
| 81 | |
| 82 InspectorTest.callFunctionInPageAsync = function(name, args) | |
| 83 { | |
| 84 args = args || []; | |
| 85 return InspectorTest.evaluateInPageAsync(name + "(" + args.map(JSON.stringif y).join(",") + ")"); | |
| 86 } | |
| 87 | |
| 59 InspectorTest.evaluateInPageWithTimeout = function(code) | 88 InspectorTest.evaluateInPageWithTimeout = function(code) |
| 60 { | 89 { |
| 61 // FIXME: we need a better way of waiting for chromium events to happen | 90 // FIXME: we need a better way of waiting for chromium events to happen |
| 62 InspectorTest.evaluateInPage("setTimeout(unescape('" + escape(code) + "'), 1 )"); | 91 InspectorTest.evaluateInPage("setTimeout(unescape('" + escape(code) + "'), 1 )"); |
| 63 } | 92 } |
| 64 | 93 |
| 65 InspectorTest.evaluateFunctionInOverlay = function(func, callback) | 94 InspectorTest.evaluateFunctionInOverlay = function(func, callback) |
| 66 { | 95 { |
| 67 var expression = "testRunner.evaluateInWebInspectorOverlay(\"(\" + " + func + " + \")()\")"; | 96 var expression = "testRunner.evaluateInWebInspectorOverlay(\"(\" + " + func + " + \")()\")"; |
| 68 var mainContext = InspectorTest.runtimeModel.executionContexts()[0]; | 97 var mainContext = InspectorTest.runtimeModel.executionContexts()[0]; |
| 69 mainContext.evaluate(expression, "", false, false, true, false, false, wrapC allback); | 98 mainContext.evaluate(expression, "", false, false, true, false, false, wrapC allback); |
| 70 | 99 |
| 71 function wrapCallback(val, err, result) | 100 function wrapCallback(val, err, result) |
| 72 { | 101 { |
| 73 callback(result.value) | 102 callback(result.value) |
| 74 } | 103 } |
| 75 } | 104 } |
| 76 | 105 |
| 77 InspectorTest.waitForOverlayRepaint = function(callback) | 106 InspectorTest.waitForOverlayRepaint = function(callback) |
| 78 { | 107 { |
| 79 InspectorTest.invokePageFunctionAsync("requestAnimationFrame", callback); | 108 InspectorTest.invokePageFunctionAsync("requestAnimationFrame", callback); |
| 80 } | 109 } |
| 81 | 110 |
| 82 var lastEvalId = 0; | 111 var lastEvalId = 0; |
| 83 var pendingEvalRequests = {}; | 112 var pendingEvalRequests = {}; |
| 84 | 113 |
| 85 var lastPromiseEvalId = 0; | |
| 86 var pendingPromiseEvalRequests = {}; | |
| 87 | |
| 88 /** | |
| 89 * The given function should take two callback paraters before the arguments: | |
| 90 * * resolve - called when successful (with optional result) | |
| 91 * * reject - called when there was a failure (with optional error) | |
| 92 */ | |
| 93 InspectorTest.invokePageFunctionPromise = function(functionName, parameters) | |
| 94 { | |
| 95 return new Promise(function(resolve, reject) { | |
| 96 var id = ++lastPromiseEvalId; | |
| 97 pendingPromiseEvalRequests[id] = { resolve: InspectorTest.safeWrap(resol ve), reject: InspectorTest.safeWrap(reject) }; | |
| 98 | |
| 99 var jsonParameters = []; | |
| 100 for (var i = 0; i < parameters.length; ++i) | |
| 101 jsonParameters.push(JSON.stringify(parameters[i])); | |
| 102 var asyncEvalWrapper = function(callId, functionName, argumentsArray) | |
| 103 { | |
| 104 function evalCallbackResolve(result) | |
| 105 { | |
| 106 testRunner.evaluateInWebInspector(evalCallbackCallId, "Inspector Test.didInvokePageFunctionPromise(" + callId + ", " + JSON.stringify(result) + " , true);"); | |
| 107 } | |
| 108 | |
| 109 function evalCallbackReject(result) | |
| 110 { | |
| 111 testRunner.evaluateInWebInspector(evalCallbackCallId, "Inspector Test.didInvokePageFunctionPromise(" + callId + ", " + JSON.stringify(result) + " , false);"); | |
| 112 } | |
| 113 | |
| 114 var args = [evalCallbackResolve, evalCallbackReject].concat(argument sArray.map(JSON.stringify)); | |
| 115 var functionCall = functionName + ".call(null, " + args.join(", ") + ")"; | |
| 116 try { | |
| 117 eval(functionCall); | |
| 118 } catch(e) { | |
| 119 InspectorTest.addResult("Error: " + e); | |
| 120 evalCallbackReject(e); | |
| 121 } | |
| 122 } | |
| 123 var pageRequest = "(" + asyncEvalWrapper.toString() + ")(" + id + ", une scape('" + escape(functionName) + "'), [" + jsonParameters.join(", ") + "])"; | |
| 124 InspectorTest.evaluateInPage(pageRequest); | |
| 125 }); | |
| 126 } | |
| 127 | |
| 128 | |
| 129 InspectorTest.didInvokePageFunctionPromise = function(callId, value, didResolve) | |
| 130 { | |
| 131 var callbacks = pendingPromiseEvalRequests[callId]; | |
| 132 if (!callbacks) { | |
| 133 InspectorTest.addResult("Missing callback for async eval " + callId + ", perhaps callback invoked twice?"); | |
| 134 return; | |
| 135 } | |
| 136 var callback = didResolve ? callbacks.resolve : callbacks.reject; | |
| 137 delete pendingPromiseEvalRequests[callId]; | |
| 138 callback(value); | |
| 139 } | |
| 140 | |
| 141 /** | 114 /** |
| 142 * @param {string} functionName | 115 * @param {string} functionName |
| 143 * @param {...} varArgs | 116 * @param {...} varArgs |
| 144 * @param {function()} callback | 117 * @param {function()} callback |
| 145 */ | 118 */ |
| 146 InspectorTest.invokePageFunctionAsync = function(functionName, varArgs) | 119 InspectorTest.invokePageFunctionAsync = function(functionName, varArgs) |
| 147 { | 120 { |
| 148 var id = ++lastEvalId; | 121 var id = ++lastEvalId; |
| 149 var args = Array.prototype.slice.call(arguments, 1); | 122 var args = Array.prototype.slice.call(arguments, 1); |
| 150 var callback = args.pop(); | 123 var callback = args.pop(); |
| (...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1218 _output("[page] " + text); | 1191 _output("[page] " + text); |
| 1219 } | 1192 } |
| 1220 | 1193 |
| 1221 function _output(result) | 1194 function _output(result) |
| 1222 { | 1195 { |
| 1223 if (!outputElement) | 1196 if (!outputElement) |
| 1224 createOutputElement(); | 1197 createOutputElement(); |
| 1225 outputElement.appendChild(document.createTextNode(result)); | 1198 outputElement.appendChild(document.createTextNode(result)); |
| 1226 outputElement.appendChild(document.createElement("br")); | 1199 outputElement.appendChild(document.createElement("br")); |
| 1227 } | 1200 } |
| OLD | NEW |