| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 logging | 5 import logging |
| 6 import urllib2 | 6 import urllib2 |
| 7 import os | 7 import os |
| 8 | 8 |
| 9 from telemetry.core import exceptions | 9 from telemetry.core import exceptions |
| 10 from telemetry import decorators | 10 from telemetry import decorators |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 self.assertFalse(login_status['isScreenLocked']) | 94 self.assertFalse(login_status['isScreenLocked']) |
| 95 | 95 |
| 96 @decorators.Enabled('chromeos') | 96 @decorators.Enabled('chromeos') |
| 97 def testLogout(self): | 97 def testLogout(self): |
| 98 """Tests autotestPrivate.logout""" | 98 """Tests autotestPrivate.logout""" |
| 99 if self._is_guest: | 99 if self._is_guest: |
| 100 return | 100 return |
| 101 with self._CreateBrowser(autotest_ext=True) as b: | 101 with self._CreateBrowser(autotest_ext=True) as b: |
| 102 extension = self._GetAutotestExtension(b) | 102 extension = self._GetAutotestExtension(b) |
| 103 try: | 103 try: |
| 104 extension.ExecuteJavaScript('chrome.autotestPrivate.logout();') | 104 extension.ExecuteJavaScript2('chrome.autotestPrivate.logout();') |
| 105 except exceptions.Error: | 105 except exceptions.Error: |
| 106 pass | 106 pass |
| 107 py_utils.WaitFor(lambda: not self._IsCryptohomeMounted(), 20) | 107 py_utils.WaitFor(lambda: not self._IsCryptohomeMounted(), 20) |
| 108 | 108 |
| 109 @decorators.Disabled('all') | 109 @decorators.Disabled('all') |
| 110 def testGaiaLogin(self): | 110 def testGaiaLogin(self): |
| 111 """Tests gaia login. Use credentials in credentials.txt if it exists, | 111 """Tests gaia login. Use credentials in credentials.txt if it exists, |
| 112 otherwise use powerloadtest.""" | 112 otherwise use powerloadtest.""" |
| 113 if self._is_guest: | 113 if self._is_guest: |
| 114 return | 114 return |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 146 |
| 147 | 147 |
| 148 class CrOSScreenLockerTest(cros_test_case.CrOSTestCase): | 148 class CrOSScreenLockerTest(cros_test_case.CrOSTestCase): |
| 149 def _IsScreenLocked(self, browser): | 149 def _IsScreenLocked(self, browser): |
| 150 return self._GetLoginStatus(browser)['isScreenLocked'] | 150 return self._GetLoginStatus(browser)['isScreenLocked'] |
| 151 | 151 |
| 152 def _LockScreen(self, browser): | 152 def _LockScreen(self, browser): |
| 153 self.assertFalse(self._IsScreenLocked(browser)) | 153 self.assertFalse(self._IsScreenLocked(browser)) |
| 154 | 154 |
| 155 extension = self._GetAutotestExtension(browser) | 155 extension = self._GetAutotestExtension(browser) |
| 156 self.assertTrue(extension.EvaluateJavaScript( | 156 self.assertTrue(extension.EvaluateJavaScript2( |
| 157 "typeof chrome.autotestPrivate.lockScreen == 'function'")) | 157 "typeof chrome.autotestPrivate.lockScreen == 'function'")) |
| 158 logging.info('Locking screen') | 158 logging.info('Locking screen') |
| 159 extension.ExecuteJavaScript('chrome.autotestPrivate.lockScreen();') | 159 extension.ExecuteJavaScript2('chrome.autotestPrivate.lockScreen();') |
| 160 | 160 |
| 161 logging.info('Waiting for the lock screen') | 161 logging.info('Waiting for the lock screen') |
| 162 def ScreenLocked(): | 162 def ScreenLocked(): |
| 163 return (browser.oobe_exists and | 163 return (browser.oobe_exists and |
| 164 browser.oobe.EvaluateJavaScript("typeof Oobe == 'function'") and | 164 browser.oobe.EvaluateJavaScript2("typeof Oobe == 'function'") and |
| 165 browser.oobe.EvaluateJavaScript( | 165 browser.oobe.EvaluateJavaScript2( |
| 166 "typeof Oobe.authenticateForTesting == 'function'")) | 166 "typeof Oobe.authenticateForTesting == 'function'")) |
| 167 py_utils.WaitFor(ScreenLocked, 10) | 167 py_utils.WaitFor(ScreenLocked, 10) |
| 168 self.assertTrue(self._IsScreenLocked(browser)) | 168 self.assertTrue(self._IsScreenLocked(browser)) |
| 169 | 169 |
| 170 def _AttemptUnlockBadPassword(self, browser): | 170 def _AttemptUnlockBadPassword(self, browser): |
| 171 logging.info('Trying a bad password') | 171 logging.info('Trying a bad password') |
| 172 def ErrorBubbleVisible(): | 172 def ErrorBubbleVisible(): |
| 173 return not browser.oobe.EvaluateJavaScript(''' | 173 return not browser.oobe.EvaluateJavaScript2( |
| 174 document.getElementById('bubble').hidden | 174 "document.getElementById('bubble').hidden") |
| 175 ''') | 175 |
| 176 self.assertFalse(ErrorBubbleVisible()) | 176 self.assertFalse(ErrorBubbleVisible()) |
| 177 # TODO(catapult:#3028): Fix interpolation of JavaScript values. | 177 browser.oobe.ExecuteJavaScript2( |
| 178 browser.oobe.ExecuteJavaScript(''' | 178 "Oobe.authenticateForTesting({{ username }}, 'bad');", |
| 179 Oobe.authenticateForTesting('%s', 'bad'); | 179 username=self._username) |
| 180 ''' % self._username) | |
| 181 py_utils.WaitFor(ErrorBubbleVisible, 10) | 180 py_utils.WaitFor(ErrorBubbleVisible, 10) |
| 182 self.assertTrue(self._IsScreenLocked(browser)) | 181 self.assertTrue(self._IsScreenLocked(browser)) |
| 183 | 182 |
| 184 def _UnlockScreen(self, browser): | 183 def _UnlockScreen(self, browser): |
| 185 logging.info('Unlocking') | 184 logging.info('Unlocking') |
| 186 # TODO(catapult:#3028): Fix interpolation of JavaScript values. | 185 browser.oobe.ExecuteJavaScript2( |
| 187 browser.oobe.ExecuteJavaScript(''' | 186 'Oobe.authenticateForTesting({{ username }}, {{ password }});', |
| 188 Oobe.authenticateForTesting('%s', '%s'); | 187 username=self._username, password=self._password) |
| 189 ''' % (self._username, self._password)) | |
| 190 py_utils.WaitFor(lambda: not browser.oobe_exists, 10) | 188 py_utils.WaitFor(lambda: not browser.oobe_exists, 10) |
| 191 self.assertFalse(self._IsScreenLocked(browser)) | 189 self.assertFalse(self._IsScreenLocked(browser)) |
| 192 | 190 |
| 193 @decorators.Disabled('all') | 191 @decorators.Disabled('all') |
| 194 def testScreenLock(self): | 192 def testScreenLock(self): |
| 195 """Tests autotestPrivate.screenLock""" | 193 """Tests autotestPrivate.screenLock""" |
| 196 if self._is_guest: | 194 if self._is_guest: |
| 197 return | 195 return |
| 198 with self._CreateBrowser(autotest_ext=True) as browser: | 196 with self._CreateBrowser(autotest_ext=True) as browser: |
| 199 self._LockScreen(browser) | 197 self._LockScreen(browser) |
| 200 self._AttemptUnlockBadPassword(browser) | 198 self._AttemptUnlockBadPassword(browser) |
| 201 self._UnlockScreen(browser) | 199 self._UnlockScreen(browser) |
| OLD | NEW |