Bug 1534112 - Test for category colours in the preferences. r+a=philipp THUNDERBIRD_69_0b1_BUILD2 THUNDERBIRD_69_0b1_RELEASE
authorGeoff Lankow <geoff@darktrojan.net>
Fri, 05 Jul 2019 22:02:02 +1200
changeset 35258 eef322757b67ee75b7d1cf8834580bf23bcc08e5
parent 35257 8f2a29618eed9f467cc11c2aeff48a216a29d736
child 35259 da623034dc84c96a59564e7b66278aeeca50be4d
push id2472
push usermozilla@jorgk.com
push dateTue, 23 Jul 2019 18:04:43 +0000
treeherdercomm-beta@eef322757b67 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1534112
Bug 1534112 - Test for category colours in the preferences. r+a=philipp
calendar/test/mozmill/moz.build
calendar/test/mozmill/mozmilltests.list
calendar/test/mozmill/preferences/testAlarmDefaultValue.js
calendar/test/mozmill/preferences/testCategoryColors.js
calendar/test/mozmill/shared-modules/test-calendar-utils.js
calendar/test/mozmill/testAlarmDefaultValue.js
--- a/calendar/test/mozmill/moz.build
+++ b/calendar/test/mozmill/moz.build
@@ -3,18 +3,18 @@
 # 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/.
 
 # Copies the files in this folder to a staging directory in the objdir.
 TEST_HARNESS_FILES.mozmill.stage += [
     'cal-recurrence/*',
     'eventDialog/*',
     'invitations/*',
+    'preferences/*',
     'recurrenceRotated/*',
-    'testAlarmDefaultValue.js',
     'testBasicFunctionality.js',
     'testLocalICS.js',
     'testTimezones.js',
     'testTodayPane.js',
     'views/*',
 ]
 
 DIRS += [
--- a/calendar/test/mozmill/mozmilltests.list
+++ b/calendar/test/mozmill/mozmilltests.list
@@ -1,10 +1,10 @@
 cal-recurrence
 eventDialog
 invitations
+preferences
 recurrenceRotated
-testAlarmDefaultValue.js
 testBasicFunctionality.js
 testLocalICS.js
 testTimezones.js
 testTodayPane.js
 views
rename from calendar/test/mozmill/testAlarmDefaultValue.js
rename to calendar/test/mozmill/preferences/testAlarmDefaultValue.js
--- a/calendar/test/mozmill/testAlarmDefaultValue.js
+++ b/calendar/test/mozmill/preferences/testAlarmDefaultValue.js
@@ -2,35 +2,39 @@
  * 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/. */
 
 /**
  * Test default alarm settings for events and tasks
  */
 
 var MODULE_NAME = "testAlarmDefaultValue";
-var RELATIVE_ROOT = "./shared-modules";
+var RELATIVE_ROOT = "../shared-modules";
 var MODULE_REQUIRES = ["calendar-utils", "content-tab-helpers"];
 
 var { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 var { PluralForm } = ChromeUtils.import("resource://gre/modules/PluralForm.jsm");
 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 const DEFVALUE = 43;
 
-var helpersForController, invokeEventDialog, openLightningPrefs, menulistSelect;
+var helpersForController, invokeEventDialog, openLightningPrefs, closeLightningPrefs;
+var menulistSelect;
 var plan_for_modal_dialog, wait_for_modal_dialog;
 var content_tab_e, content_tab_eid;
 
+var prefTab = null;
+
 function setupModule(module) {
     controller = mozmill.getMail3PaneController();
     ({
         helpersForController,
         invokeEventDialog,
         openLightningPrefs,
+        closeLightningPrefs,
         menulistSelect
     } = collector.getModule("calendar-utils"));
     collector.getModule("calendar-utils").setupModule(controller);
 
     ({ plan_for_modal_dialog, wait_for_modal_dialog } = collector.getModule("window-helpers"));
 
     ({ content_tab_e, content_tab_eid } = collector.getModule("content-tab-helpers"));
     collector.getModule("content-tab-helpers").setupModule();
@@ -86,16 +90,18 @@ function testDefaultAlarms() {
         wait_for_modal_dialog("Calendar:EventDialog:Reminder");
 
         // Close the task dialog.
         task.window.close();
     });
 }
 
 function handlePrefTab(tab) {
+    prefTab = tab;
+
     let { replaceText } = helpersForController(controller);
     // Click on the alarms tab.
     content_tab_e(tab, "calPreferencesTabAlarms").click();
 
     // Turn on alarms for events and tasks.
     menulistSelect(content_tab_eid(tab, "eventdefalarm"), "1", controller);
     menulistSelect(content_tab_eid(tab, "tododefalarm"), "1", controller);
 
@@ -136,9 +142,13 @@ function handleReminderDialog(reminders)
     reminders.window.close();
 }
 
 function teardownModule(module) {
     Services.prefs.clearUserPref("calendar.alarms.eventalarmlen");
     Services.prefs.clearUserPref("calendar.alarms.eventalarmunit");
     Services.prefs.clearUserPref("calendar.alarms.todoalarmlen");
     Services.prefs.clearUserPref("calendar.alarms.todoalarmunit");
+
+    if (prefTab) {
+        closeLightningPrefs(prefTab);
+    }
 }
new file mode 100644
--- /dev/null
+++ b/calendar/test/mozmill/preferences/testCategoryColors.js
@@ -0,0 +1,69 @@
+/* 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/. */
+
+var MODULE_NAME = "testCategoryColors";
+var RELATIVE_ROOT = "../shared-modules";
+var MODULE_REQUIRES = ["calendar-utils", "content-tab-helpers"];
+
+var helpersForController, openLightningPrefs, closeLightningPrefs;
+var wait_for_frame_load;
+var content_tab_e, content_tab_eid;
+
+var prefTab = null;
+
+function setupModule(module) {
+    controller = mozmill.getMail3PaneController();
+    ({
+        helpersForController,
+        openLightningPrefs,
+        closeLightningPrefs
+    } = collector.getModule("calendar-utils"));
+    collector.getModule("calendar-utils").setupModule(controller);
+
+    ({ wait_for_frame_load } = collector.getModule("window-helpers"));
+
+    ({ content_tab_e, content_tab_eid } = collector.getModule("content-tab-helpers"));
+    collector.getModule("content-tab-helpers").setupModule();
+}
+
+function testCategoryColors() {
+    openLightningPrefs((tab) => {
+        prefTab = tab;
+
+        content_tab_e(tab, "calPreferencesTabCategories").click();
+
+        let listBox = content_tab_e(tab, "categorieslist");
+        controller.assert(() => listBox.itemChildren.length == 22);
+
+        for (let item of listBox.itemChildren) {
+            dump(`${item.firstElementChild.value}: ${item.lastElementChild.style.backgroundColor}\n`);
+            controller.assert(() => item.lastElementChild.style.backgroundColor);
+        }
+
+        controller.click(content_tab_eid(tab, "categorieslist"), 5, 5);
+        controller.click(content_tab_eid(tab, "editCButton"));
+
+        let editFrame = wait_for_frame_load(
+            tab.browser.contentDocument.getElementById("dialogOverlay-0").querySelector("browser"),
+            "chrome://calendar/content/preferences/editCategory.xul"
+        );
+        let { replaceText, lookup } = helpersForController(editFrame);
+        let categoryName = editFrame.eid("categoryName");
+        replaceText(categoryName, "ZZZ Mozmill");
+        editFrame.e("categoryColor").value = "#00CC00";
+        editFrame.click(lookup(`
+            id("editCategory")/shadow/{"class":"dialog-button-box"}/{"dlgtype":"accept"}
+        `));
+
+        let listItem = listBox.itemChildren[listBox.itemCount - 1];
+        controller.assert(() => listItem.firstElementChild.value == "ZZZ Mozmill");
+        controller.assert(() => listItem.lastElementChild.style.backgroundColor == "rgb(0, 204, 0)");
+    }, controller);
+}
+
+function teardownModule() {
+    if (prefTab) {
+        closeLightningPrefs(prefTab);
+    }
+}
--- a/calendar/test/mozmill/shared-modules/test-calendar-utils.js
+++ b/calendar/test/mozmill/shared-modules/test-calendar-utils.js
@@ -65,27 +65,28 @@ var EVENTPATH = `
     /{"tooltip":"itemTooltip","calendar":"${CALENDARNAME.toLowerCase()}"}
 `;
 // Used after "${EVENTPATH}/${getEventDetails([view])}/".
 var ALARM_ICON_PATH = `
     anon({"anonid":"category-box-stack"})/anon({"align":"center"})/
     anon({"anonid":"alarm-icons-box"})/anon({"class":"reminder-icon"})
 `;
 
-var plan_for_modal_dialog, wait_for_modal_dialog, close_window, open_pref_tab;
+var plan_for_modal_dialog, wait_for_modal_dialog, close_window;
+var open_pref_tab, close_pref_tab;
 
 function setupModule(controller) {
     ({ plan_for_modal_dialog, wait_for_modal_dialog, close_window } =
         collector.getModule("window-helpers"));
 
     // This setup is needed for pref-win-helpers. For some reason, the automatic
     // loading of modules in shared modules does not setup the module correctly.
     collector.getModule("folder-display-helpers").setupModule();
 
-    ({ open_pref_tab } = collector.getModule("pref-window-helpers"));
+    ({ open_pref_tab, close_pref_tab } = collector.getModule("pref-window-helpers"));
     collector.getModule("pref-window-helpers").setupModule();
 
     // For our tests, we assume that Sunday is start of week.
     Services.prefs.setIntPref("calendar.week.start", 0);
 
     // We are in calendarTests, so we make sure, calendar-tab with day-view is displayed.
     let { eid } = helpersForController(controller);
     controller.click(eid("calendar-tab-button"));
@@ -130,16 +131,17 @@ function installInto(module) {
     module.viewForward = viewForward;
     module.viewBack = viewBack;
     module.closeAllEventDialogs = closeAllEventDialogs;
     module.deleteCalendars = deleteCalendars;
     module.createCalendar = createCalendar;
     module.handleNewCalendarWizard = handleNewCalendarWizard;
     module.findEventsInNode = findEventsInNode;
     module.openLightningPrefs = openLightningPrefs;
+    module.closeLightningPrefs = closeLightningPrefs;
     module.menulistSelect = menulistSelect;
 }
 
 function helpersForController(controller) {
     function selector(sel) {
         return sel.trim().replace(/\n(\s*)/g, "");
     }
 
@@ -613,16 +615,20 @@ function openLightningPrefs(aCallback, a
     categoryBox.querySelector('radio[pane="paneLightning"]').click();
     utils.waitFor(
         () => tab.browser.contentWindow.getCurrentPaneID() == "paneLightning",
         "Timed out waiting for prefpane paneLightning to load."
     );
     aCallback(tab);
 }
 
+function closeLightningPrefs(tab) {
+    close_pref_tab(tab);
+}
+
 /**
  * Helper to work around a mac bug in Thunderbird's mozmill version. This can
  * likely be removed with Mozmill 2.0's new Element Object.
  *
  * @param aMenuList     The XUL menulist to select in.
  * @param aValue        The value assigned to the desired menuitem.
  * @param aController   The mozmill controller associated to the menulist.
  */