summaryrefslogtreecommitdiffstats
path: root/dom/media/test/browser
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /dom/media/test/browser
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/test/browser')
-rw-r--r--dom/media/test/browser/browser.ini7
-rw-r--r--dom/media/test/browser/browser_tab_visibility_and_play_time.js120
-rw-r--r--dom/media/test/browser/file_media.html9
3 files changed, 136 insertions, 0 deletions
diff --git a/dom/media/test/browser/browser.ini b/dom/media/test/browser/browser.ini
new file mode 100644
index 0000000000..d828f4b6f9
--- /dev/null
+++ b/dom/media/test/browser/browser.ini
@@ -0,0 +1,7 @@
+[DEFAULT]
+tags = mediacontrol
+support-files =
+ file_media.html
+ ../gizmo.mp4
+
+[browser_tab_visibility_and_play_time.js]
diff --git a/dom/media/test/browser/browser_tab_visibility_and_play_time.js b/dom/media/test/browser/browser_tab_visibility_and_play_time.js
new file mode 100644
index 0000000000..4eb956b9ea
--- /dev/null
+++ b/dom/media/test/browser/browser_tab_visibility_and_play_time.js
@@ -0,0 +1,120 @@
+/**
+ * This test is used to ensure that invisible play time would be accumulated
+ * when tab is in background. However, this test won't directly check the
+ * reported telemetry result, because we can't check the snapshot histogram in
+ * the content process.
+ * The actual probe checking happens in `test_accumulated_play_time.html`.
+ */
+"use strict";
+
+const PAGE_URL =
+ "https://example.com/browser/dom/media/test/browser/file_media.html";
+
+add_task(async function testChangingTabVisibilityAffectsInvisiblePlayTime() {
+ const originalTab = gBrowser.selectedTab;
+ const mediaTab = await openMediaTab(PAGE_URL);
+
+ info(`measuring play time when tab is in foreground`);
+ await startMedia({
+ mediaTab,
+ shouldAccumulateTime: true,
+ shouldAccumulateInvisibleTime: false,
+ });
+ await pauseMedia(mediaTab);
+
+ info(`measuring play time when tab is in foreground`);
+ await BrowserTestUtils.switchTab(window.gBrowser, originalTab);
+ await startMedia({
+ mediaTab,
+ shouldAccumulateTime: true,
+ shouldAccumulateInvisibleTime: true,
+ });
+ await pauseMedia(mediaTab);
+
+ BrowserTestUtils.removeTab(mediaTab);
+});
+
+/**
+ * Following are helper functions.
+ */
+async function openMediaTab(url) {
+ info(`open tab for media playback`);
+ const tab = await BrowserTestUtils.openNewForegroundTab(window.gBrowser, url);
+ info(`add content helper functions and variables`);
+ await SpecialPowers.spawn(tab.linkedBrowser, [], _ => {
+ content.assertAttributeDefined = (videoChrome, checkType) => {
+ ok(videoChrome[checkType] != undefined, `${checkType} exists`);
+ };
+ content.assertValueEqualTo = (videoChrome, checkType, expectedValue) => {
+ content.assertAttributeDefined(videoChrome, checkType);
+ is(
+ videoChrome[checkType],
+ expectedValue,
+ `${checkType} equals to ${expectedValue}`
+ );
+ };
+ content.assertValueConstantlyIncreases = (videoChrome, checkType) => {
+ content.assertAttributeDefined(videoChrome, checkType);
+ const valueSnapshot = videoChrome[checkType];
+ ok(
+ videoChrome[checkType] > valueSnapshot,
+ `${checkType} keeps increasing`
+ );
+ };
+ content.assertValueKeptUnchanged = (videoChrome, checkType) => {
+ content.assertAttributeDefined(videoChrome, checkType);
+ const valueSnapshot = videoChrome[checkType];
+ ok(
+ videoChrome[checkType] == valueSnapshot,
+ `${checkType} keeps unchanged`
+ );
+ };
+ });
+ return tab;
+}
+
+function startMedia({
+ mediaTab,
+ shouldAccumulateTime,
+ shouldAccumulateInvisibleTime,
+}) {
+ return SpecialPowers.spawn(
+ mediaTab.linkedBrowser,
+ [shouldAccumulateTime, shouldAccumulateInvisibleTime],
+ async (accumulateTime, accumulateInvisibleTime) => {
+ const video = content.document.getElementById("video");
+ ok(
+ await video.play().then(
+ () => true,
+ () => false
+ ),
+ "video started playing"
+ );
+ const videoChrome = SpecialPowers.wrap(video);
+ if (accumulateTime) {
+ content.assertValueConstantlyIncreases(videoChrome, "totalPlayTime");
+ } else {
+ content.assertValueKeptUnchanged(videoChrome, "totalPlayTime");
+ }
+ if (accumulateInvisibleTime) {
+ content.assertValueConstantlyIncreases(
+ videoChrome,
+ "invisiblePlayTime"
+ );
+ } else {
+ content.assertValueKeptUnchanged(videoChrome, "invisiblePlayTime");
+ }
+ }
+ );
+}
+
+function pauseMedia(tab) {
+ return SpecialPowers.spawn(tab.linkedBrowser, [], async _ => {
+ const video = content.document.getElementById("video");
+ video.pause();
+ ok(true, "video paused");
+ const videoChrome = SpecialPowers.wrap(video);
+ content.assertValueKeptUnchanged(videoChrome, "totalPlayTime");
+ content.assertValueKeptUnchanged(videoChrome, "invisiblePlayTime");
+ });
+}
diff --git a/dom/media/test/browser/file_media.html b/dom/media/test/browser/file_media.html
new file mode 100644
index 0000000000..498c2eaad6
--- /dev/null
+++ b/dom/media/test/browser/file_media.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Non-Autoplay page</title>
+</head>
+<body>
+<video id="video" src="gizmo.mp4" loop></video>
+</body>
+</html>