1 # Copyright 2016 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 5 import logging 6 import os 7 import time 8 9 from autotest_lib.client.bin import test, utils 10 from autotest_lib.client.common_lib import error 11 from autotest_lib.client.common_lib.cros import chrome 12 from autotest_lib.client.common_lib.cros import enrollment 13 from autotest_lib.client.common_lib.cros import kiosk_utils 14 15 TIMEOUT = 20 16 17 18 class enterprise_KioskEnrollment(test.test): 19 """Enroll the device in enterprise.""" 20 version = 1 21 22 APP_NAME = 'chromesign' 23 EXT_ID = 'odjaaghiehpobimgdjjfofmablbaleem' 24 EXT_PAGE = 'viewer.html' 25 26 def _CheckKioskExtensionContexts(self, browser): 27 ext_contexts = kiosk_utils.wait_for_kiosk_ext( 28 browser, self.EXT_ID) 29 ext_urls = set([context.EvaluateJavaScript('location.href;') 30 for context in ext_contexts]) 31 expected_urls = set( 32 ['chrome-extension://' + self.EXT_ID + '/' + path 33 for path in [self.EXT_PAGE, 34 '_generated_background_page.html']]) 35 if expected_urls != ext_urls: 36 raise error.TestFail( 37 'Unexpected extension context urls, expected %s, got %s' 38 % (expected_urls, ext_urls)) 39 40 41 def run_once(self, kiosk_app_attributes=None): 42 if kiosk_app_attributes: 43 self.APP_NAME, self.EXT_ID, self.EXT_PAGE = \ 44 kiosk_app_attributes.rstrip().split(':') 45 user_id, password = utils.get_signin_credentials(os.path.join( 46 os.path.dirname(os.path.realpath(__file__)), 47 'credentials.' + self.APP_NAME)) 48 if not (user_id and password): 49 logging.warn('No credentials found - exiting test.') 50 return 51 52 with chrome.Chrome(auto_login=False, 53 disable_gaia_services=False) as cr: 54 enrollment.EnterpriseEnrollment(cr.browser, user_id, password) 55 time.sleep(TIMEOUT) 56 57 # This is a workaround fix for crbug.com/495847. A more permanent fix 58 # should be to get the kiosk app to auto launch after enrollment. 59 cr = chrome.Chrome(clear_enterprise_policy=False, 60 dont_override_profile=True, 61 disable_gaia_services=False, 62 disable_default_apps=False, 63 auto_login=False) 64 self._CheckKioskExtensionContexts(cr.browser) 65