Bug 1374776 - Convert toolkit/components/places/tests/bookmarks/test_395101.js to use the new Bookmarks async API. r?mak draft
authorMark Banner <standard8@mozilla.com>
Tue, 20 Jun 2017 21:11:09 +0100
changeset 598092 e8189bbacb338748d4c38bfc10a96d50ab8c464d
parent 595439 2a03a91b03e83300b37ad1768f02716e1c17a100
child 634412 157b1fe26021e7291ad9bef0d4012ccbe100cbe6
push id65135
push usermbanner@mozilla.com
push dateWed, 21 Jun 2017 11:31:11 +0000
reviewersmak
bugs1374776
milestone56.0a1
Bug 1374776 - Convert toolkit/components/places/tests/bookmarks/test_395101.js to use the new Bookmarks async API. r?mak MozReview-Commit-ID: 9JR0Se66Exj
toolkit/components/places/tests/bookmarks/test_395101.js
toolkit/components/places/tests/bookmarks/xpcshell.ini
toolkit/components/places/tests/queries/test_search_tags.js
toolkit/components/places/tests/queries/xpcshell.ini
--- a/toolkit/components/places/tests/bookmarks/xpcshell.ini
+++ b/toolkit/components/places/tests/bookmarks/xpcshell.ini
@@ -3,17 +3,16 @@ head = head_bookmarks.js
 skip-if = toolkit == 'android'
 
 [test_1016953-renaming-uncompressed.js]
 [test_1017502-bookmarks_foreign_count.js]
 [test_384228.js]
 [test_385829.js]
 [test_388695.js]
 [test_393498.js]
-[test_395101.js]
 [test_395593.js]
 [test_405938_restore_queries.js]
 [test_417228-exclude-from-backup.js]
 [test_417228-other-roots.js]
 [test_424958-json-quoted-folders.js]
 [test_448584.js]
 [test_458683.js]
 [test_466303-json-remove-backups.js]
rename from toolkit/components/places/tests/bookmarks/test_395101.js
rename to toolkit/components/places/tests/queries/test_search_tags.js
--- a/toolkit/components/places/tests/bookmarks/test_395101.js
+++ b/toolkit/components/places/tests/queries/test_search_tags.js
@@ -1,87 +1,65 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et: */
 /* 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/. */
 
-// Get bookmark service
-try {
-  var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].getService(Ci.nsINavBookmarksService);
-} catch (ex) {
-  do_throw("Could not get nav-bookmarks-service\n");
-}
-
-// Get history service
-try {
-  var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsINavHistoryService);
-} catch (ex) {
-  do_throw("Could not get history service\n");
-}
+add_task(async function test_search_for_tagged_bookmarks() {
+  const testURI = "http://a1.com";
 
-// Get tagging service
-try {
-  var tagssvc = Cc["@mozilla.org/browser/tagging-service;1"].
-                getService(Ci.nsITaggingService);
-} catch (ex) {
-  do_throw("Could not get tagging service\n");
-}
-
-// get bookmarks root id
-var root = bmsvc.bookmarksMenuFolder;
+  let folder = await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.menuGuid,
+    title: "bug 395101 test",
+    type: PlacesUtils.bookmarks.TYPE_FOLDER,
+  });
 
-// main
-function run_test() {
-  // test searching for tagged bookmarks
-
-  // test folder
-  var folder = bmsvc.createFolder(root, "bug 395101 test", bmsvc.DEFAULT_INDEX);
-
-  // create a bookmark
-  var testURI = uri("http://a1.com");
-  var b1 = bmsvc.insertBookmark(folder, testURI,
-                                bmsvc.DEFAULT_INDEX, "1 title");
+  let bookmark = await PlacesUtils.bookmarks.insert({
+    parentGuid: folder.guid,
+    title: "1 title",
+    url: testURI
+  });
 
   // tag the bookmarked URI
-  tagssvc.tagURI(testURI, ["elephant", "walrus", "giraffe", "turkey", "hiPPo", "BABOON", "alf"]);
+  PlacesUtils.tagging.tagURI(uri(testURI), ["elephant", "walrus", "giraffe", "turkey", "hiPPo", "BABOON", "alf"]);
 
   // search for the bookmark, using a tag
-  var query = histsvc.getNewQuery();
+  var query = PlacesUtils.history.getNewQuery();
   query.searchTerms = "elephant";
-  var options = histsvc.getNewQueryOptions();
+  var options = PlacesUtils.history.getNewQueryOptions();
   options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
   query.setFolders([folder], 1);
 
-  var result = histsvc.executeQuery(query, options);
+  var result = PlacesUtils.history.executeQuery(query, options);
   var rootNode = result.root;
   rootNode.containerOpen = true;
 
   do_check_eq(rootNode.childCount, 1);
-  do_check_eq(rootNode.getChild(0).itemId, b1);
+  do_check_eq(rootNode.getChild(0).bookmarkGuid, bookmark.guid);
   rootNode.containerOpen = false;
 
   // partial matches are okay
   query.searchTerms = "wal";
-  result = histsvc.executeQuery(query, options);
+  result = PlacesUtils.history.executeQuery(query, options);
   rootNode = result.root;
   rootNode.containerOpen = true;
   do_check_eq(rootNode.childCount, 1);
   rootNode.containerOpen = false;
 
   // case insensitive search term
   query.searchTerms = "WALRUS";
-  result = histsvc.executeQuery(query, options);
+  result = PlacesUtils.history.executeQuery(query, options);
   rootNode = result.root;
   rootNode.containerOpen = true;
   do_check_eq(rootNode.childCount, 1);
-  do_check_eq(rootNode.getChild(0).itemId, b1);
+  do_check_eq(rootNode.getChild(0).bookmarkGuid, bookmark.guid);
   rootNode.containerOpen = false;
 
   // case insensitive tag
   query.searchTerms = "baboon";
-  result = histsvc.executeQuery(query, options);
+  result = PlacesUtils.history.executeQuery(query, options);
   rootNode = result.root;
   rootNode.containerOpen = true;
   do_check_eq(rootNode.childCount, 1);
-  do_check_eq(rootNode.getChild(0).itemId, b1);
+  do_check_eq(rootNode.getChild(0).bookmarkGuid, bookmark.guid);
   rootNode.containerOpen = false;
-}
+});
--- a/toolkit/components/places/tests/queries/xpcshell.ini
+++ b/toolkit/components/places/tests/queries/xpcshell.ini
@@ -10,16 +10,17 @@ skip-if = toolkit == 'android'
 [test_history_queries_tags_liveUpdate.js]
 [test_history_queries_titles_liveUpdate.js]
 [test_onlyBookmarked.js]
 [test_queryMultipleFolder.js]
 [test_querySerialization.js]
 [test_redirects.js]
 [test_results-as-tag-contents-query.js]
 [test_results-as-visit.js]
+[test_search_tags.js]
 [test_searchterms-domain.js]
 [test_searchterms-uri.js]
 [test_searchterms-bookmarklets.js]
 [test_sort-date-site-grouping.js]
 [test_sorting.js]
 [test_tags.js]
 [test_transitions.js]
 [test_searchTerms_includeHidden.js]