blob: fda488fa9406af13bc9b43cc94c1fea796853657 [file] [log] [blame]
Achuith Bhandarkar06b98e22014-05-13 11:56:16 -07001# 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 Bhandarkar6cb16162014-06-04 17:22:14 -07005import logging
Achuith Bhandarkar06b98e22014-05-13 11:56:16 -07006
7from autotest_lib.client.bin import utils
Achuith Bhandarkar16ee9772015-01-23 17:18:18 -08008from autotest_lib.client.common_lib.cros import chrome, tpm_utils
Achuith Bhandarkar4301e942014-11-14 15:43:33 -08009from telemetry.core.platform import cros_interface
Achuith Bhandarkar06b98e22014-05-13 11:56:16 -070010
11
Achuith Bhandarkar06b98e22014-05-13 11:56:16 -070012def _ExecuteOobeCmd(browser, cmd):
13 logging.info('Invoking ' + cmd)
14 oobe = browser.oobe
15 oobe.WaitForJavaScriptExpression('typeof Oobe !== \'undefined\'', 10)
16 oobe.ExecuteJavaScript(cmd)
17
18
19def SwitchToRemora(browser):
20 """Switch to Remora enrollment.
21
22 @param browser: telemetry browser object.
23 """
24 _cri = cros_interface.CrOSInterface()
25 pid = _cri.GetChromePid()
Achuith Bhandarkar16ee9772015-01-23 17:18:18 -080026 # This will restart the browser.
27 chrome.Chrome.did_browser_crash(
28 lambda: _ExecuteOobeCmd(browser,
29 'Oobe.remoraRequisitionForTesting();'))
Achuith Bhandarkar06b98e22014-05-13 11:56:16 -070030 utils.poll_for_condition(lambda: pid != _cri.GetChromePid(), timeout=60)
31 utils.poll_for_condition(lambda: browser.oobe_exists, timeout=30)
32
33 _ExecuteOobeCmd(browser, 'Oobe.skipToLoginForTesting();')
Achuith Bhandarkar6cb16162014-06-04 17:22:14 -070034 tpm_utils.SaveTPMPassword()
Achuith Bhandarkar06b98e22014-05-13 11:56:16 -070035
36
37def FinishEnrollment(oobe):
38 """Wait for enrollment to finish and dismiss the last enrollment screen.
39
40 @param oobe: telemetry oobe object.
41 """
42 oobe.WaitForJavaScriptExpression(
43 "document.getElementById('oauth-enrollment').className."
44 "search('oauth-enroll-state-success') != -1", 30)
45 oobe.EvaluateJavaScript('Oobe.enterpriseEnrollmentDone();')
46
47
48def RemoraEnrollment(browser, user_id, password):
49 """Enterprise login for a Remora device.
50
51 @param browser: telemetry browser object.
52 @param user_id: login credentials user_id.
53 @param password: login credentials password.
54 """
55 SwitchToRemora(browser)
56 browser.oobe.NavigateGaiaLogin(user_id, password)
57 FinishEnrollment(browser.oobe)