Index: chrome/test/functional/tracing/timeline_model.py |
diff --git a/chrome/test/functional/tracing/timeline_model.py b/chrome/test/functional/tracing/timeline_model.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e655024633caee715ac6d0b046e6d369dd567614 |
--- /dev/null |
+++ b/chrome/test/functional/tracing/timeline_model.py |
@@ -0,0 +1,62 @@ |
+# Copyright (c) 2011 The Chromium Authors. All rights reserved. |
Nirnimesh
2012/07/31 20:05:57
2012
|
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import json |
+import os |
+ |
+def escape_for_quoted_javascript_execution(js): |
Nirnimesh
2012/07/31 20:05:57
CapitalizeAndRemoveSpaces
Prefix _ for private fu
|
+ # Poor man's string escape. |
+ return js.replace("'", "\\'"); |
+ |
+ |
+class TimelineModelProxy: |
+ """A proxy for the TimelineModel class located in V8 in a chrome://tracing |
Nirnimesh
2012/07/31 20:05:57
Make it fit within 1 line please.
|
+ tab. |
+ """ |
+ def __init__(self, js_executor, shim_id): |
+ self._js_executor = js_executor |
+ self._shim_id = shim_id |
+ |
+ # Warning: The JSON serialization process removes cyclic references. |
+ # TODO(eatnumber): regenerate these cyclic references on deserialization. |
+ def _CallModelMethod(self, method_name, *args): |
+ result = self._js_executor( |
+ """ |
Nirnimesh
2012/07/31 20:05:57
Can be moved to previous line
|
+ window.timelineModelShims['%s'].invokeMethod('%s', '%s') |
+ """ % ( |
Nirnimesh
2012/07/31 20:05:57
indent 2 more chars to the right
|
+ self._shim_id, |
+ escape_for_quoted_javascript_execution(method_name), |
+ escape_for_quoted_javascript_execution(json.dumps(args)) |
+ ) |
+ ) |
+ if result["success"]: |
Nirnimesh
2012/07/31 20:05:57
use ' for quoting
|
+ return result["data"] |
+ # TODO(eatnumber): Make these exceptions more reader friendly. |
+ raise Exception(result) |
Nirnimesh
2012/07/31 20:05:57
RuntimeError
|
+ |
+ def __del__(self): |
+ self._js_executor( |
+ """ |
Nirnimesh
2012/07/31 20:05:57
Needs to be indented 4 chars wrt previous line
Russ Harmon
2012/07/31 20:54:18
It doesn't make sense to further indent this as th
Nirnimesh
2012/07/31 21:15:06
Chromium python style is based loosely on google p
|
+ window.timelineModelShims['%s'] = undefined; |
+ window.domAutomationController.send(''); |
+ """ % self._shim_id |
+ ) |
+ |
+ def GetAllThreads(self): |
+ return self._CallModelMethod("getAllThreads") |
+ |
+ def GetAllCpus(self): |
+ return self._CallModelMethod("getAllCpus") |
+ |
+ def GetAllProcesses(self): |
+ return self._CallModelMethod("getAllProcesses") |
+ |
+ def GetAllCounters(self): |
+ return self._CallModelMethod("getAllCounters") |
+ |
+ def FindAllThreadsNamed(self, name): |
+ return self._CallModelMethod("findAllThreadsNamed", name); |
+ |
+# Alias TimelineModel to TimelineModelProxy for convenience. |
+TimelineModel = TimelineModelProxy |