Bug 1261963 - createData should be optional for browser.windows.create, r?kmag draft
authorbsilverberg <bsilverberg@mozilla.com>
Thu, 07 Apr 2016 13:16:46 -0400
changeset 348540 ad1480dfc5a693e35c7be98af839c2b1385026ee
parent 347336 43360777775c3049b405168c2b303941cd74b9de
child 517864 f3594f0de209b65b6b3e5cb7cc9482beb048188a
push id14841
push userbmo:bob.silverberg@gmail.com
push dateThu, 07 Apr 2016 17:17:09 +0000
reviewerskmag
bugs1261963
milestone48.0a1
Bug 1261963 - createData should be optional for browser.windows.create, r?kmag MozReview-Commit-ID: GCPFx4kuH9r
browser/components/extensions/ext-windows.js
browser/components/extensions/schemas/windows.json
browser/components/extensions/test/browser/browser_ext_windows_create.js
--- a/browser/components/extensions/ext-windows.js
+++ b/browser/components/extensions/ext-windows.js
@@ -60,16 +60,32 @@ extensions.registerSchemaAPI("windows", 
 
       getAll: function(getInfo) {
         let windows = Array.from(WindowListManager.browserWindows(),
                                  window => WindowManager.convert(extension, window, getInfo));
         return Promise.resolve(windows);
       },
 
       create: function(createData) {
+        // FIXME: This can be removed when default values are supported in schemas
+        // See https://bugzilla.mozilla.org/show_bug.cgi?id=1262250
+        if (createData === null) {
+          createData = {
+            url: null,
+            tabId: null,
+            left: null,
+            top: null,
+            width: null,
+            height: null,
+            incognito: null,
+            type: null,
+            state: null,
+          };
+        }
+
         let needResize = (createData.left !== null || createData.top !== null ||
                           createData.width !== null || createData.height !== null);
 
         if (needResize) {
           if (createData.state !== null && createData.state != "normal") {
             return Promise.reject({message: `"state": "${createData.state}" may not be combined with "left", "top", "width", or "height"`});
           }
           createData.state = "normal";
--- a/browser/components/extensions/schemas/windows.json
+++ b/browser/components/extensions/schemas/windows.json
@@ -277,16 +277,17 @@
         "name": "create",
         "type": "function",
         "description": "Creates (opens) a new browser with any optional sizing, position or default URL provided.",
         "async": "callback",
         "parameters": [
           {
             "type": "object",
             "name": "createData",
+            "optional": true,
             "properties": {
               "url": {
                 "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": "array",
--- a/browser/components/extensions/test/browser/browser_ext_windows_create.js
+++ b/browser/components/extensions/test/browser/browser_ext_windows_create.js
@@ -19,16 +19,18 @@ add_task(function* testWindowCreate() {
         return new Promise(resolve => {
           _checkWindowPromise = {resolve};
           browser.test.sendMessage("check-window", expected);
         });
       }
 
       function createWindow(params, expected, keep = false) {
         return browser.windows.create(params).then(window => {
+          // params is null when testing create without createData
+          params = params || {};
           for (let key of Object.keys(params)) {
             if (key == "state" && os == "mac" && params.state == "normal") {
               // OS-X doesn't have a hard distinction between "normal" and
               // "maximized" states.
               browser.test.assertTrue(window.state == "normal" || window.state == "maximized",
                                       `Expected window.state (currently ${window.state}) to be "normal" but will accept "maximized"`);
             } else {
               browser.test.assertEq(params[key], window[key], `Got expected value for window.${key}`);
@@ -47,16 +49,17 @@ add_task(function* testWindowCreate() {
               });
             }
             return browser.windows.remove(window.id);
           });
         });
       }
 
       browser.runtime.getPlatformInfo().then(info => { os = info.os; })
+      .then(() => createWindow(null, {state: "STATE_NORMAL"}))
       .then(() => createWindow({state: "maximized"}, {state: "STATE_MAXIMIZED"}))
       .then(() => createWindow({state: "minimized"}, {state: "STATE_MINIMIZED"}))
       .then(() => createWindow({state: "normal"}, {state: "STATE_NORMAL", hiddenChrome: []}))
       .then(() => createWindow({state: "fullscreen"}, {state: "STATE_FULLSCREEN"}))
       .then(() => {
         return createWindow({type: "popup"},
                             {hiddenChrome: ["menubar", "toolbar", "location", "directories", "status", "extrachrome"],
                              chromeFlags: ["CHROME_OPENAS_DIALOG"]},