OLD | NEW |
---|---|
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import os | 5 import os |
6 import subprocess | |
7 import sys | |
8 import time | |
9 | |
10 | |
11 def _GetHelperRunner(): | |
Nirnimesh
2012/08/06 19:13:53
Is there a reason these functions have to be globa
yihongg
2012/08/08 01:04:48
Done.
| |
12 """Returns the python binary name that runs chromoting_helper.py.""" | |
13 if sys.platform.startswith('win'): | |
14 return "python" | |
15 else: | |
16 return "suid-python" | |
17 | |
18 def _GetHelper(): | |
19 """Get chromoting_helper.py""" | |
20 return os.path.join("chrome", "test", "pyautolib", "chromoting_helper.py") | |
6 | 21 |
7 | 22 |
8 class ChromotingMixIn(object): | 23 class ChromotingMixIn(object): |
9 """MixIn for PyUITest that adds Chromoting-specific methods. | 24 """MixIn for PyUITest that adds Chromoting-specific methods. |
10 | 25 |
11 Prepend it as a base class of a test to enable Chromoting functionality. | 26 Prepend it as a base class of a test to enable Chromoting functionality. |
12 This is a separate class from PyUITest to avoid namespace collisions. | 27 This is a separate class from PyUITest to avoid namespace collisions. |
13 | 28 |
14 Example usage: | 29 Example usage: |
15 class ChromotingExample(chromoting.ChromotingMixIn, pyauto.PyUITest): | 30 class ChromotingExample(chromoting.ChromotingMixIn, pyauto.PyUITest): |
16 def testShare(self): | 31 def testShare(self): |
17 app = self.InstallApp(self.GetWebappPath()) | 32 app = self.InstallApp(self.GetWebappPath()) |
18 self.LaunchApp(app) | 33 self.LaunchApp(app) |
19 self.Authenticate() | 34 self.Authenticate() |
20 self.assertTrue(self.Share()) | 35 self.assertTrue(self.Share()) |
36 | |
21 """ | 37 """ |
22 | 38 |
23 def _ExecuteJavascript(self, command, tab_index, windex): | 39 def _ExecuteJavascript(self, command, tab_index, windex): |
24 """Helper that returns immediately after running a Javascript command.""" | 40 """Helper that returns immediately after running a Javascript command. |
25 return self.ExecuteJavascript( | 41 """ |
42 self.ExecuteJavascript( | |
26 '%s; window.domAutomationController.send("done");' % command, | 43 '%s; window.domAutomationController.send("done");' % command, |
27 tab_index, windex) | 44 tab_index, windex) |
28 | 45 |
29 def _WaitForJavascriptCondition(self, condition, tab_index, windex): | 46 def _WaitForJavascriptCondition(self, condition, tab_index, windex): |
30 """Waits until the Javascript condition is true. | 47 """Waits until the Javascript condition is true. |
31 | 48 |
32 This is different from a naive self.WaitUntil(lambda: self.GetDOMValue()) | 49 This is different from a naive self.WaitUntil(lambda: self.GetDOMValue()) |
33 because it uses Javascript to check the condition instead of Python. | 50 because it uses Javascript to check the condition instead of Python. |
51 | |
52 Returns: True if condition is satisfied or otherwise False. | |
53 | |
34 """ | 54 """ |
35 return self.WaitUntil(lambda: self.GetDOMValue( | 55 return self.WaitUntil(lambda: self.GetDOMValue( |
36 '(%s) ? "1" : ""' % condition, tab_index, windex)) | 56 '(%s) ? "1" : ""' % condition, tab_index, windex)) |
37 | 57 |
38 def _ExecuteAndWaitForMode(self, command, mode, tab_index, windex): | 58 def _ExecuteAndWaitForMode(self, command, mode, tab_index, windex): |
39 self.assertTrue(self._ExecuteJavascript(command, tab_index, windex), | 59 """ Executes JavaScript and wait for remoting app mode equal to |
40 'Javascript command did not return anything.') | 60 the given mode. |
61 | |
62 Returns: True if condition is satisfied or otherwise False. | |
63 | |
64 """ | |
65 self._ExecuteJavascript(command, tab_index, windex) | |
41 return self._WaitForJavascriptCondition( | 66 return self._WaitForJavascriptCondition( |
42 'remoting.currentMode == remoting.AppMode.%s' % mode, | 67 'remoting.currentMode == remoting.AppMode.%s' % mode, |
43 tab_index, windex) | 68 tab_index, windex) |
44 | 69 |
45 def _ExecuteAndWaitForMajorMode(self, command, mode, tab_index, windex): | 70 def _ExecuteAndWaitForMajorMode(self, command, mode, tab_index, windex): |
46 self.assertTrue(self._ExecuteJavascript(command, tab_index, windex), | 71 """ Executes JavaScript and wait for remoting app major mode equal to |
47 'Javascript command did not return anything.') | 72 the given mode. |
73 | |
74 Returns: True if condition is satisfied or otherwise False. | |
75 | |
76 """ | |
77 self._ExecuteJavascript(command, tab_index, windex) | |
48 return self._WaitForJavascriptCondition( | 78 return self._WaitForJavascriptCondition( |
49 'remoting.getMajorMode() == remoting.AppMode.%s' % mode, | 79 'remoting.getMajorMode() == remoting.AppMode.%s' % mode, |
50 tab_index, windex) | 80 tab_index, windex) |
51 | 81 |
52 def GetWebappPath(self): | 82 def GetWebappPath(self): |
53 """Returns the path to the webapp. | 83 """Returns the path to the webapp. |
54 | 84 |
55 Expects the webapp to be in the same place as the pyautolib binaries. | 85 Expects the webapp to be in the same place as the pyautolib binaries. |
86 | |
56 """ | 87 """ |
57 return os.path.join(self.BrowserPath(), 'remoting', 'remoting.webapp') | 88 return os.path.join(self.BrowserPath(), 'remoting', 'remoting.webapp') |
58 | 89 |
59 def Authenticate(self, email=None, password=None, otp=None, | 90 def InstallHostDaemon(self): |
60 tab_index=1, windex=0): | 91 """Installs the host daemon.""" |
61 """Logs a user in for Chromoting and accepts permissions for the app. | 92 subprocess.call([self._GetHelperRunner(), self._GetHelper(), |
93 "install", self.BrowserPath()]) | |
62 | 94 |
63 PyAuto tests start with a clean profile, so Chromoting tests should call | 95 def UninstallHostDaemon(self): |
64 this for every run after launching the app. If email or password is omitted, | 96 """Uninstalls the host daemon.""" |
65 the user can type it into the browser window manually. | 97 subprocess.call([self._GetHelperRunner(), self._GetHelper(), |
98 "uninstall", self.BrowserPath()]) | |
66 | 99 |
67 Raises: | 100 def ContinueAuth(self, tab_index=1, windex=0): |
68 AssertionError if the authentication flow changes or | 101 """Starts authentication.""" |
69 the credentials are incorrect. | |
70 """ | |
71 self.assertTrue( | 102 self.assertTrue( |
72 self._WaitForJavascriptCondition('window.remoting && remoting.oauth2', | 103 self._WaitForJavascriptCondition('window.remoting && remoting.oauth2', |
73 tab_index, windex), | 104 tab_index, windex), |
74 msg='Timed out while waiting for remoting app to finish loading.') | 105 msg='Timed out while waiting for remoting app to finish loading.') |
75 self._ExecuteJavascript('remoting.oauth2.doAuthRedirect();', | 106 self._ExecuteJavascript('remoting.oauth2.doAuthRedirect();', |
76 tab_index, windex) | 107 tab_index, windex) |
108 | |
109 def LogIn(self, email=None, password=None, otp=None, | |
110 tab_index=1, windex=0): | |
111 """Logs a user in. | |
112 | |
113 PyAuto tests start with a clean profile, so Chromoting tests should call | |
114 this for every run after launching the app. If email or password is | |
115 omitted, the user can type it into the browser window manually. | |
116 | |
117 """ | |
77 self.assertTrue( | 118 self.assertTrue( |
78 self._WaitForJavascriptCondition('document.getElementById("signIn")', | 119 self._WaitForJavascriptCondition('document.getElementById("signIn")', |
79 tab_index, windex), | 120 tab_index, windex), |
80 msg='Unable to redirect for authentication.') | 121 msg='Unable to redirect for authentication.') |
81 | 122 |
82 if email: | 123 if email: |
83 self._ExecuteJavascript('document.getElementById("Email").value = "%s";' | 124 self._ExecuteJavascript('document.getElementById("Email").value = "%s";' |
84 'document.getElementById("Passwd").focus();' | 125 'document.getElementById("Passwd").focus();' |
85 % email, tab_index, windex) | 126 % email, tab_index, windex) |
86 | 127 |
87 if password: | 128 if password: |
88 self._ExecuteJavascript('document.getElementById("Passwd").value = "%s";' | 129 self._ExecuteJavascript('document.getElementById("Passwd").value = "%s";' |
89 'document.getElementById("signIn").click();' | 130 'document.getElementById("signIn").click();' |
90 % password, tab_index, windex) | 131 % password, tab_index, windex) |
91 | 132 |
92 if otp: | 133 if otp: |
93 self.assertTrue( | 134 self.assertTrue( |
94 self._WaitForJavascriptCondition( | 135 self._WaitForJavascriptCondition( |
95 'document.getElementById("smsVerifyPin")', | 136 'document.getElementById("smsVerifyPin")', |
96 tab_index, windex), | 137 tab_index, windex), |
97 msg='Invalid username or password.') | 138 msg='Invalid username or password.') |
98 self._ExecuteJavascript('document.getElementById("smsUserPin").value = ' | 139 self._ExecuteJavascript( |
99 '"%s";' | 140 'document.getElementById("smsUserPin").value = "%s";' |
100 'document.getElementById("smsVerifyPin").click();' | 141 'document.getElementById("smsVerifyPin").click();' % otp, |
101 % otp, tab_index, windex) | 142 tab_index, windex) |
102 | 143 |
103 # If the account adder screen appears, then skip it. | 144 # If the account adder screen appears, then skip it. |
104 self.assertTrue( | 145 self.assertTrue( |
105 self._WaitForJavascriptCondition( | 146 self._WaitForJavascriptCondition( |
106 'document.getElementById("skip") || ' | 147 'document.getElementById("skip") || ' |
107 'document.getElementById("submit_approve_access")', | 148 'document.getElementById("submit_approve_access")', |
108 tab_index, windex), | 149 tab_index, windex), |
109 msg='No "skip adding account" or "approve access" link.') | 150 msg='No "skip adding account" or "approve access" link.') |
110 self._ExecuteJavascript( | 151 self._ExecuteJavascript( |
111 'if (document.getElementById("skip")) ' | 152 'if (document.getElementById("skip")) ' |
112 '{ document.getElementById("skip").click(); }', | 153 '{ document.getElementById("skip").click(); }', |
113 tab_index, windex) | 154 tab_index, windex) |
114 | 155 |
156 def AllowAccess(self, tab_index=1, windex=0): | |
157 """Allows access to chromoting webapp.""" | |
115 # Approve access. | 158 # Approve access. |
116 self.assertTrue( | 159 self.assertTrue( |
117 self._WaitForJavascriptCondition( | 160 self._WaitForJavascriptCondition( |
118 'document.getElementById("submit_approve_access")', | 161 'document.getElementById("submit_approve_access")', |
119 tab_index, windex), | 162 tab_index, windex), |
120 msg='Authentication failed. The username, password, or otp is invalid.') | 163 msg='Did not go to permission page.') |
121 self._ExecuteJavascript( | 164 self._ExecuteJavascript( |
122 'document.getElementById("submit_approve_access").click();', | 165 'document.getElementById("submit_approve_access").click();', |
123 tab_index, windex) | 166 tab_index, windex) |
124 | 167 |
125 # Wait for some things to be ready. | 168 # Wait for some things to be ready. |
126 self.assertTrue( | 169 self.assertTrue( |
127 self._WaitForJavascriptCondition( | 170 self._WaitForJavascriptCondition( |
128 'window.remoting && remoting.oauth2 && ' | 171 'window.remoting && remoting.oauth2 && ' |
129 'remoting.oauth2.isAuthenticated()', | 172 'remoting.oauth2.isAuthenticated()', |
130 tab_index, windex), | 173 tab_index, windex), |
131 msg='OAuth2 authentication failed.') | 174 msg='OAuth2 authentication failed.') |
132 self.assertTrue( | 175 self.assertTrue( |
133 self._WaitForJavascriptCondition( | 176 self._WaitForJavascriptCondition( |
134 'window.localStorage.getItem("remoting-email")', | 177 'window.localStorage.getItem("remoting-email")', |
135 tab_index, windex), | 178 tab_index, windex), |
136 msg='Chromoting app did not reload after authentication.') | 179 msg='Chromoting app did not reload after authentication.') |
137 | 180 |
181 def DenyAccess(self, tab_index=1, windex=0): | |
182 """Deny and then allow access to chromoting webapp.""" | |
183 self.assertTrue( | |
184 self._WaitForJavascriptCondition( | |
185 'document.getElementById("submit_deny_access")', | |
186 tab_index, windex), | |
187 msg='Did not go to permission page.') | |
188 self._ExecuteJavascript( | |
189 'document.getElementById("submit_deny_access").click();', | |
190 tab_index, windex) | |
191 | |
192 def SignOut(self, tab_index=1, windex=0): | |
193 """Signs out from chromoting and signs back in.""" | |
194 self._ExecuteAndWaitForMode( | |
195 'document.getElementById("sign-out").click();', | |
196 'UNAUTHENTICATED', tab_index, windex) | |
197 | |
198 def Authenticate(self, tab_index=1, windex=0): | |
199 """Finishes authentication flow for user.""" | |
200 self.ContinueAuth(tab_index, windex) | |
201 account = self.GetPrivateInfo()['test_chromoting_account'] | |
202 self.host.LogIn(account['username'], account['password'], None, | |
203 tab_index, windex) | |
204 self.host.AllowAccess(tab_index, windex) | |
205 | |
206 def StartMe2Me(self, tab_index=1, windex=0): | |
207 """Starts Me2Me. """ | |
208 self._ExecuteJavascript( | |
209 'document.getElementById("get-started-me2me").click();', | |
210 tab_index, windex) | |
211 | |
138 def Share(self, tab_index=1, windex=0): | 212 def Share(self, tab_index=1, windex=0): |
139 """Generates an access code and waits for incoming connections. | 213 """Generates an access code and waits for incoming connections. |
140 | 214 |
141 Returns: | 215 Returns: |
142 The access code on success; None otherwise. | 216 The access code on success; None otherwise. |
143 """ | 217 """ |
144 self._ExecuteAndWaitForMode( | 218 self._ExecuteAndWaitForMode( |
145 'remoting.tryShare();', | 219 'remoting.tryShare();', |
146 'HOST_WAITING_FOR_CONNECTION', tab_index, windex) | 220 'HOST_WAITING_FOR_CONNECTION', tab_index, windex) |
147 return self.GetDOMValue( | 221 return self.GetDOMValue( |
148 'document.getElementById("access-code-display").innerText', | 222 'document.getElementById("access-code-display").innerText', |
149 tab_index, windex) | 223 tab_index, windex) |
150 | 224 |
151 def Connect(self, access_code, wait_for_frame, tab_index=1, windex=0): | |
152 """Connects to a Chromoting host and starts the session. | |
153 | |
154 Returns: | |
155 True on success; False otherwise. | |
156 """ | |
157 if not self._ExecuteAndWaitForMode( | |
158 'document.getElementById("access-code-entry").value = "%s";' | |
159 'remoting.connectIt2Me();' % access_code, | |
160 'IN_SESSION', tab_index, windex): | |
161 return False | |
162 | |
163 if wait_for_frame and not self._WaitForJavascriptCondition( | |
164 'remoting.clientSession && remoting.clientSession.hasReceivedFrame()', | |
165 tab_index, windex): | |
166 return False | |
167 return True | |
168 | |
169 def CancelShare(self, tab_index=1, windex=0): | 225 def CancelShare(self, tab_index=1, windex=0): |
170 """Stops sharing the desktop on the host side. | 226 """Stops sharing the desktop on the host side.""" |
171 | 227 self.assertTrue( |
172 Returns: | 228 self._ExecuteAndWaitForMode( |
173 True on success; False otherwise. | 229 'remoting.cancelShare();', |
174 """ | 230 'HOST_SHARE_FINISHED', tab_index, windex), |
175 return self._ExecuteAndWaitForMode( | 231 msg='Stopping sharing from the host side failed') |
176 'remoting.cancelShare();', | 232 |
177 'HOST_SHARE_FINISHED', tab_index, windex) | 233 def EnableConnectionsInstalled(self, pin_exercise=False, |
234 tab_index=1, windex=0): | |
235 """Enables the remote connections on the host side.""" | |
236 subprocess.call([self._GetHelperRunner(), self._GetHelper(), "enable"]) | |
237 | |
238 self.assertTrue( | |
239 self._ExecuteAndWaitForMode( | |
240 'document.getElementById("start-daemon").click();', | |
241 'HOST_SETUP_ASK_PIN', tab_index, windex), | |
242 msg='Cannot start host setup') | |
243 self.assertTrue( | |
244 self._WaitForJavascriptCondition( | |
245 'document.getElementById("ask-pin-form").hidden == false', | |
246 tab_index, windex), | |
247 msg='No ask pin dialog') | |
248 | |
249 if pin_exercise: | |
250 # Cancels the pin prompt | |
251 self._ExecuteJavascript( | |
252 'document.getElementById("daemon-pin-cancel").click();', | |
253 tab_index, windex) | |
254 | |
255 # Enables again | |
256 self.assertTrue( | |
257 self._ExecuteAndWaitForMode( | |
258 'document.getElementById("start-daemon").click();', | |
259 'HOST_SETUP_ASK_PIN', tab_index, windex), | |
260 msg='Cannot start host setup') | |
261 | |
262 # Click ok without typing in pins | |
263 self._ExecuteJavascript( | |
264 'document.getElementById("daemon-pin-ok").click();', | |
265 tab_index, windex) | |
266 self.assertTrue( | |
267 self._WaitForJavascriptCondition( | |
268 'document.getElementById("daemon-pin-error-message")', | |
269 tab_index, windex), | |
270 msg='No pin error message') | |
271 | |
272 # Mis-matching pins | |
273 self._ExecuteJavascript( | |
274 'document.getElementById("daemon-pin-entry").value = "111111";', | |
275 tab_index, windex) | |
276 self._ExecuteJavascript( | |
277 'document.getElementById("daemon-pin-confirm").value = "123456";', | |
278 tab_index, windex) | |
279 self.assertTrue( | |
280 self._WaitForJavascriptCondition( | |
281 'document.getElementById("daemon-pin-error-message")', | |
282 tab_index, windex), | |
283 msg='No pin error message') | |
284 | |
285 # Types in correct pins | |
286 self._ExecuteJavascript( | |
287 'document.getElementById("daemon-pin-entry").value = "111111";', | |
288 tab_index, windex) | |
289 self._ExecuteJavascript( | |
290 'document.getElementById("daemon-pin-confirm").value = "111111";', | |
291 tab_index, windex) | |
292 self.assertTrue( | |
293 self._ExecuteAndWaitForMode( | |
294 'document.getElementById("daemon-pin-ok").click();', | |
295 'HOST_SETUP_PROCESSING', tab_index, windex), | |
296 msg='Host setup was not started') | |
297 | |
298 # Handles preference panes | |
299 self.assertTrue( | |
300 self._WaitForJavascriptCondition( | |
301 'remoting.currentMode == remoting.AppMode.HOST_SETUP_DONE', | |
302 tab_index, windex), | |
303 msg='Host setup was not done') | |
304 | |
305 # Dismisses the host config done dialog | |
306 self.assertTrue( | |
307 self._WaitForJavascriptCondition( | |
308 'document.getElementById("host-setup-dialog")' | |
309 '.childNodes[5].hidden == false', | |
310 tab_index, windex), | |
311 msg='No host setup done dialog') | |
312 self.assertTrue( | |
313 self._ExecuteAndWaitForMode( | |
314 'document.getElementById("host-config-done-dismiss").click();', | |
315 'HOME', tab_index, windex), | |
316 msg='Failed to dismiss host setup confirmation dialog') | |
317 | |
318 def EnableConnectionsUninstalledAndCancel(self, tab_index=1, windex=0): | |
319 """Enables remote connections while host is not installed yet.""" | |
320 self.assertTrue( | |
321 self._ExecuteAndWaitForMode( | |
322 'document.getElementById("start-daemon").click();', | |
323 'HOST_SETUP_INSTALL', tab_index, windex), | |
324 msg='Cannot start host install') | |
325 self.assertTrue( | |
326 self._ExecuteAndWaitForMode( | |
327 'document.getElementById("host-config-install-dismiss").click();', | |
328 'HOME', tab_index, windex), | |
329 msg='Failed to dismiss host install dialog') | |
330 | |
331 def DisableConnections(self, tab_index=1, windex=0): | |
332 """Disables the remote connections on the host side.""" | |
333 time.sleep(2) | |
334 subprocess.call([self._GetHelperRunner(), self._GetHelper(), "disable"]) | |
335 | |
336 self._ExecuteJavascript( | |
337 'window.location.reload();', | |
338 tab_index, windex) | |
339 time.sleep(2) | |
340 | |
341 self._ExecuteJavascript( | |
342 'document.getElementById("stop-daemon").click();', | |
343 tab_index, windex) | |
344 self.assertTrue( | |
345 self._ExecuteAndWaitForMode( | |
346 'document.getElementById("host-config-done-dismiss").click();', | |
347 'HOME', tab_index, windex), | |
348 msg='Failed to dismiss host setup confirmation dialog') | |
349 | |
350 def Connect(self, access_code, tab_index=1, windex=0): | |
351 """Connects to a Chromoting host and starts the session.""" | |
352 self.assertTrue( | |
353 self._ExecuteAndWaitForMode( | |
354 'document.getElementById("access-code-entry").value = "%s";' | |
355 'remoting.connectIt2Me();' % access_code, | |
356 'IN_SESSION', tab_index, windex), | |
357 msg='Cannot connect it2me session') | |
358 | |
359 def ChangePin(self, pin="222222", tab_index=1, windex=0): | |
360 """Changes pin for enabled host.""" | |
361 subprocess.call([self._GetHelperRunner(), self._GetHelper(), "changepin"]) | |
362 | |
363 self.assertTrue( | |
364 self._ExecuteAndWaitForMode( | |
365 'document.getElementById("change-daemon-pin").click();', | |
366 'HOST_SETUP_ASK_PIN', tab_index, windex), | |
367 msg='Cannot change daemon pin') | |
368 self.assertTrue( | |
369 self._WaitForJavascriptCondition( | |
370 'document.getElementById("ask-pin-form").hidden == false', | |
371 tab_index, windex), | |
372 msg='No ask pin dialog') | |
373 | |
374 self._ExecuteJavascript( | |
375 'document.getElementById("daemon-pin-entry").value = "' + pin + '";', | |
376 tab_index, windex) | |
377 self._ExecuteJavascript( | |
378 'document.getElementById("daemon-pin-confirm").value = "' + | |
379 pin + '";', tab_index, windex) | |
380 self.assertTrue( | |
381 self._ExecuteAndWaitForMode( | |
382 'document.getElementById("daemon-pin-ok").click();', | |
383 'HOST_SETUP_PROCESSING', tab_index, windex), | |
384 msg='Host setup was not started') | |
385 | |
386 # Handles preference panes | |
387 self.assertTrue( | |
388 self._WaitForJavascriptCondition( | |
389 'remoting.currentMode == remoting.AppMode.HOST_SETUP_DONE', | |
390 tab_index, windex), | |
391 msg='Host setup was not done') | |
392 | |
393 # Dismisses the host config done dialog | |
394 self.assertTrue( | |
395 self._WaitForJavascriptCondition( | |
396 'document.getElementById("host-setup-dialog")' | |
397 '.childNodes[5].hidden == false', | |
398 tab_index, windex), | |
399 msg='No host setup done dialog') | |
400 self.assertTrue( | |
401 self._ExecuteAndWaitForMode( | |
402 'document.getElementById("host-config-done-dismiss").click();', | |
403 'HOME', tab_index, windex), | |
404 msg='Failed to dismiss host setup confirmation dialog') | |
405 | |
406 def ChangeName(self, new_name="Changed", tab_index=1, windex=0): | |
407 """Changes the host name.""" | |
408 self._ExecuteJavascript( | |
409 'document.getElementById("this-host-rename").click();', | |
410 tab_index, windex) | |
411 self._ExecuteJavascript( | |
412 'document.getElementById("this-host-name").childNodes[0].value = "' + | |
413 new_name + '";', tab_index, windex) | |
414 self._ExecuteJavascript( | |
415 'document.getElementById("this-host-rename").click();', | |
416 tab_index, windex) | |
417 | |
418 def ConnectMe2Me(self, pin="111111", mode="IN_SESSION", | |
419 tab_index=1, windex=0): | |
420 """Connects to a Chromoting host and starts the session.""" | |
421 if sys.platform.startswith('win'): | |
422 time.sleep(10) | |
423 else: | |
424 time.sleep(2) | |
425 self._ExecuteJavascript( | |
426 'window.location.reload();', | |
427 tab_index, windex) | |
428 time.sleep(2) | |
429 | |
430 self.assertTrue( | |
431 self._WaitForJavascriptCondition( | |
432 'document.getElementById("this-host-connect")', | |
433 tab_index, windex), | |
434 msg='This host did not appear') | |
435 self.assertTrue( | |
436 self._ExecuteAndWaitForMode( | |
437 'document.getElementById("this-host-name").click();', | |
438 'CLIENT_PIN_PROMPT', tab_index, windex), | |
439 msg='Client pin prompt did not show') | |
440 self._ExecuteJavascript( | |
441 'document.getElementById("pin-entry").value = "' + pin + '";', | |
442 tab_index, windex) | |
443 self.assertTrue( | |
444 self._ExecuteAndWaitForMode( | |
445 'document.getElementById("pin-form").childNodes[5].click();', | |
446 mode, tab_index, windex), | |
447 msg='Session was not started') | |
178 | 448 |
179 def Disconnect(self, tab_index=1, windex=0): | 449 def Disconnect(self, tab_index=1, windex=0): |
180 """Disconnects from the Chromoting session on the client side. | 450 """Disconnects from the Chromoting it2me session on the client side.""" |
181 | 451 self.assertTrue( |
182 Returns: | 452 self._ExecuteAndWaitForMode( |
183 True on success; False otherwise. | 453 'remoting.disconnect();', |
184 """ | 454 'CLIENT_SESSION_FINISHED_IT2ME', tab_index, windex), |
185 return self._ExecuteAndWaitForMode( | 455 msg='Disconnecting it2me session from the client side failed') |
186 'remoting.disconnect();', | 456 |
187 'CLIENT_SESSION_FINISHED_IT2ME', tab_index, windex) | 457 def DisconnectMe2Me(self, confirmation=True, tab_index=1, windex=0): |
458 """Disconnects from the Chromoting me2me session on the client side.""" | |
459 self.assertTrue( | |
460 self._ExecuteAndWaitForMode( | |
461 'remoting.disconnect();', | |
462 'CLIENT_SESSION_FINISHED_ME2ME', tab_index, windex), | |
463 msg='Disconnecting me2me session from the client side failed') | |
464 | |
465 if confirmation: | |
466 self.assertTrue( | |
467 self._ExecuteAndWaitForMode( | |
468 'document.getElementById("client-finished-me2me-button")' | |
469 '.click();', 'HOME', tab_index, windex), | |
470 msg='Failed to dismiss session finished dialog') | |
471 | |
472 def ReconnectMe2Me(self, pin="111111", tab_index=1, windex=0): | |
473 """Reconnects the me2me session.""" | |
474 self._ExecuteJavascript( | |
475 'document.getElementById("client-reconnect-button").click();', | |
476 tab_index, windex) | |
477 time.sleep(2) | |
478 self._ExecuteJavascript( | |
479 'document.getElementById("pin-entry").value = "' + pin + '";', | |
480 tab_index, windex) | |
481 self.assertTrue( | |
482 self._ExecuteAndWaitForMode( | |
483 'document.getElementById("pin-form").childNodes[5].click();', | |
484 'IN_SESSION', tab_index, windex), | |
485 msg='Session was not started') | |
OLD | NEW |