Bug 1329926 - Remove deprecated API getURIForKeyword and updated test cases for PlacesUtils.keywords.fetch(). r=mak
authorMayank Srivastav <mayanksri18@yahoo.in>
Mon, 16 Jan 2017 19:59:19 +0530
changeset 374623 7feb3cffb4a2a413f19176e09ecb98b3ffe57667
parent 374622 1e4e9cc1920c6c41c2ae878603fe94ed4460d8a3
child 374624 0878ddbf3dd461b10f044a3ec0783a63eeb88355
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1329926
milestone53.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 1329926 - Remove deprecated API getURIForKeyword and updated test cases for PlacesUtils.keywords.fetch(). r=mak
toolkit/components/places/nsINavBookmarksService.idl
toolkit/components/places/nsNavBookmarks.cpp
toolkit/components/places/tests/bookmarks/test_bookmarks.js
toolkit/components/places/tests/bookmarks/test_keywords.js
toolkit/components/places/tests/unit/test_keywords.js
--- a/toolkit/components/places/nsINavBookmarksService.idl
+++ b/toolkit/components/places/nsINavBookmarksService.idl
@@ -664,25 +664,16 @@ interface nsINavBookmarksService : nsISu
 
   /**
    * Retrieves the keyword for the given bookmark. Will be void string
    * (null in JS) if no such keyword is found.
    *
    * @deprecated Use PlacesUtils.keywords.fetch() API instead.
    */
   AString getKeywordForBookmark(in long long aItemId);
-
-  /**
-   * Returns the URI associated with the given keyword. Empty if no such
-   * keyword is found.
-   *
-   * @deprecated Use PlacesUtils.keywords.fetch() API instead.
-   */
-  nsIURI getURIForKeyword(in AString keyword);
-
   /**
    * Adds a bookmark observer. If ownsWeak is false, the bookmark service will
    * keep an owning reference to the observer.  If ownsWeak is true, then
    * aObserver must implement nsISupportsWeakReference, and the bookmark
    * service will keep a weak reference to the observer.
    */
   void addObserver(in nsINavBookmarkObserver observer, in boolean ownsWeak);
 
--- a/toolkit/components/places/nsNavBookmarks.cpp
+++ b/toolkit/components/places/nsNavBookmarks.cpp
@@ -3040,57 +3040,16 @@ nsNavBookmarks::GetKeywordForBookmark(in
 
   aKeyword.SetIsVoid(true);
 
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
-nsNavBookmarks::GetURIForKeyword(const nsAString& aUserCasedKeyword,
-                                 nsIURI** aURI)
-{
-  NS_ENSURE_ARG_POINTER(aURI);
-  NS_ENSURE_TRUE(!aUserCasedKeyword.IsEmpty(), NS_ERROR_INVALID_ARG);
-  *aURI = nullptr;
-
-  PLACES_WARN_DEPRECATED();
-
-  // Shortcuts are always lowercased internally.
-  nsAutoString keyword(aUserCasedKeyword);
-  ToLowerCase(keyword);
-
-  nsCOMPtr<mozIStorageStatement> stmt = mDB->GetStatement(NS_LITERAL_CSTRING(
-    "SELECT h.url "
-    "FROM moz_places h "
-    "JOIN moz_keywords k ON k.place_id = h.id "
-    "WHERE k.keyword = :keyword"
-  ));
-  NS_ENSURE_STATE(stmt);
-  mozStorageStatementScoper scoper(stmt);
-
-  nsresult rv = stmt->BindStringByName(NS_LITERAL_CSTRING("keyword"), keyword);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  bool hasMore;
-  if (NS_SUCCEEDED(stmt->ExecuteStep(&hasMore)) && hasMore) {
-    nsAutoCString spec;
-    rv = stmt->GetUTF8String(0, spec);
-    NS_ENSURE_SUCCESS(rv, rv);
-    nsCOMPtr<nsIURI> uri;
-    rv = NS_NewURI(getter_AddRefs(uri), spec);
-    NS_ENSURE_SUCCESS(rv, rv);
-    uri.forget(aURI);
-  }
-
-  return NS_OK;
-}
-
-
-NS_IMETHODIMP
 nsNavBookmarks::RunInBatchMode(nsINavHistoryBatchCallback* aCallback,
                                nsISupports* aUserData) {
   PROFILER_LABEL("nsNavBookmarks", "RunInBatchMode",
     js::ProfileEntry::Category::OTHER);
 
   NS_ENSURE_ARG(aCallback);
 
   mBatching = true;
--- a/toolkit/components/places/tests/bookmarks/test_bookmarks.js
+++ b/toolkit/components/places/tests/bookmarks/test_bookmarks.js
@@ -324,20 +324,19 @@ add_task(function* test_bookmarks() {
   let kwTestItemId = bs.insertBookmark(testRoot, uri("http://keywordtest.com"),
                                        bs.DEFAULT_INDEX, "");
   bs.setKeywordForBookmark(kwTestItemId, "bar");
 
   // test getKeywordForBookmark
   let k = bs.getKeywordForBookmark(kwTestItemId);
   do_check_eq("bar", k);
 
-  // test getURIForKeyword
-  let u = bs.getURIForKeyword("bar");
-  do_check_eq("http://keywordtest.com/", u.spec);
-
+  // test PlacesUtils.keywords.fetch()
+  let u = yield PlacesUtils.keywords.fetch("bar");
+  do_check_eq("http://keywordtest.com/", u.url);
   // test removeFolderChildren
   // 1) add/remove each child type (bookmark, separator, folder)
   tmpFolder = bs.createFolder(testRoot, "removeFolderChildren",
                               bs.DEFAULT_INDEX);
   bs.insertBookmark(tmpFolder, uri("http://foo9.com/"), bs.DEFAULT_INDEX, "");
   bs.createFolder(tmpFolder, "subfolder", bs.DEFAULT_INDEX);
   bs.insertSeparator(tmpFolder, bs.DEFAULT_INDEX);
   // 2) confirm that folder has 3 children
--- a/toolkit/components/places/tests/bookmarks/test_keywords.js
+++ b/toolkit/components/places/tests/bookmarks/test_keywords.js
@@ -1,31 +1,31 @@
 const URI1 = NetUtil.newURI("http://test1.mozilla.org/");
 const URI2 = NetUtil.newURI("http://test2.mozilla.org/");
 const URI3 = NetUtil.newURI("http://test3.mozilla.org/");
 
-function check_keyword(aURI, aKeyword) {
+function* check_keyword(aURI, aKeyword) {
   if (aKeyword)
     aKeyword = aKeyword.toLowerCase();
 
   for (let bm of PlacesUtils.getBookmarksForURI(aURI)) {
     let keyword = PlacesUtils.bookmarks.getKeywordForBookmark(bm);
     if (keyword && !aKeyword) {
       throw (`${aURI.spec} should not have a keyword`);
     } else if (aKeyword && keyword == aKeyword) {
       Assert.equal(keyword, aKeyword);
     }
   }
 
   if (aKeyword) {
-    let uri = PlacesUtils.bookmarks.getURIForKeyword(aKeyword);
-    Assert.equal(uri.spec, aURI.spec);
+    let uri = yield PlacesUtils.keywords.fetch(aKeyword);
+    Assert.equal(uri.url, aURI.spec);
     // Check case insensitivity.
-    uri = PlacesUtils.bookmarks.getURIForKeyword(aKeyword.toUpperCase());
-    Assert.equal(uri.spec, aURI.spec);
+    uri = yield PlacesUtils.keywords.fetch(aKeyword.toUpperCase());
+    Assert.equal(uri.url, aURI.spec);
   }
 }
 
 function* check_orphans() {
   let db = yield PlacesUtils.promiseDBConnection();
   let rows = yield db.executeCached(
     `SELECT id FROM moz_keywords k
      WHERE NOT EXISTS (SELECT 1 FROM moz_places WHERE id = k.place_id)
@@ -61,20 +61,16 @@ function expectNotifications() {
       return target[name];
     }
   });
   PlacesUtils.bookmarks.addObserver(observer, false);
   return observer;
 }
 
 add_task(function test_invalid_input() {
-  Assert.throws(() => PlacesUtils.bookmarks.getURIForKeyword(null),
-                /NS_ERROR_ILLEGAL_VALUE/);
-  Assert.throws(() => PlacesUtils.bookmarks.getURIForKeyword(""),
-                /NS_ERROR_ILLEGAL_VALUE/);
   Assert.throws(() => PlacesUtils.bookmarks.getKeywordForBookmark(null),
                 /NS_ERROR_ILLEGAL_VALUE/);
   Assert.throws(() => PlacesUtils.bookmarks.getKeywordForBookmark(0),
                 /NS_ERROR_ILLEGAL_VALUE/);
   Assert.throws(() => PlacesUtils.bookmarks.setKeywordForBookmark(null, "k"),
                 /NS_ERROR_ILLEGAL_VALUE/);
   Assert.throws(() => PlacesUtils.bookmarks.setKeywordForBookmark(0, "k"),
                 /NS_ERROR_ILLEGAL_VALUE/);
--- a/toolkit/components/places/tests/unit/test_keywords.js
+++ b/toolkit/components/places/tests/unit/test_keywords.js
@@ -514,17 +514,20 @@ add_task(function* test_oldKeywordsAPI()
   yield promiseKeyword("keyword", "http://example.com/");
 
   // Remove the keyword.
   PlacesUtils.bookmarks.setKeywordForBookmark(itemId, "");
   yield promiseKeyword("keyword", null);
 
   yield PlacesUtils.keywords.insert({ keyword: "keyword", url: "http://example.com" });
   Assert.equal(PlacesUtils.bookmarks.getKeywordForBookmark(itemId), "keyword");
-  Assert.equal(PlacesUtils.bookmarks.getURIForKeyword("keyword").spec, "http://example.com/");
+
+  let entry = yield PlacesUtils.keywords.fetch("keyword");
+  Assert.equal(entry.url, "http://example.com/");
+
   yield PlacesUtils.bookmarks.remove(bookmark);
 
   check_no_orphans();
 });
 
 add_task(function* test_bookmarkURLChange() {
   let fc1 = yield foreign_count("http://example1.com/");
   let fc2 = yield foreign_count("http://example2.com/");