1# Copyright 2019 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 5from autotest_lib.client.bin import test, utils 6from autotest_lib.client.common_lib.cros import chrome, enrollment 7from telemetry.core import exceptions 8 9# Id of the Infinite Painter app. 10_INFINITE_PAINTER_APP_ID = 'afihfgfghkmdmggakhkgnfhlikhdpima' 11 12def _launch_arc_app(autotest_ext, app_id): 13 try: 14 autotest_ext.ExecuteJavaScript(''' 15 chrome.autotestPrivate.launchArcApp( 16 '%s', /* app_id */ 17 '%s', /* intent */ 18 function(app_launched) { 19 window.__app_launched = app_launched; 20 }); 21 ''' % (app_id, 'intent')) 22 return autotest_ext.EvaluateJavaScript('window.__app_launched') 23 except exceptions.EvaluateException as e: 24 pass 25 return False 26 27class enterprise_OnlineDemoModeEnrollment(test.test): 28 """Enrolls to online demo mode.""" 29 version = 1 30 31 32 def run_once(self): 33 """Starts online demo mode enrollment. Waits for active session to start 34 and launch an arc app. 35 """ 36 with chrome.Chrome( 37 auto_login=False, 38 disable_gaia_services=False, 39 autotest_ext=True, 40 extra_browser_args='--force-devtools-available') as cr: 41 enrollment.OnlineDemoMode(cr.browser) 42 utils.poll_for_condition( 43 condition=lambda: _launch_arc_app(cr.autotest_ext, 44 _INFINITE_PAINTER_APP_ID), 45 desc='Launching the app %s' % 46 _INFINITE_PAINTER_APP_ID, 47 timeout=300, 48 sleep_interval=1)