Bug 334050 - Add a test for Places queries against multiple folders. r=mak

This commit is contained in:
Akshendra Pratap 2014-11-12 08:11:00 +01:00
parent 29ed1e782f
commit 1cc444bc8e
3 changed files with 60 additions and 0 deletions

View File

@ -3381,6 +3381,8 @@ nsNavHistory::QueryToSelectClause(nsNavHistoryQuery* aQuery, // const
// folders
const nsTArray<int64_t>& folders = aQuery->Folders();
if (folders.Length() > 0) {
aOptions->SetQueryType(nsNavHistoryQueryOptions::QUERY_TYPE_BOOKMARKS);
nsTArray<int64_t> includeFolders;
includeFolders.AppendElements(folders);

View File

@ -0,0 +1,57 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
function run_test() {
run_next_test();
}
add_task(function* test_queryMultipleFolders() {
// adding bookmarks in the folders
let folderIds = [];
let bookmarkIds = [];
for (let i = 0; i < 3; ++i) {
folderIds.push(PlacesUtils.bookmarks.createFolder(PlacesUtils.bookmarksMenuFolderId,
"Folder"+ i, PlacesUtils.bookmarks.DEFAULT_INDEX));
for(let j = 0; j < 7; ++j) {
bookmarkIds.push(PlacesUtils.bookmarks.insertBookmark(folderIds[i],
uri("http://Bookmark" + i + "_" + j + ".com"),
PlacesUtils.bookmarks.DEFAULT_INDEX, ""));
}
}
// using queryStringToQueries
let query = {};
let options = {};
let maxResults = 20;
let queryString = "place:" + folderIds.map((id) => {
return "folder=" + id;
}).join('&') + "&sort=5&maxResults=" + maxResults;
PlacesUtils.history.queryStringToQueries(queryString, query, {}, options);
let rootNode = PlacesUtils.history.executeQuery(query.value[0],options.value).root;
rootNode.containerOpen = true;
let resultLength = rootNode.childCount;
Assert.equal(resultLength, maxResults);
for (let i = 0; i < resultLength; ++i) {
let node = rootNode.getChild(i);
Assert.equal(bookmarkIds[i], node.itemId, node.uri);
}
rootNode.containerOpen = false;
// using getNewQuery and getNewQueryOptions
query = PlacesUtils.history.getNewQuery();
options = PlacesUtils.history.getNewQueryOptions();
query.setFolders(folderIds, folderIds.length);
options.sortingMode = options.SORT_BY_URI_ASCENDING;
options.maxResults = maxResults;
rootNode = PlacesUtils.history.executeQuery(query, options).root;
rootNode.containerOpen = true;
resultLength = rootNode.childCount;
Assert.equal(resultLength, maxResults);
for (let i = 0; i < resultLength; ++i) {
let node = rootNode.getChild(i);
Assert.equal(bookmarkIds[i], node.itemId, node.uri);
}
rootNode.containerOpen = false;
});

View File

@ -11,6 +11,7 @@ skip-if = toolkit == 'android' || toolkit == 'gonk'
[test_history_queries_tags_liveUpdate.js]
[test_history_queries_titles_liveUpdate.js]
[test_onlyBookmarked.js]
[test_queryMultipleFolder.js]
[test_querySerialization.js]
[test_redirects.js]
# Bug 676989: test hangs consistently on Android