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

Unified 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: Fix up style issues. Add suite to PYAUTO_TESTS Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698