Bug 1311700 - Part 2. move shared function to head.js. r=jaws
MozReview-Commit-ID: 5Ym2ZAARitL
--- a/toolkit/content/tests/widgets/head.js
+++ b/toolkit/content/tests/widgets/head.js
@@ -16,8 +16,15 @@ function waitForCondition(condition, nex
}
if (conditionPassed) {
moveOn();
}
tries++;
}, 100);
var moveOn = function() { clearInterval(interval); nextTest(); };
}
+
+function getAnonElementWithinVideoByAttribute(video, aName, aValue) {
+ const videoControl = domUtils.getChildrenForNode(video, true)[1];
+
+ return SpecialPowers.wrap(videoControl.ownerDocument)
+ .getAnonymousElementByAttribute(videoControl, aName, aValue);
+}
--- a/toolkit/content/tests/widgets/test_videocontrols_error.html
+++ b/toolkit/content/tests/widgets/test_videocontrols_error.html
@@ -1,14 +1,15 @@
<!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>
+ <script type="text/javascript" src="head.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>
@@ -16,18 +17,18 @@
<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 statusOverlay = getAnonElementWithinVideoByAttribute(video, "anonid", "statusOverlay");
+ const statusIcon = getAnonElementWithinVideoByAttribute(video, "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");
@@ -48,23 +49,16 @@
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);
}
--- a/toolkit/content/tests/widgets/test_videocontrols_size.html
+++ b/toolkit/content/tests/widgets/test_videocontrols_size.html
@@ -1,14 +1,15 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Video controls test - Size</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+ <script type="text/javascript" src="head.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content">
<video controls preload="auto" width="480" height="320"></video>
<video controls preload="auto" width="320" height="320"></video>
@@ -69,25 +70,25 @@
video.style.display = "";
const videoRect = video.getBoundingClientRect();
const videoHeight = video.clientHeight;
const videoWidth = video.clientWidth;
const videoSizeMsg = `size:${videoRect.width}x${videoRect.height} -`;
- const controlBar = getElementWithinVideoByAttribute(video, "anonid", "controlBar");
- const playBtn = getElementWithinVideoByAttribute(video, "anonid", "playButton");
- const scrubber = getElementWithinVideoByAttribute(video, "anonid", "scrubberStack");
- const positionDurationBox = getElementWithinVideoByAttribute(video, "anonid", "positionDurationBox");
+ const controlBar = getAnonElementWithinVideoByAttribute(video, "anonid", "controlBar");
+ const playBtn = getAnonElementWithinVideoByAttribute(video, "anonid", "playButton");
+ const scrubber = getAnonElementWithinVideoByAttribute(video, "anonid", "scrubberStack");
+ const positionDurationBox = getAnonElementWithinVideoByAttribute(video, "anonid", "positionDurationBox");
const durationLabel = positionDurationBox.getElementsByTagName("span")[0];
- const muteBtn = getElementWithinVideoByAttribute(video, "anonid", "muteButton");
- const volumeStack = getElementWithinVideoByAttribute(video, "anonid", "volumeStack");
- const fullscreenBtn = getElementWithinVideoByAttribute(video, "anonid", "fullscreenButton");
- const clickToPlay = getElementWithinVideoByAttribute(video, "anonid", "clickToPlay");
+ const muteBtn = getAnonElementWithinVideoByAttribute(video, "anonid", "muteButton");
+ const volumeStack = getAnonElementWithinVideoByAttribute(video, "anonid", "volumeStack");
+ const fullscreenBtn = getAnonElementWithinVideoByAttribute(video, "anonid", "fullscreenButton");
+ const clickToPlay = getAnonElementWithinVideoByAttribute(video, "anonid", "clickToPlay");
// Controls should show/hide according to the priority
const prioritizedControls = [
playBtn,
muteBtn,
fullscreenBtn,
positionDurationBox,
@@ -158,23 +159,16 @@
});
}));
});
function executeTasks(tasks) {
return tasks.reduce((promise, task) => promise.then(task), Promise.resolve());
}
- function getElementWithinVideoByAttribute(video, aName, aValue) {
- const videoControl = domUtils.getChildrenForNode(video, true)[1];
-
- return SpecialPowers.wrap(videoControl.ownerDocument)
- .getAnonymousElementByAttribute(videoControl, aName, aValue);
- }
-
function start() {
executeTasks(testCases).then(SimpleTest.finish);
}
function loadevent() {
SpecialPowers.pushPrefEnv({"set": [["media.cache_size", 40000]]}, start);
}
--- a/toolkit/content/tests/widgets/test_videocontrols_vtt.html
+++ b/toolkit/content/tests/widgets/test_videocontrols_vtt.html
@@ -1,31 +1,32 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Video controls test - VTT</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+ <script type="text/javascript" src="head.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 ccBtn = getElementByAttribute("anonid", "closedCaptionButton");
+ const ccBtn = getAnonElementWithinVideoByAttribute(video, "anonid", "closedCaptionButton");
const testCases = [];
testCases.push(() => new Promise(resolve => {
is(ccBtn.getAttribute("hidden"), "true", "CC button should hide");
resolve();
}));
@@ -77,23 +78,16 @@
});
}));
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 = "seek_with_sound.ogg";
video.addEventListener("loadedmetadata", loadedmetadata, false);
}