Bug 1253129 warn when using focused property with windows.create r=robwu

Differential Revision: https://phabricator.services.mozilla.com/D76944
This commit is contained in:
Shane Caraveo
2020-06-26 16:49:20 +00:00
parent fffe9baca5
commit 7df41e1375
2 changed files with 74 additions and 4 deletions

View File

@@ -288,8 +288,17 @@
"description": "The height in pixels of the new window, including the frame. If not specified defaults to a natural height."
},
"focused": {
"unsupported": true,
"type": "boolean",
"choices": [
{
"type": "boolean",
"enum": [true]
},
{
"type": "boolean",
"enum": [false],
"deprecated": "Opening inactive windows is not supported."
}
],
"optional": true,
"description": "If true, opens an active window. If false, opens an inactive window."
},
@@ -323,8 +332,7 @@
"optional": true,
"description": "A string to add to the beginning of the window title."
}
},
"optional": true
}
},
{
"type": "function",

View File

@@ -2,6 +2,12 @@
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
const { AddonTestUtils } = ChromeUtils.import(
"resource://testing-common/AddonTestUtils.jsm"
);
AddonTestUtils.initMochitest(this);
// Tests that incompatible parameters can't be used together.
add_task(async function testWindowCreateParams() {
let extension = ExtensionTestUtils.loadExtension({
@@ -31,3 +37,59 @@ add_task(async function testWindowCreateParams() {
await extension.awaitFinish("window-create-params");
await extension.unload();
});
// We do not support the focused param, however we do not want
// to fail despite an error when it is passed. This provides
// better code level compatibility with chrome.
add_task(async function testWindowCreateFocused() {
let extension = ExtensionTestUtils.loadExtension({
async background() {
try {
let window = await browser.windows.create({});
browser.test.assertEq(
window.focused,
true,
"window is focused without focused param"
);
await browser.windows.remove(window.id);
window = await browser.windows.create({ focused: true });
browser.test.assertEq(
window.focused,
true,
"window is focused with focused: true"
);
await browser.windows.remove(window.id);
window = await browser.windows.create({ focused: false });
browser.test.assertEq(
window.focused,
true,
"window is focused with focused: false"
);
await browser.windows.remove(window.id);
browser.test.notifyPass("window-create-params");
} catch (e) {
browser.test.fail(`${e} :: ${e.stack}`);
browser.test.notifyFail("window-create-params");
}
},
});
ExtensionTestUtils.failOnSchemaWarnings(false);
let { messages } = await AddonTestUtils.promiseConsoleOutput(async () => {
await extension.startup();
await extension.awaitFinish("window-create-params");
await extension.unload();
});
AddonTestUtils.checkMessages(
messages,
{
expected: [
/Warning processing focused: Opening inactive windows is not supported./,
],
},
"Expected warning processing focused"
);
ExtensionTestUtils.failOnSchemaWarnings(true);
});