Bug 1293445 - Part 3: Fix SelectAsTag and add test. r?mak
MozReview-Commit-ID: 1moKKP7bElh
--- a/toolkit/components/places/nsNavHistory.cpp
+++ b/toolkit/components/places/nsNavHistory.cpp
@@ -1883,23 +1883,22 @@ 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 || '&queryType=%d', "
"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]