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 5import logging 6 7from autotest_lib.client.bin import utils 8from autotest_lib.client.common_lib.cros import chrome 9 10 11def _ExecuteOobeCmd(browser, cmd): 12 logging.info('Invoking ' + cmd) 13 oobe = browser.oobe 14 oobe.WaitForJavaScriptCondition('typeof Oobe !== \'undefined\'', 15 timeout=10) 16 oobe.ExecuteJavaScript(cmd) 17 18 19def SwitchToRemora(browser): 20 """Switch to Remora enrollment. 21 22 @param browser: telemetry browser object. 23 """ 24 chrome.Chrome.wait_for_browser_restart( 25 lambda: _ExecuteOobeCmd(browser, 26 'Oobe.remoraRequisitionForTesting();'), 27 browser) 28 utils.poll_for_condition(lambda: browser.oobe_exists, timeout=30) 29 30 31def RemoraEnrollment(browser, user_id, password): 32 """Enterprise login for a Remora device. 33 34 @param browser: telemetry browser object. 35 @param user_id: login credentials user_id. 36 @param password: login credentials password. 37 """ 38 SwitchToRemora(browser) 39 browser.oobe.NavigateGaiaLogin( 40 user_id, password, enterprise_enroll=True, 41 for_user_triggered_enrollment=False) 42 43 44def EnterpriseEnrollment(browser, user_id, password, auto_login=False): 45 """Enterprise login for a kiosk device. 46 47 @param browser: telemetry browser object. 48 @param user_id: login credentials user_id. 49 @param password: login credentials password. 50 @param auto_login: also login after enrollment. 51 """ 52 browser.oobe.NavigateGaiaLogin(user_id, password, 53 enterprise_enroll=True, 54 for_user_triggered_enrollment=True) 55 if auto_login: 56 browser.oobe.NavigateGaiaLogin(user_id, password) 57 # TODO(achuith): Replace with WaitForLogin. 58 utils.poll_for_condition(lambda: not browser.oobe_exists, timeout=30) 59 60 61def EnterpriseFakeEnrollment(browser, user_id, password, gaia_id, 62 auto_login=False): 63 """Enterprise fake login. 64 65 @param browser: telemetry browser object. 66 @param user_id: login credentials user_id. 67 @param password: login credentials password. 68 @param gaia_id: login credentials gaia_id. 69 @param auto_login: also login after enrollment. 70 """ 71 browser.oobe.NavigateFakeLogin(user_id, password, gaia_id, 72 enterprise_enroll=True) 73 if auto_login: 74 browser.oobe.NavigateFakeLogin(user_id, password, gaia_id) 75 # TODO(achuith): Replace with WaitForLogin. 76 utils.poll_for_condition(lambda: not browser.oobe_exists, timeout=30) 77 78 79def OnlineDemoMode(browser): 80 """Switch to online demo mode. 81 82 @param browser: telemetry browser object. 83 """ 84 _ExecuteOobeCmd(browser, 'Oobe.setUpOnlineDemoModeForTesting();') 85 utils.poll_for_condition(lambda: not browser.oobe_exists, timeout=90) 86