Bug 1623817 - Fix minimum size check on event/task dialog. r=pmorris
authorGeoff Lankow <geoff@darktrojan.net>
Fri, 20 Mar 2020 15:52:08 +1300
changeset 38544 4297a939121c367e8d0d7d1cd06ec01cdfaff2b5
parent 38543 67ab25b59f96b42a6e654ecad8437f31a5aea507
child 38545 b09bd153c9cd2d2ca58910b7b03d54fb47066679
push id400
push userclokep@gmail.com
push dateMon, 04 May 2020 18:56:09 +0000
reviewerspmorris
bugs1623817
Bug 1623817 - Fix minimum size check on event/task dialog. r=pmorris
calendar/lightning/content/lightning-item-panel.js
calendar/test/browser/eventDialog/browser_eventDialogSize.js
--- a/calendar/lightning/content/lightning-item-panel.js
+++ b/calendar/lightning/content/lightning-item-panel.js
@@ -269,34 +269,35 @@ function onLoadLightningItemPanel(aIfram
     if (typeof window.ToolbarIconColor !== "undefined") {
       window.ToolbarIconColor.init();
     }
 
     // Enlarge the dialog window so the iframe content fits, and prevent it
     // getting smaller. We don't know the minimum size of the content unless
     // it's overflowing, so don't attempt to enforce what we don't know.
     let overflowListener = () => {
+      let docEl = document.documentElement;
       let { scrollWidth, scrollHeight } = iframe.contentDocument.documentElement;
       let { clientWidth, clientHeight } = iframe;
 
       let diffX = scrollWidth - clientWidth;
       let diffY = scrollHeight - clientHeight;
       // If using a scaled screen resolution, rounding might cause
       // scrollWidth/scrollHeight to be 1px larger than
       // clientWidth/clientHeight, so we check for a difference
       // greater than 1 here, not 0.
       if (diffX > 1) {
         window.resizeBy(diffX, 0);
-        dialog.setAttribute("minwidth", dialog.getAttribute("width"));
+        docEl.setAttribute("minwidth", docEl.getAttribute("width"));
       }
       if (diffY > 1) {
         window.resizeBy(0, diffY);
-        dialog.setAttribute("minheight", dialog.getAttribute("height"));
+        docEl.setAttribute("minheight", docEl.getAttribute("height"));
       }
-      if (dialog.hasAttribute("minwidth") && dialog.hasAttribute("minheight")) {
+      if (docEl.hasAttribute("minwidth") && docEl.hasAttribute("minheight")) {
         iframe.contentWindow.removeEventListener("resize", overflowListener);
       }
     };
     iframe.contentWindow.addEventListener(
       "load",
       () => {
         // This is the first listener added, but it should run after all the others,
         // so that they can properly set up the layout they might need.
--- a/calendar/test/browser/eventDialog/browser_eventDialogSize.js
+++ b/calendar/test/browser/eventDialog/browser_eventDialogSize.js
@@ -20,68 +20,78 @@ var controller = mozmill.getMail3PaneCon
 const SMALL_TOLERANCE = 5;
 const LARGE_TOLERANCE = 10;
 
 add_task(function setupModule(module) {
   createCalendar(controller, CALENDARNAME);
 });
 
 add_task(async function testEventDialog() {
-  dump("#calendar-new-event-menuitem click\n");
+  info("#calendar-new-event-menuitem click");
   controller.mainMenu.click("#calendar-new-event-menuitem");
   await invokeEventDialog(controller, null, (event, iframe) => {
     checkLargeEnough(event, iframe);
 
     // Much larger than necessary.
     event.window.resizeTo(640, 690);
     checkWithinTolerance(event.window.outerWidth, 640);
     checkWithinTolerance(event.window.outerHeight, 690);
     event.keypress(null, "VK_ESCAPE", {});
   });
 
   checkWithinTolerance(getPersistedValue("width"), 640, LARGE_TOLERANCE);
   checkWithinTolerance(getPersistedValue("height"), 690, LARGE_TOLERANCE);
 
-  dump("#calendar-new-event-menuitem click\n");
+  info("#calendar-new-event-menuitem click");
   controller.mainMenu.click("#calendar-new-event-menuitem");
   await invokeEventDialog(controller, null, (event, iframe) => {
+    let eventDocEl = event.window.document.documentElement;
+
     checkWithinTolerance(event.window.outerWidth, 640, LARGE_TOLERANCE);
     checkWithinTolerance(event.window.outerHeight, 690, LARGE_TOLERANCE);
     checkLargeEnough(event, iframe);
 
     // Much smaller than necessary.
     event.window.resizeTo(350, 400);
-    controller.assert(() => event.window.outerWidth < 640);
-    controller.assert(() => event.window.outerHeight < 690);
-    controller.assert(() => event.window.outerWidth > 350);
-    controller.assert(() => event.window.outerHeight > 400);
     checkLargeEnough(event, iframe);
+    ok(event.window.outerWidth < 640, "dialog shrank");
+    ok(event.window.outerHeight < 690, "dialog shrank");
+    ok(event.window.outerWidth > 350, "requested size not reached");
+    ok(event.window.outerHeight > 400, "requested size not reached");
+    is(
+      eventDocEl.getAttribute("minwidth"),
+      eventDocEl.getAttribute("width"),
+      "minimum width attribute set"
+    );
+    is(
+      eventDocEl.getAttribute("minheight"),
+      eventDocEl.getAttribute("height"),
+      "minimum height attribute set"
+    );
     event.keypress(null, "VK_ESCAPE", {});
   });
 
-  dump("#calendar-new-event-menuitem click\n");
+  info("#calendar-new-event-menuitem click");
   controller.mainMenu.click("#calendar-new-event-menuitem");
   await invokeEventDialog(controller, null, (event, iframe) => {
     checkLargeEnough(event, iframe);
 
     // Much larger than necessary.
     event.window.resizeTo(640, 690);
     checkWithinTolerance(event.window.outerWidth, 640);
     checkWithinTolerance(event.window.outerHeight, 690);
     event.keypress(null, "VK_ESCAPE", {});
   });
 
   checkWithinTolerance(getPersistedValue("width"), 640, LARGE_TOLERANCE);
   checkWithinTolerance(getPersistedValue("height"), 690, LARGE_TOLERANCE);
-
-  Assert.ok(true, "Test ran to completion");
 });
 
 add_task(async function testTaskDialog() {
-  dump("#calendar-new-task-menuitem click\n");
+  info("#calendar-new-task-menuitem click");
   controller.mainMenu.click("#calendar-new-task-menuitem");
   await invokeEventDialog(controller, null, (task, iframe) => {
     checkWithinTolerance(getPersistedValue("width"), 640, LARGE_TOLERANCE);
     checkWithinTolerance(getPersistedValue("height"), 690, LARGE_TOLERANCE);
 
     checkLargeEnough(task, iframe);
 
     // Much larger than necessary.
@@ -89,46 +99,56 @@ add_task(async function testTaskDialog()
     checkWithinTolerance(task.window.outerWidth, 650);
     checkWithinTolerance(task.window.outerHeight, 700);
     task.keypress(null, "VK_ESCAPE", {});
   });
 
   checkWithinTolerance(getPersistedValue("width"), 650, LARGE_TOLERANCE);
   checkWithinTolerance(getPersistedValue("height"), 700, LARGE_TOLERANCE);
 
-  dump("#calendar-new-task-menuitem click\n");
+  info("#calendar-new-task-menuitem click");
   controller.mainMenu.click("#calendar-new-task-menuitem");
   await invokeEventDialog(controller, null, (task, iframe) => {
+    let taskDocEl = task.window.document.documentElement;
+
     checkWithinTolerance(task.window.outerWidth, 650, LARGE_TOLERANCE);
     checkWithinTolerance(task.window.outerHeight, 700, LARGE_TOLERANCE);
     checkLargeEnough(task, iframe);
 
     // Much smaller than necessary.
     task.window.resizeTo(350, 400);
-    controller.assert(() => task.window.outerWidth < 650);
-    controller.assert(() => task.window.outerHeight < 700);
-    controller.assert(() => task.window.outerWidth > 350);
-    controller.assert(() => task.window.outerHeight > 400);
     checkLargeEnough(task, iframe);
+    ok(task.window.outerWidth < 650, "dialog shrank");
+    ok(task.window.outerHeight < 700, "dialog shrank");
+    ok(task.window.outerWidth > 350, "minimum size not reached");
+    ok(task.window.outerHeight > 400, "minimum size not reached");
+    is(
+      taskDocEl.getAttribute("minwidth"),
+      taskDocEl.getAttribute("width"),
+      "minimum width attribute set"
+    );
+    is(
+      taskDocEl.getAttribute("minheight"),
+      taskDocEl.getAttribute("height"),
+      "minimum height attribute set"
+    );
     task.keypress(null, "VK_ESCAPE", {});
   });
 
-  dump("#calendar-new-task-menuitem click\n");
+  info("#calendar-new-task-menuitem click");
   controller.mainMenu.click("#calendar-new-task-menuitem");
   await invokeEventDialog(controller, null, (task, iframe) => {
     checkLargeEnough(task, iframe);
 
     // Much larger than necessary.
     task.window.resizeTo(650, 700);
     checkWithinTolerance(task.window.outerWidth, 650);
     checkWithinTolerance(task.window.outerHeight, 700);
     task.keypress(null, "VK_ESCAPE", {});
   });
-
-  Assert.ok(true, "Test ran to completion");
 });
 
 registerCleanupFunction(function teardownModule(module) {
   deleteCalendars(controller, CALENDARNAME);
   closeAllEventDialogs();
 });
 
 // Check the dialog is resized large enough to hold the iframe.
@@ -138,30 +158,30 @@ function checkLargeEnough(outer, inner) 
   let iframeNode = outerId("lightning-item-panel-iframe").getNode();
   let { scrollWidth, scrollHeight } = inner.window.document.documentElement;
   outer.waitFor(() => {
     return (
       iframeNode.clientWidth + SMALL_TOLERANCE >= scrollWidth &&
       iframeNode.clientHeight + SMALL_TOLERANCE >= scrollHeight
     );
   });
-  dump(`Dialog is ${outer.window.outerWidth} by ${outer.window.outerHeight}\n`);
+  info(`Dialog is ${outer.window.outerWidth} by ${outer.window.outerHeight}`);
 }
 
 function getPersistedValue(which) {
   return Services.xulStore.getValue(
     "chrome://calendar/content/calendar-event-dialog.xhtml",
     "calendar-event-window",
     which
   );
 }
 
 function checkWithinTolerance(value, expected, tolerance = 1) {
   if (controller.window.devicePixelRatio == 1) {
-    controller.assert(() => value == expected);
+    ok(value == expected);
     return;
   }
   // In an environment where the display is scaled, rounding errors can cause
   // problems with exact tests. The mechanism for persisting and restoring
   // window sizes also appears to be buggy, so we account for that by
   // increasing the tolerance.
-  controller.assert(() => Math.abs(value - expected) <= tolerance);
+  ok(Math.abs(value - expected) <= tolerance);
 }