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 y = buttonBoundingRect.top + buttonBoundingRect.height / 2; | |
32 var position = new Array(x, y); | |
fs
2016/05/27 17:09:02
Nit: position[1] (y) isn't used, so just using 'x'
Srirama
2016/05/27 17:39:46
Done.
| |
33 var timelinePosition = mediaControlsButtonCoordinates(video, "timeline") ; | |
34 assert_greater_than(position[0], timelinePosition[0], "button should be to right of timeline"); | |
74 | 35 |
75 // And to the left of the fullscreen button | 36 // Check that we don't have an overlay cast button |
76 fullscreenPosition = mediaControlsButtonCoordinates(video, "full screen-button"); | 37 var overlayButton = overlayCastButton(video); |
77 assert_less_than(position[0], fullscreenPosition[0], "button sho uld be to left of fullscreen button"); | 38 assert_equals(overlayButton.style.display, "none", "Overlay button shoul d not be visible with controls"); |
78 | 39 |
79 // Remove cast device - cast button should go away | 40 // And to the left of the fullscreen button |
80 internals.mediaPlayerRemoteRouteAvailabilityChanged(video, false ); | 41 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"); | 42 assert_less_than(position[0], fullscreenPosition[0], "button should be t o left of fullscreen button"); |
82 t.done(); | 43 |
83 }); | 44 // Remove cast device - cast button should go away |
84 }); | 45 internals.mediaPlayerRemoteRouteAvailabilityChanged(video, false); |
85 </script> | 46 assert_equals(button.style.display, "none", "button should not be visibl e after cast device goes away"); |
86 </body> | 47 }); |
87 </html> | 48 |
49 function castButton(element) { | |
50 var controlID = "-internal-media-controls-cast-button"; | |
51 var button = mediaControlsElement(internals.shadowRoot(element).firstChi ld, controlID); | |
52 if (!button) | |
53 throw "Failed to find cast button"; | |
54 return button; | |
55 } | |
56 | |
57 function overlayCastButton(element) { | |
58 var controlID = "-internal-media-controls-overlay-cast-button"; | |
59 var button = mediaControlsElement(internals.shadowRoot(element).firstChi ld, controlID); | |
60 if (!button) | |
61 throw "Failed to find cast button"; | |
62 return button; | |
63 } | |
64 }); | |
65 </script> | |
OLD | NEW |