Bug 1463673 - Add the expected argument to Assert.throws/rejects for toolkit/components/places. r=mak
authorMark Banner <standard8@mozilla.com>
Tue, 22 May 2018 20:48:54 +0100
changeset 420262 c9f558e4282c10db369642fbc989e975364797f0
parent 420261 015e8f74e97397b46437f5d22d88d783013e65bf
child 420263 1350bcc2983eed6a9ed95586d9807ef1ec69dd9e
push id64576
push usermbanner@mozilla.com
push dateTue, 29 May 2018 17:46:42 +0000
treeherderautoland@d73afee801c0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1463673
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1463673 - Add the expected argument to Assert.throws/rejects for toolkit/components/places. r=mak MozReview-Commit-ID: 5Rydh6dyODN
toolkit/components/places/ExtensionSearchHandler.jsm
toolkit/components/places/tests/bookmarks/test_bookmarkstree_cache.js
toolkit/components/places/tests/expiration/test_pref_interval.js
toolkit/components/places/tests/history/test_insert.js
toolkit/components/places/tests/migration/test_current_from_v36.js
toolkit/components/places/tests/sync/test_sync_utils.js
toolkit/components/places/tests/unifiedcomplete/test_extension_matches.js
toolkit/components/places/tests/unit/test_async_transactions.js
--- a/toolkit/components/places/ExtensionSearchHandler.jsm
+++ b/toolkit/components/places/ExtensionSearchHandler.jsm
@@ -257,16 +257,20 @@ var ExtensionSearchHandler = Object.free
    *    "tab": open the page in a new foreground tab.
    *    "tabshifted": open the page in a new background tab.
    */
   handleInputEntered(keyword, text, where) {
     if (!gKeywordMap.has(keyword)) {
       throw new Error(`The keyword provided is not registered: "${keyword}"`);
     }
 
+    if (!gActiveInputSession) {
+      throw new Error("There is no active input session");
+    }
+
     if (gActiveInputSession && gActiveInputSession.keyword != keyword) {
       throw new Error("A different input session is already ongoing");
     }
 
     if (!text || !text.startsWith(`${keyword} `)) {
       throw new Error(`The text provided must start with: "${keyword} "`);
     }
 
--- a/toolkit/components/places/tests/bookmarks/test_bookmarkstree_cache.js
+++ b/toolkit/components/places/tests/bookmarks/test_bookmarkstree_cache.js
@@ -9,10 +9,11 @@ add_task(async function boookmarks_tree_
   let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
                                                 uri("http://example.com"),
                                                 PlacesUtils.bookmarks.DEFAULT_INDEX,
                                                 "A title");
   await PlacesUtils.promiseBookmarksTree();
 
   PlacesUtils.bookmarks.removeItem(id);
 
-  await Assert.rejects(PlacesUtils.promiseItemGuid(id));
+  await Assert.rejects(PlacesUtils.promiseItemGuid(id),
+    /no item found for the given itemId/);
 });
--- a/toolkit/components/places/tests/expiration/test_pref_interval.js
+++ b/toolkit/components/places/tests/expiration/test_pref_interval.js
@@ -36,17 +36,18 @@ var tests = [
     interval: 100,
     expectedTimerDelay: 100 * EXPIRE_AGGRESSIVITY_MULTIPLIER
   },
 
 ];
 
 add_task(async function test() {
   // The pref should not exist by default.
-  Assert.throws(() => getInterval());
+  Assert.throws(() => getInterval(),
+    /NS_ERROR_UNEXPECTED/);
 
   // Force the component, so it will start observing preferences.
   force_expiration_start();
 
   for (let currentTest of tests) {
     currentTest = tests.shift();
     print(currentTest.desc);
     let promise = promiseTopicObserved("test-interval-changed");
--- a/toolkit/components/places/tests/history/test_insert.js
+++ b/toolkit/components/places/tests/history/test_insert.js
@@ -76,17 +76,17 @@ add_task(async function test_insert_erro
     () => PlacesUtils.history.insert({
       url: TEST_URL,
       visits: [
         {
           transition: TRANSITION_LINK,
           date: futureDate,
         }
       ]}),
-    `TypeError: date: ${futureDate} is not a valid date`,
+    /cannot be a future date/,
     "passing a visit object with a future date to History.insert should throw a TypeError"
   );
   Assert.throws(
     () => PlacesUtils.history.insert({
       url: TEST_URL,
       visits: [
         {transition: "a"}
       ]}),
--- a/toolkit/components/places/tests/migration/test_current_from_v36.js
+++ b/toolkit/components/places/tests/migration/test_current_from_v36.js
@@ -35,16 +35,17 @@ add_task(async function database_is_vali
 
   let db = await PlacesUtils.promiseDBConnection();
   Assert.equal((await db.getSchemaVersion()), CURRENT_SCHEMA_VERSION);
 });
 
 add_task(async function test_icons() {
   let db = await PlacesUtils.promiseDBConnection();
   await Assert.rejects(db.execute(`SELECT url FROM moz_favicons`),
+                       /no such table: moz_favicons/,
                        "The moz_favicons table should not exist");
   for (let entry of gTestcases) {
     info("");
     info("Checking " + entry.icon_url + " - " + entry.page_url);
     let rows = await db.execute(`SELECT id, expire_ms, width FROM moz_icons
                                  WHERE fixed_icon_url_hash = hash(fixup_url(:icon_url))
                                    AND icon_url = :icon_url
                                  `, { icon_url: entry.icon_url });
--- a/toolkit/components/places/tests/sync/test_sync_utils.js
+++ b/toolkit/components/places/tests/sync/test_sync_utils.js
@@ -445,19 +445,21 @@ add_task(async function test_dedupe() {
     kind: "bookmark",
     recordId: makeGuid(),
     parentRecordId: parentFolder.recordId,
     url: "http://getthunderbird.com",
   });
 
   await Assert.rejects(
     PlacesSyncUtils.bookmarks.dedupe(makeGuid(), makeGuid(), makeGuid()),
+    /does not exist/,
     "Should reject attempts to de-dupe nonexistent items"
   );
   await Assert.rejects(PlacesSyncUtils.bookmarks.dedupe("menu", makeGuid(), "places"),
+    /Cannot de-dupe local root/,
     "Should reject attempts to de-dupe local roots");
 
   info("De-dupe with same remote parent");
   {
     let localId = await PlacesUtils.promiseItemId(mozBmk.recordId);
     let newRemoteRecordId = makeGuid();
 
     let changes = await PlacesSyncUtils.bookmarks.dedupe(
@@ -469,16 +471,17 @@ add_task(async function test_dedupe() {
     ok(changes[mozBmk.recordId].tombstone,
       "Should write tombstone for old local sync ID");
     ok(Object.values(changes).every(change => change.counter === 1),
       "Change counter for every bookmark should be 1");
 
     ok(!(await PlacesUtils.bookmarks.fetch(mozBmk.recordId)),
       "Bookmark with old local sync ID should not exist");
     await Assert.rejects(PlacesUtils.promiseItemId(mozBmk.recordId),
+      /no item found for the given GUID/,
       "Should invalidate GUID cache entry for old local sync ID");
 
     let newMozBmk = await PlacesUtils.bookmarks.fetch(newRemoteRecordId);
     equal(newMozBmk.guid, newRemoteRecordId,
       "Should change local sync ID to remote sync ID");
     equal(await PlacesUtils.promiseItemId(newRemoteRecordId), localId,
       "Should add new remote sync ID to GUID cache");
 
@@ -1044,17 +1047,17 @@ add_task(async function test_update_move
     equal(sameRoot.parentRecordId, "places",
       "Parent Places root GUID should not change");
   }
 
   info("Try reparenting root");
   await Assert.rejects(PlacesSyncUtils.bookmarks.update({
     recordId: "menu",
     parentRecordId: "toolbar",
-  }));
+  }), /Cannot move Places root/);
 
   await PlacesUtils.bookmarks.eraseEverything();
   await PlacesSyncUtils.bookmarks.reset();
 });
 
 add_task(async function test_insert() {
   info("Insert bookmark");
   {
@@ -1214,17 +1217,18 @@ add_task(async function test_update_live
         index: PlacesUtils.bookmarks.DEFAULT_INDEX,
       });
 
       // Since we're reinserting, we need to pass all properties required
       // for a new livemark. `update` won't merge the old and new ones.
       await Assert.rejects(PlacesSyncUtils.bookmarks.update({
         recordId: livemark.guid,
         feed: site + "/feed/2",
-      }), "Reinserting livemark with changed feed URL requires full record");
+      }), /reinsert: Invalid value for property 'feed'/,
+          "Reinserting livemark with changed feed URL requires full record");
 
       let newLivemark = await PlacesSyncUtils.bookmarks.update({
         kind: "livemark",
         parentRecordId: "menu",
         recordId: livemark.guid,
         feed: site + "/feed/2",
       });
       equal(newLivemark.recordId, livemark.guid,
@@ -1240,17 +1244,18 @@ add_task(async function test_update_live
         feedURI,
       });
       ok(livemark.feedURI.equals(feedURI), "Livemark feed URI should match");
       ok(!livemark.siteURI, "Livemark should not have site URI");
 
       await Assert.rejects(PlacesSyncUtils.bookmarks.update({
         recordId: livemark.guid,
         site,
-      }), "Reinserting livemark with new site URL requires full record");
+      }), /reinsert: Invalid value for property 'site'/,
+          "Reinserting livemark with new site URL requires full record");
 
       let newLivemark = await PlacesSyncUtils.bookmarks.update({
         kind: "livemark",
         parentRecordId: "menu",
         recordId: livemark.guid,
         feed: feedURI,
         site,
       });
@@ -1271,17 +1276,18 @@ add_task(async function test_update_live
         feedURI,
         siteURI: uri(site),
         index: PlacesUtils.bookmarks.DEFAULT_INDEX,
       });
 
       await Assert.rejects(PlacesSyncUtils.bookmarks.update({
         recordId: livemark.guid,
         site: null,
-      }), "Reinserting livemark witout site URL requires full record");
+      }), /reinsert: Invalid value for property 'site'/,
+          "Reinserting livemark witout site URL requires full record");
 
       let newLivemark = await PlacesSyncUtils.bookmarks.update({
         kind: "livemark",
         parentRecordId: "menu",
         recordId: livemark.guid,
         feed: feedURI,
         site: null,
       });
@@ -1299,17 +1305,18 @@ add_task(async function test_update_live
         feedURI,
         siteURI: uri(site),
         index: PlacesUtils.bookmarks.DEFAULT_INDEX,
       });
 
       await Assert.rejects(PlacesSyncUtils.bookmarks.update({
         recordId: livemark.guid,
         site: site + "/new",
-      }), "Reinserting livemark with changed site URL requires full record");
+      }), /reinsert: Invalid value for property 'site'/,
+          "Reinserting livemark with changed site URL requires full record");
 
       let newLivemark = await PlacesSyncUtils.bookmarks.update({
         kind: "livemark",
         parentRecordId: "menu",
         recordId: livemark.guid,
         feed: feedURI,
         site: site + "/new",
       });
--- a/toolkit/components/places/tests/unifiedcomplete/test_extension_matches.js
+++ b/toolkit/components/places/tests/unifiedcomplete/test_extension_matches.js
@@ -12,131 +12,155 @@ add_task(async function test_correct_err
   let keyword = "foo";
   let anotherKeyword = "bar";
   let unregisteredKeyword = "baz";
 
   // Register a keyword.
   ExtensionSearchHandler.registerKeyword(keyword, { emit: () => {} });
 
   // Try registering the keyword again.
-  Assert.throws(() => ExtensionSearchHandler.registerKeyword(keyword, { emit: () => {} }));
+  Assert.throws(() => ExtensionSearchHandler.registerKeyword(keyword, { emit: () => {} }),
+    /The keyword provided is already registered/);
 
   // Register a different keyword.
   ExtensionSearchHandler.registerKeyword(anotherKeyword, { emit: () => {} });
 
   // Try calling handleSearch for an unregistered keyword.
-  Assert.throws(() => ExtensionSearchHandler.handleSearch(unregisteredKeyword, `${unregisteredKeyword} `, () => {}));
+  Assert.throws(() => ExtensionSearchHandler.handleSearch(unregisteredKeyword, `${unregisteredKeyword} `, () => {}),
+    /The keyword provided is not registered/);
 
   // Try calling handleSearch without a callback.
-  Assert.throws(() => ExtensionSearchHandler.handleSearch(unregisteredKeyword, `${unregisteredKeyword} `));
+  Assert.throws(() => ExtensionSearchHandler.handleSearch(unregisteredKeyword, `${unregisteredKeyword} `),
+    /The keyword provided is not registered/);
 
   // Try getting the description for a keyword which isn't registered.
-  Assert.throws(() => ExtensionSearchHandler.getDescription(unregisteredKeyword));
-
-  // Try getting the extension name for a keyword which isn't registered.
-  Assert.throws(() => ExtensionSearchHandler.getExtensionName(unregisteredKeyword));
+  Assert.throws(() => ExtensionSearchHandler.getDescription(unregisteredKeyword),
+    /The keyword provided is not registered/);
 
   // Try setting the default suggestion for a keyword which isn't registered.
-  Assert.throws(() => ExtensionSearchHandler.setDefaultSuggestion(unregisteredKeyword, "suggestion"));
+  Assert.throws(() => ExtensionSearchHandler.setDefaultSuggestion(unregisteredKeyword, "suggestion"),
+    /The keyword provided is not registered/);
 
   // Try calling handleInputCancelled when there is no active input session.
-  Assert.throws(() => ExtensionSearchHandler.handleInputCancelled());
+  Assert.throws(() => ExtensionSearchHandler.handleInputCancelled(),
+    /There is no active input session/);
 
   // Try calling handleInputEntered when there is no active input session.
-  Assert.throws(() => ExtensionSearchHandler.handleInputEntered(anotherKeyword, `${anotherKeyword} test`, "tab"));
+  Assert.throws(() => ExtensionSearchHandler.handleInputEntered(anotherKeyword, `${anotherKeyword} test`, "tab"),
+    /There is no active input session/);
 
   // Start a session by calling handleSearch with the registered keyword.
   ExtensionSearchHandler.handleSearch(keyword, `${keyword} test`, () => {});
 
   // Try providing suggestions for an unregistered keyword.
-  Assert.throws(() => ExtensionSearchHandler.addSuggestions(unregisteredKeyword, 0, []));
+  Assert.throws(() => ExtensionSearchHandler.addSuggestions(unregisteredKeyword, 0, []),
+    /The keyword provided is not registered/);
 
   // Try providing suggestions for an inactive keyword.
-  Assert.throws(() => ExtensionSearchHandler.addSuggestions(anotherKeyword, 0, []));
+  Assert.throws(() => ExtensionSearchHandler.addSuggestions(anotherKeyword, 0, []),
+    /The keyword provided is not apart of an active input session/);
 
   // Try calling handleSearch for an inactive keyword.
-  Assert.throws(() => ExtensionSearchHandler.handleSearch(anotherKeyword, `${anotherKeyword} `, () => {}));
+  Assert.throws(() => ExtensionSearchHandler.handleSearch(anotherKeyword, `${anotherKeyword} `, () => {}),
+    /A different input session is already ongoing/);
 
   // Try calling addSuggestions with an old callback ID.
-  Assert.throws(() => ExtensionSearchHandler.addSuggestions(keyword, 0, []));
+  Assert.throws(() => ExtensionSearchHandler.addSuggestions(keyword, 0, []),
+    /The callback is no longer active for the keyword provided/);
 
   // Add suggestions with a valid callback ID.
   ExtensionSearchHandler.addSuggestions(keyword, 1, []);
 
   // Add suggestions again with a valid callback ID.
   ExtensionSearchHandler.addSuggestions(keyword, 1, []);
 
   // Try calling addSuggestions with a future callback ID.
-  Assert.throws(() => ExtensionSearchHandler.addSuggestions(keyword, 2, []));
+  Assert.throws(() => ExtensionSearchHandler.addSuggestions(keyword, 2, []),
+    /The callback is no longer active for the keyword provided/);
 
   // End the input session by calling handleInputCancelled.
   ExtensionSearchHandler.handleInputCancelled();
 
   // Try calling handleInputCancelled after the session has ended.
-  Assert.throws(() => ExtensionSearchHandler.handleInputCancelled());
+  Assert.throws(() => ExtensionSearchHandler.handleInputCancelled(),
+    /There is no active input sessio/);
 
   // Try calling handleSearch that doesn't have a space after the keyword.
-  Assert.throws(() => ExtensionSearchHandler.handleSearch(anotherKeyword, `${anotherKeyword}`, () => {}));
+  Assert.throws(() => ExtensionSearchHandler.handleSearch(anotherKeyword, `${anotherKeyword}`, () => {}),
+    /The text provided must start with/);
 
   // Try calling handleSearch with text starting with the wrong keyword.
-  Assert.throws(() => ExtensionSearchHandler.handleSearch(anotherKeyword, `${keyword} test`, () => {}));
+  Assert.throws(() => ExtensionSearchHandler.handleSearch(anotherKeyword, `${keyword} test`, () => {}),
+    /The text provided must start with/);
 
   // Start a new session by calling handleSearch with a different keyword
   ExtensionSearchHandler.handleSearch(anotherKeyword, `${anotherKeyword} test`, () => {});
 
   // Try adding suggestions again with the same callback ID now that the input session has ended.
-  Assert.throws(() => ExtensionSearchHandler.addSuggestions(keyword, 1, []));
+  Assert.throws(() => ExtensionSearchHandler.addSuggestions(keyword, 1, []),
+    /The keyword provided is not apart of an active input session/);
 
   // Add suggestions with a valid callback ID.
   ExtensionSearchHandler.addSuggestions(anotherKeyword, 2, []);
 
   // Try adding suggestions with a valid callback ID but a different keyword.
-  Assert.throws(() => ExtensionSearchHandler.addSuggestions(keyword, 2, []));
+  Assert.throws(() => ExtensionSearchHandler.addSuggestions(keyword, 2, []),
+    /The keyword provided is not apart of an active input session/);
 
   // Try adding suggestions with a valid callback ID but an unregistered keyword.
-  Assert.throws(() => ExtensionSearchHandler.addSuggestions(unregisteredKeyword, 2, []));
+  Assert.throws(() => ExtensionSearchHandler.addSuggestions(unregisteredKeyword, 2, []),
+    /The keyword provided is not registered/);
 
   // Set the default suggestion.
   ExtensionSearchHandler.setDefaultSuggestion(anotherKeyword, {description: "test result"});
 
   // Try ending the session using handleInputEntered with a different keyword.
-  Assert.throws(() => ExtensionSearchHandler.handleInputEntered(keyword, `${keyword} test`, "tab"));
+  Assert.throws(() => ExtensionSearchHandler.handleInputEntered(keyword, `${keyword} test`, "tab"),
+    /A different input session is already ongoing/);
 
   // Try calling handleInputEntered with invalid text.
-  Assert.throws(() => ExtensionSearchHandler.handleInputEntered(anotherKeyword, ` test`, "tab"));
+  Assert.throws(() => ExtensionSearchHandler.handleInputEntered(anotherKeyword, ` test`, "tab"),
+    /The text provided must start with/);
 
   // Try calling handleInputEntered with an invalid disposition.
-  Assert.throws(() => ExtensionSearchHandler.handleInputEntered(anotherKeyword, `${anotherKeyword} test`, "invalid"));
+  Assert.throws(() => ExtensionSearchHandler.handleInputEntered(anotherKeyword, `${anotherKeyword} test`, "invalid"),
+    /Invalid "where" argument/);
 
   // End the session by calling handleInputEntered.
   ExtensionSearchHandler.handleInputEntered(anotherKeyword, `${anotherKeyword} test`, "tab");
 
   // Try calling handleInputEntered after the session has ended.
-  Assert.throws(() => ExtensionSearchHandler.handleInputEntered(anotherKeyword, `${anotherKeyword} test`, "tab"));
+  Assert.throws(() => ExtensionSearchHandler.handleInputEntered(anotherKeyword, `${anotherKeyword} test`, "tab"),
+    /There is no active input session/);
 
   // Unregister the keyword.
   ExtensionSearchHandler.unregisterKeyword(keyword);
 
   // Try setting the default suggestion for the unregistered keyword.
-  Assert.throws(() => ExtensionSearchHandler.setDefaultSuggestion(keyword, {description: "test"}));
+  Assert.throws(() => ExtensionSearchHandler.setDefaultSuggestion(keyword, {description: "test"}),
+    /The keyword provided is not registered/);
 
   // Try handling a search with the unregistered keyword.
-  Assert.throws(() => ExtensionSearchHandler.handleSearch(keyword, `${keyword} test`, () => {}));
+  Assert.throws(() => ExtensionSearchHandler.handleSearch(keyword, `${keyword} test`, () => {}),
+    /The keyword provided is not registered/);
 
   // Try unregistering the keyword again.
-  Assert.throws(() => ExtensionSearchHandler.unregisterKeyword(keyword));
+  Assert.throws(() => ExtensionSearchHandler.unregisterKeyword(keyword),
+    /The keyword provided is not registered/);
 
   // Unregister the other keyword.
   ExtensionSearchHandler.unregisterKeyword(anotherKeyword);
 
   // Try unregistering the word which was never registered.
-  Assert.throws(() => ExtensionSearchHandler.unregisterKeyword(unregisteredKeyword));
+  Assert.throws(() => ExtensionSearchHandler.unregisterKeyword(unregisteredKeyword),
+    /The keyword provided is not registered/);
 
   // Try setting the default suggestion for a word that was never registered.
-  Assert.throws(() => ExtensionSearchHandler.setDefaultSuggestion(unregisteredKeyword, {description: "test"}));
+  Assert.throws(() => ExtensionSearchHandler.setDefaultSuggestion(unregisteredKeyword, {description: "test"}),
+    /The keyword provided is not registered/);
 
   await cleanup();
 });
 
 add_task(async function test_correct_events_are_emitted() {
   let events = [];
   function checkEvents(expectedEvents) {
     Assert.equal(events.length, expectedEvents.length, "The correct number of events fired");
--- a/toolkit/components/places/tests/unit/test_async_transactions.js
+++ b/toolkit/components/places/tests/unit/test_async_transactions.js
@@ -1757,23 +1757,26 @@ add_task(async function test_copy_exclud
   await PT.undo();
   await PT.clearTransactionsHistory();
 });
 
 add_task(async function test_invalid_uri_spec_throws() {
   Assert.throws(() =>
     PT.NewBookmark({ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
                      url:        "invalid uri spec",
-                     title:      "test bookmark" }));
+                     title:      "test bookmark"}),
+                    /invalid uri spec is not a valid URL/);
   Assert.throws(() =>
     PT.Tag({ tag: "TheTag",
-             urls: ["invalid uri spec"] }));
+             urls: ["invalid uri spec"] }),
+           /TypeError: invalid uri spec is not a valid URL/);
   Assert.throws(() =>
     PT.Tag({ tag: "TheTag",
-             urls: ["about:blank", "invalid uri spec"] }));
+             urls: ["about:blank", "invalid uri spec"] }),
+           /TypeError: invalid uri spec is not a valid URL/);
 });
 
 add_task(async function test_annotate_multiple_items() {
   let parentGuid = menuGuid;
   let guids = [
     await PT.NewBookmark({ url: "about:blank", parentGuid }).transact(),
     await PT.NewFolder({ title: "Test Folder", parentGuid }).transact()];