Bug 1590682 - Listen for save event prompts on all event dialog tests; r+a=pmorris
authorGeoff Lankow <geoff@darktrojan.net>
Wed, 23 Oct 2019 12:45:20 +1300
changeset 36378 163dc9241deb5eaaf7d3295a7aa19f18bb2c45d0
parent 36377 2bd2944137e359094aac45f9cd3cdae34fe9e3ac
child 36379 f1bad99f776077731e4fc1c9878c62d7edd5b75b
push id2521
push usermozilla@jorgk.com
push dateWed, 06 Nov 2019 09:31:04 +0000
treeherdercomm-beta@308f336efa3e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1590682
Bug 1590682 - Listen for save event prompts on all event dialog tests; r+a=pmorris
calendar/test/browser/eventDialog/browser.ini
calendar/test/browser/eventDialog/browser_eventDialogModificationPrompt.js
calendar/test/browser/eventDialog/head.js
--- a/calendar/test/browser/eventDialog/browser.ini
+++ b/calendar/test/browser/eventDialog/browser.ini
@@ -1,10 +1,10 @@
 [default]
-head = ../head.js
+head = head.js
 prefs =
   extensions.installDistroAddons=true
   ldap_2.servers.osx.description=
   ldap_2.servers.osx.dirType=-1
   ldap_2.servers.osx.uri=
   mail.provider.suppress_dialog_on_startup=true
   mail.spotlight.firstRunDone=true
   mail.winsearch.firstRunDone=true
--- a/calendar/test/browser/eventDialog/browser_eventDialogModificationPrompt.js
+++ b/calendar/test/browser/eventDialog/browser_eventDialogModificationPrompt.js
@@ -23,37 +23,16 @@ var { setData } = ChromeUtils.import("re
 
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 
 var controller = mozmill.getMail3PaneController();
 var { eid, lookupEventBox } = helpersForController(controller);
 
 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();
-        }
-      }
-    }
-  },
-};
-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);
   let eventbox = lookupEventBox("day", EVENT_BOX, null, 1, null, EVENTPATH);
@@ -125,17 +104,16 @@ add_task(function testEventDialogModific
   }
 
   Assert.ok(true, "Test ran to completion");
 });
 
 registerCleanupFunction(function teardownModule(module) {
   deleteCalendars(controller, CALENDARNAME);
   closeAllEventDialogs();
-  Services.ww.unregisterNotification(windowObserver);
 });
 
 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: [
new file mode 100644
--- /dev/null
+++ b/calendar/test/browser/eventDialog/head.js
@@ -0,0 +1,28 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, you can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// If the "do you want to save the event?" prompt appears, the test failed.
+// Listen for all windows opening, and if one is the save prompt, fail.
+var savePromptObserver = {
+  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.report(true, undefined, undefined, "Unexpected save prompt appeared");
+          doc.documentElement.getButton("cancel").click();
+        }
+      }
+    }
+  },
+};
+Services.ww.registerNotification(savePromptObserver);
+
+registerCleanupFunction(async () => {
+  Services.ww.unregisterNotification(savePromptObserver);
+});