Bug 1470677 - Undo duplication in browser_multiselect_tabs_mute_unmute.js test file by moving browser_audioTabIcon.js to /browser/base/content/test/tabs directory. r=jaws

MozReview-Commit-ID: 6psjZW3bdNG

--HG--
rename : browser/base/content/test/general/browser_audioTabIcon.js => browser/base/content/test/tabs/browser_audioTabIcon.js
extra : rebase_source : 0ae2be71cf087237a91198888565c74e5b8194c9
This commit is contained in:
Abdoulaye O. Ly 2018-06-27 05:21:59 +00:00
parent 50c533980d
commit 24cd3a4391
6 changed files with 144 additions and 250 deletions

View File

@ -37,7 +37,6 @@ support-files =
feed_tab.html
file_generic_favicon.ico
file_with_favicon.html
file_mediaPlayback.html
file_bug970276_popup1.html
file_bug970276_popup2.html
file_bug970276_favicon1.ico
@ -82,9 +81,6 @@ support-files =
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
[browser_alltabslistener.js]
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
[browser_audioTabIcon.js]
tags = audiochannel
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
[browser_backButtonFitts.js]
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
[browser_beforeunload_duplicate_dialogs.js]

View File

@ -2,11 +2,15 @@
support-files =
head.js
dummy_page.html
../general/audio.ogg
file_mediaPlayback.html
[browser_abandonment_telemetry.js]
[browser_accessibility_indicator.js]
skip-if = (verify && debug && (os == 'linux'))
[browser_allow_process_switches_despite_related_browser.js]
[browser_audioTabIcon.js]
tags = audiochannel
[browser_bug_1387976_restore_lazy_tab_browser_muted_state.js]
[browser_bug580956.js]
[browser_close_tab_by_dblclick.js]
@ -19,9 +23,6 @@ support-files =
[browser_multiselect_tabs_close_using_shortcuts.js]
[browser_multiselect_tabs_close.js]
[browser_multiselect_tabs_mute_unmute.js]
support-files =
../general/audio.ogg
../general/file_mediaPlayback.html
[browser_multiselect_tabs_positional_attrs.js]
[browser_multiselect_tabs_using_Ctrl.js]
[browser_multiselect_tabs_using_Shift.js]

View File

@ -1,48 +1,8 @@
/* eslint-disable mozilla/no-arbitrary-setTimeout */
const PAGE = "https://example.com/browser/browser/base/content/test/general/file_mediaPlayback.html";
const PAGE = "https://example.com/browser/browser/base/content/test/tabs/file_mediaPlayback.html";
const TABATTR_REMOVAL_PREFNAME = "browser.tabs.delayHidingAudioPlayingIconMS";
const INITIAL_TABATTR_REMOVAL_DELAY_MS = Services.prefs.getIntPref(TABATTR_REMOVAL_PREFNAME);
async function wait_for_tab_playing_event(tab, expectPlaying) {
if (tab.soundPlaying == expectPlaying) {
ok(true, "The tab should " + (expectPlaying ? "" : "not ") + "be playing");
return true;
}
return BrowserTestUtils.waitForEvent(tab, "TabAttrModified", false, (event) => {
if (event.detail.changed.includes("soundplaying")) {
is(tab.hasAttribute("soundplaying"), expectPlaying, "The tab should " + (expectPlaying ? "" : "not ") + "be playing");
is(tab.soundPlaying, expectPlaying, "The tab should " + (expectPlaying ? "" : "not ") + "be playing");
return true;
}
return false;
});
}
async function is_audio_playing(tab) {
let browser = tab.linkedBrowser;
let isPlaying = await ContentTask.spawn(browser, {}, async function() {
let audio = content.document.querySelector("audio");
return !audio.paused;
});
return isPlaying;
}
async function play(tab) {
let browser = tab.linkedBrowser;
await ContentTask.spawn(browser, {}, async function() {
let audio = content.document.querySelector("audio");
audio.play();
});
// If the tab has already be muted, it means the tab won't get soundplaying,
// so we don't need to check this attribute.
if (browser.audioMuted) {
return;
}
await wait_for_tab_playing_event(tab, true);
}
async function pause(tab, options) {
let extendedDelay = options && options.extendedDelay;
if (extendedDelay) {
@ -95,32 +55,6 @@ async function show_tab(tab) {
return tabShown;
}
function disable_non_test_mouse(disable) {
let utils = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
utils.disableNonTestMouseEvents(disable);
}
function hover_icon(icon, tooltip) {
disable_non_test_mouse(true);
let popupShownPromise = BrowserTestUtils.waitForEvent(tooltip, "popupshown");
EventUtils.synthesizeMouse(icon, 1, 1, {type: "mouseover"});
EventUtils.synthesizeMouse(icon, 2, 2, {type: "mousemove"});
EventUtils.synthesizeMouse(icon, 3, 3, {type: "mousemove"});
EventUtils.synthesizeMouse(icon, 4, 4, {type: "mousemove"});
return popupShownPromise;
}
function leave_icon(icon) {
EventUtils.synthesizeMouse(icon, 0, 0, {type: "mouseout"});
EventUtils.synthesizeMouseAtCenter(document.documentElement, {type: "mousemove"});
EventUtils.synthesizeMouseAtCenter(document.documentElement, {type: "mousemove"});
EventUtils.synthesizeMouseAtCenter(document.documentElement, {type: "mousemove"});
disable_non_test_mouse(false);
}
async function test_tooltip(icon, expectedTooltip, isActiveTab) {
let tooltip = document.getElementById("tabbrowser-tab-tooltip");
@ -137,51 +71,6 @@ async function test_tooltip(icon, expectedTooltip, isActiveTab) {
leave_icon(icon);
}
// The set of tabs which have ever had their mute state changed.
// Used to determine whether the tab should have a muteReason value.
let everMutedTabs = new WeakSet();
function get_wait_for_mute_promise(tab, expectMuted) {
return BrowserTestUtils.waitForEvent(tab, "TabAttrModified", false, event => {
if (event.detail.changed.includes("muted")) {
is(tab.hasAttribute("muted"), expectMuted, "The tab should " + (expectMuted ? "" : "not ") + "be muted");
is(tab.muted, expectMuted, "The tab muted property " + (expectMuted ? "" : "not ") + "be true");
if (expectMuted || everMutedTabs.has(tab)) {
everMutedTabs.add(tab);
is(tab.muteReason, null, "The tab should have a null muteReason value");
} else {
is(tab.muteReason, undefined, "The tab should have an undefined muteReason value");
}
return true;
}
return false;
});
}
async function test_mute_tab(tab, icon, expectMuted) {
let mutedPromise = get_wait_for_mute_promise(tab, expectMuted);
let activeTab = gBrowser.selectedTab;
let tooltip = document.getElementById("tabbrowser-tab-tooltip");
await hover_icon(icon, tooltip);
EventUtils.synthesizeMouseAtCenter(icon, {button: 0});
leave_icon(icon);
is(gBrowser.selectedTab, activeTab, "Clicking on mute should not change the currently selected tab");
// If the audio is playing, we should check whether clicking on icon affects
// the media element's playing state.
let isAudioPlaying = await is_audio_playing(tab);
if (isAudioPlaying) {
await wait_for_tab_playing_event(tab, !expectMuted);
}
return mutedPromise;
}
function get_tab_state(tab) {
return JSON.parse(SessionStore.getTabState(tab));
}

View File

@ -1,127 +1,5 @@
const PREF_MULTISELECT_TABS = "browser.tabs.multiselect";
const PAGE = "https://example.com/browser/browser/base/content/test/general/file_mediaPlayback.html";
async function wait_for_tab_playing_event(tab, expectPlaying) {
if (tab.soundPlaying == expectPlaying) {
ok(true, "The tab should " + (expectPlaying ? "" : "not ") + "be playing");
return true;
}
return BrowserTestUtils.waitForEvent(tab, "TabAttrModified", false, (event) => {
if (event.detail.changed.includes("soundplaying")) {
is(tab.hasAttribute("soundplaying"), expectPlaying, "The tab should " + (expectPlaying ? "" : "not ") + "be playing");
is(tab.soundPlaying, expectPlaying, "The tab should " + (expectPlaying ? "" : "not ") + "be playing");
return true;
}
return false;
});
}
async function waitForTabMuteStateChangeEvent(tab) {
return BrowserTestUtils.waitForEvent(tab, "TabAttrModified", false, (event) => {
for (let attr of ["activemedia-blocked", "muted", "soundplaying"]) {
if (event.detail.changed.includes(attr)) {
return true;
}
}
return false;
});
}
async function is_audio_playing(tab) {
let browser = tab.linkedBrowser;
let isPlaying = await ContentTask.spawn(browser, {}, async function() {
let audio = content.document.querySelector("audio");
return !audio.paused;
});
return isPlaying;
}
async function play(tab) {
let browser = tab.linkedBrowser;
await ContentTask.spawn(browser, {}, async function() {
let audio = content.document.querySelector("audio");
audio.play();
});
// If the tab has already been muted, it means the tab won't get soundplaying,
// so we don't need to check this attribute.
if (browser.audioMuted) {
return;
}
await waitForTabMuteStateChangeEvent(tab);
}
function disable_non_test_mouse(disable) {
let utils = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
utils.disableNonTestMouseEvents(disable);
}
function hover_icon(icon, tooltip) {
disable_non_test_mouse(true);
let popupShownPromise = BrowserTestUtils.waitForEvent(tooltip, "popupshown");
EventUtils.synthesizeMouse(icon, 1, 1, {type: "mouseover"});
EventUtils.synthesizeMouse(icon, 2, 2, {type: "mousemove"});
EventUtils.synthesizeMouse(icon, 3, 3, {type: "mousemove"});
EventUtils.synthesizeMouse(icon, 4, 4, {type: "mousemove"});
return popupShownPromise;
}
function leave_icon(icon) {
EventUtils.synthesizeMouse(icon, 0, 0, {type: "mouseout"});
EventUtils.synthesizeMouseAtCenter(document.documentElement, {type: "mousemove"});
EventUtils.synthesizeMouseAtCenter(document.documentElement, {type: "mousemove"});
EventUtils.synthesizeMouseAtCenter(document.documentElement, {type: "mousemove"});
disable_non_test_mouse(false);
}
// The set of tabs which have ever had their mute state changed.
// Used to determine whether the tab should have a muteReason value.
let everMutedTabs = new WeakSet();
function get_wait_for_mute_promise(tab, expectMuted) {
return BrowserTestUtils.waitForEvent(tab, "TabAttrModified", false, event => {
if (event.detail.changed.includes("muted") || event.detail.changed.includes("activemedia-blocked")) {
is(tab.hasAttribute("muted"), expectMuted, "The tab should " + (expectMuted ? "" : "not ") + "be muted");
is(tab.muted, expectMuted, "The tab muted property " + (expectMuted ? "" : "not ") + "be true");
if (expectMuted || everMutedTabs.has(tab)) {
everMutedTabs.add(tab);
is(tab.muteReason, null, "The tab should have a null muteReason value");
} else {
is(tab.muteReason, undefined, "The tab should have an undefined muteReason value");
}
return true;
}
return false;
});
}
async function test_mute_tab(tab, icon, expectMuted) {
let mutedPromise = waitForTabMuteStateChangeEvent(tab);
let activeTab = gBrowser.selectedTab;
let tooltip = document.getElementById("tabbrowser-tab-tooltip");
await hover_icon(icon, tooltip);
EventUtils.synthesizeMouseAtCenter(icon, {button: 0});
leave_icon(icon);
is(gBrowser.selectedTab, activeTab, "Clicking on mute should not change the currently selected tab");
// If the audio is playing, we should check whether clicking on icon affects
// the media element's playing state.
let isAudioPlaying = await is_audio_playing(tab);
if (isAudioPlaying) {
await wait_for_tab_playing_event(tab, !expectMuted);
}
return mutedPromise;
}
const PAGE = "https://example.com/browser/browser/base/content/test/tabs/file_mediaPlayback.html";
function muted(tab) {
return tab.linkedBrowser.audioMuted;
@ -155,8 +33,8 @@ add_task(async function muteTabs_usingButton() {
await BrowserTestUtils.switchTab(gBrowser, tab0);
await play(tab0);
await play(tab1);
await play(tab2);
await play(tab1, false);
await play(tab2, false);
// Multiselecting tab1, tab2 and tab3
await BrowserTestUtils.switchTab(gBrowser, tab1);
@ -234,8 +112,8 @@ add_task(async function unmuteTabs_usingButton() {
await BrowserTestUtils.switchTab(gBrowser, tab0);
await play(tab0);
await play(tab1);
await play(tab2);
await play(tab1, false);
await play(tab2, false);
// Mute tab3 and tab4
tab3.toggleMuteAudio();
@ -290,8 +168,8 @@ add_task(async function playTabs_usingButton() {
await BrowserTestUtils.switchTab(gBrowser, tab0);
await play(tab0);
await play(tab1);
await play(tab2);
await play(tab1, false);
await play(tab2, false);
// Multiselecting tab0, tab1, tab2 and tab3.
await triggerClickOn(tab3, { shiftKey: true });
@ -346,9 +224,9 @@ add_task(async function checkTabContextMenu() {
let menuItemToggleMuteTab = document.getElementById("context_toggleMuteTab");
let menuItemToggleMuteSelectedTabs = document.getElementById("context_toggleMuteSelectedTabs");
await play(tab0);
await play(tab0, false);
tab0.toggleMuteAudio();
await play(tab1);
await play(tab1, false);
tab2.toggleMuteAudio();
// Mutliselect tab0, tab1, tab2.

View File

@ -28,3 +28,133 @@ async function addTab() {
await BrowserTestUtils.browserLoaded(browser);
return tab;
}
async function wait_for_tab_playing_event(tab, expectPlaying) {
if (tab.soundPlaying == expectPlaying) {
ok(true, "The tab should " + (expectPlaying ? "" : "not ") + "be playing");
return true;
}
return BrowserTestUtils.waitForEvent(tab, "TabAttrModified", false, (event) => {
if (event.detail.changed.includes("soundplaying")) {
is(tab.hasAttribute("soundplaying"), expectPlaying, "The tab should " + (expectPlaying ? "" : "not ") + "be playing");
is(tab.soundPlaying, expectPlaying, "The tab should " + (expectPlaying ? "" : "not ") + "be playing");
return true;
}
return false;
});
}
async function wait_for_tab_media_blocked_event(tab, expectMediaBlocked) {
if (tab.activeMediaBlocked == expectMediaBlocked) {
ok(true, "The tab should " + (expectMediaBlocked ? "" : "not ") + "be activemedia-blocked");
return true;
}
return BrowserTestUtils.waitForEvent(tab, "TabAttrModified", false, (event) => {
if (event.detail.changed.includes("activemedia-blocked")) {
is(tab.hasAttribute("activemedia-blocked"), expectMediaBlocked, "The tab should " + (expectMediaBlocked ? "" : "not ") + "be activemedia-blocked");
is(tab.activeMediaBlocked, expectMediaBlocked, "The tab should " + (expectMediaBlocked ? "" : "not ") + "be activemedia-blocked");
return true;
}
return false;
});
}
async function is_audio_playing(tab) {
let browser = tab.linkedBrowser;
let isPlaying = await ContentTask.spawn(browser, {}, async function() {
let audio = content.document.querySelector("audio");
return !audio.paused;
});
return isPlaying;
}
async function play(tab, expectPlaying = true) {
let browser = tab.linkedBrowser;
await ContentTask.spawn(browser, {}, async function() {
let audio = content.document.querySelector("audio");
audio.play();
});
// If the tab has already been muted, it means the tab won't get soundplaying,
// so we don't need to check this attribute.
if (browser.audioMuted) {
return;
}
if (expectPlaying) {
await wait_for_tab_playing_event(tab, true);
} else {
await wait_for_tab_media_blocked_event(tab, true);
}
}
function disable_non_test_mouse(disable) {
let utils = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
utils.disableNonTestMouseEvents(disable);
}
function hover_icon(icon, tooltip) {
disable_non_test_mouse(true);
let popupShownPromise = BrowserTestUtils.waitForEvent(tooltip, "popupshown");
EventUtils.synthesizeMouse(icon, 1, 1, {type: "mouseover"});
EventUtils.synthesizeMouse(icon, 2, 2, {type: "mousemove"});
EventUtils.synthesizeMouse(icon, 3, 3, {type: "mousemove"});
EventUtils.synthesizeMouse(icon, 4, 4, {type: "mousemove"});
return popupShownPromise;
}
function leave_icon(icon) {
EventUtils.synthesizeMouse(icon, 0, 0, {type: "mouseout"});
EventUtils.synthesizeMouseAtCenter(document.documentElement, {type: "mousemove"});
EventUtils.synthesizeMouseAtCenter(document.documentElement, {type: "mousemove"});
EventUtils.synthesizeMouseAtCenter(document.documentElement, {type: "mousemove"});
disable_non_test_mouse(false);
}
// The set of tabs which have ever had their mute state changed.
// Used to determine whether the tab should have a muteReason value.
let everMutedTabs = new WeakSet();
function get_wait_for_mute_promise(tab, expectMuted) {
return BrowserTestUtils.waitForEvent(tab, "TabAttrModified", false, event => {
if (event.detail.changed.includes("muted") || event.detail.changed.includes("activemedia-blocked")) {
is(tab.hasAttribute("muted"), expectMuted, "The tab should " + (expectMuted ? "" : "not ") + "be muted");
is(tab.muted, expectMuted, "The tab muted property " + (expectMuted ? "" : "not ") + "be true");
if (expectMuted || everMutedTabs.has(tab)) {
everMutedTabs.add(tab);
is(tab.muteReason, null, "The tab should have a null muteReason value");
} else {
is(tab.muteReason, undefined, "The tab should have an undefined muteReason value");
}
return true;
}
return false;
});
}
async function test_mute_tab(tab, icon, expectMuted) {
let mutedPromise = get_wait_for_mute_promise(tab, expectMuted);
let activeTab = gBrowser.selectedTab;
let tooltip = document.getElementById("tabbrowser-tab-tooltip");
await hover_icon(icon, tooltip);
EventUtils.synthesizeMouseAtCenter(icon, {button: 0});
leave_icon(icon);
is(gBrowser.selectedTab, activeTab, "Clicking on mute should not change the currently selected tab");
// If the audio is playing, we should check whether clicking on icon affects
// the media element's playing state.
let isAudioPlaying = await is_audio_playing(tab);
if (isAudioPlaying) {
await wait_for_tab_playing_event(tab, !expectMuted);
}
return mutedPromise;
}