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 from autotest_lib.client.common_lib import utils as utils2 15 16 KIOSK_MODE = 'Starting kiosk mode...' 17 18 19 class enterprise_KioskEnrollment(test.test): 20 """Enroll the device in enterprise.""" 21 version = 1 22 23 APP_NAME = 'chromesign' 24 EXT_ID = 'odjaaghiehpobimgdjjfofmablbaleem' 25 EXT_PAGE = 'viewer.html' 26 27 def _CheckKioskExtensionContexts(self, browser): 28 ext_contexts = kiosk_utils.wait_for_kiosk_ext( 29 browser, self.EXT_ID) 30 ext_urls = set([context.EvaluateJavaScript('location.href;') 31 for context in ext_contexts]) 32 expected_urls = set( 33 ['chrome-extension://' + self.EXT_ID + '/' + path 34 for path in [self.EXT_PAGE, 35 '_generated_background_page.html']]) 36 if expected_urls != ext_urls: 37 raise error.TestFail( 38 'Unexpected extension context urls, expected %s, got %s' 39 % (expected_urls, ext_urls)) 40 41 42 def run_once(self, kiosk_app_attributes=None): 43 if kiosk_app_attributes: 44 self.APP_NAME, self.EXT_ID, self.EXT_PAGE = \ 45 kiosk_app_attributes.rstrip().split(':') 46 user_id, password = utils.get_signin_credentials(os.path.join( 47 os.path.dirname(os.path.realpath(__file__)), 48 'credentials.' + self.APP_NAME)) 49 if not (user_id and password): 50 logging.warn('No credentials found - exiting test.') 51 return 52 53 with chrome.Chrome(auto_login=False, 54 disable_gaia_services=False) as cr: 55 enrollment.EnterpriseEnrollment(cr.browser, user_id, password) 56 # This way of checking a kiosk extension doesn't work. 57 #self._CheckKioskExtensionContexts(cr.browser) 58 time.sleep(15) 59 running_apps = utils2.system_output('cat /var/log/messages | grep kiosk') 60 if KIOSK_MODE not in running_apps: 61 raise error.TestFail( 62 'DUT did not enter kiosk mode. and it should have.') 63