diff --git a/dom/media/autoplay/moz.build b/dom/media/autoplay/moz.build index 1324cb2acef8..338f0798f8f2 100644 --- a/dom/media/autoplay/moz.build +++ b/dom/media/autoplay/moz.build @@ -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" diff --git a/dom/media/autoplay/test/browser/audio.ogg b/dom/media/autoplay/test/browser/audio.ogg new file mode 100644 index 000000000000..7f1833508ab3 Binary files /dev/null and b/dom/media/autoplay/test/browser/audio.ogg differ diff --git a/dom/media/autoplay/test/browser/browser.ini b/dom/media/autoplay/test/browser/browser.ini new file mode 100644 index 000000000000..dfff4b4099b6 --- /dev/null +++ b/dom/media/autoplay/test/browser/browser.ini @@ -0,0 +1,22 @@ +[DEFAULT] +skip-if = (os == "win" && processor == "aarch64") # aarch64 due to 1536573 +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] diff --git a/toolkit/content/tests/browser/browser_autoplay_policy.js b/dom/media/autoplay/test/browser/browser_autoplay_policy.js similarity index 96% rename from toolkit/content/tests/browser/browser_autoplay_policy.js rename to dom/media/autoplay/test/browser/browser_autoplay_policy.js index 2d6542bd2125..79b19eedc1e7 100644 --- a/toolkit/content/tests/browser/browser_autoplay_policy.js +++ b/dom/media/autoplay/test/browser/browser_autoplay_policy.js @@ -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; diff --git a/toolkit/content/tests/browser/browser_autoplay_policy_play_twice.js b/dom/media/autoplay/test/browser/browser_autoplay_policy_play_twice.js similarity index 93% rename from toolkit/content/tests/browser/browser_autoplay_policy_play_twice.js rename to dom/media/autoplay/test/browser/browser_autoplay_policy_play_twice.js index 92e66954040c..c87bbdf0f988 100644 --- a/toolkit/content/tests/browser/browser_autoplay_policy_play_twice.js +++ b/dom/media/autoplay/test/browser/browser_autoplay_policy_play_twice.js @@ -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"; diff --git a/toolkit/content/tests/browser/browser_autoplay_policy_request_permission.js b/dom/media/autoplay/test/browser/browser_autoplay_policy_request_permission.js similarity index 95% rename from toolkit/content/tests/browser/browser_autoplay_policy_request_permission.js rename to dom/media/autoplay/test/browser/browser_autoplay_policy_request_permission.js index 11453318f39a..f22fb8d1e892 100644 --- a/toolkit/content/tests/browser/browser_autoplay_policy_request_permission.js +++ b/dom/media/autoplay/test/browser/browser_autoplay_policy_request_permission.js @@ -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"; diff --git a/toolkit/content/tests/browser/browser_autoplay_policy_touchScroll.js b/dom/media/autoplay/test/browser/browser_autoplay_policy_touchScroll.js similarity index 96% rename from toolkit/content/tests/browser/browser_autoplay_policy_touchScroll.js rename to dom/media/autoplay/test/browser/browser_autoplay_policy_touchScroll.js index ef9f32bb15f1..fa28bf2943fa 100644 --- a/toolkit/content/tests/browser/browser_autoplay_policy_touchScroll.js +++ b/dom/media/autoplay/test/browser/browser_autoplay_policy_touchScroll.js @@ -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"); diff --git a/toolkit/content/tests/browser/browser_autoplay_policy_user_gestures.js b/dom/media/autoplay/test/browser/browser_autoplay_policy_user_gestures.js similarity index 98% rename from toolkit/content/tests/browser/browser_autoplay_policy_user_gestures.js rename to dom/media/autoplay/test/browser/browser_autoplay_policy_user_gestures.js index 0b2a70a20feb..bbae6ff034d6 100644 --- a/toolkit/content/tests/browser/browser_autoplay_policy_user_gestures.js +++ b/dom/media/autoplay/test/browser/browser_autoplay_policy_user_gestures.js @@ -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", diff --git a/toolkit/content/tests/browser/browser_autoplay_policy_webRTC_permission.js b/dom/media/autoplay/test/browser/browser_autoplay_policy_webRTC_permission.js similarity index 94% rename from toolkit/content/tests/browser/browser_autoplay_policy_webRTC_permission.js rename to dom/media/autoplay/test/browser/browser_autoplay_policy_webRTC_permission.js index f590c5dd3926..9a407db05743 100644 --- a/toolkit/content/tests/browser/browser_autoplay_policy_webRTC_permission.js +++ b/dom/media/autoplay/test/browser/browser_autoplay_policy_webRTC_permission.js @@ -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({ diff --git a/toolkit/content/tests/browser/browser_autoplay_policy_web_audio.js b/dom/media/autoplay/test/browser/browser_autoplay_policy_web_audio.js similarity index 98% rename from toolkit/content/tests/browser/browser_autoplay_policy_web_audio.js rename to dom/media/autoplay/test/browser/browser_autoplay_policy_web_audio.js index 9a72665413b3..5eac1398882e 100644 --- a/toolkit/content/tests/browser/browser_autoplay_policy_web_audio.js +++ b/dom/media/autoplay/test/browser/browser_autoplay_policy_web_audio.js @@ -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({ diff --git a/toolkit/content/tests/browser/browser_autoplay_policy_web_audio_with_gum.js b/dom/media/autoplay/test/browser/browser_autoplay_policy_web_audio_with_gum.js similarity index 100% rename from toolkit/content/tests/browser/browser_autoplay_policy_web_audio_with_gum.js rename to dom/media/autoplay/test/browser/browser_autoplay_policy_web_audio_with_gum.js diff --git a/toolkit/content/tests/browser/browser_autoplay_videoDocument.js b/dom/media/autoplay/test/browser/browser_autoplay_videoDocument.js similarity index 96% rename from toolkit/content/tests/browser/browser_autoplay_videoDocument.js rename to dom/media/autoplay/test/browser/browser_autoplay_videoDocument.js index 12cf35e9f919..77ce4ddbc11e 100644 --- a/toolkit/content/tests/browser/browser_autoplay_videoDocument.js +++ b/dom/media/autoplay/test/browser/browser_autoplay_videoDocument.js @@ -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({ diff --git a/dom/media/autoplay/test/browser/file_empty.html b/dom/media/autoplay/test/browser/file_empty.html new file mode 100644 index 000000000000..d2b0361f091f --- /dev/null +++ b/dom/media/autoplay/test/browser/file_empty.html @@ -0,0 +1,8 @@ + + + + Page left intentionally blank... + + + + diff --git a/toolkit/content/tests/browser/file_mediaplayback_frame.html b/dom/media/autoplay/test/browser/file_mediaplayback_frame.html similarity index 100% rename from toolkit/content/tests/browser/file_mediaplayback_frame.html rename to dom/media/autoplay/test/browser/file_mediaplayback_frame.html diff --git a/dom/media/autoplay/test/browser/file_nonAutoplayAudio.html b/dom/media/autoplay/test/browser/file_nonAutoplayAudio.html new file mode 100644 index 000000000000..4d2641021a13 --- /dev/null +++ b/dom/media/autoplay/test/browser/file_nonAutoplayAudio.html @@ -0,0 +1,7 @@ + + + + + + + diff --git a/dom/media/autoplay/test/browser/file_video.html b/dom/media/autoplay/test/browser/file_video.html new file mode 100644 index 000000000000..3c70268fbb75 --- /dev/null +++ b/dom/media/autoplay/test/browser/file_video.html @@ -0,0 +1,9 @@ + + + +video + + + + + diff --git a/dom/media/autoplay/test/browser/head.js b/dom/media/autoplay/test/browser/head.js new file mode 100644 index 000000000000..648b6df59df4 --- /dev/null +++ b/dom/media/autoplay/test/browser/head.js @@ -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); + }); +} diff --git a/toolkit/content/tests/browser/browser.ini b/toolkit/content/tests/browser/browser.ini index 9ebb1710f7a5..b4acf715b5e3 100644 --- a/toolkit/content/tests/browser/browser.ini +++ b/toolkit/content/tests/browser/browser.ini @@ -8,12 +8,12 @@ support-files = empty.png file_almostSilentAudioTrack.html file_contentTitle.html + file_empty.html file_findinframe.html file_mediaPlayback.html file_mediaPlayback2.html file_mediaPlaybackFrame.html file_mediaPlaybackFrame2.html - file_mediaplayback_frame.html file_multipleAudio.html file_multiplePlayingAudio.html file_nonAutoplayAudio.html @@ -27,40 +27,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] diff --git a/toolkit/content/tests/browser/head.js b/toolkit/content/tests/browser/head.js index ba70484c1d4c..fb404f483246 100644 --- a/toolkit/content/tests/browser/head.js +++ b/toolkit/content/tests/browser/head.js @@ -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.