Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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/. */
7 /*
8 * Tests nsNavHistoryContainerResultNode::GetChildIndex(aNode) functionality.
9 */
11 function run_test() {
12 // Add a bookmark to the menu.
13 PlacesUtils.bookmarks.insertBookmark(PlacesUtils.bookmarksMenuFolderId,
14 uri("http://test.mozilla.org/bookmark/"),
15 Ci.nsINavBookmarksService.DEFAULT_INDEX,
16 "Test bookmark");
18 // Add a bookmark to unfiled folder.
19 PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
20 uri("http://test.mozilla.org/unfiled/"),
21 Ci.nsINavBookmarksService.DEFAULT_INDEX,
22 "Unfiled bookmark");
24 // Get the unfiled bookmark node.
25 let unfiledNode = getNodeAt(PlacesUtils.unfiledBookmarksFolderId, 0);
26 if (!unfiledNode)
27 do_throw("Unable to find bookmark in hierarchy!");
28 do_check_eq(unfiledNode.title, "Unfiled bookmark");
30 let hs = PlacesUtils.history;
31 let query = hs.getNewQuery();
32 query.setFolders([PlacesUtils.bookmarksMenuFolderId], 1);
33 let options = hs.getNewQueryOptions();
34 options.queryType = options.QUERY_TYPE_BOOKMARKS;
35 let root = hs.executeQuery(query, options).root;
36 root.containerOpen = true;
38 // Check functionality for proper nodes.
39 for (let i = 0; i < root.childCount; i++) {
40 let node = root.getChild(i);
41 print("Now testing: " + node.title);
42 do_check_eq(root.getChildIndex(node), i);
43 }
45 // Now search for an invalid node and expect an exception.
46 try {
47 root.getChildIndex(unfiledNode);
48 do_throw("Searching for an invalid node should have thrown.");
49 } catch(ex) {
50 print("We correctly got an exception.");
51 }
53 root.containerOpen = false;
54 }
56 function getNodeAt(aFolderId, aIndex) {
57 let hs = PlacesUtils.history;
58 let query = hs.getNewQuery();
59 query.setFolders([aFolderId], 1);
60 let options = hs.getNewQueryOptions();
61 options.queryType = options.QUERY_TYPE_BOOKMARKS;
62 let root = hs.executeQuery(query, options).root;
63 root.containerOpen = true;
64 if (root.childCount < aIndex)
65 do_throw("Not enough children to find bookmark!");
66 let node = root.getChild(aIndex);
67 root.containerOpen = false;
68 return node;
69 }