Bug 1192818 - part3 : modify test. r=baku

MozReview-Commit-ID: HKzjFN7pJcJ

--HG--
extra : rebase_source : 0dab95da917cb9e59235b56ccd9c5969348c96c5
This commit is contained in:
Alastor Wu 2017-02-21 18:41:16 +08:00
parent f2ea075d35
commit aaa6c009ca

View File

@ -17,6 +17,15 @@ function* wait_for_tab_playing_event(tab, expectPlaying) {
});
}
function* is_audio_playing(tab) {
let browser = tab.linkedBrowser;
let isPlaying = yield ContentTask.spawn(browser, {}, function* () {
let audio = content.document.querySelector("audio");
return !audio.paused;
});
return isPlaying;
}
function* play(tab) {
let browser = tab.linkedBrowser;
yield ContentTask.spawn(browser, {}, function* () {
@ -24,12 +33,16 @@ function* play(tab) {
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;
}
yield wait_for_tab_playing_event(tab, true);
}
function* pause(tab, options) {
ok(tab.hasAttribute("soundplaying"), "The tab should have the soundplaying attribute when pause() is called");
let extendedDelay = options && options.extendedDelay;
if (extendedDelay) {
// Use 10s to remove possibility of race condition with attr removal.
@ -47,6 +60,12 @@ function* pause(tab, options) {
audio.pause();
});
// If the tab has already be muted, it means the tab won't have soundplaying,
// so we don't need to check this attribute.
if (browser.audioMuted) {
return;
}
if (extendedDelay) {
ok(tab.hasAttribute("soundplaying"), "The tab should still have the soundplaying attribute immediately after pausing");
@ -141,6 +160,13 @@ function* test_mute_tab(tab, icon, expectMuted) {
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 = yield is_audio_playing(tab);
if (isAudioPlaying) {
yield wait_for_tab_playing_event(tab, !expectMuted);
}
return mutedPromise;
}
@ -169,7 +195,7 @@ function* test_muting_using_menu(tab, expectMuted) {
yield play(tab);
is(toggleMute.hasAttribute("muted"), expectMuted, "Should have the correct state for the muted attribute");
ok(toggleMute.hasAttribute("soundplaying"), "Should have the soundplaying attribute");
is(!toggleMute.hasAttribute("soundplaying"), expectMuted, "The value of soundplaying attribute is incorrect");
yield pause(tab);
@ -234,14 +260,14 @@ function* test_playing_icon_on_tab(tab, browser, isPinned) {
}
function* test_swapped_browser_while_playing(oldTab, newBrowser) {
// The tab was muted so it won't have soundplaying attribute even it's playing.
ok(oldTab.hasAttribute("muted"), "Expected the correct muted attribute on the old tab");
is(oldTab.muteReason, null, "Expected the correct muteReason attribute on the old tab");
ok(oldTab.hasAttribute("soundplaying"), "Expected the correct soundplaying attribute on the old tab");
ok(!oldTab.hasAttribute("soundplaying"), "Expected the correct soundplaying attribute on the old tab");
let newTab = gBrowser.getTabForBrowser(newBrowser);
let AttrChangePromise = BrowserTestUtils.waitForEvent(newTab, "TabAttrModified", false, event => {
return event.detail.changed.includes("soundplaying") &&
event.detail.changed.includes("muted");
return event.detail.changed.includes("muted");
});
gBrowser.swapBrowsersAndCloseOther(newTab, oldTab);
@ -249,7 +275,7 @@ function* test_swapped_browser_while_playing(oldTab, newBrowser) {
ok(newTab.hasAttribute("muted"), "Expected the correct muted attribute on the new tab");
is(newTab.muteReason, null, "Expected the correct muteReason property on the new tab");
ok(newTab.hasAttribute("soundplaying"), "Expected the correct soundplaying attribute on the new tab");
ok(!newTab.hasAttribute("soundplaying"), "Expected the correct soundplaying attribute on the new tab");
let icon = document.getAnonymousElementByAttribute(newTab, "anonid",
"soundplaying-icon");