Bug 1458230 - Stop passing the caller or a stack for Assert.ok messages in places tests. r?paolo draft
authorMark Banner <standard8@mozilla.com>
Tue, 01 May 2018 15:27:37 +0100
changeset 790151 f981e1680ddb37165eaf16dc2cdd3e59df0ac75b
parent 790150 0ff15253a0ab290b4e0176b3c0e2d4ba2e4dda5c
push id108431
push userbmo:standard8@mozilla.com
push dateTue, 01 May 2018 14:28:33 +0000
reviewerspaolo
bugs1458230
milestone61.0a1
Bug 1458230 - Stop passing the caller or a stack for Assert.ok messages in places tests. r?paolo The stacks are now correctly output by the test harness, they may not have been before. MozReview-Commit-ID: FugywVd9xoC
toolkit/components/places/tests/head_common.js
toolkit/components/places/tests/history/test_async_history_api.js
--- a/toolkit/components/places/tests/head_common.js
+++ b/toolkit/components/places/tests/head_common.js
@@ -599,111 +599,97 @@ function waitForConnectionClosed(aCallba
 /**
  * Tests if a given guid is valid for use in Places or not.
  *
  * @param aGuid
  *        The guid to test.
  * @param [optional] aStack
  *        The stack frame used to report the error.
  */
-function do_check_valid_places_guid(aGuid,
-                                    aStack) {
-  if (!aStack) {
-    aStack = Components.stack.caller;
-  }
-  Assert.ok(/^[a-zA-Z0-9\-_]{12}$/.test(aGuid), aStack);
+function do_check_valid_places_guid(aGuid) {
+  Assert.ok(/^[a-zA-Z0-9\-_]{12}$/.test(aGuid), "Should be a valid GUID");
 }
 
 /**
  * Retrieves the guid for a given uri.
  *
  * @param aURI
  *        The uri to check.
  * @param [optional] aStack
  *        The stack frame used to report the error.
  * @return the associated the guid.
  */
-function do_get_guid_for_uri(aURI,
-                             aStack) {
-  if (!aStack) {
-    aStack = Components.stack.caller;
-  }
+function do_get_guid_for_uri(aURI) {
   let stmt = DBConn().createStatement(
     `SELECT guid
      FROM moz_places
      WHERE url_hash = hash(:url) AND url = :url`
   );
   stmt.params.url = aURI.spec;
-  Assert.ok(stmt.executeStep(), aStack);
+  Assert.ok(stmt.executeStep(), "GUID for URI statement should succeed");
   let guid = stmt.row.guid;
   stmt.finalize();
-  do_check_valid_places_guid(guid, aStack);
+  do_check_valid_places_guid(guid);
   return guid;
 }
 
 /**
  * Tests that a guid was set in moz_places for a given uri.
  *
  * @param aURI
  *        The uri to check.
  * @param [optional] aGUID
  *        The expected guid in the database.
  */
 function do_check_guid_for_uri(aURI,
                                aGUID) {
-  let caller = Components.stack.caller;
-  let guid = do_get_guid_for_uri(aURI, caller);
+  let guid = do_get_guid_for_uri(aURI);
   if (aGUID) {
-    do_check_valid_places_guid(aGUID, caller);
-    Assert.equal(guid, aGUID, caller);
+    do_check_valid_places_guid(aGUID);
+    Assert.equal(guid, aGUID, "Should have a guid in moz_places for the URI");
   }
 }
 
 /**
  * Retrieves the guid for a given bookmark.
  *
  * @param aId
  *        The bookmark id to check.
  * @param [optional] aStack
  *        The stack frame used to report the error.
  * @return the associated the guid.
  */
-function do_get_guid_for_bookmark(aId,
-                                  aStack) {
-  if (!aStack) {
-    aStack = Components.stack.caller;
-  }
+function do_get_guid_for_bookmark(aId) {
   let stmt = DBConn().createStatement(
     `SELECT guid
      FROM moz_bookmarks
      WHERE id = :item_id`
   );
   stmt.params.item_id = aId;
-  Assert.ok(stmt.executeStep(), aStack);
+  Assert.ok(stmt.executeStep(), "Should succeed executing the SQL statement");
   let guid = stmt.row.guid;
   stmt.finalize();
-  do_check_valid_places_guid(guid, aStack);
+  do_check_valid_places_guid(guid);
   return guid;
 }
 
 /**
  * Tests that a guid was set in moz_places for a given bookmark.
  *
  * @param aId
  *        The bookmark id to check.
  * @param [optional] aGUID
  *        The expected guid in the database.
  */
 function do_check_guid_for_bookmark(aId,
                                     aGUID) {
-  let caller = Components.stack.caller;
-  let guid = do_get_guid_for_bookmark(aId, caller);
+  let guid = do_get_guid_for_bookmark(aId);
   if (aGUID) {
-    do_check_valid_places_guid(aGUID, caller);
-    Assert.equal(guid, aGUID, caller);
+    do_check_valid_places_guid(aGUID);
+    Assert.equal(guid, aGUID, "Should have the correct GUID for the bookmark");
   }
 }
 
 /**
  * Compares 2 arrays returning whether they contains the same elements.
  *
  * @param a1
  *        First array to compare.
--- a/toolkit/components/places/tests/history/test_async_history_api.js
+++ b/toolkit/components/places/tests/history/test_async_history_api.js
@@ -124,25 +124,24 @@ VisitObserver.prototype = {
  *
  * @param aURI
  *        The uri to check.
  * @param aTitle
  *        The expected title in the database.
  */
 function do_check_title_for_uri(aURI,
                                 aTitle) {
-  let stack = Components.stack.caller;
   let stmt = DBConn().createStatement(
     `SELECT title
      FROM moz_places
      WHERE url_hash = hash(:url) AND url = :url`
   );
   stmt.params.url = aURI.spec;
-  Assert.ok(stmt.executeStep(), stack);
-  Assert.equal(stmt.row.title, aTitle, stack);
+  Assert.ok(stmt.executeStep());
+  Assert.equal(stmt.row.title, aTitle);
   stmt.finalize();
 }
 
 // Test Functions
 
 add_task(async function test_interface_exists() {
   let history = Cc["@mozilla.org/browser/history;1"].getService(Ci.nsISupports);
   Assert.ok(history instanceof Ci.mozIAsyncHistory);