Commit 4eb6a7b6 authored by loislo@chromium.org's avatar loislo@chromium.org

DevTools: [Timeline] extract common testing harness code from tracing tests.

BUG=

Review URL: https://codereview.chromium.org/391413003

git-svn-id: svn://svn.chromium.org/blink/trunk@178543 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 73f8d35d
......@@ -1167,8 +1167,6 @@ crbug.com/312925 webkit.org/b/90488 [ Debug Win7 ] inspector-protocol/heap-profi
crbug.com/312925 [ Release XP ] inspector-protocol/heap-profiler/heap-snapshot-with-detached-dom-tree.html [ Failure Pass ]
Bug(gardener) [ Release Linux ] inspector-protocol/stylesheet-tracking-restart.html [ Pass Timeout ]
Bug(gardener) [ Release SnowLeopard ] inspector-protocol/timeline/timeline-layout.html [ Failure Pass ]
Bug(gardener) [ Release Linux ] inspector-protocol/timeline/timeline-timer.html [ Failure Pass ]
Bug(gardener) [ Release Mavericks ] inspector-protocol/timeline/timeline-timer.html [ Failure Pass ]
crbug.com/357079 [ Release MountainLion ] inspector/audits/audits-panel-functional.html [ Failure Pass ]
crbug.com/357079 [ Release Mavericks ] inspector/audits/audits-panel-functional.html [ Failure Pass ]
crbug.com/357079 [ Release Win7 ] inspector/audits/audits-panel-functional.html [ Failure Pass ]
......
......@@ -53,7 +53,7 @@ InspectorTest.sendCommand = function(method, params, handler)
"id": this._requestId };
if (InspectorTest._dumpInspectorProtocolMessages)
testRunner.logToStderr("backend: " + JSON.stringify(messageObject));
testRunner.logToStderr("frontend: " + JSON.stringify(messageObject));
InspectorFrontendHost.sendMessageToBackend(JSON.stringify(messageObject));
return this._requestId;
......@@ -141,7 +141,7 @@ InspectorTest.sendRawCommand = function(command, handler)
InspectorFrontendAPI.dispatchMessage = function(message)
{
if (InspectorTest._dumpInspectorProtocolMessages)
testRunner.logToStderr("frontend: " + message);
testRunner.logToStderr("backend: " + message);
var messageObject = JSON.parse(message);
var messageId = messageObject["id"];
try {
......@@ -156,7 +156,7 @@ InspectorFrontendAPI.dispatchMessage = function(message)
eventHandler(messageObject);
}
} catch(e) {
InspectorTest.log("Exception when dispatching message: " + e + "\n\n message = " + JSON.stringify(messageObject, null, 2));
InspectorTest.log("Exception when dispatching message: " + e + "\n" + e.stack + "\n message = " + JSON.stringify(messageObject, null, 2));
InspectorTest.completeTest();
}
}
......@@ -243,7 +243,7 @@ InspectorTest.completeTest = function()
* @param {string} message
* @param {!function} callback
*/
InspectorTest.executeInPage = function(string, callback)
InspectorTest.evaluateInPage = function(string, callback)
{
this.sendCommand("Runtime.evaluate", { "expression": string }, function(message) {
if (message.error)
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var evalCallbackCallId = 3;
initialize_tracingHarness = function()
{
InspectorTest.startTracing = function(callback)
{
InspectorTest.sendCommand("Tracing.start", { "categories": "-*,disabled-by-default-devtools.timeline", "type": "", "options": "" }, onStart);
function onStart(response)
{
InspectorTest.log("Recording started");
callback();
}
}
InspectorTest.stopTracing = function(callback)
{
InspectorTest.eventHandler["Tracing.tracingComplete"] = tracingComplete;
InspectorTest.eventHandler["Tracing.dataCollected"] = dataCollected;
InspectorTest.sendCommand("Tracing.end", { }, onStop);
InspectorTest.devtoolsEvents = [];
function dataCollected(reply)
{
var allEvents = reply.params.value;
InspectorTest.devtoolsEvents = InspectorTest.devtoolsEvents.concat(allEvents.filter(function(e)
{
return e.cat === "disabled-by-default-devtools.timeline";
}));
}
function tracingComplete(event)
{
InspectorTest.log("Tracing complete");
InspectorTest.eventHandler["Tracing.tracingComplete"] = null;
InspectorTest.eventHandler["Tracing.dataCollected"] = null;
callback(InspectorTest.devtoolsEvents);
}
function onStop(response)
{
InspectorTest.log("Recording stopped");
}
}
InspectorTest.findEvent = function(name, ph, condition)
{
for (var i = 0; i < InspectorTest.devtoolsEvents.length; i++) {
var e = InspectorTest.devtoolsEvents[i];
if (e.name === name && e.ph === ph && (!condition || condition(e)))
return e;
}
throw new Error("Couldn't find event " + name + " / " + ph + "\n\n in " + JSON.stringify(InspectorTest.devtoolsEvents, null, 2));
}
InspectorTest.invokeAsyncWithTracing = function(functionName, callback)
{
InspectorTest.startTracing(onStart);
function onStart()
{
InspectorTest.invokePageFunctionAsync(functionName, done);
}
function done()
{
InspectorTest.stopTracing(callback);
}
}
InspectorTest._lastEvalId = 0;
InspectorTest._pendingEvalRequests = {};
InspectorTest.invokePageFunctionAsync = function(functionName, callback)
{
var id = ++InspectorTest._lastEvalId;
InspectorTest._pendingEvalRequests[id] = callback;
var asyncEvalWrapper = function(callId, functionName)
{
function evalCallback(result)
{
evaluateInFrontend("InspectorTest.didInvokePageFunctionAsync(" + callId + ", " + JSON.stringify(result) + ");");
}
eval(functionName + "(" + evalCallback + ")");
}
InspectorTest.evaluateInPage("(" + asyncEvalWrapper.toString() + ")(" + id + ", unescape('" + escape(functionName) + "'))", function() { });
}
InspectorTest.didInvokePageFunctionAsync = function(callId, value)
{
var callback = InspectorTest._pendingEvalRequests[callId];
if (!callback) {
InspectorTest.addResult("Missing callback for async eval " + callId + ", perhaps callback invoked twice?");
return;
}
delete InspectorTest._pendingEvalRequests[callId];
callback(value);
}
}
......@@ -24,7 +24,7 @@ function test()
typeTab();
type("bar");
typeTab();
InspectorTest.executeInPage("dump()", InspectorTest.completeTest.bind(InspectorTest));
InspectorTest.evaluateInPage("dump()", InspectorTest.completeTest.bind(InspectorTest));
function type(text)
{
......
......@@ -62,7 +62,7 @@ function test()
}
];
InspectorTest.executeInPage("addListeners();", function() {
InspectorTest.evaluateInPage("addListeners();", function() {
for (var i = 0; i < events.length; i++)
InspectorTest.sendCommand("Input.dispatchMouseEvent", events[i], checkResponse.bind(undefined, i == events.length - 1));
});
......
<html>
<head>
<script type="text/javascript" src="../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
<script type="text/javascript" src="../../http/tests/inspector-protocol/tracing-test.js"></script>
<script>
function testFunction()
function performAction(callback)
{
var div = document.querySelector("#my-div");
div.addEventListener("click", function(e) { }, false);
......@@ -11,39 +12,15 @@ function testFunction()
var iframe = document.createElement("iframe");
div.appendChild(iframe);
callback();
}
function test()
{
InspectorTest.eventHandler["Tracing.dataCollected"] = dataCollected;
InspectorTest.eventHandler["Tracing.tracingComplete"] = tracingComplete;
InspectorTest.sendCommand("Tracing.start", { "categories" : "disabled-by-default-devtools.timeline", "type": "" }, onStart);
InspectorTest.invokeAsyncWithTracing("performAction", finish);
function onStart(response)
function finish(devtoolsEvents)
{
InspectorTest.log("Recording started");
InspectorTest.sendCommand("Runtime.evaluate", { "expression": "testFunction()" }, didEvaluate);
}
function didEvaluate(response)
{
InspectorTest.sendCommand("Tracing.end", { }, onStop);
}
var devtoolsEvents = [];
function dataCollected(reply)
{
var allEvents = reply.params.value;
devtoolsEvents = devtoolsEvents.concat(allEvents.filter(function(e)
{
return e.cat === "disabled-by-default-devtools.timeline";
}));
}
function tracingComplete(event)
{
InspectorTest.log("Tracing complete");
function windowEventFilter(type, e)
{
return e.name === "EventDispatch" && e.args.data.type === type;
......@@ -56,15 +33,14 @@ function test()
if (events.length >= 1) {
InspectorTest.log("SUCCESS: found " + eventName + " event");
} else {
fail(eventName + " event is missing");
fail(eventName + " event is missing", devtoolsEvents);
}
}
InspectorTest.completeTest();
}
function fail(message)
function fail(message, devtoolsEvents)
{
var formattedEvents = devtoolsEvents.map(function(e)
{
......@@ -72,11 +48,6 @@ function test()
});
InspectorTest.log("FAIL: " + message + " devtools.timeline events: " + JSON.stringify(formattedEvents, null, 2));
}
function onStop(response)
{
InspectorTest.log("Recording stopped");
}
}
</script>
</head>
......
......@@ -7,55 +7,32 @@
}
</style>
<script type="text/javascript" src="../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
<script type="text/javascript" src="../../http/tests/inspector-protocol/tracing-test.js"></script>
<script>
function testFunction()
function performActions(callback)
{
var div = document.querySelector("#myDiv");
div.classList.add("my-class");
div.offsetWidth;
callback();
}
function test()
{
InspectorTest.eventHandler["Tracing.dataCollected"] = dataCollected;
InspectorTest.eventHandler["Tracing.tracingComplete"] = tracingComplete;
InspectorTest.sendCommand("Tracing.start", { "categories" : "disabled-by-default-devtools.timeline", "type": "" }, onStart);
InspectorTest.invokeAsyncWithTracing("performActions", finish);
function onStart(response)
function finish(devtoolsEvents)
{
InspectorTest.log("Recording started");
InspectorTest.sendCommand("Runtime.evaluate", { "expression": "testFunction()" }, didEvaluate);
}
function didEvaluate(response)
{
InspectorTest.sendCommand("Tracing.end", { }, onStop);
}
var devtoolsEvents = [];
function dataCollected(reply)
{
var allEvents = reply.params.value;
devtoolsEvents = devtoolsEvents.concat(allEvents.filter(function(e)
{
return e.cat === "disabled-by-default-devtools.timeline";
}));
}
function tracingComplete(event)
{
InspectorTest.log("Tracing complete");
var schedRecalc = findEvent("ScheduleStyleRecalculation", "I");
var recalcBegin = findEvent("RecalculateStyles", "B");
var recalcEnd = findEvent("RecalculateStyles", "E");
var schedRecalc = InspectorTest.findEvent("ScheduleStyleRecalculation", "I");
var recalcBegin = InspectorTest.findEvent("RecalculateStyles", "B");
var recalcEnd = InspectorTest.findEvent("RecalculateStyles", "E");
InspectorTest.assertEquals(schedRecalc.args.frame, recalcBegin.args.frame, "RecalculateStyles frame");
InspectorTest.assert(recalcEnd.args.elementCount > 0, "RecalculateStyles elementCount");
var invalidate = findEvent("InvalidateLayout", "I");
var layoutBegin = findEvent("Layout", "B");
var layoutEnd = findEvent("Layout", "E");
var invalidate = InspectorTest.findEvent("InvalidateLayout", "I");
var layoutBegin = InspectorTest.findEvent("Layout", "B");
var layoutEnd = InspectorTest.findEvent("Layout", "E");
InspectorTest.assertEquals(recalcBegin.args.frame, invalidate.args.frame, "InvalidateLayout frame");
......@@ -72,20 +49,6 @@ function test()
InspectorTest.completeTest();
}
function findEvent(name, ph)
{
for (var i = 0; i < devtoolsEvents.length; i++) {
var e = devtoolsEvents[i];
if (e.name === name && e.ph === ph)
return e;
}
throw new Error("Couldn't find event " + name + " / " + ph + "\n\n in " + JSON.stringify(devtoolsEvents, null, 2));
}
function onStop(response)
{
InspectorTest.log("Recording stopped");
}
}
</script>
</head>
......
<html>
<head>
<script type="text/javascript" src="../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
<script type="text/javascript" src="../../http/tests/inspector-protocol/tracing-test.js"></script>
<script>
function testFunction()
function performActions(callback)
{
var rafId1 = requestAnimationFrame(function()
{
evaluateInFrontend("InspectorTest.testFunctionRequestAnimationFrame(" + rafId1 + ", " + rafId2 + ")");
callback();
});
var rafId2 = requestAnimationFrame(function() { });
......@@ -16,9 +18,7 @@ function testFunction()
function test()
{
InspectorTest.eventHandler["Tracing.dataCollected"] = dataCollected;
InspectorTest.eventHandler["Tracing.tracingComplete"] = tracingComplete;
InspectorTest.sendCommand("Tracing.start", { "categories" : "disabled-by-default-devtools.timeline", "type": "" }, onStart);
InspectorTest.invokeAsyncWithTracing("performActions", finish);
var firedRaf;
var canceledRaf;
......@@ -27,58 +27,24 @@ function test()
firedRaf = rafId1;
canceledRaf = rafId2;
InspectorTest.log("SUCCESS: testFunctionRequestAnimationFrame");
InspectorTest.sendCommand("Tracing.end", { }, onStop);
}
function onStart(response)
function finish(devtoolsEvents)
{
InspectorTest.log("Recording started");
InspectorTest.sendCommand("Runtime.evaluate", { "expression": "testFunction()" });
}
var devtoolsEvents = [];
function dataCollected(reply)
{
var allEvents = reply.params.value;
devtoolsEvents = devtoolsEvents.concat(allEvents.filter(function(e)
{
return e.cat === "disabled-by-default-devtools.timeline";
}));
}
function tracingComplete(event)
{
InspectorTest.log("Tracing complete");
function hasRafId(id, e) { return e.args.data.id === id}
var raf1 = findEvent("RequestAnimationFrame", "I", hasRafId.bind(this, firedRaf));
var raf2 = findEvent("RequestAnimationFrame", "I", hasRafId.bind(this, canceledRaf));
var raf1 = InspectorTest.findEvent("RequestAnimationFrame", "I", hasRafId.bind(this, firedRaf));
var raf2 = InspectorTest.findEvent("RequestAnimationFrame", "I", hasRafId.bind(this, canceledRaf));
InspectorTest.assert(!!raf1.args.data.frame, "RequestAnimationFrame frame");
InspectorTest.assertEquals(raf1.args.data.frame, raf2.args.data.frame, "RequestAnimationFrame frame match");
findEvent("CancelAnimationFrame", "I", hasRafId.bind(this, canceledRaf));
findEvent("FireAnimationFrame", "X", hasRafId.bind(this, firedRaf));
InspectorTest.findEvent("CancelAnimationFrame", "I", hasRafId.bind(this, canceledRaf));
InspectorTest.findEvent("FireAnimationFrame", "X", hasRafId.bind(this, firedRaf));
InspectorTest.log("SUCCESS: found all expected events.");
InspectorTest.completeTest();
}
function findEvent(name, ph, condition)
{
for (var i = 0; i < devtoolsEvents.length; i++) {
var e = devtoolsEvents[i];
if (e.name === name && e.ph === ph && (!condition || condition(e)))
return e;
}
throw new Error("Couldn't find event " + name + " / " + ph + "\n\n in " + JSON.stringify(devtoolsEvents, null, 2));
}
function onStop(response)
{
InspectorTest.log("Recording stopped");
}
}
</script>
</head>
......
<html>
<head>
<script type="text/javascript" src="../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
<script type="text/javascript" src="../../http/tests/inspector-protocol/tracing-test.js"></script>
<script>
function testFunction()
function performActions(callback)
{
var timerId = setTimeout(function()
{
evaluateInFrontend("InspectorTest.testFunctionTimerFired(" + timerId + ", " + timerId2 + ")");
callback();
}, 0);
var timerId2 = setTimeout(function() { }, 0);
......@@ -17,9 +19,7 @@ function testFunction()
function test()
{
InspectorTest.eventHandler["Tracing.dataCollected"] = dataCollected;
InspectorTest.eventHandler["Tracing.tracingComplete"] = tracingComplete;
InspectorTest.sendCommand("Tracing.start", { "categories" : "disabled-by-default-devtools.timeline", "type": "" }, onStart);
InspectorTest.invokeAsyncWithTracing("performActions", finish);
var firedTimerId;
var removedTimerId;
......@@ -28,58 +28,24 @@ function test()
firedTimerId = timerId1;
removedTimerId = timerId2;
InspectorTest.log("SUCCESS: testFunctionTimerFired");
InspectorTest.sendCommand("Tracing.end", { }, onStop);
}
function onStart(response)
function finish(devtoolsEvents)
{
InspectorTest.log("Recording started");
InspectorTest.sendCommand("Runtime.evaluate", { "expression": "testFunction()" });
}
var devtoolsEvents = [];
function dataCollected(reply)
{
var allEvents = reply.params.value;
devtoolsEvents = devtoolsEvents.concat(allEvents.filter(function(e)
{
return e.cat === "disabled-by-default-devtools.timeline";
}));
}
function tracingComplete(event)
{
InspectorTest.log("Tracing complete");
function hasTimerId(id, e) { return e.args.data.timerId === id}
var installTimer1 = findEvent("TimerInstall", "I", hasTimerId.bind(this, firedTimerId));
var installTimer2 = findEvent("TimerInstall", "I", hasTimerId.bind(this, removedTimerId));
var installTimer1 = InspectorTest.findEvent("TimerInstall", "I", hasTimerId.bind(this, firedTimerId));
var installTimer2 = InspectorTest.findEvent("TimerInstall", "I", hasTimerId.bind(this, removedTimerId));
InspectorTest.assert(!!installTimer1.args.data.frame, "TimerInstall frame");
InspectorTest.assertEquals(installTimer1.args.data.frame, installTimer2.args.data.frame, "TimerInstall frame match");
findEvent("TimerRemove", "I", hasTimerId.bind(this, removedTimerId));
findEvent("TimerFire", "X", hasTimerId.bind(this, firedTimerId));
InspectorTest.findEvent("TimerRemove", "I", hasTimerId.bind(this, removedTimerId));
InspectorTest.findEvent("TimerFire", "X", hasTimerId.bind(this, firedTimerId));
InspectorTest.log("SUCCESS: found all expected events.");
InspectorTest.completeTest();
}
function findEvent(name, ph, condition)
{
for (var i = 0; i < devtoolsEvents.length; i++) {
var e = devtoolsEvents[i];
if (e.name === name && e.ph === ph && (!condition || condition(e)))
return e;
}
throw new Error("Couldn't find event " + name + " / " + ph + "\n\n in " + JSON.stringify(devtoolsEvents, null, 2));
}
function onStop(response)
{
InspectorTest.log("Recording stopped");
}
}
</script>
</head>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment