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