Bug 1253128: [webext] Support type=popup in the browser.windows API. r=billm

MozReview-Commit-ID: ALgprY2w7w9
This commit is contained in:
Kris Maglione 2016-03-03 18:44:18 -08:00
parent 0d615df633
commit 679304e427
4 changed files with 55 additions and 9 deletions

View File

@ -625,6 +625,16 @@ global.WindowManager = {
windowType(window) {
// TODO: Make this work.
let {chromeFlags} = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDocShell)
.treeOwner.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIXULWindow);
if (chromeFlags & Ci.nsIWebBrowserChrome.CHROME_OPENAS_DIALOG) {
return "popup";
}
return "normal";
},
@ -708,8 +718,6 @@ global.WindowManager = {
width: window.outerWidth,
height: window.outerHeight,
incognito: PrivateBrowsingUtils.isWindowPrivate(window),
// We fudge on these next two.
type: this.windowType(window),
state,
};

View File

@ -113,17 +113,25 @@ extensions.registerSchemaAPI("windows", null, (extension, context) => {
args.AppendElement(mkstr(aboutNewTabService.newTabURL));
}
let extraFeatures = "";
let features = ["chrome"];
if (createData.type === null || createData.type == "normal") {
features.push("dialog=no", "all");
} else {
// All other types create "popup"-type windows by default.
features.push("dialog", "resizable", "minimizable", "centerscreen", "titlebar", "close");
}
if (createData.incognito !== null) {
if (createData.incognito) {
extraFeatures += ",private";
features.push("private");
} else {
extraFeatures += ",non-private";
features.push("non-private");
}
}
let window = Services.ww.openWindow(null, "chrome://browser/content/browser.xul", "_blank",
"chrome,dialog=no,all" + extraFeatures, args);
features.join(","), args);
if (createData.left !== null || createData.top !== null) {
let left = createData.left !== null ? createData.left : window.screenX;

View File

@ -335,7 +335,6 @@
"description": "Whether the new window should be an incognito window."
},
"type": {
"unsupported": true,
"$ref": "CreateType",
"optional": true,
"description": "Specifies what type of browser window to create. The 'panel' and 'detached_panel' types create a popup unless the '--enable-panels' flag is set."

View File

@ -22,7 +22,7 @@ add_task(function* testWindowCreate() {
});
}
function createWindow(params, expected) {
function createWindow(params, expected, keep = false) {
return browser.windows.create(params).then(window => {
for (let key of Object.keys(params)) {
if (key == "state" && os == "mac" && params.state == "normal") {
@ -36,6 +36,9 @@ add_task(function* testWindowCreate() {
}
return checkWindow(expected).then(() => {
if (keep) {
return window;
}
if (params.state == "fullscreen" && os == "win") {
// FIXME: Closing a fullscreen window causes a window leak in
// Windows tests.
@ -51,9 +54,21 @@ add_task(function* testWindowCreate() {
browser.runtime.getPlatformInfo().then(info => { os = info.os; })
.then(() => createWindow({state: "maximized"}, {state: "STATE_MAXIMIZED"}))
.then(() => createWindow({state: "minimized"}, {state: "STATE_MINIMIZED"}))
.then(() => createWindow({state: "normal"}, {state: "STATE_NORMAL"}))
.then(() => createWindow({state: "normal"}, {state: "STATE_NORMAL", hiddenChrome: []}))
.then(() => createWindow({state: "fullscreen"}, {state: "STATE_FULLSCREEN"}))
.then(() => {
return createWindow({type: "popup"},
{hiddenChrome: ["menubar", "toolbar", "location", "directories", "status", "extrachrome"],
chromeFlags: ["CHROME_OPENAS_DIALOG"]},
true);
}).then(window => {
return browser.tabs.query({windowType: "popup", active: true}).then(tabs => {
browser.test.assertEq(1, tabs.length, "Expected only one popup");
browser.test.assertEq(window.id, tabs[0].windowId, "Expected new window to be returned in query");
return browser.windows.remove(window.id);
});
}).then(() => {
browser.test.notifyPass("window-create");
}).catch(e => {
browser.test.fail(`${e} :: ${e.stack}`);
@ -85,6 +100,22 @@ add_task(function* testWindowCreate() {
`Expected window state to be ${expected.state}`);
}
}
if (expected.hiddenChrome) {
let chromeHidden = latestWindow.document.documentElement.getAttribute("chromehidden");
is(chromeHidden.trim().split(/\s+/).sort().join(" "),
expected.hiddenChrome.sort().join(" "),
"Got expected hidden chrome");
}
if (expected.chromeFlags) {
let {chromeFlags} = latestWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDocShell)
.treeOwner.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIXULWindow);
for (let flag of expected.chromeFlags) {
ok(chromeFlags & Ci.nsIWebBrowserChrome[flag],
`Expected window to have the ${flag} flag`);
}
}
extension.sendMessage("checked-window");
});