blob: dbdad22e3966b9f4cd6157dda0ee382fcb7784ef [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 Bhandarkar6cb16162014-06-04 17:22:14 -07008from autotest_lib.client.common_lib.cros import tpm_utils
Achuith Bhandarkar06b98e22014-05-13 11:56:16 -07009from telemetry.core import exceptions
Achuith Bhandarkar4301e942014-11-14 15:43:33 -080010from telemetry.core.platform import cros_interface
Achuith Bhandarkar06b98e22014-05-13 11:56:16 -070011
12
Achuith Bhandarkar06b98e22014-05-13 11:56:16 -070013def _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
20def 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 Bhandarkar0d47c9a2014-12-02 15:50:34 -080031 exceptions.DevtoolsTargetCrashException):
Achuith Bhandarkar06b98e22014-05-13 11:56:16 -070032 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 Bhandarkar6cb16162014-06-04 17:22:14 -070037 tpm_utils.SaveTPMPassword()
Achuith Bhandarkar06b98e22014-05-13 11:56:16 -070038
39
40def 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
51def 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)