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

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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 // Get bookmark service
michael@0 8 try {
michael@0 9 var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].getService(Ci.nsINavBookmarksService);
michael@0 10 } catch(ex) {
michael@0 11 do_throw("Could not get nav-bookmarks-service\n");
michael@0 12 }
michael@0 13
michael@0 14 // Get history service
michael@0 15 try {
michael@0 16 var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsINavHistoryService);
michael@0 17 } catch(ex) {
michael@0 18 do_throw("Could not get history service\n");
michael@0 19 }
michael@0 20
michael@0 21 // get bookmarks root id
michael@0 22 var root = bmsvc.bookmarksMenuFolder;
michael@0 23
michael@0 24 // main
michael@0 25 function run_test() {
michael@0 26 // test querying for bookmarks in multiple folders
michael@0 27 var testFolder1 = bmsvc.createFolder(root, "bug 384228 test folder 1",
michael@0 28 bmsvc.DEFAULT_INDEX);
michael@0 29 do_check_eq(bmsvc.getItemIndex(testFolder1), 0);
michael@0 30 var testFolder2 = bmsvc.createFolder(root, "bug 384228 test folder 2",
michael@0 31 bmsvc.DEFAULT_INDEX);
michael@0 32 do_check_eq(bmsvc.getItemIndex(testFolder2), 1);
michael@0 33 var testFolder3 = bmsvc.createFolder(root, "bug 384228 test folder 3",
michael@0 34 bmsvc.DEFAULT_INDEX);
michael@0 35 do_check_eq(bmsvc.getItemIndex(testFolder3), 2);
michael@0 36
michael@0 37 var b1 = bmsvc.insertBookmark(testFolder1, uri("http://foo.tld/"),
michael@0 38 bmsvc.DEFAULT_INDEX, "title b1 (folder 1)");
michael@0 39 do_check_eq(bmsvc.getItemIndex(b1), 0);
michael@0 40 var b2 = bmsvc.insertBookmark(testFolder1, uri("http://foo.tld/"),
michael@0 41 bmsvc.DEFAULT_INDEX, "title b2 (folder 1)");
michael@0 42 do_check_eq(bmsvc.getItemIndex(b2), 1);
michael@0 43 var b3 = bmsvc.insertBookmark(testFolder2, uri("http://foo.tld/"),
michael@0 44 bmsvc.DEFAULT_INDEX, "title b3 (folder 2)");
michael@0 45 do_check_eq(bmsvc.getItemIndex(b3), 0);
michael@0 46 var b4 = bmsvc.insertBookmark(testFolder3, uri("http://foo.tld/"),
michael@0 47 bmsvc.DEFAULT_INDEX, "title b4 (folder 3)");
michael@0 48 do_check_eq(bmsvc.getItemIndex(b4), 0);
michael@0 49 // also test recursive search
michael@0 50 var testFolder1_1 = bmsvc.createFolder(testFolder1, "bug 384228 test folder 1.1",
michael@0 51 bmsvc.DEFAULT_INDEX);
michael@0 52 do_check_eq(bmsvc.getItemIndex(testFolder1_1), 2);
michael@0 53 var b5 = bmsvc.insertBookmark(testFolder1_1, uri("http://a1.com/"),
michael@0 54 bmsvc.DEFAULT_INDEX, "title b5 (folder 1.1)");
michael@0 55 do_check_eq(bmsvc.getItemIndex(b5), 0);
michael@0 56
michael@0 57 var options = histsvc.getNewQueryOptions();
michael@0 58 var query = histsvc.getNewQuery();
michael@0 59 query.searchTerms = "title";
michael@0 60 options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
michael@0 61 query.setFolders([testFolder1, testFolder2], 2);
michael@0 62
michael@0 63 var result = histsvc.executeQuery(query, options);
michael@0 64 var rootNode = result.root;
michael@0 65 rootNode.containerOpen = true;
michael@0 66
michael@0 67 // should not match item from folder 3
michael@0 68 do_check_eq(rootNode.childCount, 4);
michael@0 69
michael@0 70 do_check_eq(rootNode.getChild(0).itemId, b1);
michael@0 71 do_check_eq(rootNode.getChild(1).itemId, b2);
michael@0 72 do_check_eq(rootNode.getChild(2).itemId, b3);
michael@0 73 do_check_eq(rootNode.getChild(3).itemId, b5);
michael@0 74
michael@0 75 rootNode.containerOpen = false;
michael@0 76 }

mercurial