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

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: Remove unused unittest import. 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) 2012 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 pyauto_tracing
6 import pyauto
7 import tab_tracker
8 from timeline_model import TimelineModel
9
10 import os
11
12
13 class Tracer:
Nirnimesh 2012/07/31 23:39:10 I think the convention is to have all classes deri
14 """Controlls chrome and system tracing, returning a TimelineModel."""
15
16 def __init__(self, browser, tab_tracker):
17 """
18 Args:
19 browser: an instance of a PyUITest
20 tab_tracker: an instance of a TabTracker
21 """
22 self._browser = browser
23 self._tab_tracker = tab_tracker
24 self._tab_uuid = tab_tracker.CreateTab('chrome://tracing')
25
26 # TODO(eatnumber): Find a way to import timeline_model_shim.js from within
27 # TimelineModelProxy
28 # I'm not happy with importing timeline_model_shim.js
29 # here. I'd rather pull it in from within TimelineModelProxy.
30 # tracing_test.js depends on timeline_model_shim.js however.
31 files = ['timeline_model_shim.js', 'tracer.js']
32 for fileName in files:
33 file_js = None
Nirnimesh 2012/07/31 23:39:10 Not necessary. Either line 34 fails and throws an
34 with open(os.path.join(os.path.dirname(__file__), fileName), 'r') as fd:
35 file_js = fd.read()
36 self._ExecuteJavascript(file_js);
37
38 def __del__(self):
39 self._tab_tracker.ReleaseTab(self._tab_uuid)
40
41 def _ExecuteJavascript(self, js):
42 return self._browser.ExecuteJavascript(
43 js = js,
44 windex = self._tab_tracker.GetWindowIndex(),
45 tab_index = self._tab_tracker.GetTabIndex(self._tab_uuid)
46 )
47
48 def BeginTracing(self, system_tracing=True):
49 """Start tracing.
50
51 Args:
52 system_tracing: whether or not to gather system traces along with chrome
53 traces.
54 """
55 self._ExecuteJavascript(
56 """
57 window.domAutomationController.send(
58 window.pyautoRecordTrace(%s)
59 );
60 """ % (
61 'true' if system_tracing else 'false'
Nirnimesh 2012/07/31 23:39:10 This can fit in previous line. Also the next line
62 )
63 )
64
65 def EndTracing(self):
66 """End tracing and return a TimelineModel.
67
68 Returns:
69 an instance of a TimelineModel which contains the results of the trace
70 """
71 return TimelineModel(
72 js_executor = self._ExecuteJavascript.__get__(self, Tracer),
73 shim_id = self._ExecuteJavascript('tracingController.endTracing();')
74 )
75
76
77 class TracerFactory:
78 """A TracerFactory is used to produce a Tracer.
79
80 It's recommended to use the same TracerFactory to produce all Tracers so that
81 the same TabTracker can be used throughout
82
83 Args:
84 browser: an instance of a PyUITest
85 """
86 def __init__(self, browser):
87 self._tab_tracker = tab_tracker.TabTracker(browser)
88 self._browser = browser
89
90 def Produce(self):
91 """Produce an instance of a Tracer"""
92 return Tracer(self._browser, self._tab_tracker)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698