Achuith Bhandarkar | 06b98e2 | 2014-05-13 11:56:16 -0700 | [diff] [blame] | 1 | # Copyright 2014 The Chromium OS 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 | |
Achuith Bhandarkar | 6cb1616 | 2014-06-04 17:22:14 -0700 | [diff] [blame] | 5 | import logging |
Achuith Bhandarkar | 06b98e2 | 2014-05-13 11:56:16 -0700 | [diff] [blame] | 6 | |
| 7 | from autotest_lib.client.bin import utils |
Achuith Bhandarkar | 6cb1616 | 2014-06-04 17:22:14 -0700 | [diff] [blame] | 8 | from autotest_lib.client.common_lib.cros import tpm_utils |
Achuith Bhandarkar | 06b98e2 | 2014-05-13 11:56:16 -0700 | [diff] [blame] | 9 | from telemetry.core import exceptions |
Achuith Bhandarkar | 4301e94 | 2014-11-14 15:43:33 -0800 | [diff] [blame] | 10 | from telemetry.core.platform import cros_interface |
Achuith Bhandarkar | 06b98e2 | 2014-05-13 11:56:16 -0700 | [diff] [blame] | 11 | |
| 12 | |
Achuith Bhandarkar | 06b98e2 | 2014-05-13 11:56:16 -0700 | [diff] [blame] | 13 | def _ExecuteOobeCmd(browser, cmd): |
| 14 | logging.info('Invoking ' + cmd) |
| 15 | oobe = browser.oobe |
| 16 | oobe.WaitForJavaScriptExpression('typeof Oobe !== \'undefined\'', 10) |
| 17 | oobe.ExecuteJavaScript(cmd) |
| 18 | |
| 19 | |
| 20 | def SwitchToRemora(browser): |
| 21 | """Switch to Remora enrollment. |
| 22 | |
| 23 | @param browser: telemetry browser object. |
| 24 | """ |
| 25 | _cri = cros_interface.CrOSInterface() |
| 26 | pid = _cri.GetChromePid() |
| 27 | try: |
| 28 | # This will restart the browser. |
| 29 | _ExecuteOobeCmd(browser, 'Oobe.remoraRequisitionForTesting();') |
| 30 | except (exceptions.BrowserConnectionGoneException, |
Achuith Bhandarkar | 0d47c9a | 2014-12-02 15:50:34 -0800 | [diff] [blame] | 31 | exceptions.DevtoolsTargetCrashException): |
Achuith Bhandarkar | 06b98e2 | 2014-05-13 11:56:16 -0700 | [diff] [blame] | 32 | pass |
| 33 | utils.poll_for_condition(lambda: pid != _cri.GetChromePid(), timeout=60) |
| 34 | utils.poll_for_condition(lambda: browser.oobe_exists, timeout=30) |
| 35 | |
| 36 | _ExecuteOobeCmd(browser, 'Oobe.skipToLoginForTesting();') |
Achuith Bhandarkar | 6cb1616 | 2014-06-04 17:22:14 -0700 | [diff] [blame] | 37 | tpm_utils.SaveTPMPassword() |
Achuith Bhandarkar | 06b98e2 | 2014-05-13 11:56:16 -0700 | [diff] [blame] | 38 | |
| 39 | |
| 40 | def FinishEnrollment(oobe): |
| 41 | """Wait for enrollment to finish and dismiss the last enrollment screen. |
| 42 | |
| 43 | @param oobe: telemetry oobe object. |
| 44 | """ |
| 45 | oobe.WaitForJavaScriptExpression( |
| 46 | "document.getElementById('oauth-enrollment').className." |
| 47 | "search('oauth-enroll-state-success') != -1", 30) |
| 48 | oobe.EvaluateJavaScript('Oobe.enterpriseEnrollmentDone();') |
| 49 | |
| 50 | |
| 51 | def RemoraEnrollment(browser, user_id, password): |
| 52 | """Enterprise login for a Remora device. |
| 53 | |
| 54 | @param browser: telemetry browser object. |
| 55 | @param user_id: login credentials user_id. |
| 56 | @param password: login credentials password. |
| 57 | """ |
| 58 | SwitchToRemora(browser) |
| 59 | browser.oobe.NavigateGaiaLogin(user_id, password) |
| 60 | FinishEnrollment(browser.oobe) |