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

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

Issue 1044203004: [Storage] Cache storage inspection on all the frames! (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: comments and rebase Created 5 years, 8 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 var initialize_InspectorTest = function() { 1 var initialize_InspectorTest = function() {
2 2
3 var results = []; 3 var results = [];
4 4
5 function consoleOutputHook(messageType) 5 function consoleOutputHook(messageType)
6 { 6 {
7 InspectorTest.addResult(messageType + ": " + Array.prototype.slice.call(argu ments, 1)); 7 InspectorTest.addResult(messageType + ": " + Array.prototype.slice.call(argu ments, 1));
8 } 8 }
9 9
10 window._originalConsoleLog = console.log.bind(console); 10 window._originalConsoleLog = console.log.bind(console);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 InspectorTest.evaluateInPageWithTimeout = function(code) 52 InspectorTest.evaluateInPageWithTimeout = function(code)
53 { 53 {
54 // FIXME: we need a better way of waiting for chromium events to happen 54 // FIXME: we need a better way of waiting for chromium events to happen
55 InspectorTest.evaluateInPage("setTimeout(unescape('" + escape(code) + "'), 1 )"); 55 InspectorTest.evaluateInPage("setTimeout(unescape('" + escape(code) + "'), 1 )");
56 } 56 }
57 57
58 var lastEvalId = 0; 58 var lastEvalId = 0;
59 var pendingEvalRequests = {}; 59 var pendingEvalRequests = {};
60 60
61 var lastPromiseEvalId = 0;
62 var pendingPromiseEvalRequests = {};
63
64 /**
65 * The given function should take two callback paraters before the arguments:
66 * * resolve - called when successful (with optional result)
67 * * reject - called when there was a failure (with optional error)
68 */
69 InspectorTest.invokePageFunctionPromise = function(functionName, parameters)
70 {
71 return new Promise(function(resolve, reject) {
72 var id = ++lastPromiseEvalId;
73 pendingPromiseEvalRequests[id] = { resolve: InspectorTest.safeWrap(resol ve), reject: InspectorTest.safeWrap(reject) };
74
75 var jsonParameters = [];
76 for (var i = 0; i < parameters.length; ++i)
77 jsonParameters.push(JSON.stringify(parameters[i]));
78 var asyncEvalWrapper = function(callId, functionName, argumentsArray)
79 {
80 function evalCallbackResolve(result)
81 {
82 testRunner.evaluateInWebInspector(evalCallbackCallId, "Inspector Test.didInvokePageFunctionPromise(" + callId + ", " + JSON.stringify(result) + " , true);");
83 }
84
85 function evalCallbackReject(result)
86 {
87 testRunner.evaluateInWebInspector(evalCallbackCallId, "Inspector Test.didInvokePageFunctionPromise(" + callId + ", " + JSON.stringify(result) + " , false);");
88 }
89
90 var args = [evalCallbackResolve, evalCallbackReject].concat(argument sArray.map(JSON.stringify));
91 var functionCall = functionName + ".call(null, " + args.join(", ") + ")";
92 try {
93 eval(functionCall);
94 } catch(e) {
95 InspectorTest.addResult("Error: " + e);
96 evalCallbackReject(e);
97 }
98 }
99 var pageRequest = "(" + asyncEvalWrapper.toString() + ")(" + id + ", une scape('" + escape(functionName) + "'), [" + jsonParameters.join(", ") + "])";
100 InspectorTest.evaluateInPage(pageRequest);
101 });
102 }
103
104
105 InspectorTest.didInvokePageFunctionPromise = function(callId, value, didResolve)
106 {
107 var callbacks = pendingPromiseEvalRequests[callId];
108 if (!callbacks) {
109 InspectorTest.addResult("Missing callback for async eval " + callId + ", perhaps callback invoked twice?");
110 return;
111 }
112 var callback = didResolve ? callbacks.resolve : callbacks.reject;
113 delete pendingPromiseEvalRequests[callId];
114 callback(value);
115 }
116
61 InspectorTest.invokePageFunctionAsync = function(functionName, callback) 117 InspectorTest.invokePageFunctionAsync = function(functionName, callback)
62 { 118 {
63 var id = ++lastEvalId; 119 var id = ++lastEvalId;
64 pendingEvalRequests[id] = InspectorTest.safeWrap(callback); 120 pendingEvalRequests[id] = InspectorTest.safeWrap(callback);
65 var asyncEvalWrapper = function(callId, functionName) 121 var asyncEvalWrapper = function(callId, functionName)
66 { 122 {
67 function evalCallback(result) 123 function evalCallback(result)
68 { 124 {
69 testRunner.evaluateInWebInspector(evalCallbackCallId, "InspectorTest .didInvokePageFunctionAsync(" + callId + ", " + JSON.stringify(result) + ");"); 125 testRunner.evaluateInWebInspector(evalCallbackCallId, "InspectorTest .didInvokePageFunctionAsync(" + callId + ", " + JSON.stringify(result) + ");");
70 } 126 }
127
71 try { 128 try {
72 eval(functionName + "(" + evalCallback + ")"); 129 eval(functionName + "(" + evalCallback + ")");
73 } catch(e) { 130 } catch(e) {
74 console.error(e); 131 InspectorTest.addResult("Error: " + e);
75 evalCallback(String(e)); 132 evalCallback(String(e));
76 } 133 }
77 } 134 }
78 InspectorTest.evaluateInPage("(" + asyncEvalWrapper.toString() + ")(" + id + ", unescape('" + escape(functionName) + "'))"); 135 InspectorTest.evaluateInPage("(" + asyncEvalWrapper.toString() + ")(" + id + ", unescape('" + escape(functionName) + "'))");
79 } 136 }
80 137
81 InspectorTest.didInvokePageFunctionAsync = function(callId, value) 138 InspectorTest.didInvokePageFunctionAsync = function(callId, value)
82 { 139 {
83 var callback = pendingEvalRequests[callId]; 140 var callback = pendingEvalRequests[callId];
84 if (!callback) { 141 if (!callback) {
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 try { 479 try {
423 Array.prototype.push.call(arguments, result); 480 Array.prototype.push.call(arguments, result);
424 override.apply(this, arguments); 481 override.apply(this, arguments);
425 } catch (e) { 482 } catch (e) {
426 throw ("Exception in overriden method '" + methodName + "': " + e); 483 throw ("Exception in overriden method '" + methodName + "': " + e);
427 } 484 }
428 return result; 485 return result;
429 }; 486 };
430 } 487 }
431 488
489 InspectorTest.addSnifferPromise = function(receiver, methodName)
490 {
491 return new Promise(function (resolve, reject) {
492 var original = receiver[methodName];
493 if (typeof original !== "function") {
494 reject("Cannot find method to override: " + methodName);
495 return;
496 }
497
498 receiver[methodName] = function(var_args) {
499 try {
500 var result = original.apply(this, arguments);
501 } finally {
502 receiver[methodName] = original;
503 }
504 // In case of exception the override won't be called.
505 try {
506 Array.prototype.push.call(arguments, result);
507 resolve.apply(this, arguments);
508 } catch (e) {
509 reject("Exception in overriden method '" + methodName + "': " + e);
510 }
511 return result;
512 };
513 });
514 }
515
432 InspectorTest.addConsoleSniffer = function(override, opt_sticky) 516 InspectorTest.addConsoleSniffer = function(override, opt_sticky)
433 { 517 {
434 InspectorTest.addSniffer(WebInspector.ConsoleModel.prototype, "addMessage", override, opt_sticky); 518 InspectorTest.addSniffer(WebInspector.ConsoleModel.prototype, "addMessage", override, opt_sticky);
435 } 519 }
436 520
437 InspectorTest.override = function(receiver, methodName, override, opt_sticky) 521 InspectorTest.override = function(receiver, methodName, override, opt_sticky)
438 { 522 {
439 override = InspectorTest.safeWrap(override); 523 override = InspectorTest.safeWrap(override);
440 524
441 var original = receiver[methodName]; 525 var original = receiver[methodName];
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 _output("[page] " + text); 1058 _output("[page] " + text);
975 } 1059 }
976 1060
977 function _output(result) 1061 function _output(result)
978 { 1062 {
979 if (!outputElement) 1063 if (!outputElement)
980 createOutputElement(); 1064 createOutputElement();
981 outputElement.appendChild(document.createTextNode(result)); 1065 outputElement.appendChild(document.createTextNode(result));
982 outputElement.appendChild(document.createElement("br")); 1066 outputElement.appendChild(document.createElement("br"));
983 } 1067 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698