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

Unified Diff: chrome/test/functional/tracing/tracer.py

Issue 10736055: Smoke test for tracing infrastructure in PyAuto (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clean up js TimelineModel when the python TimelineModelProxy is deleted. Created 8 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: chrome/test/functional/tracing/tracer.py
diff --git a/chrome/test/functional/tracing/tracer.py b/chrome/test/functional/tracing/tracer.py
new file mode 100644
index 0000000000000000000000000000000000000000..0867dfb0384652735bba14a8ad37931ce904d51d
--- /dev/null
+++ b/chrome/test/functional/tracing/tracer.py
@@ -0,0 +1,70 @@
+# Copyright (c) 2011 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.
+
+import unittest
+
+import pyauto_tracing
+import pyauto
+import tab_tracker
+
+from timeline_model import TimelineModel
+
+import os
+
+class Tracer:
+ def __init__(self, browser, tab_tracker):
+ self._browser = browser
+ self._tab_tracker = tab_tracker
+ self._tab_uuid = tab_tracker.createTab('chrome://tracing')
+
+ # I'm not happy with importing timeline_model_shim.js
+ # here. I'd rather pull it in from within TimelineModelProxy.
+ # tracing_test.js depends on timeline_model_shim.js however.
+ files = ["timeline_model_shim.js", "tracer.js"]
+ for fileName in files:
+ fileJs, fd = (None, None)
+ try:
+ fd = open(os.path.join(os.path.dirname(__file__), fileName), "r")
+ fileJs = fd.read()
+ finally:
+ if fd:
+ fd.close()
+ self._executeJavascript(fileJs);
+
+ def __del__(self):
+ self._tab_tracker.releaseTab(self._tab_uuid)
+
+ def _executeJavascript(self, js):
+ return self._browser.ExecuteJavascript(
+ js = js,
+ windex = self._tab_tracker.getWindowIndex(),
+ tab_index = self._tab_tracker.getTabIndex(self._tab_uuid)
+ )
+
+ def beginTracing(self, system_tracing = True):
+ self._executeJavascript(
+ """
+ window.domAutomationController.send(
+ window.pyautoRecordTrace(%s)
+ );
+ """ % (
+ "true" if system_tracing else "false"
+ )
+ )
+
+ def endTracing(self):
+ return TimelineModel(
+ js_executor = self._executeJavascript.__get__(self, Tracer),
+ shim_id = self._executeJavascript(
+ """tracingController.endTracing();"""
+ )
+ )
+
+class TracerFactory:
+ def __init__(self, browser):
+ self._tab_tracker = tab_tracker.TabTracker(browser)
+ self._browser = browser
+
+ def produce(self):
+ return Tracer(self._browser, self._tab_tracker)

Powered by Google App Engine
This is Rietveld 408576698