diff --git a/browser/components/extensions/ext-windows.js b/browser/components/extensions/ext-windows.js index 8fdc90423092..ffc054a95c15 100644 --- a/browser/components/extensions/ext-windows.js +++ b/browser/components/extensions/ext-windows.js @@ -160,20 +160,16 @@ extensions.registerSchemaAPI("windows", "addon_parent", context => { return new Promise(resolve => { window.addEventListener("load", function listener() { window.removeEventListener("load", listener); - - if (createData.state == "maximized" || createData.state == "normal" || - (createData.state == "fullscreen" && AppConstants.platform != "macosx")) { + if (["maximized", "normal"].includes(createData.state)) { window.document.documentElement.setAttribute("sizemode", createData.state); - } else if (createData.state !== null) { - // window.minimize() has no effect until the window has been shown. - return promiseObserved("document-shown", doc => doc == window.document).then(() => { - WindowManager.setState(window, createData.state); - resolve(); - }); } - resolve(); + resolve(promiseObserved("browser-delayed-startup-finished", win => win == window)); }); }).then(() => { + // Some states only work after delayed-startup-finished + if (["minimized", "fullscreen", "docked"].includes(createData.state)) { + WindowManager.setState(window, createData.state); + } if (allowScriptsToClose) { for (let {linkedBrowser} of window.gBrowser.tabs) { onXULFrameLoaderCreated({target: linkedBrowser}); @@ -181,7 +177,7 @@ extensions.registerSchemaAPI("windows", "addon_parent", context => { "XULFrameLoaderCreated", onXULFrameLoaderCreated); } } - return WindowManager.convert(extension, window); + return WindowManager.convert(extension, window, {populate: true}); }); }, diff --git a/browser/components/extensions/test/browser/browser_ext_windows_create.js b/browser/components/extensions/test/browser/browser_ext_windows_create.js index 6cb1a26c104b..97a4acf5dc3c 100644 --- a/browser/components/extensions/test/browser/browser_ext_windows_create.js +++ b/browser/components/extensions/test/browser/browser_ext_windows_create.js @@ -35,6 +35,7 @@ add_task(function* testWindowCreate() { } } + browser.test.assertEq(1, window.tabs.length, "tabs property got populated"); return checkWindow(expected).then(() => { if (keep) { return window; diff --git a/browser/components/extensions/test/browser/browser_ext_windows_create_tabId.js b/browser/components/extensions/test/browser/browser_ext_windows_create_tabId.js index 3bd586a17f02..2b875f7066a4 100644 --- a/browser/components/extensions/test/browser/browser_ext_windows_create_tabId.js +++ b/browser/components/extensions/test/browser/browser_ext_windows_create_tabId.js @@ -24,13 +24,14 @@ add_task(function* testWindowCreate() { }); }; - let windowId; + let windowId, tabId; browser.windows.getCurrent().then(window => { windowId = window.id; browser.test.log("Create additional tab in window 1"); return browser.tabs.create({windowId, url: "about:blank"}); }).then(tab => { + tabId = tab.id; browser.test.log("Create a new window, adopting the new tab"); // Note that we want to check against actual boolean values for @@ -39,10 +40,11 @@ add_task(function* testWindowCreate() { return Promise.all([ promiseTabAttached(), - browser.windows.create({tabId: tab.id}), + browser.windows.create({tabId: tabId}), ]); }).then(([, window]) => { browser.test.assertEq(false, window.incognito, "New window is not private"); + browser.test.assertEq(tabId, window.tabs[0].id, "tabs property populated correctly"); browser.test.log("Close the new window"); return browser.windows.remove(window.id); @@ -113,6 +115,10 @@ add_task(function* testWindowCreate() { return browser.windows.create({url: ["http://example.com/", "http://example.org/"]}); }).then(window => { + browser.test.assertEq(2, window.tabs.length, "2 tabs were opened in new window"); + browser.test.assertEq("about:blank", window.tabs[0].url, "about:blank, page not loaded yet"); + browser.test.assertEq("about:blank", window.tabs[1].url, "about:blank, page not loaded yet"); + return Promise.all([ promiseTabUpdated("http://example.com/"), promiseTabUpdated("http://example.org/"), @@ -145,4 +151,3 @@ add_task(function* testWindowCreate() { yield extension.awaitFinish("window-create"); yield extension.unload(); }); -