diff --git a/toolkit/components/places/nsNavHistory.cpp b/toolkit/components/places/nsNavHistory.cpp index 41d8784905c..324b04c6414 100644 --- a/toolkit/components/places/nsNavHistory.cpp +++ b/toolkit/components/places/nsNavHistory.cpp @@ -3381,6 +3381,8 @@ nsNavHistory::QueryToSelectClause(nsNavHistoryQuery* aQuery, // const // folders const nsTArray& folders = aQuery->Folders(); if (folders.Length() > 0) { + aOptions->SetQueryType(nsNavHistoryQueryOptions::QUERY_TYPE_BOOKMARKS); + nsTArray includeFolders; includeFolders.AppendElements(folders); diff --git a/toolkit/components/places/tests/queries/test_queryMultipleFolder.js b/toolkit/components/places/tests/queries/test_queryMultipleFolder.js new file mode 100644 index 00000000000..b238d7eea0b --- /dev/null +++ b/toolkit/components/places/tests/queries/test_queryMultipleFolder.js @@ -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; +}); \ No newline at end of file diff --git a/toolkit/components/places/tests/queries/xpcshell.ini b/toolkit/components/places/tests/queries/xpcshell.ini index 7eee28ab61c..401612c57c5 100644 --- a/toolkit/components/places/tests/queries/xpcshell.ini +++ b/toolkit/components/places/tests/queries/xpcshell.ini @@ -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