Home | History | Annotate | Download | only in enterprise_RemoraRequisition
      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 
      5 import logging, os, time
      6 
      7 from autotest_lib.client.bin import test, utils
      8 from autotest_lib.client.common_lib import error
      9 from autotest_lib.client.common_lib.cros import chrome, enrollment
     10 
     11 TIMEOUT = 20
     12 
     13 class enterprise_RemoraRequisition(test.test):
     14     """Enroll as a Remora device."""
     15     version = 1
     16 
     17     _HANGOUTS_EXT_ID = 'acdafoiapclbpdkhnighhilgampkglpc'
     18 
     19     def _WaitForHangouts(self, browser):
     20         def _HangoutExtContexts():
     21             try:
     22                 ext_contexts = browser.extensions.GetByExtensionId(
     23                         self._HANGOUTS_EXT_ID)
     24                 if len(ext_contexts) > 1:
     25                     return ext_contexts
     26             except (KeyError, chrome.Error):
     27                 pass
     28             return []
     29         return utils.poll_for_condition(
     30                 _HangoutExtContexts,
     31                 exception=error.TestFail('Hangouts app failed to launch'),
     32                 timeout=30,
     33                 sleep_interval=1)
     34 
     35     def _CheckHangoutsExtensionContexts(self, browser):
     36         ext_contexts = self._WaitForHangouts(browser)
     37         ext_urls = set([context.EvaluateJavaScript('location.href;')
     38                        for context in ext_contexts])
     39         expected_urls = set(
     40                 ['chrome-extension://' + self._HANGOUTS_EXT_ID + '/' + path
     41                 for path in ['hangoutswindow.html?windowid=0',
     42                              '_generated_background_page.html']])
     43         if expected_urls != ext_urls:
     44             raise error.TestFail(
     45                     'Unexpected extension context urls, expected %s, got %s'
     46                     % (expected_urls, ext_urls))
     47 
     48 
     49     def run_once(self):
     50         user_id, password = utils.get_signin_credentials(os.path.join(
     51                 os.path.dirname(os.path.realpath(__file__)), 'credentials.txt'))
     52         if not (user_id and password):
     53             logging.warn('No credentials found - exiting test.')
     54             return
     55 
     56         with chrome.Chrome(auto_login=False) as cr:
     57             enrollment.RemoraEnrollment(cr.browser, user_id, password)
     58             # Timeout to allow for the device to stablize and go back to the
     59             # login screen before proceeding.
     60             time.sleep(TIMEOUT)
     61 
     62         # This is a workaround fix for crbug.com/495847. A more permanent fix
     63         # should be to get the hotrod app to auto launch after enrollment.
     64         with chrome.Chrome(clear_enterprise_policy=False,
     65                            dont_override_profile=True,
     66                            disable_gaia_services=False,
     67                            disable_default_apps=False,
     68                            auto_login=False) as cr:
     69             self._CheckHangoutsExtensionContexts(cr.browser)
     70