зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1341062 - part2 : remove duplicated codes. r=baku
MozReview-Commit-ID: C6N1itQAVcF --HG-- extra : rebase_source : a0f1d679d3662736bbac12f19d13891ce2e5a6e5
This commit is contained in:
Родитель
22ff369556
Коммит
c7fb5e7910
|
@ -1,19 +1,5 @@
|
||||||
const PAGE = "https://example.com/browser/toolkit/content/tests/browser/file_multipleAudio.html";
|
const PAGE = "https://example.com/browser/toolkit/content/tests/browser/file_multipleAudio.html";
|
||||||
|
|
||||||
function* wait_for_tab_playing_event(tab, expectPlaying) {
|
|
||||||
if (tab.soundPlaying == expectPlaying) {
|
|
||||||
ok(true, "The tab should " + (expectPlaying ? "" : "not ") + "be playing");
|
|
||||||
} else {
|
|
||||||
yield BrowserTestUtils.waitForEvent(tab, "TabAttrModified", false, (event) => {
|
|
||||||
if (event.detail.changed.indexOf("soundplaying") >= 0) {
|
|
||||||
is(tab.soundPlaying, expectPlaying, "The tab should " + (expectPlaying ? "" : "not ") + "be playing");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function play_audio_from_invisible_tab() {
|
function play_audio_from_invisible_tab() {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
var autoPlay = content.document.getElementById("autoplay");
|
var autoPlay = content.document.getElementById("autoplay");
|
||||||
|
@ -73,13 +59,13 @@ add_task(function* cross_tabs_audio_competing() {
|
||||||
let tab1 = yield BrowserTestUtils.openNewForegroundTab(window.gBrowser,
|
let tab1 = yield BrowserTestUtils.openNewForegroundTab(window.gBrowser,
|
||||||
"about:blank");
|
"about:blank");
|
||||||
tab1.linkedBrowser.loadURI(PAGE);
|
tab1.linkedBrowser.loadURI(PAGE);
|
||||||
yield wait_for_tab_playing_event(tab1, true);
|
yield waitForTabPlayingEvent(tab1, true);
|
||||||
|
|
||||||
info("- open tab 2 in foreground -");
|
info("- open tab 2 in foreground -");
|
||||||
let tab2 = yield BrowserTestUtils.openNewForegroundTab(window.gBrowser,
|
let tab2 = yield BrowserTestUtils.openNewForegroundTab(window.gBrowser,
|
||||||
"about:blank");
|
"about:blank");
|
||||||
tab2.linkedBrowser.loadURI(PAGE);
|
tab2.linkedBrowser.loadURI(PAGE);
|
||||||
yield wait_for_tab_playing_event(tab1, false);
|
yield waitForTabPlayingEvent(tab1, false);
|
||||||
|
|
||||||
info("- open tab 3 in foreground -");
|
info("- open tab 3 in foreground -");
|
||||||
let tab3 = yield BrowserTestUtils.openNewForegroundTab(window.gBrowser,
|
let tab3 = yield BrowserTestUtils.openNewForegroundTab(window.gBrowser,
|
||||||
|
@ -102,7 +88,7 @@ add_task(function* within_one_tab_audio_competing() {
|
||||||
let tab = yield BrowserTestUtils.openNewForegroundTab(window.gBrowser,
|
let tab = yield BrowserTestUtils.openNewForegroundTab(window.gBrowser,
|
||||||
"about:blank");
|
"about:blank");
|
||||||
tab.linkedBrowser.loadURI(PAGE);
|
tab.linkedBrowser.loadURI(PAGE);
|
||||||
yield wait_for_tab_playing_event(tab, true);
|
yield waitForTabPlayingEvent(tab, true);
|
||||||
|
|
||||||
info("- play audio2 in the same tab -");
|
info("- play audio2 in the same tab -");
|
||||||
yield ContentTask.spawn(tab.linkedBrowser, null,
|
yield ContentTask.spawn(tab.linkedBrowser, null,
|
||||||
|
|
|
@ -7,20 +7,6 @@ var SuspendedType = {
|
||||||
SUSPENDED_PAUSE_DISPOSABLE : 3
|
SUSPENDED_PAUSE_DISPOSABLE : 3
|
||||||
};
|
};
|
||||||
|
|
||||||
function* wait_for_tab_playing_event(tab, expectPlaying) {
|
|
||||||
if (tab.soundPlaying == expectPlaying) {
|
|
||||||
ok(true, "The tab should " + (expectPlaying ? "" : "not ") + "be playing");
|
|
||||||
} else {
|
|
||||||
yield BrowserTestUtils.waitForEvent(tab, "TabAttrModified", false, (event) => {
|
|
||||||
if (event.detail.changed.indexOf("soundplaying") >= 0) {
|
|
||||||
is(tab.soundPlaying, expectPlaying, "The tab should " + (expectPlaying ? "" : "not ") + "be playing");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function check_audio_suspended(suspendedType) {
|
function check_audio_suspended(suspendedType) {
|
||||||
var autoPlay = content.document.getElementById("autoplay");
|
var autoPlay = content.document.getElementById("autoplay");
|
||||||
if (!autoPlay) {
|
if (!autoPlay) {
|
||||||
|
@ -61,7 +47,7 @@ add_task(function* block_autoplay_media() {
|
||||||
yield BrowserTestUtils.switchTab(window.gBrowser, tab1);
|
yield BrowserTestUtils.switchTab(window.gBrowser, tab1);
|
||||||
|
|
||||||
info("- media should be unblocked because the tab was visited -");
|
info("- media should be unblocked because the tab was visited -");
|
||||||
yield wait_for_tab_playing_event(tab1, true);
|
yield waitForTabPlayingEvent(tab1, true);
|
||||||
yield ContentTask.spawn(tab1.linkedBrowser, SuspendedType.NONE_SUSPENDED,
|
yield ContentTask.spawn(tab1.linkedBrowser, SuspendedType.NONE_SUSPENDED,
|
||||||
check_audio_suspended);
|
check_audio_suspended);
|
||||||
|
|
||||||
|
@ -69,12 +55,12 @@ add_task(function* block_autoplay_media() {
|
||||||
let tab3 = yield BrowserTestUtils.openNewForegroundTab(window.gBrowser,
|
let tab3 = yield BrowserTestUtils.openNewForegroundTab(window.gBrowser,
|
||||||
"about:blank");
|
"about:blank");
|
||||||
info("- should still play media from tab1 -");
|
info("- should still play media from tab1 -");
|
||||||
yield wait_for_tab_playing_event(tab1, true);
|
yield waitForTabPlayingEvent(tab1, true);
|
||||||
yield ContentTask.spawn(tab1.linkedBrowser, SuspendedType.NONE_SUSPENDED,
|
yield ContentTask.spawn(tab1.linkedBrowser, SuspendedType.NONE_SUSPENDED,
|
||||||
check_audio_suspended);
|
check_audio_suspended);
|
||||||
|
|
||||||
info("- should still block media from tab2 -");
|
info("- should still block media from tab2 -");
|
||||||
yield wait_for_tab_playing_event(tab2, false);
|
yield waitForTabPlayingEvent(tab2, false);
|
||||||
yield ContentTask.spawn(tab2.linkedBrowser, SuspendedType.SUSPENDED_BLOCK,
|
yield ContentTask.spawn(tab2.linkedBrowser, SuspendedType.SUSPENDED_BLOCK,
|
||||||
check_audio_suspended);
|
check_audio_suspended);
|
||||||
|
|
||||||
|
|
|
@ -7,21 +7,6 @@ var SuspendedType = {
|
||||||
SUSPENDED_PAUSE_DISPOSABLE : 3
|
SUSPENDED_PAUSE_DISPOSABLE : 3
|
||||||
};
|
};
|
||||||
|
|
||||||
function* wait_for_tab_playing_event(tab, expectPlaying) {
|
|
||||||
if (tab.soundPlaying == expectPlaying) {
|
|
||||||
ok(true, "The tab should " + (expectPlaying ? "" : "not ") + "be playing");
|
|
||||||
} else {
|
|
||||||
info("Playing state doens't match, wait for attributes changes.");
|
|
||||||
yield BrowserTestUtils.waitForEvent(tab, "TabAttrModified", false, (event) => {
|
|
||||||
if (event.detail.changed.indexOf("soundplaying") >= 0) {
|
|
||||||
is(tab.soundPlaying, expectPlaying, "The tab should " + (expectPlaying ? "" : "not ") + "be playing");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function disable_non_test_mouse(disable) {
|
function disable_non_test_mouse(disable) {
|
||||||
let utils = window.QueryInterface(Ci.nsIInterfaceRequestor)
|
let utils = window.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||||
.getInterface(Ci.nsIDOMWindowUtils);
|
.getInterface(Ci.nsIDOMWindowUtils);
|
||||||
|
@ -97,7 +82,7 @@ add_task(function* unblock_icon_should_disapear_after_resume_tab() {
|
||||||
yield waitForTabBlockEvent(tab, false);
|
yield waitForTabBlockEvent(tab, false);
|
||||||
|
|
||||||
info("- should not display sound indicator icon -");
|
info("- should not display sound indicator icon -");
|
||||||
yield wait_for_tab_playing_event(tab, false);
|
yield waitForTabPlayingEvent(tab, false);
|
||||||
|
|
||||||
info("- remove tab -");
|
info("- remove tab -");
|
||||||
yield BrowserTestUtils.removeTab(tab);
|
yield BrowserTestUtils.removeTab(tab);
|
||||||
|
@ -127,7 +112,7 @@ add_task(function* should_not_show_sound_indicator_after_resume_tab() {
|
||||||
yield waitForTabBlockEvent(tab, false);
|
yield waitForTabBlockEvent(tab, false);
|
||||||
|
|
||||||
info("- should not display sound indicator icon -");
|
info("- should not display sound indicator icon -");
|
||||||
yield wait_for_tab_playing_event(tab, false);
|
yield waitForTabPlayingEvent(tab, false);
|
||||||
|
|
||||||
info("- remove tab -");
|
info("- remove tab -");
|
||||||
yield BrowserTestUtils.removeTab(tab);
|
yield BrowserTestUtils.removeTab(tab);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче