Bug 1421664 - Part 2: Fix SelectAsTag and add test. draft
authorMilindL <i.milind.luthra@gmail.com>
Sun, 19 Nov 2017 22:33:42 +0530
changeset 705699 5e2d70ae96aa632a06ac17e615db528b67ebddf7
parent 705698 fbbf0bc4311601f0481e3a84a15c8634eada18e8
child 742427 a61580ea7d328c4e8eb25246a326c1633e742aef
push id91548
push userbmo:i.milind.luthra@gmail.com
push dateThu, 30 Nov 2017 14:18:29 +0000
bugs1421664
milestone58.0a1
Bug 1421664 - Part 2: Fix SelectAsTag and add test. MozReview-Commit-ID: JaMRXfkjjsw
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
@@ -1883,23 +1883,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::Where()
new file mode 100644
--- /dev/null
+++ b/toolkit/components/places/tests/queries/test_results-as-tag-query.js
@@ -0,0 +1,54 @@
+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
@@ -9,16 +9,17 @@ skip-if = toolkit == 'android'
 [test_containersQueries_sorting.js]
 [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-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]