1 # Copyright 2015 The Chromium 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.
5 from telemetry
import decorators
6 from telemetry
.internal
.actions
.load_media
import LoadMediaAction
7 from telemetry
.testing
import tab_test_case
12 class LoadMediaActionTest(tab_test_case
.TabTestCase
):
15 tab_test_case
.TabTestCase
.setUp(self
)
16 self
.Navigate('video_test.html')
18 def eventFired(self
, selector
, event
):
19 return self
._tab
.EvaluateJavaScript(
20 'window.__hasEventCompleted({{ selector }}, {{ event }});',
21 selector
=selector
, event
=event
)
23 @decorators.Disabled('linux', # crbug.com/418577
24 'chromeos') # crbug.com/632802
25 def testAwaitedEventIsConfigurable(self
):
26 """It's possible to wait for different events."""
27 action
= LoadMediaAction(selector
='#video_1', timeout_in_seconds
=0.1,
28 event_to_await
='loadedmetadata')
29 action
.WillRunAction(self
._tab
)
30 action
.RunAction(self
._tab
)
31 self
.assertTrue(self
.eventFired('#video_1', 'loadedmetadata'))
33 @decorators.Disabled('linux') # crbug.com/418577
34 def testLoadWithNoSelector(self
):
35 """With no selector the first media element is loaded."""
36 action
= LoadMediaAction(timeout_in_seconds
=5)
37 action
.WillRunAction(self
._tab
)
38 action
.RunAction(self
._tab
)
39 self
.assertTrue(self
.eventFired('#video_1', 'canplaythrough'))
40 self
.assertFalse(self
.eventFired('#audio_1', 'canplaythrough'))
42 @decorators.Disabled('linux') # crbug.com/418577
43 def testLoadWithSelector(self
):
44 """Only the element matching the selector is loaded."""
45 action
= LoadMediaAction(selector
='#audio_1', timeout_in_seconds
=5)
46 action
.WillRunAction(self
._tab
)
47 action
.RunAction(self
._tab
)
48 self
.assertFalse(self
.eventFired('#video_1', 'canplaythrough'))
49 self
.assertTrue(self
.eventFired('#audio_1', 'canplaythrough'))
51 @decorators.Disabled('linux') # crbug.com/418577
52 def testLoadWithAllSelector(self
):
53 """Both elements are loaded with selector='all'."""
54 action
= LoadMediaAction(selector
='all', timeout_in_seconds
=5)
55 action
.WillRunAction(self
._tab
)
56 action
.RunAction(self
._tab
)
57 self
.assertTrue(self
.eventFired('#video_1', 'canplaythrough'))
58 self
.assertTrue(self
.eventFired('#audio_1', 'canplaythrough'))
60 @decorators.Disabled('linux') # crbug.com/418577
61 def testLoadRaisesAnExceptionOnTimeout(self
):
62 """The load action times out if the event does not fire."""
63 action
= LoadMediaAction(selector
='#video_1', timeout_in_seconds
=0.1,
64 event_to_await
='a_nonexistent_event')
65 action
.WillRunAction(self
._tab
)
66 self
.assertRaises(py_utils
.TimeoutException
, action
.RunAction
, self
._tab
)