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

Unified Diff: LayoutTests/http/tests/inspector-protocol/tracing-test.js

Issue 391413003: DevTools: [Timeline] extract common infrastructure from tracing tests. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: syntax error was fixed Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: LayoutTests/http/tests/inspector-protocol/tracing-test.js
diff --git a/LayoutTests/http/tests/inspector-protocol/tracing-test.js b/LayoutTests/http/tests/inspector-protocol/tracing-test.js
new file mode 100644
index 0000000000000000000000000000000000000000..8120abda577bde7830b2b6779da938b184a9d795
--- /dev/null
+++ b/LayoutTests/http/tests/inspector-protocol/tracing-test.js
@@ -0,0 +1,107 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
yurys 2014/07/21 06:32:22 This file should be under .../timeline/tracing/
loislo 2014/07/21 07:28:48 there is no timeline tracing tests and correspondi
+// 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);
+ }
+}
+
+var lastEvalId = 0;
yurys 2014/07/21 06:32:22 pendingEvalRequests._lastEvalId
loislo 2014/07/21 07:28:48 Done.
+var pendingEvalRequests = {};
yurys 2014/07/21 06:32:22 InspectorTest._pendingEvalRequests
loislo 2014/07/21 07:28:48 Done.
+
+InspectorTest.invokePageFunctionAsync = function(functionName, callback)
+{
+ var id = ++lastEvalId;
+ pendingEvalRequests[id] = callback;
+ var asyncEvalWrapper = function(callId, functionName)
+ {
+ function evalCallback(result)
+ {
+ testRunner.evaluateInWebInspector(evalCallbackCallId, "InspectorTest.didInvokePageFunctionAsync(" + callId + ", " + JSON.stringify(result) + ");");
yurys 2014/07/21 06:32:22 evaluateInFrontend(...)
loislo 2014/07/21 07:28:48 Done.
+ }
+ eval(functionName + "(" + evalCallback + ")");
+ }
+ InspectorTest.evaluateInPage("(" + asyncEvalWrapper.toString() + ")(" + id + ", unescape('" + escape(functionName) + "'))", function() { });
+}
+
+InspectorTest.didInvokePageFunctionAsync = function(callId, value)
+{
+ var callback = pendingEvalRequests[callId];
+
+ if (!callback) {
+ InspectorTest.addResult("Missing callback for async eval " + callId + ", perhaps callback invoked twice?");
+ return;
+ }
+ delete pendingEvalRequests[callId];
+ callback(value);
+}
+
+}
+

Powered by Google App Engine
This is Rietveld 408576698