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.
6 """Basic playback test. Checks playback, seek, and replay based on events.
8 This test uses the bear videos from the test matrix in h264, vp8, and theora
18 # HTML test path; relative to src/chrome/test/data.
19 _TEST_HTML_PATH = os.path.join('media', 'html', 'media_basic_playback.html')
21 # Test videos to play. TODO(dalecurtis): Convert to text matrix parser when we
22 # have more test videos in the matrix. Code already written, see patch here:
23 # https://chromiumcodereview.appspot.com/9290008/#ps12
25 pyauto.PyUITest.GetFileURLForContentDataPath('media', name)
26 for name in ['bear.mp4', 'bear.ogv', 'bear.webm', 'bear_silent.mp4',
27 'bear_silent.ogv', 'bear_silent.webm']]
29 # Expected events for the first iteration and every iteration thereafter.
30 _EXPECTED_EVENTS_0 = [('ended', 2), ('playing', 2), ('seeked', 1),
32 _EXPECTED_EVENTS_n = [('abort', 1), ('emptied', 1)] + _EXPECTED_EVENTS_0
35 class MediaBasicPlaybackTest(pyauto.PyUITest):
36 """PyAuto test container. See file doc string for more information."""
38 def testBasicPlaybackMatrix(self):
39 """Launches HTML test which plays each video until end, seeks, and replays.
41 Specifically ensures that after the above sequence of events, the following
44 1. The first video has only 2x playing, 2x ended, and 1x seeked events.
45 2. Each subsequent video additionally has 1x abort and 1x emptied due to
46 switching of the src attribute.
47 3. video.currentTime == video.duration for each video.
49 See the HTML file at _TEST_HTML_PATH for more information.
51 self.NavigateToURL(self.GetFileURLForDataPath(_TEST_HTML_PATH))
53 for i, media in enumerate(_TEST_VIDEOS):
54 logging.debug('Running basic playback test for %s', media)
56 # Block until the test finishes and notifies us. Upon return the value of
57 # video.currentTime == video.duration is provided.
59 self.assertTrue(self.ExecuteJavascript("startTest('%s');" % media))
61 # PyAuto has trouble with arrays, so convert to string prior to request.
62 events = self.GetDOMValue("events.join(',')").split(',')
63 counts = [(item, events.count(item)) for item in sorted(set(events))]
65 # The first loop will not have the abort and emptied events triggered by
66 # changing the video src.
68 self.assertEqual(counts, _EXPECTED_EVENTS_0)
70 self.assertEqual(counts, _EXPECTED_EVENTS_n)
73 'Test failed with events: %s', self.GetDOMValue("events.join(',')"))
77 if __name__ == '__main__':