Bug 1586979 - Improve browser_eventDialogModificationPrompt.js. r=pmorris DONTBUILD
authorGeoff Lankow <geoff@darktrojan.net>
Tue, 08 Oct 2019 16:15:29 +1300
changeset 27892 55f15b85ce9b7532b09d56840457304e79aa9406
parent 27891 f6d43522feaca6cc1e9d37e5c7085ec6873c7b61
child 27893 8acf218742e206e590fc05519463b7cfa3a3bbe3
push id16537
push usermozilla@jorgk.com
push dateThu, 10 Oct 2019 07:04:18 +0000
treeherdercomm-central@55f15b85ce9b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspmorris
bugs1586979
Bug 1586979 - Improve browser_eventDialogModificationPrompt.js. r=pmorris DONTBUILD
calendar/test/browser/eventDialog/browser_eventDialogModificationPrompt.js
--- a/calendar/test/browser/eventDialog/browser_eventDialogModificationPrompt.js
+++ b/calendar/test/browser/eventDialog/browser_eventDialogModificationPrompt.js
@@ -15,38 +15,44 @@ var {
   createCalendar,
   deleteCalendars,
   goToDate,
   helpersForController,
   invokeEventDialog,
   switchToView,
 } = ChromeUtils.import("resource://testing-common/mozmill/CalendarUtils.jsm");
 var { setData } = ChromeUtils.import("resource://testing-common/mozmill/ItemEditingHelpers.jsm");
-var { mark_failure } = ChromeUtils.import(
-  "resource://testing-common/mozmill/FolderDisplayHelpers.jsm"
-);
-
-var { plan_for_modal_dialog, wait_for_modal_dialog } = ChromeUtils.import(
-  "resource://testing-common/mozmill/WindowHelpers.jsm"
-);
 
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 
 var controller = mozmill.getMail3PaneController();
 var { eid, lookupEventBox } = helpersForController(controller);
 
-const TIMEOUT_COMMON_DIALOG = 3000;
-var savePromptAppeared = false;
-var failPoints = {
-  first: "no change",
-  second: "change all and back",
-  third: ["1st pass", "2nd pass", "3rd pass", "4th pass", "5th pass"],
+var { date1, date2, date3, data, newlines } = setupData();
+
+// If the "do you want to save the event?" prompt appears, this test failed.
+// Listen for all windows opening, and if one is the save prompt, fail.
+var windowObserver = {
+  async observe(win, topic) {
+    if (topic == "domwindowopened") {
+      await BrowserTestUtils.waitForEvent(win, "load");
+      // Make sure this is a prompt window.
+      if (win.location.href == "chrome://global/content/commonDialog.xul") {
+        let doc = win.document;
+        // Adding attachments also shows a prompt, but we can tell which one
+        // this is by checking whether the textbox is visible.
+        if (doc.querySelector("#loginContainer").hasAttribute("hidden")) {
+          Assert.ok(false, "Unexpected save prompt appeared");
+          doc.documentElement.getButton("cancel").click();
+        }
+      }
+    }
+  },
 };
-
-var { date1, date2, date3, data, newlines } = setupData();
+Services.ww.registerNotification(windowObserver);
 
 // Test that closing an event dialog with no changes does not prompt for save.
 add_task(function testEventDialogModificationPrompt() {
   createCalendar(controller, CALENDARNAME);
   switchToView(controller, "day");
   goToDate(controller, 2009, 1, 1);
 
   let createbox = lookupEventBox("day", CANVAS_BOX, null, 1, 8);
@@ -62,46 +68,36 @@ add_task(function testEventDialogModific
 
     // Enter first set of data.
     setData(event, iframe, data[0]);
 
     // save
     event.click(eventid("button-saveandclose"));
   });
 
+  // Open, but change nothing.
   invokeEventDialog(controller, eventbox, (event, iframe) => {
-    // Open, but change nothing.
-    plan_for_modal_dialog("commonDialog", handleSavePrompt);
-
     // Escape the event window, there should be no prompt to save event.
     event.keypress(null, "VK_ESCAPE", {});
-    try {
-      wait_for_modal_dialog("commonDialog", TIMEOUT_COMMON_DIALOG);
-    } catch (e) {
-      failPoints.first = "";
-    }
+    // Wait to see if the prompt appears.
+    controller.sleep(2000);
   });
 
-  // open
+  // Open, change all values then revert the changes.
   invokeEventDialog(controller, eventbox, (event, iframe) => {
     // Change all values.
     setData(event, iframe, data[1]);
 
     // Edit all values back to original.
     setData(event, iframe, data[0]);
 
-    plan_for_modal_dialog("commonDialog", handleSavePrompt);
-
     // Escape the event window, there should be no prompt to save event.
     event.keypress(null, "VK_ESCAPE", {});
-    try {
-      wait_for_modal_dialog("commonDialog", TIMEOUT_COMMON_DIALOG);
-    } catch (e) {
-      failPoints.second = "";
-    }
+    // Wait to see if the prompt appears.
+    controller.sleep(2000);
   });
 
   // Delete event.
   controller.click(eventbox);
   controller.keypress(eid("day-view"), "VK_DELETE", {});
   controller.waitForElementNotPresent(eventbox);
 
   for (let i = 0; i < newlines.length; i++) {
@@ -111,63 +107,37 @@ add_task(function testEventDialogModific
 
       setData(event, iframe, newlines[i]);
       event.click(eventid("button-saveandclose"));
     });
 
     // Open and close.
     invokeEventDialog(controller, eventbox, (event, iframe) => {
       setData(event, iframe, newlines[i]);
-      plan_for_modal_dialog("commonDialog", handleSavePrompt);
       event.keypress(null, "VK_ESCAPE", {});
-      try {
-        wait_for_modal_dialog("commonDialog", TIMEOUT_COMMON_DIALOG);
-      } catch (e) {
-        failPoints.third[i] = "";
-      }
+      // Wait to see if the prompt appears.
+      controller.sleep(2000);
     });
 
     // Delete it.
     // XXX Somehow the event is selected at this point, this didn't use to
     // be the case and can't be reproduced manually.
     controller.keypress(eid("day-view"), "VK_DELETE", {});
     controller.waitForElementNotPresent(eventbox);
   }
 
   Assert.ok(true, "Test ran to completion");
 });
 
 registerCleanupFunction(function teardownModule(module) {
   deleteCalendars(controller, CALENDARNAME);
-  if (savePromptAppeared) {
-    mark_failure([
-      "Save Prompt unexpectedly appeared on: ",
-      failPoints.first,
-      failPoints.second,
-      failPoints.third,
-    ]);
-  }
   closeAllEventDialogs();
+  Services.ww.unregisterNotification(windowObserver);
 });
 
-function handleSavePrompt(dialogController) {
-  let { lookup: cdlglookup } = helpersForController(dialogController);
-  // Unexpected prompt, thus the test has already failed.
-  // Can't trigger a failure though, because the following click wouldn't
-  // be executed. So remembering it.
-  savePromptAppeared = true;
-
-  // application close is blocked without it
-  controller.waitThenClick(
-    cdlglookup(`
-        /id("commonDialog")/shadow/{"class":"dialog-button-box"}/{"dlgtype":"extra1"}
-    `)
-  );
-}
-
 function setupData() {
   return {
     date1: new Date(2009, 0, 1, 8, 0),
     date2: new Date(2009, 0, 2, 9, 0),
     date3: new Date(2009, 0, 3, 10, 0),
     data: [
       {
         title: "title1",