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.
michael@0 | 1 | /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim:set ts=2 sw=2 sts=2 et: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | /** |
michael@0 | 8 | * Obtains the id of the folder obtained from the query. |
michael@0 | 9 | * |
michael@0 | 10 | * @param aQuery |
michael@0 | 11 | * The query to obtain the folder id from. |
michael@0 | 12 | * @returns the folder id of the folder of the root node of the query. |
michael@0 | 13 | */ |
michael@0 | 14 | function folder_id(aQuery) |
michael@0 | 15 | { |
michael@0 | 16 | var hs = Cc["@mozilla.org/browser/nav-history-service;1"]. |
michael@0 | 17 | getService(Ci.nsINavHistoryService); |
michael@0 | 18 | |
michael@0 | 19 | dump("Checking query '" + aQuery + "'\n"); |
michael@0 | 20 | var options = { }; |
michael@0 | 21 | var queries = { }; |
michael@0 | 22 | var size = { }; |
michael@0 | 23 | hs.queryStringToQueries(aQuery, queries, size, options); |
michael@0 | 24 | var result = hs.executeQueries(queries.value, size.value, options.value); |
michael@0 | 25 | var root = result.root; |
michael@0 | 26 | root.containerOpen = true; |
michael@0 | 27 | do_check_true(root.hasChildren); |
michael@0 | 28 | var folderID = root.getChild(0).parent.itemId; |
michael@0 | 29 | root.containerOpen = false; |
michael@0 | 30 | return folderID; |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | function run_test() |
michael@0 | 34 | { |
michael@0 | 35 | var hs = Cc["@mozilla.org/browser/nav-history-service;1"]. |
michael@0 | 36 | getService(Ci.nsINavHistoryService); |
michael@0 | 37 | var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. |
michael@0 | 38 | getService(Ci.nsINavBookmarksService); |
michael@0 | 39 | |
michael@0 | 40 | const QUERIES = [ |
michael@0 | 41 | "place:folder=PLACES_ROOT" |
michael@0 | 42 | , "place:folder=BOOKMARKS_MENU" |
michael@0 | 43 | , "place:folder=TAGS" |
michael@0 | 44 | , "place:folder=UNFILED_BOOKMARKS" |
michael@0 | 45 | , "place:folder=TOOLBAR" |
michael@0 | 46 | ]; |
michael@0 | 47 | const FOLDER_IDS = [ |
michael@0 | 48 | bs.placesRoot |
michael@0 | 49 | , bs.bookmarksMenuFolder |
michael@0 | 50 | , bs.tagsFolder |
michael@0 | 51 | , bs.unfiledBookmarksFolder |
michael@0 | 52 | , bs.toolbarFolder |
michael@0 | 53 | ]; |
michael@0 | 54 | |
michael@0 | 55 | // add something in the bookmarks menu folder so a query to it returns results |
michael@0 | 56 | bs.insertBookmark(bs.bookmarksMenuFolder, uri("http://example.com/bmf/"), |
michael@0 | 57 | Ci.nsINavBookmarksService.DEFAULT_INDEX, "bmf"); |
michael@0 | 58 | |
michael@0 | 59 | // add something to the tags folder |
michael@0 | 60 | var ts = Cc["@mozilla.org/browser/tagging-service;1"]. |
michael@0 | 61 | getService(Ci.nsITaggingService); |
michael@0 | 62 | ts.tagURI(uri("http://www.example.com/"), ["tag"]); |
michael@0 | 63 | |
michael@0 | 64 | // add something to the unfiled bookmarks folder |
michael@0 | 65 | bs.insertBookmark(bs.unfiledBookmarksFolder, uri("http://example.com/ubf/"), |
michael@0 | 66 | Ci.nsINavBookmarksService.DEFAULT_INDEX, "ubf"); |
michael@0 | 67 | |
michael@0 | 68 | // add something to the toolbar folder |
michael@0 | 69 | bs.insertBookmark(bs.toolbarFolder, uri("http://example.com/tf/"), |
michael@0 | 70 | Ci.nsINavBookmarksService.DEFAULT_INDEX, "tf"); |
michael@0 | 71 | |
michael@0 | 72 | for (var i = 0; i < QUERIES.length; i++) { |
michael@0 | 73 | var result = folder_id(QUERIES[i]); |
michael@0 | 74 | dump("expected " + FOLDER_IDS[i] + ", got " + result + "\n"); |
michael@0 | 75 | do_check_eq(FOLDER_IDS[i], result); |
michael@0 | 76 | } |
michael@0 | 77 | } |