Bug 1253130: [webext] Support the `alwaysOnTop` in the browser.windows API. r=gabor
authorKris Maglione <maglione.k@gmail.com>
Tue, 22 Mar 2016 23:11:35 +0100
changeset 289912 1f4e567893feb5e288621c50d58e99232a141c48
parent 289911 abfac0d05b79b49597d5fa8d4ce87caf4caaff8e
child 289913 3ad9e7d55c6e393323c4afb57d4ce32e8d8a89cc
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgabor
bugs1253130
milestone48.0a1
Bug 1253130: [webext] Support the `alwaysOnTop` in the browser.windows API. r=gabor MozReview-Commit-ID: FNBCsDt0UT8
browser/components/extensions/ext-utils.js
browser/components/extensions/schemas/windows.json
browser/components/extensions/test/browser/browser.ini
browser/components/extensions/test/browser/browser_ext_windows.js
--- a/browser/components/extensions/ext-utils.js
+++ b/browser/components/extensions/ext-utils.js
@@ -733,26 +733,32 @@ global.WindowManager = {
       [window.STATE_MINIMIZED]: "minimized",
       [window.STATE_NORMAL]: "normal",
     };
     let state = STATES[window.windowState];
     if (window.fullScreen) {
       state = "fullscreen";
     }
 
+    let xulWindow = window.QueryInterface(Ci.nsIInterfaceRequestor)
+                          .getInterface(Ci.nsIDocShell)
+                          .treeOwner.QueryInterface(Ci.nsIInterfaceRequestor)
+                          .getInterface(Ci.nsIXULWindow);
+
     let result = {
       id: this.getId(window),
       focused: window.document.hasFocus(),
       top: window.screenY,
       left: window.screenX,
       width: window.outerWidth,
       height: window.outerHeight,
       incognito: PrivateBrowsingUtils.isWindowPrivate(window),
       type: this.windowType(window),
       state,
+      alwaysOnTop: xulWindow.zLevel >= Ci.nsIXULWindow.raisedZ,
     };
 
     if (getInfo && getInfo.populate) {
       result.tabs = TabManager.for(extension).getTabs(window);
     }
 
     return result;
   },
--- a/browser/components/extensions/schemas/windows.json
+++ b/browser/components/extensions/schemas/windows.json
@@ -83,17 +83,16 @@
             "description": "The type of browser window this is."
           },
           "state": {
             "$ref": "WindowState",
             "optional": true,
             "description": "The state of this browser window."
           },
           "alwaysOnTop": {
-            "unsupported": true,
             "type": "boolean",
             "description": "Whether the window is set to be always on top."
           },
           "sessionId": {
             "unsupported": true,
             "type": "string",
             "optional": true,
             "description": "The session ID used to uniquely identify a Window obtained from the $(ref:sessions) API."
--- a/browser/components/extensions/test/browser/browser.ini
+++ b/browser/components/extensions/test/browser/browser.ini
@@ -51,14 +51,15 @@ support-files =
 [browser_ext_tabs_move.js]
 [browser_ext_tabs_move_window.js]
 [browser_ext_tabs_move_window_multiple.js]
 [browser_ext_tabs_move_window_pinned.js]
 [browser_ext_tabs_onHighlighted.js]
 [browser_ext_windows_create.js]
 tags = fullscreen
 [browser_ext_windows_create_tabId.js]
+[browser_ext_windows.js]
 [browser_ext_windows_update.js]
 tags = fullscreen
 [browser_ext_contentscript_connect.js]
 [browser_ext_tab_runtimeConnect.js]
 [browser_ext_topwindowid.js]
 [browser_ext_webNavigation_getFrames.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/extensions/test/browser/browser_ext_windows.js
@@ -0,0 +1,33 @@
+/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set sts=2 sw=2 et tw=80: */
+"use strict";
+
+add_task(function* () {
+  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({
+    background: function() {
+      browser.windows.getAll((wins) => {
+        browser.test.assertEq(wins.length, 2, "Expect two windows");
+
+        browser.test.assertEq(false, wins[0].alwaysOnTop,
+                              "Expect first window not to be always on top");
+        browser.test.assertEq(true, wins[1].alwaysOnTop,
+                              "Expect first window to be always on top");
+
+        browser.test.notifyPass("alwaysOnTop");
+      });
+    },
+  });
+
+  yield extension.startup();
+  yield extension.awaitFinish("alwaysOnTop");
+  yield extension.unload();
+
+  yield BrowserTestUtils.closeWindow(raisedWin);
+});