Bug 1261185 - Complete test coverage for browser.windows.create, r?kmag
Add coverage for:
* passing an invalid |tabId|
* passing an array of URLs to open in |url|
MozReview-Commit-ID: EW8sh0p6hgB
--- a/browser/components/extensions/test/browser/browser_ext_windows_create_tabId.js
+++ b/browser/components/extensions/test/browser/browser_ext_windows_create_tabId.js
@@ -8,16 +8,27 @@ add_task(function* testWindowCreate() {
return new Promise(resolve => {
browser.tabs.onAttached.addListener(function listener() {
browser.tabs.onAttached.removeListener(listener);
resolve();
});
});
};
+ let promiseTabUpdated = (expected) => {
+ return new Promise(resolve => {
+ browser.tabs.onUpdated.addListener(function listener(tabId, changeInfo, tab) {
+ if (changeInfo.url === expected) {
+ browser.tabs.onUpdated.removeListener(listener);
+ resolve();
+ }
+ });
+ });
+ };
+
let windowId;
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 => {
browser.test.log("Create a new window, adopting the new tab");
@@ -81,16 +92,45 @@ add_task(function* testWindowCreate() {
window => {
browser.test.fail("Create call should have failed");
},
error => {
browser.test.assertTrue(/`incognito` property must match the incognito state of tab/.test(error.message),
"Create call failed as expected");
});
}).then(() => {
+ browser.test.log("Try to create a window with an invalid tabId");
+
+ return browser.windows.create({tabId: 0}).then(
+ window => {
+ browser.test.fail("Create call should have failed");
+ },
+ error => {
+ browser.test.assertTrue(/Invalid tab ID: 0/.test(error.message),
+ "Create call failed as expected");
+ }
+ );
+ }).then(() => {
+ browser.test.log("Try to create a window with two URLs");
+
+ return browser.windows.create({url: ["http://example.com/", "http://example.org/"]});
+ }).then(window => {
+ return Promise.all([
+ promiseTabUpdated("http://example.com/"),
+ promiseTabUpdated("http://example.org/"),
+ Promise.resolve(window),
+ ]);
+ }).then(([, , window]) => {
+ return browser.windows.get(window.id, {populate: true});
+ }).then(window => {
+ browser.test.assertEq(2, window.tabs.length, "2 tabs were opened in new window");
+ browser.test.assertEq("http://example.com/", window.tabs[0].url, "Correct URL was loaded in tab 1");
+ browser.test.assertEq("http://example.org/", window.tabs[1].url, "Correct URL was loaded in tab 2");
+ return browser.windows.remove(window.id);
+ }).then(() => {
browser.test.notifyPass("window-create");
}).catch(e => {
browser.test.fail(`${e} :: ${e.stack}`);
browser.test.notifyFail("window-create");
});
}
let extension = ExtensionTestUtils.loadExtension({