var initialize_InspectorTest = function() {
var results = [];
-var resultsSynchronized = false;
function consoleOutputHook(messageType)
{
InspectorTest.addResult(new Error(message).stack);
}
-InspectorTest.Output = { // override in window.initialize_yourName
- testComplete: function()
- {
- RuntimeAgent.evaluate("didEvaluateForTestInFrontend(" + InspectorTest.completeTestCallId + ", \"\")", "test");
- },
-
- addResult: function(text)
- {
- InspectorTest.evaluateInPage("output(unescape('" + escape(text) + "'))");
- },
-
- clearResults: function()
- {
- InspectorTest.evaluateInPage("clearOutput()");
- }
-};
-
InspectorTest.startDumpingProtocolMessages = function()
{
InspectorBackendClass.Connection.prototype._dumpProtocolMessage = testRunner.logToStderr.bind(testRunner);
InspectorTest.completeTest = function()
{
- InspectorTest.Output.testComplete();
-}
-
-InspectorTest.evaluateInConsole = function(code, callback)
-{
- callback = InspectorTest.safeWrap(callback);
-
- WebInspector.inspectorView.panel("console");
- var consoleView = WebInspector.ConsolePanel._view();
- consoleView.visible = true;
- consoleView._prompt.text = code;
- var event = document.createEvent("KeyboardEvent");
- event.initKeyboardEvent("keydown", true, true, null, "Enter", "");
- consoleView._prompt.proxyElement.dispatchEvent(event);
- InspectorTest.addConsoleSniffer(
- function(commandResult) {
- callback(commandResult.toMessageElement().textContent);
- });
+ RuntimeAgent.evaluate("completeTest(\"" + escape(JSON.stringify(results)) + "\")", "test");
}
-InspectorTest.evaluateInConsoleAndDump = function(code, callback)
+InspectorTest.flushResults = function()
{
- callback = InspectorTest.safeWrap(callback);
-
- function mycallback(text)
- {
- InspectorTest.addResult(code + " = " + text);
- callback(text);
- }
- InspectorTest.evaluateInConsole(code, mycallback);
+ RuntimeAgent.evaluate("flushResults(\"" + escape(JSON.stringify(results)) + "\")", "test");
+ results = [];
}
InspectorTest.evaluateInPage = function(code, callback)
InspectorTest.evaluateInPageWithTimeout = function(code)
{
- InspectorTest.evaluateInPage("setTimeout(unescape('" + escape(code) + "'))");
+ // FIXME: we need a better way of waiting for chromium events to happen
+ InspectorTest.evaluateInPage("setTimeout(unescape('" + escape(code) + "'), 1)");
}
var lastEvalId = 0;
{
var callback = pendingEvalRequests[callId];
if (!callback) {
- InspectorTest.addResult("Missing callback for ascyn eval " + callId + ", perhaps callback invoked twice?");
+ InspectorTest.addResult("Missing callback for async eval " + callId + ", perhaps callback invoked twice?");
return;
}
delete pendingEvalRequests[callId];
InspectorTest.addResult = function(text)
{
- results.push(text);
- if (resultsSynchronized)
- InspectorTest.Output.addResult(text);
- else {
- InspectorTest.Output.clearResults();
- for (var i = 0; i < results.length; ++i)
- InspectorTest.Output.addResult(results[i]);
- resultsSynchronized = true;
- }
+ results.push(String(text));
}
InspectorTest.addResults = function(textArray)
propertyNames.sort();
for (var i = 0; i < propertyNames.length; ++i) {
var prop = propertyNames[i];
- if (typeof object.hasOwnProperty === "function" && !object.hasOwnProperty(prop))
+ if (!object.hasOwnProperty(prop))
continue;
var prefixWithName = " " + prefix + prop + " : ";
var propValue = object[prop];
InspectorTest.navigate = function(url, callback)
{
InspectorTest._pageLoadedCallback = InspectorTest.safeWrap(callback);
-
- WebInspector.inspectorView.panel("network")._reset();
- InspectorTest.evaluateInConsole("window.location = '" + url + "'");
-}
-
-InspectorTest.recordNetwork = function()
-{
- WebInspector.inspectorView.panel("network")._networkLogView._recordButton.toggled = true;
+ InspectorTest.evaluateInPage("window.location = '" + url + "'");
}
InspectorTest.hardReloadPage = function(callback, scriptToEvaluateOnLoad, scriptPreprocessor)
InspectorTest._pageLoadedCallback = InspectorTest.safeWrap(callback);
if (WebInspector.panels.network)
- WebInspector.panels.network._reset();
+ WebInspector.panels.network._networkLogView._reset();
PageAgent.reload(hardReload, scriptToEvaluateOnLoad, scriptPreprocessor);
}
InspectorTest.pageLoaded = function()
{
- resultsSynchronized = false;
InspectorTest.addResult("Page reloaded.");
if (InspectorTest._pageLoadedCallback) {
var callback = InspectorTest._pageLoadedCallback;
InspectorTest.runAfterPendingDispatches = function(callback)
{
- callback = InspectorTest.safeWrap(callback);
- InspectorBackend.connection().runAfterPendingDispatches(callback);
+ var barrier = new CallbackBarrier();
+ var targets = WebInspector.targetManager.targets();
+ for (var i = 0; i < targets.length; ++i)
+ targets[i]._connection.runAfterPendingDispatches(barrier.createCallback());
+ barrier.callWhenDone(InspectorTest.safeWrap(callback));
}
InspectorTest.createKeyEvent = function(keyIdentifier, ctrlKey, altKey, shiftKey, metaKey)
InspectorTest.addConsoleSniffer = function(override, opt_sticky)
{
- var sniffer = function (viewMessage) {
- override(viewMessage);
- };
-
- WebInspector.inspectorView.panel("console");
- InspectorTest.addSniffer(WebInspector.ConsoleView.prototype, "_showConsoleMessage", sniffer, opt_sticky);
+ InspectorTest.addSniffer(WebInspector.ConsoleModel.prototype, "addMessage", override, opt_sticky);
}
InspectorTest.override = function(receiver, methodName, override, opt_sticky)
InspectorTest.textContentWithLineBreaks = function(node)
{
+ function padding(currentNode)
+ {
+ var result = 0;
+ while (currentNode && currentNode !== node) {
+ if (currentNode.nodeName === "OL")
+ ++result;
+ currentNode = currentNode.parentNode;
+ }
+ return Array(result * 4 + 1).join(" ");
+ }
+
var buffer = "";
var currentNode = node;
while (currentNode = currentNode.traverseNextNode(node)) {
if (currentNode.nodeType === Node.TEXT_NODE)
buffer += currentNode.nodeValue;
else if (currentNode.nodeName === "LI")
- buffer += "\n ";
+ buffer += "\n" + padding(currentNode);
else if (currentNode.classList.contains("console-message"))
buffer += "\n\n";
}
{
this._chunks = [];
this._name = name;
- setTimeout(callback.bind(this, this), 0);
+ setTimeout(callback.bind(this, this), 1);
}
InspectorTest.TempFileMock.prototype = {
/**
- * @param {!string} data
+ * @param {!Array.<string>} chunks
* @param {!function(boolean)} callback
*/
- write: function(data, callback)
+ write: function(chunks, callback)
{
- this._chunks.push(data);
- setTimeout(callback.bind(this, true), 0);
+ this._chunks.push.apply(this._chunks, chunks);
+ setTimeout(callback.bind(this, true), 1);
},
finishWriting: function() { },
*/
read: function(callback)
{
- callback(this._chunks.join(""));
+ this.readRange(undefined, undefined, callback);
+ },
+
+ /**
+ * @param {number|undefined} startOffset
+ * @param {number|undefined} endOffset
+ * @param {function(?string)} callback
+ */
+ readRange: function(startOffset, endOffset, callback)
+ {
+ var blob = new Blob(this._chunks);
+ blob = blob.slice(startOffset || 0, endOffset || blob.size);
+ reader = new FileReader();
+ var self = this;
+ reader.onloadend = function()
+ {
+ callback(reader.result);
+ }
+ reader.readAsText(blob);
},
/**
InspectorTest.dumpLoadedModules = function(next)
{
+ function moduleSorter(left, right)
+ {
+ return String.naturalOrderComparator(left._descriptor.name, right._descriptor.name);
+ }
+
InspectorTest.addResult("Loaded modules:");
- var modules = WebInspector.moduleManager._modules;
+ var modules = self.runtime._modules;
+ modules.sort(moduleSorter);
for (var i = 0; i < modules.length; ++i) {
- if (modules[i]._loaded) {
+ if (modules[i]._loaded)
InspectorTest.addResult(" " + modules[i]._descriptor.name);
- }
}
if (next)
next();
WebInspector.TempFile = InspectorTest.TempFileMock;
-};
+WebInspector.targetManager.observeTargets({
+ targetAdded: function(target)
+ {
+ if (!WebInspector.domModel)
+ WebInspector.domModel = target.domModel;
+ if (!WebInspector.consoleModel)
+ WebInspector.consoleModel = target.consoleModel;
+ if (!WebInspector.networkManager)
+ WebInspector.networkManager = target.networkManager;
+ if (!WebInspector.timelineManager)
+ WebInspector.timelineManager = target.timelineManager;
+ },
+
+ targetRemoved: function(target) { }
+});
+
+InspectorTest._panelsToPreload = [];
+
+InspectorTest.preloadPanel = function(panelName)
+{
+ InspectorTest._panelsToPreload.push(panelName);
+}
+
+}; // initialize_InspectorTest
var initializeCallId = 0;
var runTestCallId = 1;
-var completeTestCallId = 2;
-var evalCallbackCallId = 3;
+var evalCallbackCallId = 2;
var frontendReopeningCount = 0;
function reopenFrontend()
{
// Do this asynchronously to allow InspectorBackendDispatcher to send response
// back to the frontend before it's destroyed.
+ // FIXME: we need a better way of waiting for chromium events to happen
setTimeout(function() {
testRunner.closeWebInspector();
callback();
- }, 0);
+ }, 1);
}
function openFrontendAndIncrement()
{
frontendReopeningCount++;
testRunner.showWebInspector();
- setTimeout(runTest, 0);
+ setTimeout(runTest, 1);
}
function runAfterIframeIsLoaded()
try {
initializationFunctions[i]();
} catch (e) {
- console.error("Exception in test initialization: " + e);
+ console.error("Exception in test initialization: " + e + " " + e.stack);
InspectorTest.completeTest();
}
}
}
- function runTestInFrontend(testFunction, completeTestCallId)
+ function runTestInFrontend(testFunction)
{
- if (InspectorTest.completeTestCallId)
+ if (InspectorTest.wasAlreadyExecuted)
return;
- InspectorTest.completeTestCallId = completeTestCallId;
+ InspectorTest.wasAlreadyExecuted = true;
- try {
+ // 1. Preload panels.
+ var lastLoadedPanel;
+
+ var promises = [];
+ for (var i = 0; i < InspectorTest._panelsToPreload.length; ++i) {
+ lastLoadedPanel = InspectorTest._panelsToPreload[i];
+ promises.push(WebInspector.inspectorView.panel(lastLoadedPanel));
+ }
+
+ var testPath = WebInspector.settings.testPath.get();
+
+ // FIXME(399531): enable timelineOnTraceEvents experiment when running layout tests under inspector/tracing/. This code
+ // should be removed along with the old Timeline implementation once we move tracing based Timeline out of experimental.
+ if (testPath.indexOf("tracing/") !== -1)
+ Runtime.experiments.setEnabled("timelineOnTraceEvents", true);
+
+ if (testPath.indexOf("layers/") !== -1)
+ Runtime.experiments.setEnabled("layersPanel", true);
+
+ // 2. Show initial panel based on test path.
+ var initialPanelByFolder = {
+ "audits": "audits",
+ "console": "console",
+ "elements": "elements",
+ "editor": "sources",
+ "layers": "layers",
+ "profiler": "profiles",
+ "resource-tree": "resources",
+ "search": "sources",
+ "sources": "sources",
+ "timeline": "timeline",
+ "tracing": "timeline",
+ }
+ var initialPanelShown = false;
+ for (var folder in initialPanelByFolder) {
+ if (testPath.indexOf(folder + "/") !== -1) {
+ lastLoadedPanel = initialPanelByFolder[folder];
+ promises.push(WebInspector.inspectorView.panel(lastLoadedPanel));
+ break;
+ }
+ }
+
+ // 3. Run test function.
+ Promise.all(promises).then(function() {
+ if (lastLoadedPanel)
+ WebInspector.inspectorView.showInitialPanelForTest(lastLoadedPanel);
testFunction();
- } catch (e) {
- console.error("Exception during test execution: " + e, (e.stack ? e.stack : "") );
+ }).catch(function(e) {
+ console.error(e);
InspectorTest.completeTest();
- }
+ });
}
var initializationFunctions = [ String(initialize_InspectorTest) ];
if (name.indexOf("initialize_") === 0 && typeof window[name] === "function" && name !== "initialize_InspectorTest")
initializationFunctions.push(window[name].toString());
}
- var parameters = ["[" + initializationFunctions + "]"];
- var toEvaluate = "(" + initializeFrontend + ")(" + parameters.join(", ") + ");";
+ var toEvaluate = "(" + initializeFrontend + ")(" + "[" + initializationFunctions + "]" + ");";
testRunner.evaluateInWebInspector(initializeCallId, toEvaluate);
- parameters = [test, completeTestCallId];
- toEvaluate = "(" + runTestInFrontend + ")(" + parameters.join(", ") + ");";
+ toEvaluate = "(" + runTestInFrontend + ")(" + test + ");";
testRunner.evaluateInWebInspector(runTestCallId, toEvaluate);
if (enableWatchDogWhileDebugging) {
requestAnimationFrame(runTest.bind(this, enableWatchDogWhileDebugging));
}
-function didEvaluateForTestInFrontend(callId)
+function completeTest(results)
{
- if (callId !== completeTestCallId)
- return;
- delete window.completeTestCallId;
- if (outputElement && window.quietUntilDone)
- outputElementParent.appendChild(outputElement);
+ flushResults(results);
closeInspectorAndNotifyDone();
}
+function flushResults(results)
+{
+ results = (JSON && JSON.parse ? JSON.parse : eval)(unescape(results));
+ for (var i = 0; i < results.length; ++i)
+ _output(results[i]);
+}
+
function closeInspectorAndNotifyDone()
{
if (window._watchDogTimer)
}
var outputElement;
-var outputElementParent;
-function output(text)
+function createOutputElement()
{
- if (!outputElement) {
- var intermediate = document.createElement("div");
- document.body.appendChild(intermediate);
-
- outputElementParent = document.createElement("div");
- intermediate.appendChild(outputElementParent);
-
- outputElement = document.createElement("div");
- outputElement.className = "output";
- outputElement.id = "output";
+ outputElement = document.createElement("div");
+ // Support for svg - add to document, not body, check for style.
+ if (outputElement.style) {
outputElement.style.whiteSpace = "pre";
- if (!window.quietUntilDone)
- outputElementParent.appendChild(outputElement);
+ outputElement.style.height = "10px";
+ outputElement.style.overflow = "hidden";
}
- outputElement.appendChild(document.createTextNode(text));
- outputElement.appendChild(document.createElement("br"));
+ document.documentElement.appendChild(outputElement);
}
-function clearOutput()
+function output(text)
{
- if (outputElement) {
- outputElement.remove();
- outputElement = null;
- }
+ _output("[page] " + text);
}
-function StandaloneTestRunnerStub()
+function _output(result)
{
+ if (!outputElement)
+ createOutputElement();
+ outputElement.appendChild(document.createTextNode(result));
+ outputElement.appendChild(document.createElement("br"));
}
-
-StandaloneTestRunnerStub.prototype = {
- dumpAsText: function()
- {
- },
-
- waitUntilDone: function()
- {
- },
-
- closeWebInspector: function()
- {
- window.opener.postMessage(["closeWebInspector"], "*");
- },
-
- notifyDone: function()
- {
- var actual = document.body.innerText + "\n";
- window.opener.postMessage(["notifyDone", actual], "*");
- },
-
- evaluateInWebInspector: function(callId, script)
- {
- window.opener.postMessage(["evaluateInWebInspector", callId, script], "*");
- },
-
- display: function() { }
-}
-
-if (!window.testRunner && window.opener)
- window.testRunner = new StandaloneTestRunnerStub();