Bug 1381876 - Include window state in window rect. r?automatedtester
The window state was included for only some of the commands' responses
earlier.
MozReview-Commit-ID: DdNyR7vdgtY
--- a/testing/marionette/browser.js
+++ b/testing/marionette/browser.js
@@ -9,17 +9,17 @@ const {utils: Cu} = Components;
Cu.import("chrome://marionette/content/element.js");
const {
NoSuchWindowError,
UnsupportedOperationError,
} = Cu.import("chrome://marionette/content/error.js", {});
Cu.import("chrome://marionette/content/frame.js");
-this.EXPORTED_SYMBOLS = ["browser"];
+this.EXPORTED_SYMBOLS = ["browser", "WindowState"];
/** @namespace */
this.browser = {};
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
/**
* Get the <code><xul:browser></code> for the specified tab.
@@ -200,16 +200,17 @@ browser.Context = class {
* Object with |x|, |y|, |width|, and |height| properties.
*/
get rect() {
return {
x: this.window.screenX,
y: this.window.screenY,
width: this.window.outerWidth,
height: this.window.outerHeight,
+ state: WindowState.from(this.window.windowState),
};
}
/**
* Retrieves the current tabmodal UI object. According to the browser
* associated with the currently selected tab.
*/
getTabModalUI() {
@@ -447,8 +448,53 @@ browser.Windows = class extends Map {
let wref = super.get(id);
if (!wref) {
throw new RangeError();
}
return wref.get();
}
};
+
+// TODO(ato): Move this to testing/marionette/wm.js
+// after https://bugzil.la/1311041
+/**
+ * Marionette representation of the {@link ChromeWindow} window state.
+ *
+ * @enum {string}
+ */
+const WindowState = {
+ Maximized: "maximized",
+ Minimized: "minimized",
+ Normal: "normal",
+ Fullscreen: "fullscreen",
+
+ /**
+ * Converts {@link nsIDOMChromeWindow.windowState} to WindowState.
+ *
+ * @param {unsigned short} windowState
+ * Attribute from {@link nsIDOMChromeWindow.windowState}.
+ *
+ * @return {WindowState}
+ * JSON representation.
+ *
+ * @throws {TypeError}
+ * If <var>windowState</var> was unknown.
+ */
+ from(windowState) {
+ switch (windowState) {
+ case 1:
+ return WindowState.Maximized;
+
+ case 2:
+ return WindowState.Minimized;
+
+ case 3:
+ return WindowState.Normal;
+
+ case 4:
+ return WindowState.Fullscreen;
+
+ default:
+ throw new TypeError(`Unknown window state: ${windowState}`);
+ }
+ },
+};