OLD | NEW |
1 <!doctype html> | 1 <!DOCTYPE html> |
2 <html> | 2 <title>media controls cast button</title> |
3 <head> | 3 <script src="../resources/testharness.js"></script> |
4 <title>media controls cast button</title> | 4 <script src="../resources/testharnessreport.js"></script> |
5 <script src="../resources/testharness.js"></script> | 5 <script src="media-file.js"></script> |
6 <script src="../resources/testharnessreport.js"></script> | 6 <script src="media-controls.js"></script> |
7 <script src="media-file.js"></script> | 7 <video controls width="500"></video> |
8 <script src="media-controls.js"></script> | 8 <script> |
9 <!-- TODO(foolip): Convert test to testharness.js. crbug.com/588956 | 9 async_test(function(t) { |
10 (Please avoid writing new tests using video-test.js) --> | 10 var video = document.querySelector("video"); |
11 <script src="video-test.js"></script> | 11 video.src = findMediaFile("video", "content/test"); |
12 </head> | |
13 <body> | |
14 <video controls width=500></video> | |
15 <script> | |
16 function castButton(element) | |
17 { | |
18 var controlID = "-internal-media-controls-cast-button"; | |
19 var button = mediaControlsElement(window.internals.shadowRoot(elemen
t).firstChild, controlID); | |
20 if (!button) | |
21 throw "Failed to find cast button"; | |
22 return button; | |
23 } | |
24 function overlayCastButton(element) | |
25 { | |
26 var controlID = "-internal-media-controls-overlay-cast-button"; | |
27 var button = mediaControlsElement(window.internals.shadowRoot(elemen
t).firstChild, controlID); | |
28 if (!button) | |
29 throw "Failed to find cast button"; | |
30 return button; | |
31 } | |
32 function castButtonDimensions(element) | |
33 { | |
34 var button = castButton(element); | |
35 var buttonBoundingRect = button.getBoundingClientRect(); | |
36 return new Array(buttonBoundingRect.width, buttonBoundingRect.height
); | |
37 } | |
38 function castButtonCoordinates(element, id) | |
39 { | |
40 var button = castButton(element); | |
41 var buttonBoundingRect = button.getBoundingClientRect(); | |
42 var x = buttonBoundingRect.left + buttonBoundingRect.width / 2; | |
43 var y = buttonBoundingRect.top + buttonBoundingRect.height / 2; | |
44 return new Array(x, y); | |
45 } | |
46 async_test(function(t) | |
47 { | |
48 findMediaElement(); | |
49 video.src = findMediaFile("video", "content/test"); | |
50 mediaElement.addEventListener("loadedmetadata", function() | |
51 { | |
52 // Should not have a cast button by default | |
53 button = castButton(video); | |
54 assert_equals(button.style.display, "none", "button should not b
e visible with no cast devices"); | |
55 | 12 |
56 // Pretend we have a cast device | 13 video.onloadedmetadata = t.step_func_done(function() { |
57 internals.mediaPlayerRemoteRouteAvailabilityChanged(video, true)
; | 14 // Should not have a cast button by default |
| 15 var button = castButton(video); |
| 16 assert_equals(button.style.display, "none", "button should not be visibl
e with no cast devices"); |
58 | 17 |
59 // Now should have cast button | 18 // Pretend we have a cast device |
60 assert_false(("display" in button.style) && (button.style.displa
y == "none"), "button should exist"); | 19 internals.mediaPlayerRemoteRouteAvailabilityChanged(video, true); |
61 dimensions = castButtonDimensions(video); | |
62 assert_not_equals(dimensions[0], 0, "button should exist"); | |
63 assert_not_equals(dimensions[1], 0, "button should exist"); | |
64 | 20 |
65 // Check its position is to the right of the timeline | 21 // Now should have cast button |
66 // (can't test against volume control or closed caption button,
since these don't always exist) | 22 assert_false(("display" in button.style) && (button.style.display == "no
ne"), "button should exist"); |
67 position = castButtonCoordinates(video); | 23 var buttonBoundingRect = button.getBoundingClientRect(); |
68 timelinePosition = mediaControlsButtonCoordinates(video, "timeli
ne"); | 24 var dimensions = new Array(buttonBoundingRect.width, buttonBoundingRect.
height); |
69 assert_greater_than(position[0], timelinePosition[0], "button sh
ould be to right of timeline"); | 25 assert_not_equals(dimensions[0], 0, "button should exist"); |
| 26 assert_not_equals(dimensions[1], 0, "button should exist"); |
70 | 27 |
71 // Check that we don't have an overlay cast button | 28 // Check its position is to the right of the timeline |
72 overlayButton = overlayCastButton(video); | 29 // (can't test against volume control or closed caption button, since th
ese don't always exist) |
73 assert_equals(overlayButton.style.display, "none", "Overlay butt
on should not be visible with controls"); | 30 var x = buttonBoundingRect.left + buttonBoundingRect.width / 2; |
| 31 var timelinePosition = mediaControlsButtonCoordinates(video, "timeline")
; |
| 32 assert_greater_than(x, timelinePosition[0], "button should be to right o
f timeline"); |
74 | 33 |
75 // And to the left of the fullscreen button | 34 // Check that we don't have an overlay cast button |
76 fullscreenPosition = mediaControlsButtonCoordinates(video, "full
screen-button"); | 35 var overlayButton = overlayCastButton(video); |
77 assert_less_than(position[0], fullscreenPosition[0], "button sho
uld be to left of fullscreen button"); | 36 assert_equals(overlayButton.style.display, "none", "Overlay button shoul
d not be visible with controls"); |
78 | 37 |
79 // Remove cast device - cast button should go away | 38 // And to the left of the fullscreen button |
80 internals.mediaPlayerRemoteRouteAvailabilityChanged(video, false
); | 39 var fullscreenPosition = mediaControlsButtonCoordinates(video, "fullscre
en-button"); |
81 assert_equals(button.style.display, "none", "button should not b
e visible after cast device goes away"); | 40 assert_less_than(x, fullscreenPosition[0], "button should be to left of
fullscreen button"); |
82 t.done(); | 41 |
83 }); | 42 // Remove cast device - cast button should go away |
84 }); | 43 internals.mediaPlayerRemoteRouteAvailabilityChanged(video, false); |
85 </script> | 44 assert_equals(button.style.display, "none", "button should not be visibl
e after cast device goes away"); |
86 </body> | 45 }); |
87 </html> | 46 |
| 47 function castButton(element) { |
| 48 var controlID = "-internal-media-controls-cast-button"; |
| 49 var button = mediaControlsElement(internals.shadowRoot(element).firstChi
ld, controlID); |
| 50 if (!button) |
| 51 throw "Failed to find cast button"; |
| 52 return button; |
| 53 } |
| 54 |
| 55 function overlayCastButton(element) { |
| 56 var controlID = "-internal-media-controls-overlay-cast-button"; |
| 57 var button = mediaControlsElement(internals.shadowRoot(element).firstChi
ld, controlID); |
| 58 if (!button) |
| 59 throw "Failed to find cast button"; |
| 60 return button; |
| 61 } |
| 62 }); |
| 63 </script> |
OLD | NEW |