Bug 1276738 - Add a test for the size of newly opened window from content. r=gabor
authorMike Conley <mconley@mozilla.com>
Mon, 30 May 2016 15:23:01 -0400
changeset 339207 c66723bf292698444a723269dca9c9bb58ab3d21
parent 339206 c1e4d8d8f4d3e861a7b2dc2390002e45d1d4d526
child 339208 e5abd4c6319dc6296fa322cac1c4e0f853ae6757
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgabor
bugs1276738, 1276802
milestone49.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 1276738 - Add a test for the size of newly opened window from content. r=gabor This notably fails for me on Windows, for which I've filed bug 1276802. Until that's figured out, this test is disabled on Windows. MozReview-Commit-ID: Hx24driJ80w
embedding/components/windowwatcher/test/browser.ini
embedding/components/windowwatcher/test/browser_new_sized_window.js
--- a/embedding/components/windowwatcher/test/browser.ini
+++ b/embedding/components/windowwatcher/test/browser.ini
@@ -1,5 +1,7 @@
 [DEFAULT]
 tags = openwindow
 
 [browser_new_remote_window_flags.js]
 run-if = e10s
+[browser_new_sized_window.js]
+skip-if = os == 'win' # Bug 1276802 - Opening windows from content on Windows might not get the size right
new file mode 100644
--- /dev/null
+++ b/embedding/components/windowwatcher/test/browser_new_sized_window.js
@@ -0,0 +1,67 @@
+"use strict";
+
+/**
+ * Tests that content can open windows at requested dimensions
+ * of height and width.
+ */
+
+/**
+ * This utility function does most of the actual testing. We
+ * construct a feature string suitable for the passed in width
+ * and height, and then run that script in content to open the
+ * new window. When the new window comes up, this function tests
+ * to ensure that the content area of the initial browser is the
+ * requested dimensions. Finally, we also ensure that we're not
+ * persisting the position, size or sizemode of the new browser
+ * window.
+ */
+function test_dimensions({ width, height}) {
+  let features = [];
+  if (width) {
+    features.push(`width=${width}`);
+  }
+  if (height) {
+    features.push(`height=${height}`);
+  }
+  const FEATURE_STR = features.join(",");
+  const SCRIPT_PAGE = `data:text/html,<script>window.open("about:blank", "_blank", "${FEATURE_STR}");</script>`;
+
+  let newWinPromise = BrowserTestUtils.waitForNewWindow();
+
+  return BrowserTestUtils.withNewTab({
+    gBrowser,
+    url: SCRIPT_PAGE,
+  }, function*(browser) {
+    let win = yield newWinPromise;
+    let rect = win.gBrowser.selectedBrowser.getBoundingClientRect();
+
+    if (width) {
+      Assert.equal(rect.width, width, "Should have the requested width");
+    }
+
+    if (height) {
+      Assert.equal(rect.height, height, "Should have the requested height");
+    }
+
+    let treeOwner = win.QueryInterface(Ci.nsIInterfaceRequestor)
+                       .getInterface(Ci.nsIDocShell)
+                       .QueryInterface(Ci.nsIDocShellTreeItem)
+                       .treeOwner;
+    let persistPosition = {};
+    let persistSize = {};
+    let persistSizeMode = {};
+    treeOwner.getPersistence(persistPosition, persistSize, persistSizeMode);
+
+    Assert.ok(!persistPosition.value, "Should not persist position");
+    Assert.ok(!persistSize.value, "Should not persist size");
+    Assert.ok(!persistSizeMode.value, "Should not persist size mode");
+
+    yield BrowserTestUtils.closeWindow(win);
+  });
+}
+
+add_task(function* test_new_sized_window() {
+  yield test_dimensions({ width: 100 });
+  yield test_dimensions({ height: 150 });
+  yield test_dimensions({ width: 300, height: 200 });
+});