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

Unified Diff: tools/chrome_remote_control/chrome_remote_control/javascript_runner_interaction.py

Issue 11369075: Chrome remote control multipage tests: Add interactions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: refactoring; add click_element.py, and js runner superclass for interactions. Created 8 years, 1 month 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: 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

Powered by Google App Engine
This is Rietveld 408576698