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

Unified Diff: chrome/test/functional/tracing.py

Issue 10736055: Smoke test for tracing infrastructure in PyAuto (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/functional/tracing.py
diff --git a/chrome/test/functional/tracing.py b/chrome/test/functional/tracing.py
new file mode 100755
index 0000000000000000000000000000000000000000..5c85456f50dec0a36d0c3c2b9c61c5cc730291a2
--- /dev/null
+++ b/chrome/test/functional/tracing.py
@@ -0,0 +1,84 @@
+#!/usr/bin/env python
+# 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 unittest
+
+import pyauto_functional
+import pyauto
nduca 2012/07/13 17:36:08 Lets split this into timeline_model.pyand tracing_
+import inspect
+import json
+import string
+
+class TimelineModel:
nduca 2012/07/13 09:47:56 TimelineModelProxy
+ def __init__(self, test):
nduca 2012/07/13 09:47:56 test -> automationController? So you're initializ
+ self._test = test
+
+ # Do note that the JSON serialization process removes cyclic references.
+ # TODO(eatnumber) regenerate these cyclic references on deserialization.
+ def __js_call__(self, name, *args):
nduca 2012/07/13 09:47:56 python convention say def _js_call(self, name, *a
+ return json.loads(self._test.ExecuteJavascript("""
+ var self = profilingView.timelineView.model;
+ var res = self['%s'].apply(self, JSON.parse('%s'));
nduca 2012/07/13 09:47:56 why [%s]? var res = %s.%s(%s)" % (self._remoteObj
+ window.domAutomationController.sendJSON(
+ JSON.stringify(JSON.stringify(res))
nduca 2012/07/13 09:47:56 Probably worth setting up some basic error handlin
+ );
+ """ % (
+ # Poor man's string escape.
+ string.replace(name, "'", "\\'"),
nduca 2012/07/13 09:47:56 make this a method called escapeForJavascriptExecu
+ string.replace(json.dumps(args), "'", "\\'")
+ ), 0, self._test.trace_win))
+
+ def getAllThreads(self):
+ return self.__js_call__(inspect.stack()[0][3]);
nduca 2012/07/13 09:47:56 Too magic. Hard code it. Also, does PyAuto not fol
+
+ def getAllCpus(self):
+ return self.__js_call__(inspect.stack()[0][3]);
+
+ def getAllProcesses(self):
+ return self.__js_call__(inspect.stack()[0][3]);
+
+ def getAllCounters(self):
+ return self.__js_call__(inspect.stack()[0][3]);
+
+class TraceTest(pyauto.PyUITest):
+ def setUp(self):
+ super(TraceTest, self).setUp()
+ self.trace_win = self.GetBrowserWindowCount()
+ self.OpenNewBrowserWindow(False)
+ self.NavigateToURL('chrome://tracing', self.trace_win)
nduca 2012/07/13 09:47:56 do we know if NavigateToURL waits for the DOMConte
Russ Harmon 2012/07/13 23:24:24 Other tests do it this way, so I'd assume yes.
+ self.ExecuteJavascript("""
+ tracingController.addEventListener("traceEnded", function() {
nduca 2012/07/13 09:47:56 single quotes in javascript
+ window.domAutomationController.send("");
nduca 2012/07/13 09:47:56 So if you pair this with the codereview I just pos
+ });
+ window.domAutomationController.send("");
+ """, 0, self.trace_win)
+
+ def tearDown(self):
+ self.CloseBrowserWindow(self.trace_win)
+ self.trace_win = None
nduca 2012/07/13 09:47:56 presumably this is _trace_win since you probably d
+ super(TraceTest, self).tearDown()
+
+ def _BeginTracing(self):
+ # TODO(nduca) Make the chrome tracing ui easier to automate
+ self.ExecuteJavascript("""
+ tracingController.beginTracing(true);
+ window.domAutomationController.send("");
+ """, 0, self.trace_win)
+
+ def _EndTracing(self):
+ # TODO(nduca) Make the chrome tracing ui easier to automate
+ self.ExecuteJavascript("""
+ tracingController.endTracing();
+ """, 0, self.trace_win)
+ return TimelineModel(self);
nduca 2012/07/13 09:47:56 What in the test does this cause us to wait on the
Russ Harmon 2012/07/13 23:24:24 I hope I understand this question correctly. Exec
+
+ def testBlah(self):
+ self._BeginTracing()
+ self.NavigateToURL('http://google.com')
+ model = self._EndTracing()
+
+
+if __name__ == '__main__':
+ pyauto_functional.Main()
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698