Bug 1627999 - part5 : remove out-of-date test. r=bryce

This patch will do :
- remove out-of-date test that uses the previous implementation of determining the active media session

The advantage of doing so :
- prevent the failure causing by out-of-date test

Differential Revision: https://phabricator.services.mozilla.com/D72499
This commit is contained in:
alwu 2020-05-15 21:49:56 +00:00
Родитель b80c125661
Коммит b37d0955bb
4 изменённых файлов: 0 добавлений и 270 удалений

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

@ -1,16 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test active media session within a page</title>
<script src="MediaSessionTestUtils.js"></script>
</head>
<body>
<script>
navigator.mediaSession.setActionHandler("play", () => {
const w = window.opener || window.parent;
w.postMessage("play", "*");
});
</script>
</body>
</html>

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

@ -1,149 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test active media session within a page</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="MediaSessionTestUtils.js"></script>
</head>
<body>
<video id="testVideo" src="gizmo.mp4" loop></video>
<script>
var gActiveSessionShouldBeFrom = "none";
nextWindowMessage().then(
async (event) => {
const {testCommands} = event.data;
// Media session would only become active if there is any media currently
// playing. Non-active media session won't receive any actions. Therefore,
// we start media playback before testing media session.
await startMediaPlayback();
for (const command of testCommands) {
info(`execute command '${command}'`);
switch (command) {
case gCommands.createMainFrameSession:
createSessionInMainFrame();
break;
case gCommands.createChildFrameSession:
await createSessionInChildFrame();
break;
case gCommands.destroyChildFrameSessions:
await destroyAllChildFrames();
break;
case gCommands.destroyActiveChildFrameSession:
await destroyChildFrameWithActiveSession();
break;
case gCommands.destroyInactiveChildFrameSession:
await destroyChildFrameWithInactiveSession();
break;
};
}
// Finished running all commands, so we can return testing result.
await endTestAndReportResult();
});
/**
* The following are helper functions
*/
async function startMediaPlayback() {
info(`wait until media starts playing`);
const video = document.getElementById("testVideo");
await video.play();
// As we can't observe `main-media-controller-playback-changed` notification,
// which can only be observed in the chrome process. Therefore, we use a
// workaround instead which is to wait for a while to ensure that the
// controller has already been created in the chrome process.
let timeupdatecount = 0;
await new Promise(r => video.ontimeupdate = () => {
if (++timeupdatecount == 3) {
video.ontimeupdate = null;
r();
}
});
}
function createSessionInMainFrame() {
// Simply referencing media session will create media session.
navigator.mediaSession;
// Media session created in main frame should always be an active session.
gActiveSessionShouldBeFrom = "main-frame";
}
async function createSessionInChildFrame() {
const frame = document.createElement("iframe");
frame.src = "file_active_mediasession_within_page_frame.html";
frame.id = "child-frame-" + document.getElementsByTagName("iframe").length;
document.body.appendChild(frame);
info(`wait until ${frame.id } finishing loading`);
await new Promise(r => frame.onload = r);
// If we haven't created any media session, then this media session should
// become an active session. Otherwise, session created in child frame won't
// override the current active session and should be inactive session.
if (gActiveSessionShouldBeFrom == "none") {
gActiveSessionShouldBeFrom = frame.id;
}
}
async function destroyAllChildFrames() {
const frames = document.getElementsByTagName("iframe");
for (const frame of frames) {
document.body.removeChild(frame);
}
}
async function destroyChildFrameWithActiveSession() {
const frames = document.getElementsByTagName("iframe");
for (const frame of frames) {
if (frame.id == gActiveSessionShouldBeFrom) {
document.body.removeChild(frame);
return;
}
}
}
async function destroyChildFrameWithInactiveSession() {
const frames = document.getElementsByTagName("iframe");
for (const frame of frames) {
if (frame.id != gActiveSessionShouldBeFrom) {
document.body.removeChild(frame);
}
}
}
async function getActiveSessionResult() {
// The way we check which session is active is by generating `play` action and
// see which session's action hanlder is triggered, because we would only
// trigger active session's action handler.
const action = "play";
info(`we assume active session should be from ${gActiveSessionShouldBeFrom}`);
if (gActiveSessionShouldBeFrom == "main-frame") {
let promise = new Promise(r => {
navigator.mediaSession.setActionHandler(action, () => {
info(`active session is from main main-frame`);
r();
});
});
SpecialPowers.generateMediaControlKeyTestEvent(action);
await promise;
return gResults.mainFrameSession;
}
SpecialPowers.generateMediaControlKeyTestEvent(action);
const event = await nextWindowMessage();
if (gActiveSessionShouldBeFrom == event.source.frameElement.id) {
return gResults.childFrameSession;
}
return gResults.childFrameSessionUpdated;
}
async function endTestAndReportResult() {
const rv = await getActiveSessionResult();
const w = window.opener || window.parent;
w.postMessage(rv, "*");
}
</script>
</body>
</html>

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

@ -4,12 +4,9 @@ tags = mediasession mediacontrol
support-files =
../../test/gizmo.mp4
file_active_mediasession_within_page_frame.html
file_active_mediasession_within_page_window.html
file_trigger_actionhanlder_frame.html
file_trigger_actionhanlder_window.html
MediaSessionTestUtils.js
[test_active_mediasession_within_page.html]
[test_setactionhandler.html]
[test_trigger_actionhanlder.html]

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

@ -1,102 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test active media session within a page</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script src="MediaSessionTestUtils.js"></script>
</head>
<body>
<script>
/**
* This test is used to check if the active media session is selected correctly
* when there are multiple media sessions existing within a same page.
*
* `testCases` contains all test cases we're going to execute in this test, and
* each test would be run in a new window. For each test case, we have several
* test commands which we would send to window, and the test running in window
* would do different operations depending on what command we send. After the
* window finishes running all those commands, it would post a message to tell
* us its testing result, which can represent if where active media session is
* created and if the active media session has been changed during testing.
*/
const testCases = [
{
name: "Session created in main-frame is always active session",
testCommands: [
gCommands.createMainFrameSession,
gCommands.createChildFrameSession,
],
expectedResult: gResults.mainFrameSession,
},
{
name: "Session created in child-frame will be overwrited by main-frame's session",
testCommands: [
gCommands.createChildFrameSession,
gCommands.createMainFrameSession,
],
expectedResult: gResults.mainFrameSession,
},
{
name: "Session created in child-frame won't be overwrited by other child-frame's session",
testCommands: [
gCommands.createChildFrameSession,
gCommands.createChildFrameSession,
],
expectedResult: gResults.childFrameSession,
},
{
name: "Session created in main-frame won't be affected by creation and destruction of child-frame session",
testCommands: [
gCommands.createMainFrameSession,
gCommands.createChildFrameSession,
gCommands.destroyChildFrameSessions,
],
expectedResult: gResults.mainFrameSession,
},
{
name: "Session created in child-frame won't be affected by creation and destruction of non active child-frame session",
testCommands: [
gCommands.createChildFrameSession,
gCommands.createChildFrameSession,
gCommands.destroyInactiveChildFrameSession,
],
expectedResult: gResults.childFrameSession,
},
{
name: "Inactive session would become active after active session is destroyed",
testCommands: [
gCommands.createChildFrameSession,
gCommands.createChildFrameSession,
gCommands.destroyActiveChildFrameSession,
],
expectedResult: gResults.childFrameSessionUpdated,
},
];
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [
["dom.media.mediasession.enabled", true],
["media.mediacontrol.testingevents.enabled", true],
]}, startTest());
async function startTest() {
for (const testCase of testCases) {
info(`- loading test '${testCase.name}' in a new window -`);
const testURL = "file_active_mediasession_within_page_window.html";
const testWindow = window.open(testURL, "", "width=500,height=500");
await new Promise(r => testWindow.onload = r);
info("- start running test -");
testWindow.postMessage(testCase, window.origin);
is((await nextWindowMessage()).data, testCase.expectedResult,
`- finished test '${testCase.name}' -`);
testWindow.close();
}
SimpleTest.finish();
}
</script>
</body>
</html>