Bug 1317909 - Add a test to confirm status overlay show in error state. r=jaws draft
authorRay Lin <ralin@mozilla.com>
Wed, 16 Nov 2016 14:40:39 +0800
changeset 441697 130510876284c134573466dd3b303370f38b8bba
parent 441645 b7f895c1dc2e91530240efbf50ac063a0f8a9cb5
child 537618 6218f7740d281a9544bc3cf2d8ae6a103144de0d
push id36500
push userbmo:ralin@mozilla.com
push dateMon, 21 Nov 2016 02:40:30 +0000
reviewersjaws
bugs1317909
milestone53.0a1
Bug 1317909 - Add a test to confirm status overlay show in error state. r=jaws MozReview-Commit-ID: 85vatvLSSEf
toolkit/content/tests/widgets/mochitest.ini
toolkit/content/tests/widgets/test_videocontrols_error.html
--- a/toolkit/content/tests/widgets/mochitest.ini
+++ b/toolkit/content/tests/widgets/mochitest.ini
@@ -33,8 +33,9 @@ skip-if = toolkit == 'android'
 [test_videocontrols_audio_direction.html]
 [test_videocontrols_jsdisabled.html]
 skip-if = toolkit == 'android' # bug 1272646
 [test_videocontrols_standalone.html]
 skip-if = toolkit == 'android' # bug 1075573
 [test_videocontrols_video_direction.html]
 skip-if = os == 'win'
 [test_bug898940.html]
+[test_videocontrols_error.html]
new file mode 100644
--- /dev/null
+++ b/toolkit/content/tests/widgets/test_videocontrols_error.html
@@ -0,0 +1,75 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Video controls test - Error</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 statusOverlay = getElementByAttribute("anonid", "statusOverlay");
+  const statusIcon = getElementByAttribute("anonid", "statusIcon");
+
+  const testCases = [];
+
+  testCases.push(() => new Promise(resolve => {
+    ok(statusOverlay.hidden, "statusOverlay shoud not present without error");
+    ok(!statusOverlay.hasAttribute("error"), "statusOverlay should not in error state");
+    isnot(statusIcon.getAttribute("type"), "error", "should not show error icon");
+
+    resolve();
+  }));
+
+  testCases.push(() => new Promise(resolve => {
+    video.src = "invalid-path.ogg";
+    video.addEventListener("error", resolve);
+  }));
+
+  testCases.push(() => new Promise(resolve => {
+    const errorType = "errorSrcNotSupported";
+
+    ok(!statusOverlay.hidden, `statusOverlay should show when ${errorType}`);
+    is(statusOverlay.getAttribute("error"), errorType, `statusOverlay should have correct error state: ${errorType}`);
+    is(statusIcon.getAttribute("type"), "error", `should show error icon when ${errorType}`);
+
+    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 startTest() {
+    executeTestCases(testCases).then(SimpleTest.finish);
+  }
+
+  function loadevent() {
+    SpecialPowers.pushPrefEnv({"set": [["media.cache_size", 40000]]}, startTest);
+  }
+
+  window.addEventListener("load", loadevent, false);
+</script>
+</pre>
+</body>
+</html>