| 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.core import util | |
| 11 from telemetry import decorators | 10 from telemetry import decorators |
| 12 from telemetry.internal.backends.chrome import cros_test_case | 11 from telemetry.internal.backends.chrome import cros_test_case |
| 13 | 12 |
| 13 import py_utils |
| 14 |
| 14 | 15 |
| 15 class CrOSCryptohomeTest(cros_test_case.CrOSTestCase): | 16 class CrOSCryptohomeTest(cros_test_case.CrOSTestCase): |
| 16 @decorators.Enabled('chromeos') | 17 @decorators.Enabled('chromeos') |
| 17 def testCryptohome(self): | 18 def testCryptohome(self): |
| 18 """Verifies cryptohome mount status for regular and guest user and when | 19 """Verifies cryptohome mount status for regular and guest user and when |
| 19 logged out""" | 20 logged out""" |
| 20 with self._CreateBrowser() as b: | 21 with self._CreateBrowser() as b: |
| 21 self.assertEquals(1, len(b.tabs)) | 22 self.assertEquals(1, len(b.tabs)) |
| 22 self.assertTrue(b.tabs[0].url) | 23 self.assertTrue(b.tabs[0].url) |
| 23 self.assertTrue(self._IsCryptohomeMounted()) | 24 self.assertTrue(self._IsCryptohomeMounted()) |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 def testLogout(self): | 93 def testLogout(self): |
| 93 """Tests autotestPrivate.logout""" | 94 """Tests autotestPrivate.logout""" |
| 94 if self._is_guest: | 95 if self._is_guest: |
| 95 return | 96 return |
| 96 with self._CreateBrowser(autotest_ext=True) as b: | 97 with self._CreateBrowser(autotest_ext=True) as b: |
| 97 extension = self._GetAutotestExtension(b) | 98 extension = self._GetAutotestExtension(b) |
| 98 try: | 99 try: |
| 99 extension.ExecuteJavaScript('chrome.autotestPrivate.logout();') | 100 extension.ExecuteJavaScript('chrome.autotestPrivate.logout();') |
| 100 except exceptions.Error: | 101 except exceptions.Error: |
| 101 pass | 102 pass |
| 102 util.WaitFor(lambda: not self._IsCryptohomeMounted(), 20) | 103 py_utils.WaitFor(lambda: not self._IsCryptohomeMounted(), 20) |
| 103 | 104 |
| 104 @decorators.Disabled('all') | 105 @decorators.Disabled('all') |
| 105 def testGaiaLogin(self): | 106 def testGaiaLogin(self): |
| 106 """Tests gaia login. Use credentials in credentials.txt if it exists, | 107 """Tests gaia login. Use credentials in credentials.txt if it exists, |
| 107 otherwise use powerloadtest.""" | 108 otherwise use powerloadtest.""" |
| 108 if self._is_guest: | 109 if self._is_guest: |
| 109 return | 110 return |
| 110 username, password = self._GetCredentials() | 111 username, password = self._GetCredentials() |
| 111 if not username or not password: | 112 if not username or not password: |
| 112 username = 'powerloadtest@gmail.com' | 113 username = 'powerloadtest@gmail.com' |
| 113 password = urllib2.urlopen( | 114 password = urllib2.urlopen( |
| 114 'https://sites.google.com/a/chromium.org/dev/chromium-os/testing/' | 115 'https://sites.google.com/a/chromium.org/dev/chromium-os/testing/' |
| 115 'power-testing/pltp/pltp').read().rstrip() | 116 'power-testing/pltp/pltp').read().rstrip() |
| 116 with self._CreateBrowser(gaia_login=True, | 117 with self._CreateBrowser(gaia_login=True, |
| 117 username=username, | 118 username=username, |
| 118 password=password): | 119 password=password): |
| 119 self.assertTrue(util.WaitFor(self._IsCryptohomeMounted, 10)) | 120 self.assertTrue(py_utils.WaitFor(self._IsCryptohomeMounted, 10)) |
| 120 | 121 |
| 121 @decorators.Enabled('chromeos') | 122 @decorators.Enabled('chromeos') |
| 122 def testEnterpriseEnroll(self): | 123 def testEnterpriseEnroll(self): |
| 123 """Tests enterprise enrollment. Credentials are expected to be found in a | 124 """Tests enterprise enrollment. Credentials are expected to be found in a |
| 124 credentials.txt file. The account must be from an enterprise domain and | 125 credentials.txt file. The account must be from an enterprise domain and |
| 125 have device enrollment permission. The device must be unowned.""" | 126 have device enrollment permission. The device must be unowned.""" |
| 126 if self._is_guest: | 127 if self._is_guest: |
| 127 return | 128 return |
| 128 | 129 |
| 129 username, password = self._GetCredentials() | 130 username, password = self._GetCredentials() |
| 130 if not username or not password: | 131 if not username or not password: |
| 131 return | 132 return |
| 132 # Enroll the device. | 133 # Enroll the device. |
| 133 with self._CreateBrowser(auto_login=False) as browser: | 134 with self._CreateBrowser(auto_login=False) as browser: |
| 134 browser.oobe.NavigateGaiaLogin(username, password, | 135 browser.oobe.NavigateGaiaLogin(username, password, |
| 135 enterprise_enroll=True, | 136 enterprise_enroll=True, |
| 136 for_user_triggered_enrollment=True) | 137 for_user_triggered_enrollment=True) |
| 137 | 138 |
| 138 # Check for the existence of the device policy file. | 139 # Check for the existence of the device policy file. |
| 139 self.assertTrue(util.WaitFor(lambda: self._cri.FileExistsOnDevice( | 140 self.assertTrue(py_utils.WaitFor(lambda: self._cri.FileExistsOnDevice( |
| 140 '/home/.shadow/install_attributes.pb'), 15)) | 141 '/home/.shadow/install_attributes.pb'), 15)) |
| 141 | 142 |
| 142 | 143 |
| 143 class CrOSScreenLockerTest(cros_test_case.CrOSTestCase): | 144 class CrOSScreenLockerTest(cros_test_case.CrOSTestCase): |
| 144 def _IsScreenLocked(self, browser): | 145 def _IsScreenLocked(self, browser): |
| 145 return self._GetLoginStatus(browser)['isScreenLocked'] | 146 return self._GetLoginStatus(browser)['isScreenLocked'] |
| 146 | 147 |
| 147 def _LockScreen(self, browser): | 148 def _LockScreen(self, browser): |
| 148 self.assertFalse(self._IsScreenLocked(browser)) | 149 self.assertFalse(self._IsScreenLocked(browser)) |
| 149 | 150 |
| 150 extension = self._GetAutotestExtension(browser) | 151 extension = self._GetAutotestExtension(browser) |
| 151 self.assertTrue(extension.EvaluateJavaScript( | 152 self.assertTrue(extension.EvaluateJavaScript( |
| 152 "typeof chrome.autotestPrivate.lockScreen == 'function'")) | 153 "typeof chrome.autotestPrivate.lockScreen == 'function'")) |
| 153 logging.info('Locking screen') | 154 logging.info('Locking screen') |
| 154 extension.ExecuteJavaScript('chrome.autotestPrivate.lockScreen();') | 155 extension.ExecuteJavaScript('chrome.autotestPrivate.lockScreen();') |
| 155 | 156 |
| 156 logging.info('Waiting for the lock screen') | 157 logging.info('Waiting for the lock screen') |
| 157 def ScreenLocked(): | 158 def ScreenLocked(): |
| 158 return (browser.oobe_exists and | 159 return (browser.oobe_exists and |
| 159 browser.oobe.EvaluateJavaScript("typeof Oobe == 'function'") and | 160 browser.oobe.EvaluateJavaScript("typeof Oobe == 'function'") and |
| 160 browser.oobe.EvaluateJavaScript( | 161 browser.oobe.EvaluateJavaScript( |
| 161 "typeof Oobe.authenticateForTesting == 'function'")) | 162 "typeof Oobe.authenticateForTesting == 'function'")) |
| 162 util.WaitFor(ScreenLocked, 10) | 163 py_utils.WaitFor(ScreenLocked, 10) |
| 163 self.assertTrue(self._IsScreenLocked(browser)) | 164 self.assertTrue(self._IsScreenLocked(browser)) |
| 164 | 165 |
| 165 def _AttemptUnlockBadPassword(self, browser): | 166 def _AttemptUnlockBadPassword(self, browser): |
| 166 logging.info('Trying a bad password') | 167 logging.info('Trying a bad password') |
| 167 def ErrorBubbleVisible(): | 168 def ErrorBubbleVisible(): |
| 168 return not browser.oobe.EvaluateJavaScript(''' | 169 return not browser.oobe.EvaluateJavaScript(''' |
| 169 document.getElementById('bubble').hidden | 170 document.getElementById('bubble').hidden |
| 170 ''') | 171 ''') |
| 171 self.assertFalse(ErrorBubbleVisible()) | 172 self.assertFalse(ErrorBubbleVisible()) |
| 172 browser.oobe.ExecuteJavaScript(''' | 173 browser.oobe.ExecuteJavaScript(''' |
| 173 Oobe.authenticateForTesting('%s', 'bad'); | 174 Oobe.authenticateForTesting('%s', 'bad'); |
| 174 ''' % self._username) | 175 ''' % self._username) |
| 175 util.WaitFor(ErrorBubbleVisible, 10) | 176 py_utils.WaitFor(ErrorBubbleVisible, 10) |
| 176 self.assertTrue(self._IsScreenLocked(browser)) | 177 self.assertTrue(self._IsScreenLocked(browser)) |
| 177 | 178 |
| 178 def _UnlockScreen(self, browser): | 179 def _UnlockScreen(self, browser): |
| 179 logging.info('Unlocking') | 180 logging.info('Unlocking') |
| 180 browser.oobe.ExecuteJavaScript(''' | 181 browser.oobe.ExecuteJavaScript(''' |
| 181 Oobe.authenticateForTesting('%s', '%s'); | 182 Oobe.authenticateForTesting('%s', '%s'); |
| 182 ''' % (self._username, self._password)) | 183 ''' % (self._username, self._password)) |
| 183 util.WaitFor(lambda: not browser.oobe_exists, 10) | 184 py_utils.WaitFor(lambda: not browser.oobe_exists, 10) |
| 184 self.assertFalse(self._IsScreenLocked(browser)) | 185 self.assertFalse(self._IsScreenLocked(browser)) |
| 185 | 186 |
| 186 @decorators.Disabled('all') | 187 @decorators.Disabled('all') |
| 187 def testScreenLock(self): | 188 def testScreenLock(self): |
| 188 """Tests autotestPrivate.screenLock""" | 189 """Tests autotestPrivate.screenLock""" |
| 189 if self._is_guest: | 190 if self._is_guest: |
| 190 return | 191 return |
| 191 with self._CreateBrowser(autotest_ext=True) as browser: | 192 with self._CreateBrowser(autotest_ext=True) as browser: |
| 192 self._LockScreen(browser) | 193 self._LockScreen(browser) |
| 193 self._AttemptUnlockBadPassword(browser) | 194 self._AttemptUnlockBadPassword(browser) |
| 194 self._UnlockScreen(browser) | 195 self._UnlockScreen(browser) |
| OLD | NEW |