Index: chrome/test/functional/tracing/timeline_model_shim.js |
diff --git a/chrome/test/functional/tracing/timeline_model_shim.js b/chrome/test/functional/tracing/timeline_model_shim.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..be4fcdb0b8f4031bf62629464953f6d9d7db0d15 |
--- /dev/null |
+++ b/chrome/test/functional/tracing/timeline_model_shim.js |
@@ -0,0 +1,53 @@ |
+// 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 TimelineModelShim() { |
+ tracing.TimelineModel.apply(this, arguments); |
+} |
+ |
+TimelineModelShim.prototype = { |
+ __proto__: tracing.TimelineModel.prototype, |
+ |
+ invokeMethod: function(methodName, args) { |
+ 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 |
+ }); |
+ } |
+}, |
+ |
+// This causes the PyAuto ExecuteJavascript call which executed this file to |
+// return. |
+window.domAutomationController.send(''); |