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

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: Fix more style issues. 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
« no previous file with comments | « chrome/test/functional/tracing/tracer.js ('k') | chrome/test/functional/tracing/tracing_smoke_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..168dc0c8fbf19b39d937b73af2cc7b15d0d42a2c
--- /dev/null
+++ b/chrome/test/functional/tracing/tracer.py
@@ -0,0 +1,96 @@
+# Copyright (c) 2012 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:
+ """Controlls chrome and system tracing, returning a TimelineModel."""
+
+ def __init__(self, browser, tab_tracker):
+ """
+ Args:
+ browser: an instance of a PyUITest
+ tab_tracker: an instance of a TabTracker
+ """
+ self._browser = browser
+ self._tab_tracker = tab_tracker
+ self._tab_uuid = tab_tracker.CreateTab('chrome://tracing')
+
+ # TODO(eatnumber): Find a way to import timeline_model_shim.js from within
+ # TimelineModelProxy
+ # 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:
+ file_js = None
+ with open(os.path.join(os.path.dirname(__file__), fileName), 'r') as fd:
+ file_js = fd.read()
+ self._ExecuteJavascript(file_js);
+
+ 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):
+ """Start tracing.
+
+ Args:
+ system_tracing: whether or not to gather system traces along with chrome
+ traces.
+ """
+ self._ExecuteJavascript(
+ """
+ window.domAutomationController.send(
+ window.pyautoRecordTrace(%s)
+ );
+ """ % (
+ 'true' if system_tracing else 'false'
+ )
+ )
+
+ def EndTracing(self):
+ """End tracing and return a TimelineModel.
+
+ Returns:
+ an instance of a TimelineModel which contains the results of the trace
+ """
+ return TimelineModel(
+ js_executor = self._ExecuteJavascript.__get__(self, Tracer),
+ shim_id = self._ExecuteJavascript(
+ """tracingController.endTracing();"""
+ )
+ )
+
+
+class TracerFactory:
+ """A TracerFactory is used to produce a Tracer.
+
+ It's recommended to use the same TracerFactory to produce all Tracers so that
+ the same TabTracker can be used throughout
+
+ Args:
+ browser: an instance of a PyUITest
+ """
+ def __init__(self, browser):
+ self._tab_tracker = tab_tracker.TabTracker(browser)
+ self._browser = browser
+
+ def Produce(self):
+ """Produce an instance of a Tracer"""
+ return Tracer(self._browser, self._tab_tracker)
« no previous file with comments | « chrome/test/functional/tracing/tracer.js ('k') | chrome/test/functional/tracing/tracing_smoke_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698