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 * Obtains the id of the folder obtained from the query.
9 *
10 * @param aQuery
11 * The query to obtain the folder id from.
12 * @returns the folder id of the folder of the root node of the query.
13 */
14 function folder_id(aQuery)
15 {
16 var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
17 getService(Ci.nsINavHistoryService);
19 dump("Checking query '" + aQuery + "'\n");
20 var options = { };
21 var queries = { };
22 var size = { };
23 hs.queryStringToQueries(aQuery, queries, size, options);
24 var result = hs.executeQueries(queries.value, size.value, options.value);
25 var root = result.root;
26 root.containerOpen = true;
27 do_check_true(root.hasChildren);
28 var folderID = root.getChild(0).parent.itemId;
29 root.containerOpen = false;
30 return folderID;
31 }
33 function run_test()
34 {
35 var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
36 getService(Ci.nsINavHistoryService);
37 var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
38 getService(Ci.nsINavBookmarksService);
40 const QUERIES = [
41 "place:folder=PLACES_ROOT"
42 , "place:folder=BOOKMARKS_MENU"
43 , "place:folder=TAGS"
44 , "place:folder=UNFILED_BOOKMARKS"
45 , "place:folder=TOOLBAR"
46 ];
47 const FOLDER_IDS = [
48 bs.placesRoot
49 , bs.bookmarksMenuFolder
50 , bs.tagsFolder
51 , bs.unfiledBookmarksFolder
52 , bs.toolbarFolder
53 ];
55 // add something in the bookmarks menu folder so a query to it returns results
56 bs.insertBookmark(bs.bookmarksMenuFolder, uri("http://example.com/bmf/"),
57 Ci.nsINavBookmarksService.DEFAULT_INDEX, "bmf");
59 // add something to the tags folder
60 var ts = Cc["@mozilla.org/browser/tagging-service;1"].
61 getService(Ci.nsITaggingService);
62 ts.tagURI(uri("http://www.example.com/"), ["tag"]);
64 // add something to the unfiled bookmarks folder
65 bs.insertBookmark(bs.unfiledBookmarksFolder, uri("http://example.com/ubf/"),
66 Ci.nsINavBookmarksService.DEFAULT_INDEX, "ubf");
68 // add something to the toolbar folder
69 bs.insertBookmark(bs.toolbarFolder, uri("http://example.com/tf/"),
70 Ci.nsINavBookmarksService.DEFAULT_INDEX, "tf");
72 for (var i = 0; i < QUERIES.length; i++) {
73 var result = folder_id(QUERIES[i]);
74 dump("expected " + FOLDER_IDS[i] + ", got " + result + "\n");
75 do_check_eq(FOLDER_IDS[i], result);
76 }
77 }