Skip to content

Commit

Permalink
Bug 1674845 - part4 : add 'browser' subfolder for autoplay browser te…
Browse files Browse the repository at this point in the history
…sts. r=bryce

subsuite media for browser tests.

Differential Revision: https://phabricator.services.mozilla.com/D95881
  • Loading branch information
alastor0325 committed Nov 5, 2020
1 parent 89a2733 commit af08036
Show file tree
Hide file tree
Showing 19 changed files with 169 additions and 136 deletions.
2 changes: 2 additions & 0 deletions dom/media/autoplay/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ XPIDL_SOURCES += [

MOCHITEST_MANIFESTS += ["test/mochitest/mochitest.ini"]

BROWSER_CHROME_MANIFESTS += ["test/browser/browser.ini"]

include("/ipc/chromium/chromium-config.mozbuild")

FINAL_LIBRARY = "xul"
Binary file added dom/media/autoplay/test/browser/audio.ogg
Binary file not shown.
23 changes: 23 additions & 0 deletions dom/media/autoplay/test/browser/browser.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[DEFAULT]
skip-if = (os == "win" && processor == "aarch64") # aarch64 due to 1536573
subsuite = media
tags = autoplay
support-files =
../../../test/gizmo.mp4
audio.ogg
file_empty.html
file_mediaplayback_frame.html
file_nonAutoplayAudio.html
file_video.html
head.js

[browser_autoplay_policy.js]
[browser_autoplay_policy_play_twice.js]
[browser_autoplay_policy_user_gestures.js]
[browser_autoplay_policy_request_permission.js]
[browser_autoplay_policy_touchScroll.js]
[browser_autoplay_policy_web_audio.js]
[browser_autoplay_policy_web_audio_with_gum.js]
[browser_autoplay_policy_webRTC_permission.js]
skip-if = true # Bug 1518429
[browser_autoplay_videoDocument.js]
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
* under different situations.
* Spec discussion : https://github.com/WICG/autoplay/issues/1
*/
const PAGE =
"https://example.com/browser/toolkit/content/tests/browser/file_empty.html";
const PAGE = GetTestWebBasedURL("file_empty.html");

function setupTestPreferences(isAllowedAutoplay, isAllowedMuted) {
let autoplayDefault = SpecialPowers.Ci.nsIAutoplay.ALLOWED;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const VIDEO_PAGE =
"https://example.com/browser/toolkit/content/tests/browser/file_video.html";
const VIDEO_PAGE = GetTestWebBasedURL("file_video.html");

function setup_test_preference(enableUserGesture) {
let state = enableUserGesture ? "enable" : "disable";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);

const VIDEO_PAGE_URI =
"https://example.com/browser/toolkit/content/tests/browser/file_empty.html";
const SAME_ORIGIN_FRAME_URI =
"https://example.com/browser/toolkit/content/tests/browser/file_mediaplayback_frame.html";
const DIFFERENT_ORIGIN_FRAME_URI =
"https://example.org/browser/toolkit/content/tests/browser/file_mediaplayback_frame.html";
const VIDEO_PAGE_URI = GetTestWebBasedURL("file_empty.html");
const SAME_ORIGIN_FRAME_URI = GetTestWebBasedURL(
"file_mediaplayback_frame.html"
);
const DIFFERENT_ORIGIN_FRAME_URI = GetTestWebBasedURL(
"file_mediaplayback_frame.html",
{ crossOrigin: true }
);

const gPermissionName = "autoplay-media";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
/* eslint-disable mozilla/no-arbitrary-setTimeout */
"use strict";

const PAGE =
"https://example.com/browser/toolkit/content/tests/browser/file_nonAutoplayAudio.html";
const PAGE = GetTestWebBasedURL("file_nonAutoplayAudio.html");

function checkMediaPlayingState(isPlaying) {
let audio = content.document.getElementById("testAudio");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable mozilla/no-arbitrary-setTimeout */

const VIDEO_PAGE =
"https://example.com/browser/toolkit/content/tests/browser/file_video.html";
const VIDEO_PAGE = GetTestWebBasedURL("file_video.html");

const UserGestures = {
MOUSE_CLICK: "mouse-click",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);

const VIDEO_PAGE =
"https://example.com/browser/toolkit/content/tests/browser/file_empty.html";
const VIDEO_PAGE = GetTestWebBasedURL("file_empty.html");

add_task(() => {
return SpecialPowers.pushPrefEnv({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);

const PAGE =
"https://example.com/browser/toolkit/content/tests/browser/file_empty.html";
const PAGE = GetTestWebBasedURL("file_empty.html");

function setup_test_preference() {
return SpecialPowers.pushPrefEnv({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use strict";

const PAGE =
"https://example.com/browser/toolkit/content/tests/browser/audio.ogg";
const PAGE = GetTestWebBasedURL("audio.ogg");

function setup_test_preference() {
return SpecialPowers.pushPrefEnv({
Expand Down
8 changes: 8 additions & 0 deletions dom/media/autoplay/test/browser/file_empty.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<title>Page left intentionally blank...</title>
</head>
<body>
</body>
</html>
7 changes: 7 additions & 0 deletions dom/media/autoplay/test/browser/file_nonAutoplayAudio.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
</head>
<body>
<audio id="testAudio" src="audio.ogg" loop></audio>
9 changes: 9 additions & 0 deletions dom/media/autoplay/test/browser/file_video.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>video</title>
</head>
<body>
<video id="v" src="gizmo.mp4" controls loop></video>
</body>
</html>
105 changes: 105 additions & 0 deletions dom/media/autoplay/test/browser/head.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* Return a web-based URL for a given file based on the testing directory.
* @param {String} fileName
* file that caller wants its web-based url
* @param {Boolean} crossOrigin [optional]
* if set, then return a url with different origin. The default value is
* false.
*/
function GetTestWebBasedURL(fileName, { crossOrigin = false } = {}) {
const origin = crossOrigin ? "http://example.org" : "http://example.com";
return (
getRootDirectory(gTestPath).replace("chrome://mochitests/content", origin) +
fileName
);
}

/**
* Runs a content script that creates an autoplay video.
* @param {browserElement} browser
* the browser to run the script in
* @param {object} args
* test case definition, required members
* {
* mode: String, "autoplay attribute" or "call play".
* }
*/
function loadAutoplayVideo(browser, args) {
return SpecialPowers.spawn(browser, [args], async args => {
info("- create a new autoplay video -");
let video = content.document.createElement("video");
video.id = "v1";
video.didPlayPromise = new Promise((resolve, reject) => {
video.addEventListener(
"playing",
e => {
video.didPlay = true;
resolve();
},
{ once: true }
);
video.addEventListener(
"blocked",
e => {
video.didPlay = false;
resolve();
},
{ once: true }
);
});
if (args.mode == "autoplay attribute") {
info("autoplay attribute set to true");
video.autoplay = true;
} else if (args.mode == "call play") {
info("will call play() when reached loadedmetadata");
video.addEventListener(
"loadedmetadata",
e => {
video.play().then(
() => {
info("video play() resolved");
},
() => {
info("video play() rejected");
}
);
},
{ once: true }
);
} else {
ok(false, "Invalid 'mode' arg");
}
video.src = "gizmo.mp4";
content.document.body.appendChild(video);
});
}

/**
* Runs a content script that checks whether the video created by
* loadAutoplayVideo() started playing.
* @param {browserElement} browser
* the browser to run the script in
* @param {object} args
* test case definition, required members
* {
* name: String, description of test.
* mode: String, "autoplay attribute" or "call play".
* shouldPlay: boolean, whether video should play.
* }
*/
function checkVideoDidPlay(browser, args) {
return SpecialPowers.spawn(browser, [args], async args => {
let video = content.document.getElementById("v1");
await video.didPlayPromise;
is(
video.didPlay,
args.shouldPlay,
args.name +
" should " +
(!args.shouldPlay ? "not " : "") +
"be able to autoplay"
);
video.src = "";
content.document.body.remove(video);
});
}
35 changes: 0 additions & 35 deletions toolkit/content/tests/browser/browser.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ support-files =
file_mediaPlayback2.html
file_mediaPlaybackFrame.html
file_mediaPlaybackFrame2.html
file_mediaplayback_frame.html
file_multipleAudio.html
file_multiplePlayingAudio.html
file_nonAutoplayAudio.html
Expand All @@ -27,40 +26,6 @@ support-files =
image_page.html
silentAudioTrack.webm

[browser_autoplay_policy.js]
support-files =
file_empty.html
skip-if = (os == "win" && processor == "aarch64") # aarch64 due to 1536573
[browser_autoplay_policy_play_twice.js]
support-files =
gizmo.mp4
file_video.html
skip-if = (os == "win" && processor == "aarch64") # aarch64 due to 1536573
[browser_autoplay_policy_request_permission.js]
support-files =
file_empty.html
gizmo.mp4
skip-if = (os == "win" && processor == "aarch64") # aarch64 due to 1536573
[browser_autoplay_policy_user_gestures.js]
support-files =
gizmo.mp4
file_video.html
skip-if = (os == "win" && processor == "aarch64") # aarch64 due to 1536573
[browser_autoplay_policy_touchScroll.js]
skip-if = (os == "win" && processor == "aarch64") # aarch64 due to 1536573
[browser_autoplay_policy_web_audio.js]
support-files =
file_empty.html
skip-if = (os == "win" && processor == "aarch64") # aarch64 due to 1536573
[browser_autoplay_policy_web_audio_with_gum.js]
skip-if = (os == "win" && processor == "aarch64") # aarch64 due to 1536573
[browser_autoplay_policy_webRTC_permission.js]
skip-if = true # Bug 1518429
support-files =
file_empty.html
gizmo.mp4
[browser_autoplay_videoDocument.js]
skip-if = (os == "win" && processor == "aarch64") # aarch64 due to 1536573
[browser_autoscroll_disabled.js]
skip-if = true # Bug 1312652
[browser_delay_autoplay_media.js]
Expand Down
81 changes: 0 additions & 81 deletions toolkit/content/tests/browser/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,87 +279,6 @@ function once(target, name) {
return p;
}

// Runs a content script that creates an autoplay video.
// browser: the browser to run the script in.
// args: test case definition, required members {
// mode: String, "autoplay attribute" or "call play".
// }
function loadAutoplayVideo(browser, args) {
return SpecialPowers.spawn(browser, [args], async args => {
info("- create a new autoplay video -");
let video = content.document.createElement("video");
video.id = "v1";
video.didPlayPromise = new Promise((resolve, reject) => {
video.addEventListener(
"playing",
e => {
video.didPlay = true;
resolve();
},
{ once: true }
);
video.addEventListener(
"blocked",
e => {
video.didPlay = false;
resolve();
},
{ once: true }
);
});
if (args.mode == "autoplay attribute") {
info("autoplay attribute set to true");
video.autoplay = true;
} else if (args.mode == "call play") {
info("will call play() when reached loadedmetadata");
video.addEventListener(
"loadedmetadata",
e => {
video.play().then(
() => {
info("video play() resolved");
},
() => {
info("video play() rejected");
}
);
},
{ once: true }
);
} else {
ok(false, "Invalid 'mode' arg");
}
video.src = "gizmo.mp4";
content.document.body.appendChild(video);
});
}

// Runs a content script that checks whether the video created by
// loadAutoplayVideo() started playing.
// Parameters:
// browser: the browser to run the script in.
// args: test case definition, required members {
// name: String, description of test.
// mode: String, "autoplay attribute" or "call play".
// shouldPlay: boolean, whether video should play.
// }
function checkVideoDidPlay(browser, args) {
return SpecialPowers.spawn(browser, [args], async args => {
let video = content.document.getElementById("v1");
await video.didPlayPromise;
is(
video.didPlay,
args.shouldPlay,
args.name +
" should " +
(!args.shouldPlay ? "not " : "") +
"be able to autoplay"
);
video.src = "";
content.document.body.remove(video);
});
}

/**
* check if current wakelock is equal to expected state, if not, then wait until
* the wakelock changes its state to expected state.
Expand Down

0 comments on commit af08036

Please sign in to comment.