Bug 1260535 - Update the UI of the tab when window.open() is executed from a container tab, r=mconley

This commit is contained in:
Andrea Marchesini 2016-04-13 05:15:36 -04:00
Родитель a49aa74ce1
Коммит 8c8d080c16
4 изменённых файлов: 73 добавлений и 0 удалений

Просмотреть файл

@ -848,6 +848,28 @@ var RefreshBlocker = {
RefreshBlocker.init();
var UserContextIdNotifier = {
init() {
addEventListener("DOMContentLoaded", this);
},
uninit() {
removeEventListener("DOMContentLoaded", this);
},
handleEvent(aEvent) {
// When the first content is loaded, we want to inform the tabbrowser about
// the userContextId in use in order to update the UI correctly.
// Just because we cannot change the userContextId from an active docShell,
// we don't need to check DOMContentLoaded again.
this.uninit();
let userContextId = content.document.nodePrincipal.originAttributes.userContextId;
sendAsyncMessage("Browser:FirstContentLoaded", { userContextId });
}
};
UserContextIdNotifier.init();
ExtensionContent.init(this);
addEventListener("unload", () => {
ExtensionContent.uninit(this);

Просмотреть файл

@ -4285,6 +4285,14 @@
browser.messageManager.sendAsyncMessage("Browser:AppTab", { isAppTab: tab.pinned })
break;
}
case "Browser:FirstContentLoaded": {
let tab = this.getTabForBrowser(browser);
if (tab && data.userContextId) {
tab.setUserContextId(data.userContextId);
}
break;
}
case "Findbar:Keypress": {
let tab = this.getTabForBrowser(browser);
// If the find bar for this tab is not yet alive, only initialize
@ -4431,6 +4439,7 @@
messageManager.addMessageListener("DOMWebNotificationClicked", this);
messageManager.addMessageListener("DOMServiceWorkerFocusClient", this);
messageManager.addMessageListener("RefreshBlocker:Blocked", this);
messageManager.addMessageListener("Browser:FirstContentLoaded", this);
// To correctly handle keypresses for potential FindAsYouType, while
// the tab's find bar is not yet initialized.

Просмотреть файл

@ -6,3 +6,4 @@ support-files =
[browser_usercontext.js]
[browser_windowName.js]
[browser_windowOpen.js]

Просмотреть файл

@ -0,0 +1,41 @@
"use strict";
// Here we want to test that a new opened window shows the same UI of the
// parent one if this has been loaded from a particular container.
const BASE_URI = "http://mochi.test:8888/browser/browser/components/"
+ "contextualidentity/test/browser/empty_file.html";
add_task(function* setup() {
yield new Promise((resolve) => {
SpecialPowers.pushPrefEnv({"set": [
["privacy.userContext.enabled", true],
["browser.link.open_newwindow", 2],
]}, resolve);
});
});
add_task(function* test() {
info("Creating a tab with UCI = 1...");
let tab = gBrowser.addTab(BASE_URI, {userContextId: 1});
is(tab.getAttribute('usercontextid'), 1, "New tab has UCI equal 1");
let browser = gBrowser.getBrowserForTab(tab);
yield BrowserTestUtils.browserLoaded(browser);
info("Opening a new window from this tab...");
ContentTask.spawn(browser, BASE_URI, function(url) {
content.window.newWindow = content.window.open(url, "_blank");
});
let newWin = yield BrowserTestUtils.waitForNewWindow();
let newTab = newWin.gBrowser.selectedTab;
yield BrowserTestUtils.browserLoaded(newTab.linkedBrowser);
is(newTab.getAttribute('usercontextid'), 1, "New tab has UCI equal 1");
info("Closing the new window and tab...");
yield BrowserTestUtils.closeWindow(newWin);
yield BrowserTestUtils.removeTab(tab);
});