1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/bookmarks/test_395101.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,87 @@ 1.4 +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +// Get bookmark service 1.11 +try { 1.12 + var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].getService(Ci.nsINavBookmarksService); 1.13 +} catch(ex) { 1.14 + do_throw("Could not get nav-bookmarks-service\n"); 1.15 +} 1.16 + 1.17 +// Get history service 1.18 +try { 1.19 + var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsINavHistoryService); 1.20 +} catch(ex) { 1.21 + do_throw("Could not get history service\n"); 1.22 +} 1.23 + 1.24 +// Get tagging service 1.25 +try { 1.26 + var tagssvc = Cc["@mozilla.org/browser/tagging-service;1"]. 1.27 + getService(Ci.nsITaggingService); 1.28 +} catch(ex) { 1.29 + do_throw("Could not get tagging service\n"); 1.30 +} 1.31 + 1.32 +// get bookmarks root id 1.33 +var root = bmsvc.bookmarksMenuFolder; 1.34 + 1.35 +// main 1.36 +function run_test() { 1.37 + // test searching for tagged bookmarks 1.38 + 1.39 + // test folder 1.40 + var folder = bmsvc.createFolder(root, "bug 395101 test", bmsvc.DEFAULT_INDEX); 1.41 + 1.42 + // create a bookmark 1.43 + var testURI = uri("http://a1.com"); 1.44 + var b1 = bmsvc.insertBookmark(folder, testURI, 1.45 + bmsvc.DEFAULT_INDEX, "1 title"); 1.46 + 1.47 + // tag the bookmarked URI 1.48 + tagssvc.tagURI(testURI, ["elephant", "walrus", "giraffe", "turkey", "hiPPo", "BABOON", "alf"]); 1.49 + 1.50 + // search for the bookmark, using a tag 1.51 + var query = histsvc.getNewQuery(); 1.52 + query.searchTerms = "elephant"; 1.53 + var options = histsvc.getNewQueryOptions(); 1.54 + options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS; 1.55 + query.setFolders([folder], 1); 1.56 + 1.57 + var result = histsvc.executeQuery(query, options); 1.58 + var rootNode = result.root; 1.59 + rootNode.containerOpen = true; 1.60 + 1.61 + do_check_eq(rootNode.childCount, 1); 1.62 + do_check_eq(rootNode.getChild(0).itemId, b1); 1.63 + rootNode.containerOpen = false; 1.64 + 1.65 + // partial matches are okay 1.66 + query.searchTerms = "wal"; 1.67 + var result = histsvc.executeQuery(query, options); 1.68 + var rootNode = result.root; 1.69 + rootNode.containerOpen = true; 1.70 + do_check_eq(rootNode.childCount, 1); 1.71 + rootNode.containerOpen = false; 1.72 + 1.73 + // case insensitive search term 1.74 + query.searchTerms = "WALRUS"; 1.75 + var result = histsvc.executeQuery(query, options); 1.76 + var rootNode = result.root; 1.77 + rootNode.containerOpen = true; 1.78 + do_check_eq(rootNode.childCount, 1); 1.79 + do_check_eq(rootNode.getChild(0).itemId, b1); 1.80 + rootNode.containerOpen = false; 1.81 + 1.82 + // case insensitive tag 1.83 + query.searchTerms = "baboon"; 1.84 + var result = histsvc.executeQuery(query, options); 1.85 + var rootNode = result.root; 1.86 + rootNode.containerOpen = true; 1.87 + do_check_eq(rootNode.childCount, 1); 1.88 + do_check_eq(rootNode.getChild(0).itemId, b1); 1.89 + rootNode.containerOpen = false; 1.90 +}