Bug 1421664 - 2 - Change SelectAsTag to use place: tag queries. r=mak draft
authormilindl <i.milind.luthra@gmail.com>
Tue, 20 Mar 2018 17:27:44 +0100
changeset 774813 e943690591ad87b256323bfe1b40f7bfca6c6beb
parent 774812 c8e1174f77e5b4c15b09eacecae06a54b7fb5f4e
child 774814 359627a6564a6746bfaeea175e3977b6eb9d8652
child 775140 10066aa0bdb6a598fc6af638fed455d58422b7fb
push id104515
push usermak77@bonardo.net
push dateThu, 29 Mar 2018 16:37:36 +0000
reviewersmak
bugs1421664
milestone61.0a1
Bug 1421664 - 2 - Change SelectAsTag to use place: tag queries. r=mak MozReview-Commit-ID: JauduB7A5TZ
toolkit/components/places/nsNavHistory.cpp
toolkit/components/places/tests/queries/test_results-as-tag-query.js
toolkit/components/places/tests/queries/xpcshell.ini
--- a/toolkit/components/places/nsNavHistory.cpp
+++ b/toolkit/components/places/nsNavHistory.cpp
@@ -1650,23 +1650,21 @@ PlacesSQLQueryBuilder::SelectAsTag()
   nsNavHistory *history = nsNavHistory::GetHistoryService();
   NS_ENSURE_STATE(history);
 
   // This allows sorting by date fields what is not possible with
   // other history queries.
   mHasDateColumns = true;
 
   mQueryString = nsPrintfCString(
-    "SELECT null, 'place:folder=' || id || '&queryType=%d&type=%d', "
+    "SELECT null, 'place:tag=' || title, "
            "title, null, null, null, null, null, dateAdded, "
            "lastModified, null, null, null, null, null, null "
     "FROM moz_bookmarks "
     "WHERE parent = %" PRId64,
-    nsINavHistoryQueryOptions::QUERY_TYPE_BOOKMARKS,
-    nsINavHistoryQueryOptions::RESULTS_AS_TAG_CONTENTS,
     history->GetTagsFolder()
   );
 
   return NS_OK;
 }
 
 nsresult
 PlacesSQLQueryBuilder::SelectAsRoots()
new file mode 100644
--- /dev/null
+++ b/toolkit/components/places/tests/queries/test_results-as-tag-query.js
@@ -0,0 +1,57 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+const testData = {
+  "http://foo.com/": ["tag1", "tag 2", "Space ☺️ Between"].sort(),
+  "http://bar.com/": ["tag1", "tag 2"].sort(),
+  "http://baz.com/": ["tag 2", "Space ☺️ Between"].sort(),
+  "http://qux.com/": ["Space ☺️ Between"]
+};
+
+const formattedTestData = [];
+for (const [uri, tagArray] of Object.entries(testData)) {
+  formattedTestData.push({
+    title: `Title of ${uri}`,
+    uri,
+    isBookmark: true,
+    isTag: true,
+    tagArray
+  });
+}
+
+add_task(async function test_results_as_tag_query() {
+  await task_populateDB(formattedTestData);
+
+  // Construct URL - tag mapping from tag query.
+  const actualData = {};
+  for (const uri in testData) {
+    if (testData.hasOwnProperty(uri)) {
+      actualData[uri] = [];
+    }
+  }
+
+  const options = PlacesUtils.history.getNewQueryOptions();
+  options.resultType = options.RESULTS_AS_TAG_QUERY;
+  const query = PlacesUtils.history.getNewQuery();
+  const root = PlacesUtils.history.executeQuery(query, options).root;
+
+  root.containerOpen = true;
+  Assert.equal(root.childCount, 3, "We should get as many results as tags.");
+  displayResultSet(root);
+
+  for (let i = 0; i < root.childCount; ++i) {
+    const node = root.getChild(i);
+    const tagName = node.title;
+    Assert.equal(node.type, node.RESULT_TYPE_QUERY,
+                 "Result type should be RESULT_TYPE_QUERY.");
+    const subRoot = node.QueryInterface(Ci.nsINavHistoryContainerResultNode);
+    subRoot.containerOpen = true;
+    for (let j = 0; j < subRoot.childCount; ++j) {
+      actualData[subRoot.getChild(j).uri].push(tagName);
+      actualData[subRoot.getChild(j).uri].sort();
+    }
+  }
+
+  Assert.deepEqual(actualData, testData,
+                   "URI-tag mapping should be same from query and initial data.");
+});
--- a/toolkit/components/places/tests/queries/xpcshell.ini
+++ b/toolkit/components/places/tests/queries/xpcshell.ini
@@ -15,16 +15,17 @@ skip-if = (os == 'win' && ccov) # Bug 14
 [test_onlyBookmarked.js]
 [test_options_inherit.js]
 [test_queryMultipleFolder.js]
 [test_querySerialization.js]
 [test_redirects.js]
 [test_results-as-left-pane.js]
 [test_results-as-roots.js]
 [test_results-as-tag-contents-query.js]
+[test_results-as-tag-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]