Bug 1266611 - Multiple tab prompts should not overlap, r=gijs

MozReview-Commit-ID: 6wjdoiR38Wb

--HG--
rename : browser/base/content/test/general/openPromptOffTimeout.html => browser/base/content/test/tabPrompts/openPromptOffTimeout.html
extra : rebase_source : dab1ec206a4f511f7bdf2108ed22d73d0df4c4c7
This commit is contained in:
Timothy Guan-tin Chien 2016-05-21 21:13:10 +08:00
parent 4e3d081905
commit b7fa00b590
7 changed files with 79 additions and 5 deletions

View File

@ -7833,11 +7833,17 @@ TabModalPromptBox.prototype = {
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
let newPrompt = document.createElementNS(XUL_NS, "tabmodalprompt");
let browser = this.browser;
browser.parentNode.appendChild(newPrompt);
browser.parentNode.insertBefore(newPrompt, browser.nextSibling);
browser.setAttribute("tabmodalPromptShowing", true);
newPrompt.clientTop; // style flush to assure binding is attached
let prompts = this.listPrompts();
if (prompts.length > 1) {
// Let's hide ourself behind the current prompt.
newPrompt.hidden = true;
}
let principalToAllowFocusFor = this._allowTabFocusByPromptPrincipal;
delete this._allowTabFocusByPromptPrincipal;
@ -7872,6 +7878,7 @@ TabModalPromptBox.prototype = {
let prompts = this.listPrompts();
if (prompts.length) {
let prompt = prompts[prompts.length - 1];
prompt.hidden = false;
prompt.Dialog.setDefaultFocus();
} else {
browser.removeAttribute("tabmodalPromptShowing");

View File

@ -343,8 +343,6 @@ support-files = feed_discovery.html
[browser_gZipOfflineChild.js]
skip-if = buildapp == 'mulet' # Bug 1066070 - I don't think either popup notifications nor addon install stuff works?
support-files = test_offline_gzip.html gZipOfflineChild.cacheManifest gZipOfflineChild.cacheManifest^headers^ gZipOfflineChild.html gZipOfflineChild.html^headers^
[browser_openPromptInBackgroundTab.js]
support-files = openPromptOffTimeout.html
[browser_overflowScroll.js]
[browser_pageInfo.js]
skip-if = buildapp == 'mulet'

View File

@ -0,0 +1,3 @@
[browser_multiplePrompts.js]
[browser_openPromptInBackgroundTab.js]
support-files = openPromptOffTimeout.html

View File

@ -0,0 +1,66 @@
"use strict";
/*
* This test triggers multiple alerts on one single tab, because it"s possible
* for web content to do so. The behavior is described in bug 1266353.
*
* We assert the presentation of the multiple alerts, ensuring we show only
* the oldest one.
*/
add_task(function*() {
const PROMPTCOUNT = 5;
let contentScript = function() {
var i = 5; // contentScript has no access to PROMPTCOUNT.
window.addEventListener("message", function() {
i--;
if (i) {
window.postMessage("ping", "*");
}
alert("Alert countdown #" + i);
});
window.postMessage("ping", "*");
};
let url = "data:text/html,<script>(" + encodeURIComponent(contentScript.toSource()) + ")();</script>"
let promptsOpenedPromise = new Promise(function(resolve) {
let unopenedPromptCount = PROMPTCOUNT;
Services.obs.addObserver(function observer() {
unopenedPromptCount--;
if (!unopenedPromptCount) {
Services.obs.removeObserver(observer, "tabmodal-dialog-loaded");
info("Prompts opened.");
resolve();
}
}, "tabmodal-dialog-loaded", false);
});
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, url, true);
info("Tab loaded");
yield promptsOpenedPromise;
let promptsCount = PROMPTCOUNT;
while (promptsCount--) {
let prompts = tab.linkedBrowser.parentNode.querySelectorAll("tabmodalprompt");
is(prompts.length, promptsCount + 1, "There should be " + (promptsCount + 1) + " prompt(s).");
// The oldest should be the first.
let i = 0;
for (let prompt of prompts) {
is(prompt.Dialog.args.text, "Alert countdown #" + i, "The #" + i + " alert should be labelled as such.");
if (i !== promptsCount) {
is(prompt.hidden, true, "This prompt should be hidden.");
i++;
continue;
}
is(prompt.hidden, false, "The last prompt should not be hidden.");
prompt.onButtonClick(0);
}
}
let prompts = tab.linkedBrowser.parentNode.querySelectorAll("tabmodalprompt");
is(prompts.length, 0, "Prompts should all be dismissed.");
yield BrowserTestUtils.removeTab(tab);
});

View File

@ -15,7 +15,7 @@ registerCleanupFunction(function() {
* checking the checkbox does actually enable that behaviour.
*/
add_task(function*() {
yield pushPrefs(["browser.tabs.dontfocusfordialogs", true]);
yield SpecialPowers.pushPrefEnv({"set": [["browser.tabs.dontfocusfordialogs", true]]});
let firstTab = gBrowser.selectedTab;
// load page that opens prompt when page is hidden
let openedTab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, pageWithAlert, true);
@ -60,4 +60,3 @@ add_task(function*() {
yield BrowserTestUtils.removeTab(openedTab);
});

View File

@ -23,6 +23,7 @@ BROWSER_CHROME_MANIFESTS += [
'content/test/popupNotifications/browser.ini',
'content/test/referrer/browser.ini',
'content/test/social/browser.ini',
'content/test/tabPrompts/browser.ini',
'content/test/urlbar/browser.ini',
]