bug 1307012 raise an error on invalid id r=kmag
authorAndy McKay <amckay@mozilla.com>
Thu, 08 Dec 2016 08:09:08 -1000
changeset 325526 628708af83de4e24c58f7105b6a904cf1d14e5f8
parent 325525 9db5834b7c36c53e3af2307b4c8551979e415ead
child 325527 c98f0110352b3b07ae61d0c26555b22a48f1273e
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewerskmag
bugs1307012
milestone53.0a1
bug 1307012 raise an error on invalid id r=kmag MozReview-Commit-ID: FDdPzmtN2mq
browser/components/extensions/ext-windows.js
browser/components/extensions/test/browser/browser_ext_windows.js
--- a/browser/components/extensions/ext-windows.js
+++ b/browser/components/extensions/ext-windows.js
@@ -55,16 +55,19 @@ extensions.registerSchemaAPI("windows", 
         return () => {
           AllWindowEvents.removeListener("focus", listener);
           AllWindowEvents.removeListener("blur", listener);
         };
       }).api(),
 
       get: function(windowId, getInfo) {
         let window = WindowManager.getWindow(windowId, context);
+        if (!window) {
+          return Promise.reject({message: `Invalid window ID: ${windowId}`});
+        }
         return Promise.resolve(WindowManager.convert(extension, window, getInfo));
       },
 
       getCurrent: function(getInfo) {
         let window = currentWindow(context);
         return Promise.resolve(WindowManager.convert(extension, window, getInfo));
       },
 
--- a/browser/components/extensions/test/browser/browser_ext_windows.js
+++ b/browser/components/extensions/test/browser/browser_ext_windows.js
@@ -1,13 +1,13 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
-add_task(function* () {
+add_task(function* testWindowGetAll() {
   let raisedWin = Services.ww.openWindow(
     null, Services.prefs.getCharPref("browser.chromeURL"), "_blank",
     "chrome,dialog=no,all,alwaysRaised", null);
 
   yield TestUtils.topicObserved("browser-delayed-startup-finished",
                                 subject => subject == raisedWin);
 
   let extension = ExtensionTestUtils.loadExtension({
@@ -26,8 +26,25 @@ add_task(function* () {
   });
 
   yield extension.startup();
   yield extension.awaitFinish("alwaysOnTop");
   yield extension.unload();
 
   yield BrowserTestUtils.closeWindow(raisedWin);
 });
+
+add_task(function* testInvalidWindowId() {
+  let extension = ExtensionTestUtils.loadExtension({
+    async background() {
+      await browser.test.assertRejects(
+        // Assuming that this windowId does not exist.
+        browser.windows.get(123456789),
+        /Invalid window/,
+        "Should receive invalid window");
+      browser.test.notifyPass("windows.get.invalid");
+    },
+  });
+
+  yield extension.startup();
+  yield extension.awaitFinish("windows.get.invalid");
+  yield extension.unload();
+});