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

Unified Diff: chrome/test/functional/tracing/timeline_model_decorator.js

Issue 10736055: Smoke test for tracing infrastructure in PyAuto (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use argument slices rather than explicit argument lists where appropriate. 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_decorator.js
diff --git a/chrome/test/functional/tracing/timeline_model_decorator.js b/chrome/test/functional/tracing/timeline_model_decorator.js
new file mode 100644
index 0000000000000000000000000000000000000000..cc6b9043273aff89dcb479ccead007152c1f1c5b
--- /dev/null
+++ b/chrome/test/functional/tracing/timeline_model_decorator.js
@@ -0,0 +1,66 @@
+// 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.
+
+function TimelineModelDecorator() {
+ tracing.TimelineModel.apply(this, arguments);
+}
+
nduca 2012/07/20 07:13:13 I'm struggling with naming here. Decorator is not
+TimelineModelDecorator.prototype = {
+ __proto__: tracing.TimelineModel.prototype,
+
+ invokeOnTimelineModel: function(methodName, args) {
nduca 2012/07/20 07:13:13 since you've made this a subclass of TimelineModel
+ var sendToPython = function(obj) {
+ // We use sendJSON here because domAutomationController's send() chokes on
+ // large amounts of data. Inside of send() it converts the arg to JSON and
+ // invokes sendJSON. The JSON conversion is what fails. This way works
+ // around the bad code, but note that the recieving python converts from
+ // JSON before passing it back to the pyauto test.
+ window.domAutomationController.sendJSON(
+ JSON.stringify(obj)
+ );
+ };
+ var result;
+ try {
+ result = this[methodName].apply(this, JSON.parse(args));
+ } catch( e ) {
+ var ret = {
+ success: false,
+ message: 'Unspecified error',
+ };
+ // We'll try sending the entire exception. If that doesn't work, it's ok.
+ try {
+ ret.exception = JSON.stringify(e);
+ } catch(e2) {}
+ if( typeof(e) == 'string' || e instanceof String ) {
+ ret.message = e;
+ } else {
+ if( e.stack != undefined ) ret.stack = e.stack;
+ if( e.message != undefined ) ret.message = e.message;
+ }
+ sendToPython(ret);
+ throw e;
+ }
+ sendToPython({
+ success: true,
+ data: result
+ });
+ }
+},
+
+TimelineModelDecorator.recordTrace = function(callback) {
+ var handler = function() {
+ tracingController.removeEventListener('traceEnded', handler);
+ var model = new TimelineModelDecorator(
+ Array.prototype.slice.call(arguments, 1)
+ );
+ var events = [tracingController.traceEvents_];
+ if (tracingController.supportsSystemTracing)
+ events.push(tracingController.systemTraceEvents_);
+ model.importTraces(events);
+ callback(model);
+ };
+ tracingController.addEventListener('traceEnded', handler);
+}
+
+window.domAutomationController.send('');
nduca 2012/07/20 07:13:13 Put a comment about what this does? It doesn't mak

Powered by Google App Engine
This is Rietveld 408576698