toolkit/components/places/tests/bookmarks/test_395101.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:7feab8d4bb81
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 // Get bookmark service
8 try {
9 var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].getService(Ci.nsINavBookmarksService);
10 } catch(ex) {
11 do_throw("Could not get nav-bookmarks-service\n");
12 }
13
14 // Get history service
15 try {
16 var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsINavHistoryService);
17 } catch(ex) {
18 do_throw("Could not get history service\n");
19 }
20
21 // Get tagging service
22 try {
23 var tagssvc = Cc["@mozilla.org/browser/tagging-service;1"].
24 getService(Ci.nsITaggingService);
25 } catch(ex) {
26 do_throw("Could not get tagging service\n");
27 }
28
29 // get bookmarks root id
30 var root = bmsvc.bookmarksMenuFolder;
31
32 // main
33 function run_test() {
34 // test searching for tagged bookmarks
35
36 // test folder
37 var folder = bmsvc.createFolder(root, "bug 395101 test", bmsvc.DEFAULT_INDEX);
38
39 // create a bookmark
40 var testURI = uri("http://a1.com");
41 var b1 = bmsvc.insertBookmark(folder, testURI,
42 bmsvc.DEFAULT_INDEX, "1 title");
43
44 // tag the bookmarked URI
45 tagssvc.tagURI(testURI, ["elephant", "walrus", "giraffe", "turkey", "hiPPo", "BABOON", "alf"]);
46
47 // search for the bookmark, using a tag
48 var query = histsvc.getNewQuery();
49 query.searchTerms = "elephant";
50 var options = histsvc.getNewQueryOptions();
51 options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
52 query.setFolders([folder], 1);
53
54 var result = histsvc.executeQuery(query, options);
55 var rootNode = result.root;
56 rootNode.containerOpen = true;
57
58 do_check_eq(rootNode.childCount, 1);
59 do_check_eq(rootNode.getChild(0).itemId, b1);
60 rootNode.containerOpen = false;
61
62 // partial matches are okay
63 query.searchTerms = "wal";
64 var result = histsvc.executeQuery(query, options);
65 var rootNode = result.root;
66 rootNode.containerOpen = true;
67 do_check_eq(rootNode.childCount, 1);
68 rootNode.containerOpen = false;
69
70 // case insensitive search term
71 query.searchTerms = "WALRUS";
72 var result = histsvc.executeQuery(query, options);
73 var rootNode = result.root;
74 rootNode.containerOpen = true;
75 do_check_eq(rootNode.childCount, 1);
76 do_check_eq(rootNode.getChild(0).itemId, b1);
77 rootNode.containerOpen = false;
78
79 // case insensitive tag
80 query.searchTerms = "baboon";
81 var result = histsvc.executeQuery(query, options);
82 var rootNode = result.root;
83 rootNode.containerOpen = true;
84 do_check_eq(rootNode.childCount, 1);
85 do_check_eq(rootNode.getChild(0).itemId, b1);
86 rootNode.containerOpen = false;
87 }

mercurial