Chromium Code Reviews| 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 { |
|
fs
2016/05/27 14:30:06
Should we go with
async_test(function(t) {
style
Srirama
2016/05/27 16:49:56
Done.
| |
| 11 <script src="video-test.js"></script> | 11 var video = document.querySelector("video"); |
| 12 </head> | 12 video.src = findMediaFile("video", "content/test"); |
| 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 | 13 |
| 56 // Pretend we have a cast device | 14 video.onloadedmetadata = t.step_func_done(function() |
| 57 internals.mediaPlayerRemoteRouteAvailabilityChanged(video, true) ; | 15 { |
| 16 // Should not have a cast button by default | |
| 17 var button = castButton(video); | |
| 18 assert_equals(button.style.display, "none", "button should not be visibl e with no cast devices"); | |
| 58 | 19 |
| 59 // Now should have cast button | 20 // Pretend we have a cast device |
| 60 assert_false(("display" in button.style) && (button.style.displa y == "none"), "button should exist"); | 21 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 | 22 |
| 65 // Check its position is to the right of the timeline | 23 // Now should have cast button |
| 66 // (can't test against volume control or closed caption button, since these don't always exist) | 24 assert_false(("display" in button.style) && (button.style.display == "no ne"), "button should exist"); |
| 67 position = castButtonCoordinates(video); | 25 var dimensions = castButtonDimensions(video); |
| 68 timelinePosition = mediaControlsButtonCoordinates(video, "timeli ne"); | 26 assert_not_equals(dimensions[0], 0, "button should exist"); |
| 69 assert_greater_than(position[0], timelinePosition[0], "button sh ould be to right of timeline"); | 27 assert_not_equals(dimensions[1], 0, "button should exist"); |
| 70 | 28 |
| 71 // Check that we don't have an overlay cast button | 29 // Check its position is to the right of the timeline |
| 72 overlayButton = overlayCastButton(video); | 30 // (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"); | 31 var position = castButtonCoordinates(video); |
| 32 var timelinePosition = mediaControlsButtonCoordinates(video, "timeline") ; | |
| 33 assert_greater_than(position[0], timelinePosition[0], "button should be to right of timeline"); | |
| 74 | 34 |
| 75 // And to the left of the fullscreen button | 35 // Check that we don't have an overlay cast button |
| 76 fullscreenPosition = mediaControlsButtonCoordinates(video, "full screen-button"); | 36 var overlayButton = overlayCastButton(video); |
| 77 assert_less_than(position[0], fullscreenPosition[0], "button sho uld be to left of fullscreen button"); | 37 assert_equals(overlayButton.style.display, "none", "Overlay button shoul d not be visible with controls"); |
| 78 | 38 |
| 79 // Remove cast device - cast button should go away | 39 // And to the left of the fullscreen button |
| 80 internals.mediaPlayerRemoteRouteAvailabilityChanged(video, false ); | 40 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"); | 41 assert_less_than(position[0], fullscreenPosition[0], "button should be t o left of fullscreen button"); |
| 82 t.done(); | 42 |
| 83 }); | 43 // Remove cast device - cast button should go away |
| 84 }); | 44 internals.mediaPlayerRemoteRouteAvailabilityChanged(video, false); |
| 85 </script> | 45 assert_equals(button.style.display, "none", "button should not be visibl e after cast device goes away"); |
| 86 </body> | 46 }); |
| 87 </html> | 47 |
| 48 function castButton(element) | |
| 49 { | |
| 50 var controlID = "-internal-media-controls-cast-button"; | |
| 51 var button = mediaControlsElement(window.internals.shadowRoot(element).f irstChild, controlID); | |
| 52 if (!button) | |
| 53 throw "Failed to find cast button"; | |
| 54 return button; | |
| 55 } | |
| 56 | |
| 57 function overlayCastButton(element) | |
| 58 { | |
| 59 var controlID = "-internal-media-controls-overlay-cast-button"; | |
| 60 var button = mediaControlsElement(window.internals.shadowRoot(element).f irstChild, controlID); | |
| 61 if (!button) | |
| 62 throw "Failed to find cast button"; | |
| 63 return button; | |
| 64 } | |
| 65 | |
| 66 function castButtonDimensions(element) | |
|
fs
2016/05/27 14:30:06
These two functions (this one and the one below) s
Srirama
2016/05/27 16:49:57
Done.
| |
| 67 { | |
| 68 var button = castButton(element); | |
| 69 var buttonBoundingRect = button.getBoundingClientRect(); | |
| 70 return new Array(buttonBoundingRect.width, buttonBoundingRect.height); | |
| 71 } | |
| 72 | |
| 73 function castButtonCoordinates(element, id) | |
| 74 { | |
| 75 var button = castButton(element); | |
| 76 var buttonBoundingRect = button.getBoundingClientRect(); | |
| 77 var x = buttonBoundingRect.left + buttonBoundingRect.width / 2; | |
| 78 var y = buttonBoundingRect.top + buttonBoundingRect.height / 2; | |
| 79 return new Array(x, y); | |
| 80 } | |
| 81 }); | |
| 82 </script> | |
| OLD | NEW |