bug 841350 - register pageshow handler earlier in browser.js r=ttaubert

This commit is contained in:
David Keeler 2013-02-28 14:53:00 -08:00
parent 13751f7ffa
commit fb9e612e8b
3 changed files with 67 additions and 6 deletions

View File

@ -202,6 +202,10 @@ XPCOMUtils.defineLazyGetter(this, "PageMenu", function() {
* one listener that calls all real handlers.
*/
function pageShowEventHandlers(event) {
// Filter out events that are not about the document load we are interested in
if (event.target != content.document)
return;
charsetLoadListener();
XULBrowserWindow.asyncUpdateUI();
@ -1338,6 +1342,15 @@ var gBrowserInit = {
var isLoadingBlank = isBlankPageURL(uriToLoad);
gBrowser.addEventListener("pageshow", function(event) {
// The XULWindow::mPrimaryContentShell isn't up-to-date when pageshow
// is fired by a swapFrameLoaders() call (i.e. when we swap the docShells
// of two tabs). Get around this by using setTimeout - everything should
// be in the right state on the next tick.
if (content)
setTimeout(pageShowEventHandlers, 0, event);
}, true);
if (uriToLoad && uriToLoad != "about:blank") {
if (uriToLoad instanceof Ci.nsISupportsArray) {
let count = uriToLoad.Count();
@ -1396,12 +1409,6 @@ var gBrowserInit = {
AddonManager.addAddonListener(AddonsMgrListener);
WebrtcIndicator.init();
gBrowser.addEventListener("pageshow", function(event) {
// Filter out events that are not about the document load we are interested in
if (content && event.target == content.document)
setTimeout(pageShowEventHandlers, 0, event);
}, true);
// Ensure login manager is up and running.
Services.logins;

View File

@ -185,6 +185,7 @@ _BROWSER_FILES = \
browser_pluginnotification.js \
browser_plugins_added_dynamically.js \
browser_CTPScriptPlugin.js \
browser_CTP_drag_drop.js \
browser_pluginplaypreview.js \
browser_pluginplaypreview2.js \
browser_private_browsing_window.js \

View File

@ -0,0 +1,53 @@
let gHttpTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
let gNextTest = null;
let gNewWindow = null;
Components.utils.import("resource://gre/modules/Services.jsm");
function test() {
waitForExplicitFinish();
registerCleanupFunction(function() { Services.prefs.clearUserPref("plugins.click_to_play"); });
Services.prefs.setBoolPref("plugins.click_to_play", true);
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("PluginBindingAttached", handleEvent, true, true);
gNextTest = part1;
gBrowser.selectedBrowser.contentDocument.location = gHttpTestRoot + "plugin_test.html";
}
function handleEvent() {
gNextTest();
}
function part1() {
gBrowser.selectedBrowser.removeEventListener("PluginBindingAttached", handleEvent);
ok(PopupNotifications.getNotification("click-to-play-plugins", gBrowser.selectedBrowser), "Should have a click-to-play notification in the initial tab");
gNextTest = part2;
gNewWindow = gBrowser.replaceTabWithWindow(gBrowser.selectedTab);
gNewWindow.addEventListener("load", handleEvent, true);
}
function part2() {
gNewWindow.removeEventListener("load", handleEvent);
let condition = function() PopupNotifications.getNotification("click-to-play-plugins", gNewWindow.gBrowser.selectedBrowser);
waitForCondition(condition, part3, "Waited too long for click-to-play notification");
}
function part3() {
ok(PopupNotifications.getNotification("click-to-play-plugins", gNewWindow.gBrowser.selectedBrowser), "Should have a click-to-play notification in the tab in the new window");
ok(!PopupNotifications.getNotification("click-to-play-plugins", gBrowser.selectedBrowser), "Should not have a click-to-play notification in the old window now");
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.swapBrowsersAndCloseOther(gBrowser.selectedTab, gNewWindow.gBrowser.selectedTab);
let condition = function() PopupNotifications.getNotification("click-to-play-plugins", gBrowser.selectedBrowser);
waitForCondition(condition, part4, "Waited too long for click-to-play notification");
}
function part4() {
ok(PopupNotifications.getNotification("click-to-play-plugins", gBrowser.selectedBrowser), "Should have a click-to-play notification in the initial tab again");
gBrowser.removeCurrentTab();
finish();
}