| 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></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></video> |  | 
| 15         <script> |  | 
| 16         function overlayCastButton(element) |  | 
| 17         { |  | 
| 18             var controlID = "-internal-media-controls-overlay-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 overlayCastButtonDimensions(element) |  | 
| 25         { |  | 
| 26             var button = overlayCastButton(element); |  | 
| 27             var buttonBoundingRect = button.getBoundingClientRect(); |  | 
| 28             return new Array(buttonBoundingRect.width, buttonBoundingRect.height
    ); |  | 
| 29         } |  | 
| 30         async_test(function(t) |  | 
| 31         { |  | 
| 32             findMediaElement(); |  | 
| 33             video.src = findMediaFile("video", "content/test"); |  | 
| 34             mediaElement.addEventListener("loadedmetadata", function() |  | 
| 35             { |  | 
| 36                 // Should not have a cast button by default |  | 
| 37                 button = overlayCastButton(video); |  | 
| 38                 assert_equals(button.style.display, "none", "button should not b
    e visible with no cast devices"); |  | 
| 39 | 12 | 
| 40                 // Pretend we have a cast device | 13     video.onloadedmetadata = t.step_func_done(function() { | 
| 41                 internals.mediaPlayerRemoteRouteAvailabilityChanged(video, true)
    ; | 14         // Should not have a cast button by default | 
| 42                 // Now should have cast button | 15         var button = overlayCastButton(video); | 
| 43                 assert_false(("display" in button.style) && (button.style.displa
    y == "none"), "button should exist"); | 16         assert_equals(button.style.display, "none", "button should not be visibl
    e with no cast devices"); | 
| 44                 dimensions = overlayCastButtonDimensions(video); |  | 
| 45                 assert_not_equals(dimensions[0], 0, "button should exist"); |  | 
| 46                 assert_not_equals(dimensions[1], 0, "button should exist"); |  | 
| 47 | 17 | 
| 48                 // Check position, should be in the top left corner of the video | 18         // Pretend we have a cast device | 
| 49                 rect = button.getBoundingClientRect(); | 19         internals.mediaPlayerRemoteRouteAvailabilityChanged(video, true); | 
| 50                 videoRect = video.getBoundingClientRect(); | 20         // Now should have cast button | 
| 51                 assert_greater_than_equal(rect.top, videoRect.top, "button shoul
    d be at top left of video"); | 21         assert_false(("display" in button.style) && (button.style.display == "no
    ne"), "button should exist"); | 
| 52                 assert_greater_than_equal(rect.left, videoRect.left, "button sho
    uld be at top left of video"); | 22         var rect = button.getBoundingClientRect(); | 
| 53                 assert_less_than_equal(rect.bottom, videoRect.top + videoRect.he
    ight / 2, "button should be at top left of video"); | 23         assert_not_equals(rect.width, 0, "button should exist"); | 
| 54                 assert_less_than_equal(rect.right, videoRect.left + videoRect.wi
    dth / 2, "button should be at top left of video"); | 24         assert_not_equals(rect.height, 0, "button should exist"); | 
| 55 | 25 | 
| 56                 // Remove cast device - cast button should go away | 26         // Check position, should be in the top left corner of the video | 
| 57                 internals.mediaPlayerRemoteRouteAvailabilityChanged(video, false
    ); | 27         var videoRect = video.getBoundingClientRect(); | 
| 58                 assert_equals(button.style.display, "none", "button should not b
    e visible after cast device goes away"); | 28         assert_greater_than_equal(rect.top, videoRect.top, "button should be at 
    top left of video"); | 
| 59                 t.done(); | 29         assert_greater_than_equal(rect.left, videoRect.left, "button should be a
    t top left of video"); | 
| 60             }) | 30         assert_less_than_equal(rect.bottom, videoRect.top + videoRect.height / 2
    , "button should be at top left of video"); | 
| 61         }); | 31         assert_less_than_equal(rect.right, videoRect.left + videoRect.width / 2,
     "button should be at top left of video"); | 
| 62         </script> | 32 | 
| 63     </body> | 33         // Remove cast device - cast button should go away | 
| 64 </html> | 34         internals.mediaPlayerRemoteRouteAvailabilityChanged(video, false); | 
|  | 35         assert_equals(button.style.display, "none", "button should not be visibl
    e after cast device goes away"); | 
|  | 36     }); | 
|  | 37 | 
|  | 38     function overlayCastButton(element) { | 
|  | 39         var controlID = "-internal-media-controls-overlay-cast-button"; | 
|  | 40         var button = mediaControlsElement(internals.shadowRoot(element).firstChi
    ld, controlID); | 
|  | 41         if (!button) | 
|  | 42             throw "Failed to find cast button"; | 
|  | 43         return button; | 
|  | 44     } | 
|  | 45 }); | 
|  | 46 </script> | 
| OLD | NEW | 
|---|