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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 // 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 search on folder with various sorts and max results
michael@0 27 // see bug #385829 for more details
michael@0 28 var folder = bmsvc.createFolder(root, "bug 385829 test", bmsvc.DEFAULT_INDEX);
michael@0 29 var b1 = bmsvc.insertBookmark(folder, uri("http://a1.com/"),
michael@0 30 bmsvc.DEFAULT_INDEX, "1 title");
michael@0 31
michael@0 32 var b2 = bmsvc.insertBookmark(folder, uri("http://a2.com/"),
michael@0 33 bmsvc.DEFAULT_INDEX, "2 title");
michael@0 34
michael@0 35 var b3 = bmsvc.insertBookmark(folder, uri("http://a3.com/"),
michael@0 36 bmsvc.DEFAULT_INDEX, "3 title");
michael@0 37
michael@0 38 var b4 = bmsvc.insertBookmark(folder, uri("http://a4.com/"),
michael@0 39 bmsvc.DEFAULT_INDEX, "4 title");
michael@0 40
michael@0 41 // ensure some unique values for date added and last modified
michael@0 42 // for date added: b1 < b2 < b3 < b4
michael@0 43 // for last modified: b1 > b2 > b3 > b4
michael@0 44 bmsvc.setItemDateAdded(b1, 1000);
michael@0 45 bmsvc.setItemDateAdded(b2, 2000);
michael@0 46 bmsvc.setItemDateAdded(b3, 3000);
michael@0 47 bmsvc.setItemDateAdded(b4, 4000);
michael@0 48
michael@0 49 bmsvc.setItemLastModified(b1, 4000);
michael@0 50 bmsvc.setItemLastModified(b2, 3000);
michael@0 51 bmsvc.setItemLastModified(b3, 2000);
michael@0 52 bmsvc.setItemLastModified(b4, 1000);
michael@0 53
michael@0 54 var options = histsvc.getNewQueryOptions();
michael@0 55 var query = histsvc.getNewQuery();
michael@0 56 options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
michael@0 57 options.maxResults = 3;
michael@0 58 query.setFolders([folder], 1);
michael@0 59
michael@0 60 var result = histsvc.executeQuery(query, options);
michael@0 61 var rootNode = result.root;
michael@0 62 rootNode.containerOpen = true;
michael@0 63
michael@0 64 // test SORT_BY_DATEADDED_ASCENDING (live update)
michael@0 65 result.sortingMode = options.SORT_BY_DATEADDED_ASCENDING;
michael@0 66 do_check_eq(rootNode.childCount, 3);
michael@0 67 do_check_eq(rootNode.getChild(0).itemId, b1);
michael@0 68 do_check_eq(rootNode.getChild(1).itemId, b2);
michael@0 69 do_check_eq(rootNode.getChild(2).itemId, b3);
michael@0 70 do_check_true(rootNode.getChild(0).dateAdded <
michael@0 71 rootNode.getChild(1).dateAdded);
michael@0 72 do_check_true(rootNode.getChild(1).dateAdded <
michael@0 73 rootNode.getChild(2).dateAdded);
michael@0 74
michael@0 75 // test SORT_BY_DATEADDED_DESCENDING (live update)
michael@0 76 result.sortingMode = options.SORT_BY_DATEADDED_DESCENDING;
michael@0 77 do_check_eq(rootNode.childCount, 3);
michael@0 78 do_check_eq(rootNode.getChild(0).itemId, b3);
michael@0 79 do_check_eq(rootNode.getChild(1).itemId, b2);
michael@0 80 do_check_eq(rootNode.getChild(2).itemId, b1);
michael@0 81 do_check_true(rootNode.getChild(0).dateAdded >
michael@0 82 rootNode.getChild(1).dateAdded);
michael@0 83 do_check_true(rootNode.getChild(1).dateAdded >
michael@0 84 rootNode.getChild(2).dateAdded);
michael@0 85
michael@0 86 // test SORT_BY_LASTMODIFIED_ASCENDING (live update)
michael@0 87 result.sortingMode = options.SORT_BY_LASTMODIFIED_ASCENDING;
michael@0 88 do_check_eq(rootNode.childCount, 3);
michael@0 89 do_check_eq(rootNode.getChild(0).itemId, b3);
michael@0 90 do_check_eq(rootNode.getChild(1).itemId, b2);
michael@0 91 do_check_eq(rootNode.getChild(2).itemId, b1);
michael@0 92 do_check_true(rootNode.getChild(0).lastModified <
michael@0 93 rootNode.getChild(1).lastModified);
michael@0 94 do_check_true(rootNode.getChild(1).lastModified <
michael@0 95 rootNode.getChild(2).lastModified);
michael@0 96
michael@0 97 // test SORT_BY_LASTMODIFIED_DESCENDING (live update)
michael@0 98 result.sortingMode = options.SORT_BY_LASTMODIFIED_DESCENDING;
michael@0 99
michael@0 100 do_check_eq(rootNode.childCount, 3);
michael@0 101 do_check_eq(rootNode.getChild(0).itemId, b1);
michael@0 102 do_check_eq(rootNode.getChild(1).itemId, b2);
michael@0 103 do_check_eq(rootNode.getChild(2).itemId, b3);
michael@0 104 do_check_true(rootNode.getChild(0).lastModified >
michael@0 105 rootNode.getChild(1).lastModified);
michael@0 106 do_check_true(rootNode.getChild(1).lastModified >
michael@0 107 rootNode.getChild(2).lastModified);
michael@0 108 rootNode.containerOpen = false;
michael@0 109
michael@0 110 // test SORT_BY_DATEADDED_ASCENDING
michael@0 111 options.sortingMode = options.SORT_BY_DATEADDED_ASCENDING;
michael@0 112 result = histsvc.executeQuery(query, options);
michael@0 113 rootNode = result.root;
michael@0 114 rootNode.containerOpen = true;
michael@0 115 do_check_eq(rootNode.childCount, 3);
michael@0 116 do_check_eq(rootNode.getChild(0).itemId, b1);
michael@0 117 do_check_eq(rootNode.getChild(1).itemId, b2);
michael@0 118 do_check_eq(rootNode.getChild(2).itemId, b3);
michael@0 119 do_check_true(rootNode.getChild(0).dateAdded <
michael@0 120 rootNode.getChild(1).dateAdded);
michael@0 121 do_check_true(rootNode.getChild(1).dateAdded <
michael@0 122 rootNode.getChild(2).dateAdded);
michael@0 123 rootNode.containerOpen = false;
michael@0 124
michael@0 125 // test SORT_BY_DATEADDED_DESCENDING
michael@0 126 options.sortingMode = options.SORT_BY_DATEADDED_DESCENDING;
michael@0 127 result = histsvc.executeQuery(query, options);
michael@0 128 rootNode = result.root;
michael@0 129 rootNode.containerOpen = true;
michael@0 130 do_check_eq(rootNode.childCount, 3);
michael@0 131 do_check_eq(rootNode.getChild(0).itemId, b4);
michael@0 132 do_check_eq(rootNode.getChild(1).itemId, b3);
michael@0 133 do_check_eq(rootNode.getChild(2).itemId, b2);
michael@0 134 do_check_true(rootNode.getChild(0).dateAdded >
michael@0 135 rootNode.getChild(1).dateAdded);
michael@0 136 do_check_true(rootNode.getChild(1).dateAdded >
michael@0 137 rootNode.getChild(2).dateAdded);
michael@0 138 rootNode.containerOpen = false;
michael@0 139
michael@0 140 // test SORT_BY_LASTMODIFIED_ASCENDING
michael@0 141 options.sortingMode = options.SORT_BY_LASTMODIFIED_ASCENDING;
michael@0 142 result = histsvc.executeQuery(query, options);
michael@0 143 rootNode = result.root;
michael@0 144 rootNode.containerOpen = true;
michael@0 145 do_check_eq(rootNode.childCount, 3);
michael@0 146 do_check_eq(rootNode.getChild(0).itemId, b4);
michael@0 147 do_check_eq(rootNode.getChild(1).itemId, b3);
michael@0 148 do_check_eq(rootNode.getChild(2).itemId, b2);
michael@0 149 do_check_true(rootNode.getChild(0).lastModified <
michael@0 150 rootNode.getChild(1).lastModified);
michael@0 151 do_check_true(rootNode.getChild(1).lastModified <
michael@0 152 rootNode.getChild(2).lastModified);
michael@0 153 rootNode.containerOpen = false;
michael@0 154
michael@0 155 // test SORT_BY_LASTMODIFIED_DESCENDING
michael@0 156 options.sortingMode = options.SORT_BY_LASTMODIFIED_DESCENDING;
michael@0 157 result = histsvc.executeQuery(query, options);
michael@0 158 rootNode = result.root;
michael@0 159 rootNode.containerOpen = true;
michael@0 160 do_check_eq(rootNode.childCount, 3);
michael@0 161 do_check_eq(rootNode.getChild(0).itemId, b1);
michael@0 162 do_check_eq(rootNode.getChild(1).itemId, b2);
michael@0 163 do_check_eq(rootNode.getChild(2).itemId, b3);
michael@0 164 do_check_true(rootNode.getChild(0).lastModified >
michael@0 165 rootNode.getChild(1).lastModified);
michael@0 166 do_check_true(rootNode.getChild(1).lastModified >
michael@0 167 rootNode.getChild(2).lastModified);
michael@0 168 rootNode.containerOpen = false;
michael@0 169 }

mercurial