michael@0: /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // Get history service michael@0: try { michael@0: var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsINavHistoryService); michael@0: } catch(ex) { michael@0: do_throw("Could not get history service\n"); michael@0: } michael@0: michael@0: var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. michael@0: getService(Ci.nsINavBookmarksService); michael@0: michael@0: // main michael@0: function run_test() { michael@0: // add a folder michael@0: var folder = bmsvc.createFolder(bmsvc.placesRoot, "test folder", bmsvc.DEFAULT_INDEX); michael@0: michael@0: // add a bookmark to the folder michael@0: var b1 = bmsvc.insertBookmark(folder, uri("http://a1.com/"), michael@0: bmsvc.DEFAULT_INDEX, "1 title"); michael@0: // add a subfolder michael@0: var sf1 = bmsvc.createFolder(folder, "subfolder 1", bmsvc.DEFAULT_INDEX); michael@0: michael@0: // add a bookmark to the subfolder michael@0: var b2 = bmsvc.insertBookmark(sf1, uri("http://a2.com/"), michael@0: bmsvc.DEFAULT_INDEX, "2 title"); michael@0: michael@0: // add a subfolder to the subfolder michael@0: var sf2 = bmsvc.createFolder(sf1, "subfolder 2", bmsvc.DEFAULT_INDEX); michael@0: michael@0: // add a bookmark to the subfolder of the subfolder michael@0: var b3 = bmsvc.insertBookmark(sf2, uri("http://a3.com/"), michael@0: bmsvc.DEFAULT_INDEX, "3 title"); michael@0: michael@0: // bookmark query that should result in the "hierarchical" result michael@0: // because there is one query, one folder, michael@0: // no begin time, no end time, no domain, no uri, no search term michael@0: // and no max results. See GetSimpleBookmarksQueryFolder() michael@0: // for more details. michael@0: var options = histsvc.getNewQueryOptions(); michael@0: options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS; michael@0: var query = histsvc.getNewQuery(); michael@0: query.setFolders([folder], 1); michael@0: var result = histsvc.executeQuery(query, options); michael@0: var root = result.root; michael@0: root.containerOpen = true; michael@0: do_check_eq(root.childCount, 2); michael@0: do_check_eq(root.getChild(0).itemId, b1); michael@0: do_check_eq(root.getChild(1).itemId, sf1); michael@0: michael@0: // check the contents of the subfolder michael@0: var sf1Node = root.getChild(1); michael@0: sf1Node = sf1Node.QueryInterface(Ci.nsINavHistoryContainerResultNode); michael@0: sf1Node.containerOpen = true; michael@0: do_check_eq(sf1Node.childCount, 2); michael@0: do_check_eq(sf1Node.getChild(0).itemId, b2); michael@0: do_check_eq(sf1Node.getChild(1).itemId, sf2); michael@0: michael@0: // check the contents of the subfolder's subfolder michael@0: var sf2Node = sf1Node.getChild(1); michael@0: sf2Node = sf2Node.QueryInterface(Ci.nsINavHistoryContainerResultNode); michael@0: sf2Node.containerOpen = true; michael@0: do_check_eq(sf2Node.childCount, 1); michael@0: do_check_eq(sf2Node.getChild(0).itemId, b3); michael@0: michael@0: sf2Node.containerOpen = false; michael@0: sf1Node.containerOpen = false; michael@0: root.containerOpen = false; michael@0: michael@0: // bookmark query that should result in a flat list michael@0: // because we specified max results michael@0: var options = histsvc.getNewQueryOptions(); michael@0: options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS; michael@0: options.maxResults = 10; michael@0: var query = histsvc.getNewQuery(); michael@0: query.setFolders([folder], 1); michael@0: var result = histsvc.executeQuery(query, options); michael@0: var root = result.root; michael@0: root.containerOpen = true; michael@0: do_check_eq(root.childCount, 3); michael@0: do_check_eq(root.getChild(0).itemId, b1); michael@0: do_check_eq(root.getChild(1).itemId, b2); michael@0: do_check_eq(root.getChild(2).itemId, b3); michael@0: root.containerOpen = false; michael@0: michael@0: // XXX TODO michael@0: // test that if we have: more than one query, michael@0: // multiple folders, a begin time, an end time, a domain, a uri michael@0: // or a search term, that we get the (correct) flat list results michael@0: // (like we do when specified maxResults) michael@0: }