toolkit/components/places/tests/unit/test_331487.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:4b34878970eb
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 history service
8 try {
9 var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsINavHistoryService);
10 } catch(ex) {
11 do_throw("Could not get history service\n");
12 }
13
14 var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
15 getService(Ci.nsINavBookmarksService);
16
17 // main
18 function run_test() {
19 // add a folder
20 var folder = bmsvc.createFolder(bmsvc.placesRoot, "test folder", bmsvc.DEFAULT_INDEX);
21
22 // add a bookmark to the folder
23 var b1 = bmsvc.insertBookmark(folder, uri("http://a1.com/"),
24 bmsvc.DEFAULT_INDEX, "1 title");
25 // add a subfolder
26 var sf1 = bmsvc.createFolder(folder, "subfolder 1", bmsvc.DEFAULT_INDEX);
27
28 // add a bookmark to the subfolder
29 var b2 = bmsvc.insertBookmark(sf1, uri("http://a2.com/"),
30 bmsvc.DEFAULT_INDEX, "2 title");
31
32 // add a subfolder to the subfolder
33 var sf2 = bmsvc.createFolder(sf1, "subfolder 2", bmsvc.DEFAULT_INDEX);
34
35 // add a bookmark to the subfolder of the subfolder
36 var b3 = bmsvc.insertBookmark(sf2, uri("http://a3.com/"),
37 bmsvc.DEFAULT_INDEX, "3 title");
38
39 // bookmark query that should result in the "hierarchical" result
40 // because there is one query, one folder,
41 // no begin time, no end time, no domain, no uri, no search term
42 // and no max results. See GetSimpleBookmarksQueryFolder()
43 // for more details.
44 var options = histsvc.getNewQueryOptions();
45 options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
46 var query = histsvc.getNewQuery();
47 query.setFolders([folder], 1);
48 var result = histsvc.executeQuery(query, options);
49 var root = result.root;
50 root.containerOpen = true;
51 do_check_eq(root.childCount, 2);
52 do_check_eq(root.getChild(0).itemId, b1);
53 do_check_eq(root.getChild(1).itemId, sf1);
54
55 // check the contents of the subfolder
56 var sf1Node = root.getChild(1);
57 sf1Node = sf1Node.QueryInterface(Ci.nsINavHistoryContainerResultNode);
58 sf1Node.containerOpen = true;
59 do_check_eq(sf1Node.childCount, 2);
60 do_check_eq(sf1Node.getChild(0).itemId, b2);
61 do_check_eq(sf1Node.getChild(1).itemId, sf2);
62
63 // check the contents of the subfolder's subfolder
64 var sf2Node = sf1Node.getChild(1);
65 sf2Node = sf2Node.QueryInterface(Ci.nsINavHistoryContainerResultNode);
66 sf2Node.containerOpen = true;
67 do_check_eq(sf2Node.childCount, 1);
68 do_check_eq(sf2Node.getChild(0).itemId, b3);
69
70 sf2Node.containerOpen = false;
71 sf1Node.containerOpen = false;
72 root.containerOpen = false;
73
74 // bookmark query that should result in a flat list
75 // because we specified max results
76 var options = histsvc.getNewQueryOptions();
77 options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
78 options.maxResults = 10;
79 var query = histsvc.getNewQuery();
80 query.setFolders([folder], 1);
81 var result = histsvc.executeQuery(query, options);
82 var root = result.root;
83 root.containerOpen = true;
84 do_check_eq(root.childCount, 3);
85 do_check_eq(root.getChild(0).itemId, b1);
86 do_check_eq(root.getChild(1).itemId, b2);
87 do_check_eq(root.getChild(2).itemId, b3);
88 root.containerOpen = false;
89
90 // XXX TODO
91 // test that if we have: more than one query,
92 // multiple folders, a begin time, an end time, a domain, a uri
93 // or a search term, that we get the (correct) flat list results
94 // (like we do when specified maxResults)
95 }

mercurial