Bug 1493461 - consolidate main TB window size handling in MozMill tests. r=jorgk
authoraceman <acelists@atlas.sk>
Mon, 24 Sep 2018 22:45:00 +0200
changeset 33226 1b38cacc09e510c2e418a9af31bd3bcaf55404f2
parent 33225 f600e1fb24b3695e08aeee35363b91c344382f38
child 33227 bff3cba93b7ce29a2a0747c540e4ec59461b54b1
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersjorgk
bugs1493461
Bug 1493461 - consolidate main TB window size handling in MozMill tests. r=jorgk
mail/test/mozmill/message-header/test-message-header.js
mail/test/mozmill/quick-filter-bar/test-display-issues.js
mail/test/mozmill/shared-modules/test-dom-helpers.js
mail/test/mozmill/shared-modules/test-folder-display-helpers.js
mail/test/mozmill/shared-modules/test-window-helpers.js
--- a/mail/test/mozmill/message-header/test-message-header.js
+++ b/mail/test/mozmill/message-header/test-message-header.js
@@ -886,37 +886,33 @@ function test_toolbar_collapse_and_expan
   let curMessage = select_click_row(-1);
 
   try {
     let expandedHeadersTopBox = mc.e("expandedHeadersTopBox");
     let toolbar = mc.e("header-view-toolbar");
     let mode = toolbar.getAttribute("mode");
 
     // Get really big, so that we can figure out how big we actually want to be.
-    mc.window.resizeTo(1200, 600);
-    // spin the event loop once
-    mc.sleep(0);
+    resize_to(mc, 1200, gDefaultWindowHeight);
 
     let fromWidth = mc.e("expandedfromRow").clientWidth;
 
     // This is the biggest we need to be.
     let bigWidth = fromWidth + toolbar.clientWidth;
 
     // Now change to icons-only mode for a much smaller toolbar.
     toolbar.setAttribute("mode", "icons");
     let smallWidth = fromWidth + toolbar.clientWidth;
 
     // Re-set the mode to its original value.
     toolbar.setAttribute("mode", mode);
 
     // And resize to half way between the big and small widths, so that we
     //  can toggle the mode to force the overflow.
-    mc.window.resizeTo((bigWidth + smallWidth) / 2, 600);
-    // spin the event loop once
-    mc.sleep(0);
+    resize_to(mc, Math.round((bigWidth + smallWidth) / 2), gDefaultWindowHeight);
 
     // Make sure we are too small to contain the buttons and from line, so
     //  we will be tall.
     let tallHeight = expandedHeadersTopBox.clientHeight;
 
     // Change from icons and text to just icons to make our toolbar
     //  narrower, and by extension our header shorter.
     toolbar.setAttribute("mode", "icons");
@@ -927,27 +923,23 @@ function test_toolbar_collapse_and_expan
 
     // Change back to icons and text to make our toolbar wider and our
     //   header taller again.
     toolbar.setAttribute("mode", mode);
     if (expandedHeadersTopBox.clientHeight != tallHeight)
       throw new Error("The header box should have returned to its original size!");
 
     // And make our window big to achieve the same effect as the just icons mode.
-    mc.window.resizeTo(1200, 600);
-    // spin the event loop once
-    mc.sleep(0);
+    resize_to(mc, 1200, gDefaultWindowHeight);
     mc.waitFor(() => expandedHeadersTopBox.clientHeight == shortHeight,
                "The header box should have returned to its wide size!")
   }
   finally {
-    // restore window to nominal dimensions; saving was not working out
-    //  See also: quick-filter-bar/test-display-issues.js if we change the
-    //            default window size.
-    mc.window.resizeTo(1024, 768);
+    // restore window to nominal dimensions
+    restore_default_window_size();
   }
 }
 
 /**
  * Test if the tooltip text of the more widget contains the correct addresses
  * not shown in the header and the number of addresses also hidden in the
  * tooltip text.
  * @param aMsg the message for which the subtest should be performed
--- a/mail/test/mozmill/quick-filter-bar/test-display-issues.js
+++ b/mail/test/mozmill/quick-filter-bar/test-display-issues.js
@@ -10,51 +10,44 @@
  */
 
 "use strict";
 
 var MODULE_NAME = "test-display-issues";
 
 var RELATIVE_ROOT = '../shared-modules';
 
-var MODULE_REQUIRES = ['folder-display-helpers', 'window-helpers',
+var MODULE_REQUIRES = ["folder-display-helpers", "window-helpers",
                        "quick-filter-bar-helper", "dom-helpers"];
 
 var folder;
 var setUnstarred, setStarred;
 var gOriginalPaneWidth;
 
+var gEnlargedWindowWidth = 1260;
+var gShrunkenWindowWidth = 600;
+
 function setupModule(module) {
   for (let lib of MODULE_REQUIRES) {
     collector.getModule(lib).installInto(module);
   }
+
   folder = create_folder("QuickFilterBarDisplayIssues");
   be_in_folder(folder);
-  // Let's check window sizes as we will restore back to them after the end of the test.
-  assert_equals(mc.window.outerWidth, 1024, "Main window didn't meet the expected width");
-  assert_equals(mc.window.outerHeight, 768, "Main window didn't meet the expected height");
+
+  // Let's check window dimensions so we can enlarge from them.
+  assert_default_window_size();
+  assert_true(gEnlargedWindowWidth > gDefaultWindowWidth,
+              "Main window too large for the test logic");
+
+  // Store folder pane width that we will change temporarily.
   let folderPaneBox = mc.e("folderPaneBox");
   gOriginalPaneWidth = folderPaneBox.width;
 }
 
-function wait_for_resize(width) {
-  mc.waitFor(() => (mc.window.outerWidth == width),
-             "Timeout waiting for resize (is the screen resolution 1280 x 1024?)", 1000, 50);
-}
-
-function resize_to(width, height) {
-  mark_action("test", "resize_to", [width, "x", height]);
-  mc.window.resizeTo(width, height);
-  // Give the event loop a spin in order to let the reality of an asynchronously
-  //  interacting window manager have its impact.  This still may not be
-  //  sufficient.
-  mc.sleep(0);
-  wait_for_resize(width);
-}
-
 /**
  * When the window gets too narrow the collapsible button labels need to get
  *  gone.  Then they need to come back when we get large enough again.
  *
  * Because the mozmill window sizing is weird and confusing, we force our size
  *  in both cases but do save/restore around our test.
  */
 function test_buttons_collapse_and_expand() {
@@ -69,100 +62,82 @@ function test_buttons_collapse_and_expan
     mark_action("test", "log_window_state",
                 [aWhen,
                  "location:", mc.window.screenX, mc.window.screenY,
                  "dims:", mc.window.outerWidth, mc.window.outerHeight,
                  "Collapsy bar width:", qfbCollapsy.clientWidth,
                  "shrunk?", qfbCollapsy.getAttribute("shrink")]);
   }
 
-  function assertCollapsed(width) {
-    // It's possible the window hasn't actually resized yet, so double-check and
-    // spin if needed.
-    wait_for_resize(width);
-
+  function assertCollapsed() {
     // The bar should be shrunken and the button should be the same size as its
     // image!
     if (qfbCollapsy.getAttribute("shrink") != "true")
       throw new Error("The collapsy bar should be shrunk!");
     if (qfbExemplarLabel.clientWidth != 0)
       throw new Error("The exemplar label should be collapsed!");
   }
-  function assertExpanded(width) {
-    // It's possible the window hasn't actually resized yet, so double-check and
-    // spin if needed.
-    wait_for_resize(width);
-
+  function assertExpanded() {
     // The bar should not be shrunken and the button should be smaller than its
     // label!
     if (qfbCollapsy.hasAttribute("shrink"))
       throw new Error("The collapsy bar should not be shrunk!");
     if (qfbExemplarLabel.clientWidth == 0)
       throw new Error("The exemplar label should not be collapsed!");
   }
 
   logState("entry");
 
   // -- GIANT!
-  resize_to(1260, 600);
+  resize_to(mc, gEnlargedWindowWidth, gDefaultWindowHeight);
   // Right, so resizeTo caps us at the display size limit, so we may end up
   // smaller than we want.  So let's turn off the folder pane too.
   collapse_panes(mc.e("folderpane_splitter"), true);
-
-  // spin the event loop once
-  mc.sleep(50);
   logState("giant");
-  assertExpanded(1260);
+  assertExpanded();
   // NOTE! 1260 is actually not much above what's needed to get the
   // expanded qfb.
 
   // -- tiny.
   collapse_panes(mc.e("folderpane_splitter"), false);
-  resize_to(600, 600);
-  // spin the event loop once
-  mc.sleep(0);
+  resize_to(mc, gShrunkenWindowWidth, gDefaultWindowHeight);
   logState("tiny");
-  assertCollapsed(600);
+  assertCollapsed();
 
   // -- GIANT again!
-  resize_to(1260, 600);
+  resize_to(mc, gEnlargedWindowWidth, gDefaultWindowHeight);
   collapse_panes(mc.e("folderpane_splitter"), true);
-  // spin the event loop once
-  mc.sleep(50);
   logState("giant again!");
-  assertExpanded(1260);
+  assertExpanded();
 }
 
 function test_buttons_collapse_and_expand_on_spawn_in_vertical_mode() {
   // Assume we're in classic layout to start - since this is where we'll
   // reset to once we're done.
   assert_pane_layout(kClassicMailLayout);
 
   // Put us in vertical mode
   set_pane_layout(kVerticalMailLayout);
 
   // Make our window nice and wide.
-  resize_to(1200, 600);
-  wait_for_resize(1200);
+  resize_to(mc, gEnlargedWindowWidth, gDefaultWindowHeight);
 
   // Now expand the folder pane to cause the QFB buttons to shrink
   let folderPaneBox = mc.e("folderPaneBox");
   folderPaneBox.width = 600;
 
   // Now spawn a new 3pane...
   let mc2 = open_folder_in_new_window(folder);
   let qfb = mc2.e("quick-filter-bar-collapsible-buttons");
   mc2.waitFor(() => (qfb.getAttribute("shrink") == "true"),
               "New 3pane should have had a collapsed QFB");
   close_window(mc2);
 
   set_pane_layout(kClassicMailLayout);
 }
 
 function teardownModule() {
-  // restore window to nominal dimensions; saving was not working out
-  //  See also: message-header/test-message-header.js if we change the
-  //            default window size.
-  resize_to(1024, 768);
+  // Restore the window to original layout.
+  restore_default_window_size();
   collapse_panes(mc.e("folderpane_splitter"), false);
   let folderPaneBox = mc.e("folderPaneBox");
   folderPaneBox.width = gOriginalPaneWidth;
 }
--- a/mail/test/mozmill/shared-modules/test-dom-helpers.js
+++ b/mail/test/mozmill/shared-modules/test-dom-helpers.js
@@ -224,9 +224,11 @@ function collapse_panes(aElement, aShoul
     aElement.setAttribute("state", state);
   } else {
     for (let n of aElement.childNodes) {
       if (n.localName == "splitter") {
         n.setAttribute("state", state);
       }
     }
   }
+  // Spin the event loop once to let other window elements redraw.
+  mc.sleep(50);
 }
--- a/mail/test/mozmill/shared-modules/test-folder-display-helpers.js
+++ b/mail/test/mozmill/shared-modules/test-folder-display-helpers.js
@@ -87,16 +87,21 @@ var inboxFolder = null;
 
 // logHelper exports
 var mark_action;
 var mark_failure;
 
 // the windowHelper module
 var windowHelper;
 
+
+// Default size of the main Thunderbird window in which the tests will run.
+var gDefaultWindowWidth = 1024;
+var gDefaultWindowHeight = 768;
+
 var initialized = false;
 function setupModule() {
   if (initialized)
     return;
   initialized = true;
 
   testHelperModule = {
     Cc: Cc,
@@ -254,23 +259,25 @@ function setupModule() {
 }
 
 /**
  * Install this module into the provided module.
  */
 function installInto(module) {
   setupModule();
 
-  // force the window to be a nice size we all can love.
-  // note that we can't resize a window larger than the display it lives on!
+  // Force the window to be a nice size we all can love.
+  // Note that we can't resize a window larger than the display it lives on!
   // (I think the inner window is actually limited to the display size, so since
   // resizeTo operates on outerWidth/outerHeight, their limit is actually
-  // screen size + window border size)
-  if (mc.window.outerWidth != 1024 || mc.window.outerHeight != 768)
-    mc.window.resizeTo(1024, 768);
+  // screen size + window border size.)
+  if (mc.window.outerWidth != gDefaultWindowWidth ||
+      mc.window.outerHeight != gDefaultWindowHeight) {
+    restore_default_window_size();
+  }
 
   // now copy everything into the module they provided to us...
   let us = collector.getModule('folder-display-helpers');
   let self = this;
   for (let key in us) {
     let value = us[key];
     if (key in EXPORT_VIA_GETTER_SETTER) {
       // The value of |key| changes between iterations, so it's important to
@@ -2825,34 +2832,54 @@ function throw_and_dump_view_state(aMess
  * Copy constants from mailWindowOverlay.js
  */
 
 var kClassicMailLayout = 0;
 var kWideMailLayout = 1;
 var kVerticalMailLayout = 2;
 
 /**
- * Assert that the current mail pane layout is shown
+ * Assert that the expected mail pane layout is shown.
+ *
+ * @param aLayout  layout code
  */
-
 function assert_pane_layout(aLayout) {
   let actualPaneLayout = Services.prefs.getIntPref("mail.pane_config.dynamic");
   if (actualPaneLayout != aLayout)
     throw new Error("The mail pane layout should be " + aLayout +
                     ", but is actually " + actualPaneLayout);
 }
 
 /**
- * Change that the current mail pane layout
+ * Change the current mail pane layout.
+ *
+ * @param aLayout  layout code
  */
-
 function set_pane_layout(aLayout) {
   Services.prefs.setIntPref("mail.pane_config.dynamic", aLayout);
 }
 
+/*
+ * Check window sizes of the main Tb window whether they are at the default values.
+ * Some tests change the window size so need to be sure what size they start with.
+ */
+function assert_default_window_size() {
+  assert_equals(mc.window.outerWidth, gDefaultWindowWidth,
+                "Main window didn't meet the expected width");
+  assert_equals(mc.window.outerHeight, gDefaultWindowHeight,
+                "Main window didn't meet the expected height");
+}
+
+/**
+ * Restore window to nominal dimensions; saving the size was not working out.
+ */
+function restore_default_window_size() {
+  windowHelper.resize_to(mc, gDefaultWindowWidth, gDefaultWindowHeight);
+}
+
 /** exported from messageInjection */
 var make_new_sets_in_folders;
 var make_new_sets_in_folder;
 var add_sets_to_folders;
 var delete_message_set;
 var make_folder_with_sets;
 var make_virtual_folder;
 var SyntheticPartLeaf;
--- a/mail/test/mozmill/shared-modules/test-window-helpers.js
+++ b/mail/test/mozmill/shared-modules/test-window-helpers.js
@@ -86,16 +86,18 @@ function installInto(module) {
   module.wait_for_window_focused = wait_for_window_focused;
 
   module.wait_for_browser_load = wait_for_browser_load;
   module.wait_for_frame_load = wait_for_frame_load;
 
   module.plan_for_observable_event = plan_for_observable_event;
   module.wait_for_observable_event = wait_for_observable_event;
 
+  module.resize_to = resize_to;
+
   module.augment_controller = augment_controller;
 }
 
 function getWindowTypeOrId(aWindowElem) {
   let windowType = aWindowElem.getAttribute("windowtype");
   // Ignore types that start with "prompt:". This prefix gets added in
   // toolkit/components/prompts/src/CommonDialog.jsm since bug 1388238.
   if (windowType && !windowType.startsWith("prompt:"))
@@ -803,16 +805,35 @@ function wait_for_observable_event(aTopi
   }
   finally {
     Services.obs.removeObserver(observationWaitFuncs[aTopic], aTopic);
     delete observationWaitFuncs[aTopic];
     delete observationSaw[aTopic];
   }
 }
 
+/**
+ * Resize given window to new dimensions.
+ *
+ * @param aController  window controller
+ * @param aWidth       the requested window width
+ * @param aHeight      the requested window height
+ */
+function resize_to(aController, aWidth, aHeight) {
+  mark_action("test", "resize_to", [aWidth, "x", aHeight]);
+  aController.window.resizeTo(aWidth, aHeight);
+  // Give the event loop a spin in order to let the reality of an asynchronously
+  // interacting window manager have its impact. This still may not be
+  // sufficient.
+  aController.sleep(0);
+  aController.waitFor(() => (aController.window.outerWidth == aWidth) &&
+                            (aController.window.outerHeight == aHeight),
+                      "Timeout waiting for resize (is the screen resolution at least 1280 x 1024?)",
+                      10000, 50);
+}
 
 /**
  * Methods to augment every controller that passes through augment_controller.
  */
 var AugmentEverybodyWith = {
   methods: {
     /**
      * @param aId The element id to use to locate the (initial) element.