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 5import logging 6import os 7 8from autotest_lib.client.bin import test, utils 9from autotest_lib.client.common_lib import error 10from autotest_lib.client.common_lib.cros import chrome 11from autotest_lib.client.common_lib.cros import enrollment 12from autotest_lib.client.common_lib.cros import kiosk_utils 13 14 15class enterprise_KioskEnrollment(test.test): 16 """Enroll the device in enterprise.""" 17 version = 1 18 19 APP_NAME = 'chromesign' 20 EXT_ID = 'odjaaghiehpobimgdjjfofmablbaleem' 21 EXT_PAGE = 'viewer.html' 22 23 def _CheckKioskExtensionContexts(self, browser): 24 ext_contexts = kiosk_utils.wait_for_kiosk_ext( 25 browser, self.EXT_ID) 26 ext_urls = set([context.EvaluateJavaScript('location.href;') 27 for context in ext_contexts]) 28 expected_urls = set( 29 ['chrome-extension://' + self.EXT_ID + '/' + path 30 for path in [self.EXT_PAGE, 31 '_generated_background_page.html']]) 32 if expected_urls != ext_urls: 33 raise error.TestFail( 34 'Unexpected extension context urls, expected %s, got %s' 35 % (expected_urls, ext_urls)) 36 37 38 def run_once(self, kiosk_app_attributes=None): 39 if kiosk_app_attributes: 40 self.APP_NAME, self.EXT_ID, self.EXT_PAGE = \ 41 kiosk_app_attributes.rstrip().split(':') 42 user_id, password = utils.get_signin_credentials(os.path.join( 43 os.path.dirname(os.path.realpath(__file__)), 44 'credentials.' + self.APP_NAME)) 45 if not (user_id and password): 46 logging.warn('No credentials found - exiting test.') 47 return 48 49 with chrome.Chrome(auto_login=False, 50 disable_gaia_services=False) as cr: 51 enrollment.EnterpriseEnrollment(cr.browser, user_id, password) 52 self._CheckKioskExtensionContexts(cr.browser) 53