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..28bad81d2dd7201e632d79486b9620ffb5d87a29 |
--- /dev/null |
+++ b/chrome/test/functional/tracing/timeline_model.py |
@@ -0,0 +1,58 @@ |
+# Copyright (c) 2012 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 _EscapeForQuotedJavascriptExecution(js): |
Nirnimesh
2012/07/31 23:39:10
Move this inside the class as @staticmethod
|
+ # Poor man's string escape. |
+ return js.replace('\'', '\\\''); |
+ |
+ |
+class TimelineModel: |
+ """A proxy for about:tracing's TimelineModel class. |
+ |
+ Test authors should never need to know that this class is a proxy. |
+ """ |
+ 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( |
+ """window.timelineModelShims['%s'].invokeMethod('%s', '%s')""" % ( |
+ self._shim_id, |
+ _EscapeForQuotedJavascriptExecution(method_name), |
+ _EscapeForQuotedJavascriptExecution(json.dumps(args)) |
+ ) |
+ ) |
+ if result['success']: |
+ return result['data'] |
+ # TODO(eatnumber): Make these exceptions more reader friendly. |
+ raise RuntimeError(result) |
+ |
+ def __del__(self): |
+ self._js_executor( |
+ """ |
+ window.timelineModelShims['%s'] = undefined; |
Nirnimesh
2012/07/31 23:39:10
You didn't need to indent this block further, if y
|
+ 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); |