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

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: Add more docstrings. 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..aa8c33d0904e91f44a4ece4f37fad1f813392cc4
--- /dev/null
+++ b/chrome/test/functional/tracing/tracer.py
@@ -0,0 +1,102 @@
+# 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:
+ """Allows you to start and stop chrome and system tracing,
Nirnimesh 2012/07/31 20:05:57 First sentence should be a one-liner. Details in
+ and get an instance of a TimelineModel which represents the results from a
+ trace.
+ """
+
+ 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')
+
+ # 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.
+ # TODO(eatnumber): Find a way to import timeline_model_shim.js from within
Nirnimesh 2012/07/31 20:05:57 Move TODO to line 31
+ # TimelineModelProxy
+ files = ["timeline_model_shim.js", "tracer.js"]
Nirnimesh 2012/07/31 20:05:57 use '
+ for fileName in files:
+ fileJs, fd = (None, None)
Nirnimesh 2012/07/31 20:05:57 fileJs -> file_js
+ try:
Nirnimesh 2012/07/31 20:05:57 do not use try block. with open(...) as fd: fil
+ 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):
+ """Start tracing
+
+ Args:
+ system_tracing: whether or not to gather system traces along with chrome
+ traces.
+ """
+ self._ExecuteJavascript(
+ """
Nirnimesh 2012/07/31 20:05:57 This needs to be indented by 4 spaces wrt previous
Russ Harmon 2012/07/31 20:54:18 See my previous comment in timeline_model.py
+ window.domAutomationController.send(
+ window.pyautoRecordTrace(%s)
+ );
+ """ % (
+ "true" if system_tracing else "false"
Nirnimesh 2012/07/31 20:05:57 use ' (I'm not pointing it out anymore. Please fi
Russ Harmon 2012/07/31 20:54:18 Sorry about that. I'll go through and fix every oc
+ )
+ )
+
+ 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();"""
Nirnimesh 2012/07/31 20:05:57 why """?
Russ Harmon 2012/07/31 20:54:18 For consistency with everywhere else I call Execut
Nirnimesh 2012/07/31 21:15:06 On the contrary, it breaks consistency. """ is sup
+ )
+ )
+
Nirnimesh 2012/07/31 20:05:57 Need another blank line
+class TracerFactory:
+ """A TracerFactory is used to produce a Tracer
Nirnimesh 2012/07/31 20:05:57 End with . for consistency
+
+ 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)

Powered by Google App Engine
This is Rietveld 408576698