OLD | NEW |
---|---|
(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 json | |
6 import os | |
7 | |
8 def escape_for_quoted_javascript_execution(js): | |
9 # Poor man's string escape. | |
10 return js.replace("'", "\\'"); | |
11 | |
12 class TimelineModelProxy: | |
13 def __init__(self, js_executor, shim_id): | |
14 self._js_executor = js_executor | |
15 self._shim_id = shim_id | |
16 | |
17 # Warning: The JSON serialization process removes cyclic references. | |
18 # TODO(eatnumber) regenerate these cyclic references on deserialization. | |
Nirnimesh
2012/07/30 21:03:51
Need : after TODO(eatnumber)
| |
19 def _CallModelMethod(self, method_name, *args): | |
20 result = self._js_executor( | |
21 """ | |
22 window.timelineModelShims['%s'].invokeMethod('%s', '%s') | |
23 """ % ( | |
24 self._shim_id, | |
25 escape_for_quoted_javascript_execution(method_name), | |
26 escape_for_quoted_javascript_execution(json.dumps(args)) | |
27 ) | |
28 ) | |
29 if result["success"]: | |
30 return result["data"] | |
31 # TODO(eatnumber) Make these exceptions more reader friendly. | |
32 raise Exception(result) | |
33 | |
34 def __del__(self): | |
35 self._js_executor( | |
36 """ | |
37 window.timelineModelShims['%s'] = undefined; | |
38 window.domAutomationController.send(''); | |
39 """ % self._shim_id | |
40 ) | |
41 | |
42 def GetAllThreads(self): | |
43 return self._CallModelMethod("getAllThreads") | |
44 | |
45 def GetAllCpus(self): | |
46 return self._CallModelMethod("getAllCpus") | |
47 | |
48 def GetAllProcesses(self): | |
49 return self._CallModelMethod("getAllProcesses") | |
50 | |
51 def GetAllCounters(self): | |
52 return self._CallModelMethod("getAllCounters") | |
53 | |
54 def FindAllThreadsNamed(self, name): | |
55 return self._CallModelMethod("findAllThreadsNamed", name); | |
56 | |
57 # Alias TimelineModel to TimelineModelProxy for convenience. | |
58 TimelineModel = TimelineModelProxy | |
Nirnimesh
2012/07/30 21:03:51
Why not change line 12 instead?
Russ Harmon
2012/07/31 01:11:16
Because while I don't want authors of tests to kno
Nirnimesh
2012/07/31 20:05:57
That seems like a good note to put in the docstrin
Russ Harmon
2012/07/31 20:54:18
How can it be avoided while both keeping a name fo
Nirnimesh
2012/07/31 21:15:05
I don't understand your motivation. You want test
| |
OLD | NEW |