1#!/usr/bin/env python
2# Copyright (c) 2012 The Chromium 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
6"""Audio latency performance test.
7
8Benchmark measuring how fast we can continuously repeat a short sound
9clip, while another clip is running in the background. In the ideal
10scenario we'd have zero latency processing script, seeking back to the
11beginning of the clip, and resuming audio playback.
12
13Performance is recorded as the average latency of N playbacks.  I.e., if we play
14a clip 50 times and the ideal duration of all playbacks is 1000ms and the total
15duration is 1500ms, the recorded result is (1500ms - 1000ms) / 50 == 10ms.
16"""
17import os
18
19import pyauto_media
20import pyauto_utils
21import pyauto
22
23
24# HTML test path; relative to src/chrome/test/data.
25_TEST_HTML_PATH = os.path.join('media', 'html', 'mixed_audio_latency_perf.html')
26
27
28class MixedAudioLatencyPerfTest(pyauto.PyUITest):
29  """PyAuto test container.  See file doc string for more information."""
30
31  def testAudioLatency(self):
32    """Launches HTML test which runs the audio latency test."""
33    self.NavigateToURL(self.GetFileURLForDataPath(_TEST_HTML_PATH))
34
35    # Block until the test finishes and notifies us.
36    self.assertTrue(self.ExecuteJavascript('startTest();'))
37    latency = float(self.GetDOMValue('averageLatency'))
38    pyauto_utils.PrintPerfResult('audio_latency', 'latency_bg_clip', latency,
39                                 'ms')
40
41
42if __name__ == '__main__':
43  pyauto_media.Main()
44