Bug 1781917 - Try to make test_videocontrols_audio.html more robust to address the frequent failures. r=Gijs

Attempting to make test more robust to reduce the opportunity for intermittant failures.

Differential Revision: https://phabricator.services.mozilla.com/D153385
This commit is contained in:
Bernard Igiri 2022-08-11 21:23:01 +00:00
Родитель 8158c6a1d3
Коммит 58e7783c9d
3 изменённых файлов: 34 добавлений и 34 удалений

Просмотреть файл

@ -65,3 +65,23 @@ function once(target, name, cb) {
}
return p;
}
class EventLogger {
constructor(expectedNumberOfEvents = Number.MAX_VALUE) {
this._log = [];
this._eventsPromise = new Promise(r => (this._countReached = r));
this._expectedNumberOfEvents = expectedNumberOfEvents;
}
handleEvent(event) {
this._log.push(event);
if (this._log.length >= this._expectedNumberOfEvents) {
this._countReached(this._log);
}
}
get log() {
return this._log;
}
waitForExpectedEvents() {
return this._eventsPromise;
}
}

Просмотреть файл

@ -446,11 +446,17 @@ add_task(async function ensure_fullscreen_button() {
});
add_task(async function ensure_doubleclick_triggers_fullscreen() {
const logger = new EventLogger(1);
document.addEventListener("mozfullscreenchange", logger);
const { x, y } = video.getBoundingClientRect();
info("attempt double click");
synthesizeMouse(video, x, y, { clickCount: 2 });
await waitForEvent("play");
await waitForEvent("mozfullscreenchange");
const events = await logger.waitForExpectedEvents();
is(
events[0].type,
"mozfullscreenchange",
"Double clicking should trigger fullscreen event"
);
});
</script>

Просмотреть файл

@ -4,6 +4,7 @@
<title>Video controls with Audio file test</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script 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>
@ -18,36 +19,6 @@
const video = document.getElementById("video");
class EventLogger {
constructor() {
this._log = [];
this._xEventsPromise = new Promise(r => this._xReached = r);
this._x = Number.MAX_VALUE;
}
createListener() {
return e => {
this._log.push(e);
if (this._log.length >= this._x) {
this._xReached(this._log);
}
}
}
waitForXEvents(x) {
this._x = x;
return this._xEventsPromise;
}
clearEvents() {
this._log = [];
}
}
const logger = new EventLogger();
video.addEventListener("play", logger.createListener());
video.addEventListener("pause", logger.createListener());
document.addEventListener("mozfullscreenchange", logger.createListener());
const InspectorUtils = SpecialPowers.InspectorUtils;
function findElementByAttribute(element, aName, aValue) {
if (!("getAttribute" in element)) {
return false;
@ -71,9 +42,12 @@
const { x, y } = video.getBoundingClientRect();
const controlBar = findElementByAttribute(video, "class", "controlBar");
is(controlBar.getAttribute("fullscreen-unavailable"), "true", "Fullscreen button is hidden");
logger.clearEvents();
const eventLogger = new EventLogger(2);
video.addEventListener("play", eventLogger);
video.addEventListener("pause", eventLogger);
document.addEventListener("mozfullscreenchange", eventLogger);
synthesizeMouse(video, x, y, { clickCount: 2 });
const events = await logger.waitForXEvents(2);
const events = await eventLogger.waitForExpectedEvents();
ok(
!events.find(e => e.type === "mozfullscreenchange"),
"Double clicking should not trigger fullscreen event"