1# Lint as: python2, python3
2# Copyright 2019 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5"""
6This is a server side audio test testing assumptions other audio tests
7rely on.
8"""
9
10from autotest_lib.client.common_lib import error
11from autotest_lib.client.cros.chameleon import audio_test_utils
12from autotest_lib.server.cros.audio import audio_test
13
14
15class audio_AudioTestAssumptionCheck(audio_test.AudioTest):
16    """
17    This test talks to a Cros device to verify if some basic functions that
18    other audio tests rely on still work after a suspension.
19    """
20    version = 1
21
22    def verify_chrome_audio(self):
23        """"Verify if chrome.audio API is available"""
24        if not self.facade.get_chrome_audio_availablity():
25            raise error.TestFail("chrome.audio API is not available")
26
27    def verify_suspend(self):
28        """"Verify and trigger a suspension"""
29        audio_test_utils.suspend_resume_and_verify(self.host, self.factory)
30
31    def run_once(self, suspend_only=False):
32        """Runs Audio confidence test to make sure chrome api works. """
33
34        # Check if the chrome.audio API is available
35        self.verify_chrome_audio()
36
37        self.verify_suspend()
38        # The suspend_only flag is for crbug:978593, which causes the audio API
39        # check to fail. However, we still want to check the suspend operation
40        # as it also potentially fails the audio tests. This should be removed
41        # once the blocker is fixed
42        if suspend_only:
43            return
44
45        # chrome.audio API should remain available after a suspension
46        self.verify_chrome_audio()
47