Bug 1457673 - Support WINDOW_ID_CURRENT in browser.windows.remove r=mixedpuppy
authorOriol Brufau <oriol-bugzilla@hotmail.com>
Tue, 01 May 2018 03:25:41 +0200
changeset 472814 5ea81be0d0285cbcebb752a03fa3309eadbeaac6
parent 472813 93311fa8576201ff0dfaa8b2ae0a1b67485004b4
child 472815 1d86574e9bfdaf55d67734470f1ff1bed6a8d6a3
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy
bugs1457673
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1457673 - Support WINDOW_ID_CURRENT in browser.windows.remove r=mixedpuppy MozReview-Commit-ID: LkjDD2U9knB
browser/components/extensions/schemas/windows.json
browser/components/extensions/test/browser/browser-common.ini
browser/components/extensions/test/browser/browser_ext_windows_remove.js
--- a/browser/components/extensions/schemas/windows.json
+++ b/browser/components/extensions/schemas/windows.json
@@ -439,17 +439,17 @@
         "name": "remove",
         "type": "function",
         "description": "Removes (closes) a window, and all the tabs inside it.",
         "async": "callback",
         "parameters": [
           {
             "type": "integer",
             "name": "windowId",
-            "minimum": 0
+            "minimum": -2
           },
           {
             "type": "function",
             "name": "callback",
             "optional": true,
             "parameters": []
           }
         ]
--- a/browser/components/extensions/test/browser/browser-common.ini
+++ b/browser/components/extensions/test/browser/browser-common.ini
@@ -212,13 +212,14 @@ skip-if = debug || os == "linux" #Bug 13
 [browser_ext_webNavigation_urlbar_transitions.js]
 [browser_ext_windows.js]
 [browser_ext_windows_create.js]
 tags = fullscreen
 [browser_ext_windows_create_params.js]
 [browser_ext_windows_create_tabId.js]
 [browser_ext_windows_create_url.js]
 [browser_ext_windows_events.js]
+[browser_ext_windows_remove.js]
 [browser_ext_windows_size.js]
 skip-if = os == 'mac' # Fails when windows are randomly opened in fullscreen mode
 [browser_ext_windows_update.js]
 tags = fullscreen
 [browser_ext_contentscript_animate.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/extensions/test/browser/browser_ext_windows_remove.js
@@ -0,0 +1,45 @@
+/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set sts=2 sw=2 et tw=80: */
+"use strict";
+
+add_task(async function testWindowRemove() {
+  let extension = ExtensionTestUtils.loadExtension({
+    async background() {
+      async function closeWindow(id) {
+        let window = await browser.windows.get(id);
+        return new Promise(function(resolve) {
+          browser.windows.onRemoved.addListener(async function listener(windowId) {
+            browser.windows.onRemoved.removeListener(listener);
+            await browser.test.assertEq(windowId, window.id, "The right window was closed");
+            await browser.test.assertRejects(
+              browser.windows.get(windowId),
+              new RegExp(`Invalid window ID: ${windowId}`),
+              "The window was really closed.");
+            resolve();
+          });
+          browser.windows.remove(id);
+        });
+      }
+
+      browser.test.log("Create a new window and close it by its ID");
+      let newWindow = await browser.windows.create();
+      await closeWindow(newWindow.id);
+
+      browser.test.log("Create a new window and close it by WINDOW_ID_CURRENT");
+      await browser.windows.create();
+      await closeWindow(browser.windows.WINDOW_ID_CURRENT);
+
+      browser.test.log("Assert failure for bad parameter.");
+      await browser.test.assertThrows(
+        () => browser.windows.remove(-3),
+        /-3 is too small \(must be at least -2\)/,
+        "Invalid windowId throws");
+
+      browser.test.notifyPass("window-remove");
+    },
+  });
+
+  await extension.startup();
+  await extension.awaitFinish("window-remove");
+  await extension.unload();
+});