Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/inspector/inspector-test.js

Issue 2207163002: [DevTools] Removed InspectorTest.invokePageFunctionPromise (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: a Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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, exceptionDetails)
75 {
76 if (!error && !wasThrown) {
77 callback(InspectorTest.runtimeModel.createRemoteObject(result));
78 } else {
79 if (error)
80 InspectorTest.addResult("Error: " + error);
81 else
82 InspectorTest.addResult("Error: " + (exceptionDetails ? exceptio nDetails.text : " exception while evaluation in page."));
83 InspectorTest.completeTest();
84 }
85 }
86 return promise;
87 }
88
89 InspectorTest.callFunctionInPageAsync = function(name, args)
90 {
91 args = args || [];
92 return InspectorTest.evaluateInPageAsync(name + "(" + args.map(JSON.stringif y).join(",") + ")");
93 }
94
59 InspectorTest.evaluateInPageWithTimeout = function(code) 95 InspectorTest.evaluateInPageWithTimeout = function(code)
60 { 96 {
61 // FIXME: we need a better way of waiting for chromium events to happen 97 // FIXME: we need a better way of waiting for chromium events to happen
62 InspectorTest.evaluateInPage("setTimeout(unescape('" + escape(code) + "'), 1 )"); 98 InspectorTest.evaluateInPage("setTimeout(unescape('" + escape(code) + "'), 1 )");
63 } 99 }
64 100
65 InspectorTest.evaluateFunctionInOverlay = function(func, callback) 101 InspectorTest.evaluateFunctionInOverlay = function(func, callback)
66 { 102 {
67 var expression = "testRunner.evaluateInWebInspectorOverlay(\"(\" + " + func + " + \")()\")"; 103 var expression = "testRunner.evaluateInWebInspectorOverlay(\"(\" + " + func + " + \")()\")";
68 var mainContext = InspectorTest.runtimeModel.executionContexts()[0]; 104 var mainContext = InspectorTest.runtimeModel.executionContexts()[0];
69 mainContext.evaluate(expression, "", false, false, true, false, false, wrapC allback); 105 mainContext.evaluate(expression, "", false, false, true, false, false, wrapC allback);
70 106
71 function wrapCallback(val, err, result) 107 function wrapCallback(val, err, result)
72 { 108 {
73 callback(result.value) 109 callback(result.value)
74 } 110 }
75 } 111 }
76 112
77 InspectorTest.waitForOverlayRepaint = function(callback) 113 InspectorTest.waitForOverlayRepaint = function(callback)
78 { 114 {
79 InspectorTest.invokePageFunctionAsync("requestAnimationFrame", callback); 115 InspectorTest.invokePageFunctionAsync("requestAnimationFrame", callback);
80 } 116 }
81 117
82 var lastEvalId = 0; 118 var lastEvalId = 0;
83 var pendingEvalRequests = {}; 119 var pendingEvalRequests = {};
84 120
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 /** 121 /**
142 * @param {string} functionName 122 * @param {string} functionName
143 * @param {...} varArgs 123 * @param {...} varArgs
144 * @param {function()} callback 124 * @param {function()} callback
145 */ 125 */
146 InspectorTest.invokePageFunctionAsync = function(functionName, varArgs) 126 InspectorTest.invokePageFunctionAsync = function(functionName, varArgs)
147 { 127 {
148 var id = ++lastEvalId; 128 var id = ++lastEvalId;
149 var args = Array.prototype.slice.call(arguments, 1); 129 var args = Array.prototype.slice.call(arguments, 1);
150 var callback = args.pop(); 130 var callback = args.pop();
(...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 _output("[page] " + text); 1198 _output("[page] " + text);
1219 } 1199 }
1220 1200
1221 function _output(result) 1201 function _output(result)
1222 { 1202 {
1223 if (!outputElement) 1203 if (!outputElement)
1224 createOutputElement(); 1204 createOutputElement();
1225 outputElement.appendChild(document.createTextNode(result)); 1205 outputElement.appendChild(document.createTextNode(result));
1226 outputElement.appendChild(document.createElement("br")); 1206 outputElement.appendChild(document.createElement("br"));
1227 } 1207 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698