diff --git a/browser/components/extensions/schemas/windows.json b/browser/components/extensions/schemas/windows.json index dd333cedc4d2..f74cded680bc 100644 --- a/browser/components/extensions/schemas/windows.json +++ b/browser/components/extensions/schemas/windows.json @@ -273,10 +273,10 @@ "description": "A URL or array of URLs to open as tabs in the window. Fully-qualified URLs must include a scheme (i.e. 'http://www.google.com', not 'www.google.com'). Relative URLs will be relative to the current page within the extension. Defaults to the New Tab Page.", "optional": true, "choices": [ - { "type": "string" }, + { "type": "string", "format": "relativeUrl" }, { "type": "array", - "items": { "type": "string" } + "items": { "type": "string", "format": "relativeUrl" } } ] }, diff --git a/browser/components/extensions/test/browser/browser.ini b/browser/components/extensions/test/browser/browser.ini index c72456b46f23..0e4f8bdd9f4e 100644 --- a/browser/components/extensions/test/browser/browser.ini +++ b/browser/components/extensions/test/browser/browser.ini @@ -92,6 +92,7 @@ tags = webextensions [browser_ext_windows_create.js] tags = fullscreen [browser_ext_windows_create_tabId.js] +[browser_ext_windows_create_url.js] [browser_ext_windows_events.js] [browser_ext_windows_size.js] skip-if = os == 'mac' # Fails when windows are randomly opened in fullscreen mode diff --git a/browser/components/extensions/test/browser/browser_ext_windows_create_url.js b/browser/components/extensions/test/browser/browser_ext_windows_create_url.js new file mode 100644 index 000000000000..3f783840fd6d --- /dev/null +++ b/browser/components/extensions/test/browser/browser_ext_windows_create_url.js @@ -0,0 +1,84 @@ +/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set sts=2 sw=2 et tw=80: */ +"use strict"; + +add_task(function* testWindowCreate() { + let extension = ExtensionTestUtils.loadExtension({ + manifest: { + permissions: ["tabs"], + }, + + background() { + const EXTENSION_URL = browser.runtime.getURL("test.html"); + const REMOTE_URL = browser.runtime.getURL("test.html"); + + let windows = new class extends Map { // eslint-disable-line new-parens + get(id) { + if (!this.has(id)) { + let window = { + tabs: new Map(), + }; + window.promise = new Promise(resolve => { + window.resolvePromise = resolve; + }); + + this.set(id, window); + } + + return super.get(id); + } + }; + + browser.tabs.onUpdated.addListener((tabId, changed, tab) => { + if (changed.status == "complete" && tab.url !== "about:blank") { + let window = windows.get(tab.windowId); + window.tabs.set(tab.index, tab); + + if (window.tabs.size === window.expectedTabs) { + window.resolvePromise(window); + } + } + }); + + function create(options) { + return browser.windows.create(options).then(window => { + let win = windows.get(window.id); + + win.expectedTabs = Array.isArray(options.url) ? options.url.length : 1; + + return win.promise; + }); + } + + Promise.all([ + create({url: REMOTE_URL}), + create({url: "test.html"}), + create({url: EXTENSION_URL}), + create({url: [REMOTE_URL, "test.html", EXTENSION_URL]}), + ]).then(windows => { + browser.test.assertEq(REMOTE_URL, windows[0].tabs.get(0).url, "Single, absolute, remote URL"); + + browser.test.assertEq(REMOTE_URL, windows[1].tabs.get(0).url, "Single, relative URL"); + + browser.test.assertEq(REMOTE_URL, windows[2].tabs.get(0).url, "Single, absolute, extension URL"); + + browser.test.assertEq(REMOTE_URL, windows[3].tabs.get(0).url, "url[0]: Absolute, remote URL"); + browser.test.assertEq(EXTENSION_URL, windows[3].tabs.get(1).url, "url[1]: Relative URL"); + browser.test.assertEq(EXTENSION_URL, windows[3].tabs.get(2).url, "url[2]: Absolute, extension URL"); + }).then(() => { + browser.test.notifyPass("window-create-url"); + }).catch(e => { + browser.test.fail(`${e} :: ${e.stack}`); + browser.test.notifyFail("window-create-url"); + }); + }, + + files: { + "test.html": ``, + }, + }); + + yield extension.startup(); + yield extension.awaitFinish("window-create-url"); + yield extension.unload(); +}); diff --git a/toolkit/components/extensions/Extension.jsm b/toolkit/components/extensions/Extension.jsm index 2cffd2652979..73fe32c201d0 100644 --- a/toolkit/components/extensions/Extension.jsm +++ b/toolkit/components/extensions/Extension.jsm @@ -687,6 +687,10 @@ GlobalManager = { let schemaWrapper = { isChromeCompat, + get url() { + return context.uri.spec; + }, + get principal() { return context.principal; },