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

Side by Side 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, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import unittest
6
7 import pyauto_tracing
8 import pyauto
9 import tab_tracker
10 from timeline_model import TimelineModel
11
12 import os
13
14
15 class Tracer:
16 """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
17 and get an instance of a TimelineModel which represents the results from a
18 trace.
19 """
20
21 def __init__(self, browser, tab_tracker):
22 """
23 Args:
24 browser: an instance of a PyUITest
25 tab_tracker: an instance of a TabTracker
26 """
27 self._browser = browser
28 self._tab_tracker = tab_tracker
29 self._tab_uuid = tab_tracker.CreateTab('chrome://tracing')
30
31 # I'm not happy with importing timeline_model_shim.js
32 # here. I'd rather pull it in from within TimelineModelProxy.
33 # tracing_test.js depends on timeline_model_shim.js however.
34 # 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
35 # TimelineModelProxy
36 files = ["timeline_model_shim.js", "tracer.js"]
Nirnimesh 2012/07/31 20:05:57 use '
37 for fileName in files:
38 fileJs, fd = (None, None)
Nirnimesh 2012/07/31 20:05:57 fileJs -> file_js
39 try:
Nirnimesh 2012/07/31 20:05:57 do not use try block. with open(...) as fd: fil
40 fd = open(os.path.join(os.path.dirname(__file__), fileName), "r")
41 fileJs = fd.read()
42 finally:
43 if fd:
44 fd.close()
45 self._ExecuteJavascript(fileJs);
46
47 def __del__(self):
48 self._tab_tracker.ReleaseTab(self._tab_uuid)
49
50 def _ExecuteJavascript(self, js):
51 return self._browser.ExecuteJavascript(
52 js = js,
53 windex = self._tab_tracker.GetWindowIndex(),
54 tab_index = self._tab_tracker.GetTabIndex(self._tab_uuid)
55 )
56
57 def BeginTracing(self, system_tracing=True):
58 """Start tracing
59
60 Args:
61 system_tracing: whether or not to gather system traces along with chrome
62 traces.
63 """
64 self._ExecuteJavascript(
65 """
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
66 window.domAutomationController.send(
67 window.pyautoRecordTrace(%s)
68 );
69 """ % (
70 "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
71 )
72 )
73
74 def EndTracing(self):
75 """End tracing and return a TimelineModel
76
77 Returns:
78 an instance of a TimelineModel which contains the results of the trace
79 """
80 return TimelineModel(
81 js_executor = self._ExecuteJavascript.__get__(self, Tracer),
82 shim_id = self._ExecuteJavascript(
83 """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
84 )
85 )
86
Nirnimesh 2012/07/31 20:05:57 Need another blank line
87 class TracerFactory:
88 """A TracerFactory is used to produce a Tracer
Nirnimesh 2012/07/31 20:05:57 End with . for consistency
89
90 It's recommended to use the same TracerFactory to produce all Tracers so that
91 the same TabTracker can be used throughout
92
93 Args:
94 browser: an instance of a PyUITest
95 """
96 def __init__(self, browser):
97 self._tab_tracker = tab_tracker.TabTracker(browser)
98 self._browser = browser
99
100 def Produce(self):
101 """Produce an instance of a Tracer"""
102 return Tracer(self._browser, self._tab_tracker)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698