Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 import json | |
| 5 import os | |
| 6 | |
| 7 from chrome_remote_control import page_interaction | |
| 8 | |
| 9 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
| |
| 10 def __init__(self, js_filename, function_to_call, data): | |
| 11 super(JavaScriptRunnerInteraction, self).__init__() | |
| 12 self._js_filename = js_filename | |
| 13 self._function_to_call = function_to_call | |
| 14 self._data = data | |
| 15 | |
| 16 def SupportedForPage(self, page, tab): | |
| 17 return True | |
| 18 | |
| 19 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.)
| |
| 20 self.InjectCode(tab) | |
| 21 test.WillPerformInteraction(self, page, tab) | |
| 22 self.MakeJSCall(tab) | |
| 23 self.WaitForCompletion(tab) | |
| 24 test.DidPerformInteraction(self, page, tab) | |
| 25 | |
| 26 def CleanUp(self, page, tab): | |
| 27 pass | |
| 28 | |
| 29 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.)
| |
| 30 js_path = os.path.join(os.path.dirname(__file__), self._js_filename) | |
| 31 js_file = open(js_path, 'r').read() | |
| 32 tab.runtime.Execute(js_file) | |
| 33 | |
| 34 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.)
| |
| 35 code = ('window.__' + self._function_to_call + '(' + | |
| 36 json.dumps(self._data) + ');') | |
| 37 result = tab.runtime.Evaluate(code) | |
| 38 if not result: | |
| 39 raise page_interaction.PageInteractionFailed() | |
| 40 | |
| 41 # 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.)
| |
| 42 # function. For more complex waiting conditions, they need to override | |
| 43 # PerformInteraction. | |
| 44 def WaitForCompletion(self, tab): | |
| 45 pass | |
| OLD | NEW |