toolkit/content/tests/widgets/test_videocontrols_standalone.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/content/tests/widgets/test_videocontrols_standalone.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,90 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Video controls test</title>
     1.8 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    1.10 +  <script type="text/javascript" src="head.js"></script>
    1.11 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.12 +</head>
    1.13 +<body>
    1.14 +<p id="display"></p>
    1.15 +
    1.16 +<pre id="test">
    1.17 +<script class="testbody" type="text/javascript">
    1.18 +
    1.19 +const videoWidth = 320;
    1.20 +const videoHeight = 240;
    1.21 +
    1.22 +function getMediaElement(aWindow) {
    1.23 +  return aWindow.document.getElementsByTagName("video")[0];
    1.24 +}
    1.25 +
    1.26 +var popup = window.open("seek_with_sound.ogg");
    1.27 +popup.addEventListener("load", function onLoad() {
    1.28 +  popup.removeEventListener("load", onLoad);
    1.29 +  var video = getMediaElement(popup);
    1.30 +  if (!video.paused)
    1.31 +    runTestVideo(video);
    1.32 +  else {
    1.33 +    video.addEventListener("play", function onPlay() {
    1.34 +      video.removeEventListener("play", onPlay);
    1.35 +      runTestVideo(video);
    1.36 +    });
    1.37 +  }
    1.38 +});
    1.39 +
    1.40 +function runTestVideo(aVideo) {
    1.41 +  var condition = function() {
    1.42 +    var boundingRect = aVideo.getBoundingClientRect();
    1.43 +    return boundingRect.width == videoWidth &&
    1.44 +           boundingRect.height == videoHeight;
    1.45 +  };
    1.46 +  waitForCondition(condition, function() {
    1.47 +    var boundingRect = aVideo.getBoundingClientRect();
    1.48 +    is(boundingRect.width, videoWidth, "Width of the video should match expectation");
    1.49 +    is(boundingRect.height, videoHeight, "Height of video should match expectation");
    1.50 +    popup.close();
    1.51 +    runTestAudioPre();
    1.52 +  }, "The media element should eventually be resized to match the intrinsic size of the video.");
    1.53 +}
    1.54 +
    1.55 +function runTestAudioPre() {
    1.56 +  popup = window.open("audio.ogg");
    1.57 +  popup.addEventListener("load", function onLoad() {
    1.58 +    popup.removeEventListener("load", onLoad);
    1.59 +    var audio = getMediaElement(popup);
    1.60 +    if (!audio.paused)
    1.61 +      runTestAudio(audio);
    1.62 +    else {
    1.63 +      audio.addEventListener("play", function onPlay() {
    1.64 +        audio.removeEventListener("play", onPlay);
    1.65 +        runTestAudio(audio);
    1.66 +      })
    1.67 +    }
    1.68 +  })
    1.69 +}
    1.70 +
    1.71 +function runTestAudio(aAudio) {
    1.72 +  info("User agent (help diagnose bug #943556): " + navigator.userAgent);
    1.73 +  var isAndroid = navigator.userAgent.contains("Android");
    1.74 +  var expectedHeight = isAndroid ? 123 : 28;
    1.75 +  var condition = function () {
    1.76 +    var boundingRect = aAudio.getBoundingClientRect();
    1.77 +    return boundingRect.height == expectedHeight;
    1.78 +  };
    1.79 +  waitForCondition(condition, function () {
    1.80 +    var boundingRect = aAudio.getBoundingClientRect();
    1.81 +    is(boundingRect.height, expectedHeight,
    1.82 +       "Height of audio element should be " + expectedHeight + ", which is equal to the controls bar.");
    1.83 +    popup.close();
    1.84 +    SimpleTest.finish();
    1.85 +  }, "The media element should eventually be resized to match the height of the audio controls.");
    1.86 +}
    1.87 +
    1.88 +SimpleTest.waitForExplicitFinish();
    1.89 +
    1.90 +</script>
    1.91 +</pre>
    1.92 +</body>
    1.93 +</html>

mercurial