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 bookmark service michael@0: try { michael@0: var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].getService(Ci.nsINavBookmarksService); michael@0: } catch(ex) { michael@0: do_throw("Could not get nav-bookmarks-service\n"); michael@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: // Get tagging service michael@0: try { michael@0: var tagssvc = Cc["@mozilla.org/browser/tagging-service;1"]. michael@0: getService(Ci.nsITaggingService); michael@0: } catch(ex) { michael@0: do_throw("Could not get tagging service\n"); michael@0: } michael@0: michael@0: // get bookmarks root id michael@0: var root = bmsvc.bookmarksMenuFolder; michael@0: michael@0: // main michael@0: function run_test() { michael@0: // test searching for tagged bookmarks michael@0: michael@0: // test folder michael@0: var folder = bmsvc.createFolder(root, "bug 395101 test", bmsvc.DEFAULT_INDEX); michael@0: michael@0: // create a bookmark michael@0: var testURI = uri("http://a1.com"); michael@0: var b1 = bmsvc.insertBookmark(folder, testURI, michael@0: bmsvc.DEFAULT_INDEX, "1 title"); michael@0: michael@0: // tag the bookmarked URI michael@0: tagssvc.tagURI(testURI, ["elephant", "walrus", "giraffe", "turkey", "hiPPo", "BABOON", "alf"]); michael@0: michael@0: // search for the bookmark, using a tag michael@0: var query = histsvc.getNewQuery(); michael@0: query.searchTerms = "elephant"; michael@0: var options = histsvc.getNewQueryOptions(); michael@0: options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS; michael@0: query.setFolders([folder], 1); michael@0: michael@0: var result = histsvc.executeQuery(query, options); michael@0: var rootNode = result.root; michael@0: rootNode.containerOpen = true; michael@0: michael@0: do_check_eq(rootNode.childCount, 1); michael@0: do_check_eq(rootNode.getChild(0).itemId, b1); michael@0: rootNode.containerOpen = false; michael@0: michael@0: // partial matches are okay michael@0: query.searchTerms = "wal"; michael@0: var result = histsvc.executeQuery(query, options); michael@0: var rootNode = result.root; michael@0: rootNode.containerOpen = true; michael@0: do_check_eq(rootNode.childCount, 1); michael@0: rootNode.containerOpen = false; michael@0: michael@0: // case insensitive search term michael@0: query.searchTerms = "WALRUS"; michael@0: var result = histsvc.executeQuery(query, options); michael@0: var rootNode = result.root; michael@0: rootNode.containerOpen = true; michael@0: do_check_eq(rootNode.childCount, 1); michael@0: do_check_eq(rootNode.getChild(0).itemId, b1); michael@0: rootNode.containerOpen = false; michael@0: michael@0: // case insensitive tag michael@0: query.searchTerms = "baboon"; michael@0: var result = histsvc.executeQuery(query, options); michael@0: var rootNode = result.root; michael@0: rootNode.containerOpen = true; michael@0: do_check_eq(rootNode.childCount, 1); michael@0: do_check_eq(rootNode.getChild(0).itemId, b1); michael@0: rootNode.containerOpen = false; michael@0: }