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

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 more stylistic issues. 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..68573093a0760b696d249cdc3d626da17e122d3e
--- /dev/null
+++ b/chrome/test/functional/tracing/timeline_model.py
@@ -0,0 +1,57 @@
+# 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
+
+
+class TimelineModel(object):
+ """A proxy for about:tracing's TimelineModel class.
+
+ Test authors should never need to know that this class is a proxy.
+ """
+ @staticmethod
+ def _EscapeForQuotedJavascriptExecution(js):
+ # Poor man's string escape.
+ return js.replace('\'', '\\\'');
+
+ 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,
+ self._EscapeForQuotedJavascriptExecution(method_name),
+ self._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;
+ 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);
« no previous file with comments | « chrome/test/functional/tracing/tab_tracker.py ('k') | chrome/test/functional/tracing/timeline_model_shim.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698