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. 4import logging 5import time 6 7from autotest_lib.server.cros.audio import audio_test 8from autotest_lib.client.cros.audio import audio_test_data 9from autotest_lib.client.cros.chameleon import chameleon_audio_helper 10from autotest_lib.client.cros.chameleon import chameleon_audio_ids 11from autotest_lib.client.common_lib import error 12from autotest_lib.client.common_lib import utils 13from autotest_lib.server import test 14from autotest_lib.server.cros.multimedia import remote_facade_factory 15 16class audio_AudioBasicAssistant(audio_test.AudioTest): 17 """A basic assistant voice command test.""" 18 version = 1 19 DELAY_AFTER_BINDING_SECS = 0.5 20 DELAY_AFTER_COMMAND_SECS = 3 21 GOOGLE_URL = 'google.com' 22 23 def run_once(self, host, enable_dsp_hotword=False): 24 """Run Basic Audio Assistant Test. 25 26 @param host: Device under test CrosHost 27 @param enable_dsp_hotword: A bool to control the usage of dsp for 28 hotword. 29 """ 30 # TODO(paulhsia): Use gtts to generate command in runtime 31 hotword_file = audio_test_data.HOTWORD_OPEN_TAB_TEST_FILE 32 chameleon_board = host.chameleon 33 factory = remote_facade_factory.RemoteFacadeFactory( 34 host, results_dir=self.resultsdir) 35 36 # Prepares chameleon speaker resource 37 chameleon_board.setup_and_reset(self.outputdir) 38 widget_factory = chameleon_audio_helper.AudioWidgetFactory( 39 factory, host) 40 source = widget_factory.create_widget( 41 chameleon_audio_ids.ChameleonIds.LINEOUT) 42 sink = widget_factory.create_widget( 43 chameleon_audio_ids.PeripheralIds.SPEAKER) 44 binder = widget_factory.create_binder(source, sink) 45 46 # Restarts Chrome with assistant enabled and enables hotword 47 assistant_facade = factory.create_assistant_facade() 48 assistant_facade.restart_chrome_for_assistant(enable_dsp_hotword) 49 assistant_facade.enable_hotword() 50 51 browser_facade = factory.create_browser_facade() 52 53 # Tests voice command with chameleon 54 with chameleon_audio_helper.bind_widgets(binder): 55 time.sleep(self.DELAY_AFTER_BINDING_SECS) 56 logging.info('Setting hotword playback data on Chameleon') 57 remote_hotword_file_path = source.set_playback_data(hotword_file) 58 source.start_playback_with_path(remote_hotword_file_path) 59 time.sleep(hotword_file.duration_secs) 60 time.sleep(self.DELAY_AFTER_COMMAND_SECS) 61 62 # Checks urls in open tabs 63 urls = browser_facade.get_tab_urls() 64 if len(urls) != 2: 65 raise error.TestFail('There should be an empty tab and a tab with ' 66 'Google.') 67 # Checks if google.com exists in tabs 68 for url in urls: 69 logging.debug(url) 70 if self.GOOGLE_URL in url.lower(): 71 break 72 else: 73 raise error.TestFail('There is no google.com opened in tabs.') 74