Bug 1614860 - Stop using assert_true, assert_false, assert_equals and assert_not_equals in ex-Mozmill tests. r=mkmelin
authorGeoff Lankow <geoff@darktrojan.net>
Thu, 13 Feb 2020 12:26:48 +0200
changeset 28753 59a1899adf445ba3990004e9310d4934744324a3
parent 28752 23b8d13cf05890273eb37d63c2f7543416773c94
child 28754 72e16c6f960ab78cb558e949852a22de78895647
push id17020
push usermkmelin@iki.fi
push dateThu, 13 Feb 2020 10:29:45 +0000
treeherdercomm-central@2e35a75dba0a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1614860
Bug 1614860 - Stop using assert_true, assert_false, assert_equals and assert_not_equals in ex-Mozmill tests. r=mkmelin
mail/test/browser/shared-modules/CloudfileHelpers.jsm
mail/test/browser/shared-modules/ComposeHelpers.jsm
mail/test/browser/shared-modules/CustomizationHelpers.jsm
mail/test/browser/shared-modules/DOMHelpers.jsm
mail/test/browser/shared-modules/FolderDisplayHelpers.jsm
mail/test/browser/shared-modules/MouseEventHelpers.jsm
mail/test/browser/shared-modules/NewMailAccountHelpers.jsm
mail/test/browser/shared-modules/QuickFilterBarHelpers.jsm
--- a/mail/test/browser/shared-modules/CloudfileHelpers.jsm
+++ b/mail/test/browser/shared-modules/CloudfileHelpers.jsm
@@ -12,16 +12,17 @@ const EXPORTED_SYMBOLS = [
 ];
 
 var os = ChromeUtils.import("resource://testing-common/mozmill/os.jsm");
 
 var fdh = ChromeUtils.import(
   "resource://testing-common/mozmill/FolderDisplayHelpers.jsm"
 );
 
+var { Assert } = ChromeUtils.import("resource://testing-common/Assert.jsm");
 var { cloudFileAccounts } = ChromeUtils.import(
   "resource:///modules/cloudFileAccounts.jsm"
 );
 
 var kDefaults = {
   type: "default",
   iconURL: "chrome://messenger/content/extension.svg",
   accountKey: null,
@@ -32,17 +33,17 @@ var kDefaults = {
   uploadWouldExceedQuota: cloudFileAccounts.constants.uploadWouldExceedQuota,
   uploadExceedsFileLimit: cloudFileAccounts.constants.uploadExceedsFileLimit,
   uploadCancelled: cloudFileAccounts.constants.uploadCancelled,
 };
 
 function getFile(aFilename, aRoot) {
   let path = os.getFileForPath(aRoot);
   let file = os.getFileForPath(os.abspath(aFilename, path));
-  fdh.assert_true(file.exists, "File " + aFilename + " does not exist.");
+  Assert.ok(file.exists, "File " + aFilename + " does not exist.");
   return file;
 }
 
 /**
  * Helper function for getting the nsIFile's for some files located
  * in a subdirectory of the test directory.
  *
  * @param aFiles an array of filename strings for files underneath the test
--- a/mail/test/browser/shared-modules/ComposeHelpers.jsm
+++ b/mail/test/browser/shared-modules/ComposeHelpers.jsm
@@ -37,16 +37,18 @@ var utils = ChromeUtils.import("resource
 
 var folderDisplayHelper = ChromeUtils.import(
   "resource://testing-common/mozmill/FolderDisplayHelpers.jsm"
 );
 var windowHelper = ChromeUtils.import(
   "resource://testing-common/mozmill/WindowHelpers.jsm"
 );
 
+var { Assert } = ChromeUtils.import("resource://testing-common/Assert.jsm");
+
 var kTextNodeType = 3;
 
 var mc = folderDisplayHelper.mc;
 
 /**
  * Opens the compose window by starting a new message
  *
  * @param aController the controller for the mail:3pane from which to spawn
@@ -412,17 +414,17 @@ function add_attachments(aController, aU
   let attachments = [];
 
   for (let [i, url] of aUrls.entries()) {
     attachments.push(create_msg_attachment(url, aSizes[i]));
   }
 
   let attachmentsDone = false;
   function collectAddedAttachments(event) {
-    folderDisplayHelper.assert_equals(event.detail.length, attachments.length);
+    Assert.equal(event.detail.length, attachments.length);
     attachmentsDone = true;
   }
 
   let bucket = aController.e("attachmentBucket");
   if (aWaitAdded) {
     bucket.addEventListener("attachments-added", collectAddedAttachments, {
       once: true,
     });
--- a/mail/test/browser/shared-modules/CustomizationHelpers.jsm
+++ b/mail/test/browser/shared-modules/CustomizationHelpers.jsm
@@ -5,23 +5,21 @@
 "use strict";
 
 const EXPORTED_SYMBOLS = ["CustomizeDialogHelper"];
 
 var elib = ChromeUtils.import(
   "resource://testing-common/mozmill/elementslib.jsm"
 );
 
-var fdh = ChromeUtils.import(
-  "resource://testing-common/mozmill/FolderDisplayHelpers.jsm"
-);
 var wh = ChromeUtils.import(
   "resource://testing-common/mozmill/WindowHelpers.jsm"
 );
 
+var { Assert } = ChromeUtils.import("resource://testing-common/Assert.jsm");
 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 var USE_SHEET_PREF = "toolbar.customization.usesheet";
 
 /**
  * Initialize the help for a customization dialog
  * @param {} aToolbarId
  *   the ID of the toolbar to be customized
@@ -71,20 +69,17 @@ CustomizeDialogHelper.prototype = {
       wh.plan_for_window_close(aCtc);
     }
 
     aCtc.click(aCtc.eid("donebutton"));
     // XXX There should be an equivalent for testing the closure of
     // XXX the dialog embedded in a sheet, but I do not know how.
     if (this._openInWindow) {
       wh.wait_for_window_close();
-      fdh.assert_true(
-        aCtc.window.closed,
-        "The customization dialog is not closed."
-      );
+      Assert.ok(aCtc.window.closed, "The customization dialog is not closed.");
     }
   },
 
   /**
    *  Restore the default buttons in the header pane toolbar
    *  by clicking the corresponding button in the palette dialog
    *  and check if it worked.
    * @param {} aController
@@ -101,11 +96,11 @@ CustomizeDialogHelper.prototype = {
 
     ctc.click(new elib.Elem(restoreButton));
 
     this.close(ctc);
 
     let toolbar = aController.e(this._toolbarId);
     let defaultSet = toolbar.getAttribute("defaultset");
 
-    fdh.assert_equals(toolbar.currentSet, defaultSet);
+    Assert.equal(toolbar.currentSet, defaultSet);
   },
 };
--- a/mail/test/browser/shared-modules/DOMHelpers.jsm
+++ b/mail/test/browser/shared-modules/DOMHelpers.jsm
@@ -18,16 +18,18 @@ const EXPORTED_SYMBOLS = [
   "collapse_panes",
 ];
 
 var folderDisplayHelper = ChromeUtils.import(
   "resource://testing-common/mozmill/FolderDisplayHelpers.jsm"
 );
 var mc = folderDisplayHelper.mc;
 
+var { Assert } = ChromeUtils.import("resource://testing-common/Assert.jsm");
+
 /**
  * This function takes either a string or an elementlibs.Elem, and returns
  * whether it is hidden or not (simply by poking at its hidden property). It
  * doesn't try to do anything smart, like is it not into view, or whatever.
  *
  * @param aElt The element to query.
  * @return Whether the element is visible or not.
  */
@@ -42,17 +44,17 @@ function element_visible(aElt) {
 }
 
 /**
  * Assert that en element's visible.
  * @param aElt The element, an ID or an elementlibs.Elem
  * @param aWhy The error message in case of failure
  */
 function assert_element_visible(aElt, aWhy) {
-  folderDisplayHelper.assert_true(element_visible(aElt), aWhy);
+  Assert.ok(element_visible(aElt), aWhy);
 }
 
 /**
  * Returns if a element is visible by traversing all parent elements and check
  * that all are visible.
  *
  * @param aElem The element to be checked
  */
@@ -78,17 +80,17 @@ function element_visible_recursive(aElem
 }
 
 /**
  * Assert that en element's not visible.
  * @param aElt The element, an ID or an elementlibs.Elem
  * @param aWhy The error message in case of failure
  */
 function assert_element_not_visible(aElt, aWhy) {
-  folderDisplayHelper.assert_true(!element_visible(aElt), aWhy);
+  Assert.ok(!element_visible(aElt), aWhy);
 }
 
 /**
  * Wait for and return an element matching a particular CSS selector.
  *
  * @param aParent the node to begin searching from
  * @param aSelector the CSS selector to search with
  */
--- a/mail/test/browser/shared-modules/FolderDisplayHelpers.jsm
+++ b/mail/test/browser/shared-modules/FolderDisplayHelpers.jsm
@@ -9,19 +9,17 @@ const EXPORTED_SYMBOLS = [
   "add_sets_to_folders",
   "add_to_toolbar",
   "archive_messages",
   "archive_selected_messages",
   "assert_attachment_list_focused",
   "assert_collapsed",
   "assert_default_window_size",
   "assert_displayed",
-  "assert_equals",
   "assert_expanded",
-  "assert_false",
   "assert_folder_at_index_as",
   "assert_folder_child_in_view",
   "assert_folder_collapsed",
   "assert_folder_displayed",
   "assert_folder_expanded",
   "assert_folder_mode",
   "assert_folder_not_visible",
   "assert_folder_selected",
@@ -36,34 +34,32 @@ const EXPORTED_SYMBOLS = [
   "assert_message_pane_focused",
   "assert_message_pane_hidden",
   "assert_message_pane_visible",
   "assert_messages_in_view",
   "assert_messages_not_in_view",
   "assert_messages_summarized",
   "assert_multimessage_pane_focused",
   "assert_no_folders_selected",
-  "assert_not_equals",
   "assert_not_selected_tab",
   "assert_not_showing_unread_only",
   "assert_not_shown",
   "assert_nothing_selected",
   "assert_number_of_tabs_open",
   "assert_pane_layout",
   "assert_row_visible",
   "assert_selected",
   "assert_selected_and_displayed",
   "assert_selected_tab",
   "assert_showing_unread_only",
   "assert_summary_contains_N_elts",
   "assert_tab_has_title",
   "assert_tab_mode_name",
   "assert_tab_titled_from",
   "assert_thread_tree_focused",
-  "assert_true",
   "assert_visible",
   "be_in_folder",
   "click_tree_row",
   "close_message_window",
   "close_popup",
   "close_tab",
   "collapse_all_threads",
   "collapse_folder",
@@ -3105,17 +3101,17 @@ function assert_folder_tree_view_row_cou
   }
 }
 
 /**
  * Assert that the displayed text of the folder at index n equals to str.
  */
 function assert_folder_at_index_as(n, str) {
   let folderN = mc.window.gFolderTreeView.getFTVItemForIndex(n);
-  assert_equals(folderN.text, str);
+  Assert.equal(folderN.text, str);
 }
 
 /**
  * Since indexOf does strict equality checking, we need this.
  */
 function _non_strict_index_of(aArray, aSearchElement) {
   for (let [i, item] of aArray.entries()) {
     if (item == aSearchElement) {
@@ -3390,22 +3386,22 @@ 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(
+  Assert.equal(
     mc.window.outerWidth,
     gDefaultWindowWidth,
     "Main window didn't meet the expected width"
   );
-  assert_equals(
+  Assert.equal(
     mc.window.outerHeight,
     gDefaultWindowHeight,
     "Main window didn't meet the expected height"
   );
 }
 
 /**
  * Restore window to nominal dimensions; saving the size was not working out.
@@ -3476,42 +3472,8 @@ function load_via_src_path(aPath, aModul
         );
       }
     }
   }
 
   // If we've got this far, then we weren't successful, fail out.
   throw new Error("Could not find " + aPath + " in available paths");
 }
-
-function assert_equals(a, b, comment) {
-  if (!comment) {
-    comment = "a != b";
-  }
-  assert_true(a == b, comment + ": '" + a + "' != '" + b + "'.");
-}
-
-function assert_not_equals(a, b, comment) {
-  if (!comment) {
-    comment = "a == b";
-  }
-  assert_true(a != b, comment + ": '" + a + "' == '" + b + "'.");
-}
-
-// something less sucky than do_check_true
-function assert_true(
-  aBeTrue,
-  aWhy = "Expected value of expression is not 'true'"
-) {
-  if (!aBeTrue) {
-    throw new Error(aWhy);
-  }
-}
-
-// something less sucky than do_check_false
-function assert_false(
-  aBeTrue,
-  aWhy = "Expected value of expression is not 'false'"
-) {
-  if (aBeTrue) {
-    throw new Error(aWhy);
-  }
-}
--- a/mail/test/browser/shared-modules/MouseEventHelpers.jsm
+++ b/mail/test/browser/shared-modules/MouseEventHelpers.jsm
@@ -11,19 +11,17 @@ const EXPORTED_SYMBOLS = [
   "synthesize_drag_end",
   "synthesize_drop",
 ];
 
 var EventUtils = ChromeUtils.import(
   "resource://testing-common/mozmill/EventUtils.jsm"
 );
 
-var fdh = ChromeUtils.import(
-  "resource://testing-common/mozmill/FolderDisplayHelpers.jsm"
-);
+var { Assert } = ChromeUtils.import("resource://testing-common/Assert.jsm");
 
 /**
  * Execute a drag and drop session.
  * @param {XULElement} aDragObject
  *   the element from which the drag session should be started.
  * @param {} aDragWindow
  *   the window the aDragObject is in
  * @param {XULElement} aDropObject
@@ -44,17 +42,17 @@ function drag_n_drop_element(
   aDragWindow,
   aDropObject,
   aDropWindow,
   aRelDropX,
   aRelDropY,
   aListener
 ) {
   let dt = synthesize_drag_start(aDragWindow, aDragObject, aListener);
-  fdh.assert_true(dt, "Drag target was undefined");
+  Assert.ok(dt, "Drag target was undefined");
 
   synthesize_drag_over(aDropWindow, aDropObject, dt);
 
   let dropRect = aDropObject.getBoundingClientRect();
   synthesize_drop(aDropWindow, aDropObject, dt, {
     screenX: aDropObject.screenX + dropRect.width * aRelDropX,
     screenY: aDropObject.screenY + dropRect.height * aRelDropY,
   });
--- a/mail/test/browser/shared-modules/NewMailAccountHelpers.jsm
+++ b/mail/test/browser/shared-modules/NewMailAccountHelpers.jsm
@@ -25,16 +25,17 @@ var elib = ChromeUtils.import(
 var dh = ChromeUtils.import("resource://testing-common/mozmill/DOMHelpers.jsm");
 var fdh = ChromeUtils.import(
   "resource://testing-common/mozmill/FolderDisplayHelpers.jsm"
 );
 var { input_value } = ChromeUtils.import(
   "resource://testing-common/mozmill/KeyboardHelpers.jsm"
 );
 
+var { Assert } = ChromeUtils.import("resource://testing-common/Assert.jsm");
 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var { fixIterator } = ChromeUtils.import(
   "resource:///modules/iteratorUtils.jsm"
 );
 var { MailServices } = ChromeUtils.import(
   "resource:///modules/MailServices.jsm"
 );
 
@@ -89,36 +90,36 @@ function assert_links_shown(aController,
   if (!Array.isArray(aLinks)) {
     aLinks = [aLinks];
   }
 
   aLinks.forEach(function(aLink) {
     let anchors = aController.window.document.querySelectorAll(
       'a[href="' + aLink + '"]'
     );
-    fdh.assert_true(anchors.length > 0);
+    Assert.ok(anchors.length > 0);
     for (let anchor of anchors) {
-      fdh.assert_false(anchor.hidden);
+      Assert.ok(!anchor.hidden);
     }
   });
 }
 
 /* Asserts that a series of links are currently invisible. aLinks can either
  * be a single link, or an Array of links.
  */
 function assert_links_not_shown(aController, aLinks) {
   if (!Array.isArray(aLinks)) {
     aLinks = [aLinks];
   }
 
   aLinks.forEach(function(aLink) {
     let anchors = aController.window.document.querySelectorAll(
       'a[href="' + aLink + '"]'
     );
-    fdh.assert_equals(anchors.length, 0);
+    Assert.equal(anchors.length, 0);
   });
 }
 
 /* Waits for account provisioner search results to come in.
  */
 function wait_for_search_results(w) {
   w.waitFor(
     () => w.e("results").children.length > 0,
--- a/mail/test/browser/shared-modules/QuickFilterBarHelpers.jsm
+++ b/mail/test/browser/shared-modules/QuickFilterBarHelpers.jsm
@@ -20,16 +20,19 @@ const EXPORTED_SYMBOLS = [
   "assert_filter_text",
   "assert_results_label_count",
   "clear_constraints",
 ];
 
 var fdh = ChromeUtils.import(
   "resource://testing-common/mozmill/FolderDisplayHelpers.jsm"
 );
+
+var { Assert } = ChromeUtils.import("resource://testing-common/Assert.jsm");
+
 var mc = fdh.mc;
 // disable the deferred search processing!
 mc.window.QuickFilterBarMuxer.deferredUpdateSearch =
   mc.window.QuickFilterBarMuxer.updateSearch;
 
 /**
  * Maps names to bar DOM ids to simplify checking.
  */
@@ -106,20 +109,20 @@ function toggle_tag_constraints(...aArgs
 
 /**
  * Set the tag filtering mode. Wait for messages after.
  */
 function toggle_tag_mode() {
   let qbm = mc.e("qfb-boolean-mode");
   if (qbm.value === "AND") {
     qbm.selectedIndex--; // = move to "OR";
-    fdh.assert_equals(qbm.value, "OR", "qfb-boolean-mode has wrong state");
+    Assert.equal(qbm.value, "OR", "qfb-boolean-mode has wrong state");
   } else if (qbm.value === "OR") {
     qbm.selectedIndex++; // = move to "AND";
-    fdh.assert_equals(qbm.value, "AND", "qfb-boolean-mode has wrong state");
+    Assert.equal(qbm.value, "AND", "qfb-boolean-mode has wrong state");
   } else {
     throw new Error("qfb-boolean-mode value=" + qbm.value);
   }
   fdh.wait_for_all_messages_to_load(mc);
 }
 
 /**
  * Verify that tag buttons exist for exactly the given set of tag keys in the