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

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: Clean up js TimelineModel when the python TimelineModelProxy is deleted. 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
11 from timeline_model import TimelineModel
12
13 import os
14
15 class Tracer:
16 def __init__(self, browser, tab_tracker):
17 self._browser = browser
18 self._tab_tracker = tab_tracker
19 self._tab_uuid = tab_tracker.createTab('chrome://tracing')
20
21 # I'm not happy with importing timeline_model_shim.js
22 # here. I'd rather pull it in from within TimelineModelProxy.
23 # tracing_test.js depends on timeline_model_shim.js however.
24 files = ["timeline_model_shim.js", "tracer.js"]
25 for fileName in files:
26 fileJs, fd = (None, None)
27 try:
28 fd = open(os.path.join(os.path.dirname(__file__), fileName), "r")
29 fileJs = fd.read()
30 finally:
31 if fd:
32 fd.close()
33 self._executeJavascript(fileJs);
34
35 def __del__(self):
36 self._tab_tracker.releaseTab(self._tab_uuid)
37
38 def _executeJavascript(self, js):
39 return self._browser.ExecuteJavascript(
40 js = js,
41 windex = self._tab_tracker.getWindowIndex(),
42 tab_index = self._tab_tracker.getTabIndex(self._tab_uuid)
43 )
44
45 def beginTracing(self, system_tracing = True):
46 self._executeJavascript(
47 """
48 window.domAutomationController.send(
49 window.pyautoRecordTrace(%s)
50 );
51 """ % (
52 "true" if system_tracing else "false"
53 )
54 )
55
56 def endTracing(self):
57 return TimelineModel(
58 js_executor = self._executeJavascript.__get__(self, Tracer),
59 shim_id = self._executeJavascript(
60 """tracingController.endTracing();"""
61 )
62 )
63
64 class TracerFactory:
65 def __init__(self, browser):
66 self._tab_tracker = tab_tracker.TabTracker(browser)
67 self._browser = browser
68
69 def produce(self):
70 return Tracer(self._browser, self._tab_tracker)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698