Index: tools/chrome_remote_control/chrome_remote_control/javascript_runner_interaction.py |
diff --git a/tools/chrome_remote_control/chrome_remote_control/javascript_runner_interaction.py b/tools/chrome_remote_control/chrome_remote_control/javascript_runner_interaction.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..900ec3eb41661c07ff04b9e145bcd47c8bd8d6ed |
--- /dev/null |
+++ b/tools/chrome_remote_control/chrome_remote_control/javascript_runner_interaction.py |
@@ -0,0 +1,45 @@ |
+# 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 |
+ |
+from chrome_remote_control import page_interaction |
+ |
+class JavaScriptRunnerInteraction(page_interaction.PageInteraction): |
nduca
2012/11/07 04:13:49
Once you do the chagnes below, you should be able
marja
2012/11/07 10:52:27
(This file has been removed. I can add the helpers
|
+ def __init__(self, js_filename, function_to_call, data): |
+ super(JavaScriptRunnerInteraction, self).__init__() |
+ self._js_filename = js_filename |
+ self._function_to_call = function_to_call |
+ self._data = data |
+ |
+ def SupportedForPage(self, page, tab): |
+ return True |
+ |
+ def PerformInteraction(self, page, tab, test): |
nduca
2012/11/07 04:13:49
Would ratehr this not be implemented.
marja
2012/11/07 10:52:27
(This file has been removed.)
|
+ self.InjectCode(tab) |
+ test.WillPerformInteraction(self, page, tab) |
+ self.MakeJSCall(tab) |
+ self.WaitForCompletion(tab) |
+ test.DidPerformInteraction(self, page, tab) |
+ |
+ def CleanUp(self, page, tab): |
+ pass |
+ |
+ def InjectCode(self, tab): |
nduca
2012/11/07 04:13:49
How about making this be InjectFileIfNeeded(self,
marja
2012/11/07 10:52:27
(This file has been removed.)
|
+ js_path = os.path.join(os.path.dirname(__file__), self._js_filename) |
+ js_file = open(js_path, 'r').read() |
+ tab.runtime.Execute(js_file) |
+ |
+ def MakeJSCall(self, tab): |
nduca
2012/11/07 04:13:49
I dont think this helper is needed. We should make
marja
2012/11/07 10:52:27
(This file has been removed.)
|
+ code = ('window.__' + self._function_to_call + '(' + |
+ json.dumps(self._data) + ');') |
+ result = tab.runtime.Evaluate(code) |
+ if not result: |
+ raise page_interaction.PageInteractionFailed() |
+ |
+ # For simple waiting conditions, subclasses can just override this |
nduca
2012/11/07 04:13:49
I'd rather the place that makes the call just does
marja
2012/11/07 10:52:27
(This file has been removed.)
|
+ # function. For more complex waiting conditions, they need to override |
+ # PerformInteraction. |
+ def WaitForCompletion(self, tab): |
+ pass |