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..6d75a1859f8f9752a2b3f7b607c95b966111bd3c |
--- /dev/null |
+++ b/chrome/test/functional/tracing/timeline_model.py |
@@ -0,0 +1,58 @@ |
+# Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+# 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): |
+ # Poor man's string escape. |
+ return js.replace("'", "\\'"); |
+ |
+class TimelineModelProxy: |
+ 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. |
Nirnimesh
2012/07/30 21:03:51
Need : after TODO(eatnumber)
|
+ def _CallModelMethod(self, method_name, *args): |
+ result = self._js_executor( |
+ """ |
+ window.timelineModelShims['%s'].invokeMethod('%s', '%s') |
+ """ % ( |
+ self._shim_id, |
+ escape_for_quoted_javascript_execution(method_name), |
+ escape_for_quoted_javascript_execution(json.dumps(args)) |
+ ) |
+ ) |
+ if result["success"]: |
+ return result["data"] |
+ # TODO(eatnumber) Make these exceptions more reader friendly. |
+ raise Exception(result) |
+ |
+ def __del__(self): |
+ self._js_executor( |
+ """ |
+ 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 |
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
|