Bug 1421664 - 2 - Change SelectAsTag to use place: tag queries. r=mak
authormilindl <i.milind.luthra@gmail.com>
Tue, 20 Mar 2018 17:27:44 +0100
changeset 410769 4b1ce6bf8518e00a5c5125d905173d28a11e72e2
parent 410768 7f8bb8f9998e0cd3a7c76e10bb3d47ec3c85fb6e
child 410770 147023fe220ca9b4235aa2900972a4affc79bab3
push id33739
push usernbeleuzu@mozilla.com
push dateFri, 30 Mar 2018 21:47:45 +0000
treeherdermozilla-central@10c662d8416e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1421664
milestone61.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 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]