Home | History | Annotate | Download | only in audio_AudioCorruption
      1 # Copyright (c) 2013 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 os
      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
     10 
     11 WAIT_TIMEOUT_S = 30
     12 
     13 class audio_AudioCorruption(test.test):
     14     """This test verifies playing corrupted audio in Chrome."""
     15     version = 1
     16 
     17     def run_once(self, audio):
     18         """Tests whether Chrome handles corrupted audio gracefully.
     19 
     20         @param audio: Sample corrupted audio file to be played in Chrome.
     21         """
     22         with chrome.Chrome(init_network_controller=True) as cr:
     23             cr.browser.platform.SetHTTPServerDirectories(self.bindir)
     24             tab = cr.browser.tabs[0]
     25             tab.Navigate(cr.browser.platform.http_server.UrlOf(
     26                     os.path.join(self.bindir, 'audio.html')))
     27             tab.WaitForDocumentReadyStateToBeComplete()
     28 
     29             tab.EvaluateJavaScript(
     30                     'loadSourceAndRunCorruptionTest("%s")' % audio)
     31 
     32             # Expect corruption being detected after playing corrupted audio.
     33             utils.poll_for_condition(
     34                     lambda: tab.EvaluateJavaScript('corruptionDetected()'),
     35                     exception=error.TestError('Corruption test is timeout'),
     36                     timeout=WAIT_TIMEOUT_S,
     37                     sleep_interval=1)
     38