toolkit/content/tests/widgets/test_videocontrols_video_noaudio.html
author Ray Lin <ralin@mozilla.com>
Thu, 22 Sep 2016 15:30:48 +0800
changeset 323995 4e27de747d61e73f4f162012265f1e15c3f074af
parent 323963 84fee6da47a6df048b50d1c710070aa9aee47152
permissions -rw-r--r--
Bug 1302320 - add noaudio icon test for video control. r=jaws MozReview-Commit-ID: KfrsEJ3mgB6

<!DOCTYPE HTML>
<html>
<head>
  <title>Video controls test</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>

<div id="content">
  <video id="video" controls preload="auto"></video>
</div>

<pre id="test">
<script clas="testbody" type="application/javascript">
  SimpleTest.waitForExplicitFinish();

  const domUtils = SpecialPowers.Cc["@mozilla.org/inspector/dom-utils;1"].
    getService(SpecialPowers.Ci.inIDOMUtils);
  const video = document.getElementById("video");
  const muteButton = getElementByAttribute("class", "muteButton");
  const volumeStack = getElementByAttribute("class", "volumeStack");
  const testCases = [];

  testCases.push(() => new Promise(resolve => {
    is(muteButton.getAttribute("noAudio"), "true");
    is(muteButton.getAttribute("disabled"), "true");

    if (volumeStack) {
      ok(volumeStack.hidden);
    }

    resolve();
  }));

  function executeTestCases(tasks) {
    return tasks.reduce((promise, task) => promise.then(task), Promise.resolve());
  }

  function getElementByAttribute(aName, aValue) {
    const videoControl = domUtils.getChildrenForNode(video, true)[1];

    return SpecialPowers.wrap(document)
      .getAnonymousElementByAttribute(videoControl, aName, aValue);
  }

  function loadedmetadata() {
    executeTestCases(testCases).then(SimpleTest.finish);
  }

  function startMediaLoad() {
    video.src = "video.ogg";
    video.addEventListener("loadedmetadata", loadedmetadata, false);
  }

  function loadevent() {
    SpecialPowers.pushPrefEnv({"set": [["media.cache_size", 40000]]}, startMediaLoad);
  }

  window.addEventListener("load", loadevent, false);
</script>
</pre>
</body>
</html>