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

Side by Side Diff: chrome/test/functional/tracing/timeline_model.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 json
6 import os
7
8 def _EscapeForQuotedJavascriptExecution(js):
Nirnimesh 2012/07/31 23:39:10 Move this inside the class as @staticmethod
9 # Poor man's string escape.
10 return js.replace('\'', '\\\'');
11
12
13 class TimelineModel:
14 """A proxy for about:tracing's TimelineModel class.
15
16 Test authors should never need to know that this class is a proxy.
17 """
18 def __init__(self, js_executor, shim_id):
19 self._js_executor = js_executor
20 self._shim_id = shim_id
21
22 # Warning: The JSON serialization process removes cyclic references.
23 # TODO(eatnumber): regenerate these cyclic references on deserialization.
24 def _CallModelMethod(self, method_name, *args):
25 result = self._js_executor(
26 """window.timelineModelShims['%s'].invokeMethod('%s', '%s')""" % (
27 self._shim_id,
28 _EscapeForQuotedJavascriptExecution(method_name),
29 _EscapeForQuotedJavascriptExecution(json.dumps(args))
30 )
31 )
32 if result['success']:
33 return result['data']
34 # TODO(eatnumber): Make these exceptions more reader friendly.
35 raise RuntimeError(result)
36
37 def __del__(self):
38 self._js_executor(
39 """
40 window.timelineModelShims['%s'] = undefined;
Nirnimesh 2012/07/31 23:39:10 You didn't need to indent this block further, if y
41 window.domAutomationController.send('');
42 """ % self._shim_id
43 )
44
45 def GetAllThreads(self):
46 return self._CallModelMethod('getAllThreads')
47
48 def GetAllCpus(self):
49 return self._CallModelMethod('getAllCpus')
50
51 def GetAllProcesses(self):
52 return self._CallModelMethod('getAllProcesses')
53
54 def GetAllCounters(self):
55 return self._CallModelMethod('getAllCounters')
56
57 def FindAllThreadsNamed(self, name):
58 return self._CallModelMethod('findAllThreadsNamed', name);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698