toolkit/components/places/tests/unit/test_history.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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 history services
michael@0 8 var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
michael@0 9 getService(Ci.nsINavHistoryService);
michael@0 10
michael@0 11 /**
michael@0 12 * Checks to see that a URI is in the database.
michael@0 13 *
michael@0 14 * @param aURI
michael@0 15 * The URI to check.
michael@0 16 * @returns true if the URI is in the DB, false otherwise.
michael@0 17 */
michael@0 18 function uri_in_db(aURI) {
michael@0 19 var options = histsvc.getNewQueryOptions();
michael@0 20 options.maxResults = 1;
michael@0 21 options.resultType = options.RESULTS_AS_URI
michael@0 22 var query = histsvc.getNewQuery();
michael@0 23 query.uri = aURI;
michael@0 24 var result = histsvc.executeQuery(query, options);
michael@0 25 var root = result.root;
michael@0 26 root.containerOpen = true;
michael@0 27 var cc = root.childCount;
michael@0 28 root.containerOpen = false;
michael@0 29 return (cc == 1);
michael@0 30 }
michael@0 31
michael@0 32 // main
michael@0 33 function run_test()
michael@0 34 {
michael@0 35 run_next_test();
michael@0 36 }
michael@0 37
michael@0 38 add_task(function test_execute()
michael@0 39 {
michael@0 40 // we have a new profile, so we should have imported bookmarks
michael@0 41 do_check_eq(histsvc.databaseStatus, histsvc.DATABASE_STATUS_CREATE);
michael@0 42
michael@0 43 // add a visit
michael@0 44 var testURI = uri("http://mozilla.com");
michael@0 45 yield promiseAddVisits(testURI);
michael@0 46
michael@0 47 // now query for the visit, setting sorting and limit such that
michael@0 48 // we should retrieve only the visit we just added
michael@0 49 var options = histsvc.getNewQueryOptions();
michael@0 50 options.sortingMode = options.SORT_BY_DATE_DESCENDING;
michael@0 51 options.maxResults = 1;
michael@0 52 // TODO: using full visit crashes in xpcshell test
michael@0 53 //options.resultType = options.RESULTS_AS_FULL_VISIT;
michael@0 54 options.resultType = options.RESULTS_AS_VISIT;
michael@0 55 var query = histsvc.getNewQuery();
michael@0 56 var result = histsvc.executeQuery(query, options);
michael@0 57 var root = result.root;
michael@0 58 root.containerOpen = true;
michael@0 59 var cc = root.childCount;
michael@0 60 for (var i=0; i < cc; ++i) {
michael@0 61 var node = root.getChild(i);
michael@0 62 // test node properties in RESULTS_AS_VISIT
michael@0 63 do_check_eq(node.uri, testURI.spec);
michael@0 64 do_check_eq(node.type, Ci.nsINavHistoryResultNode.RESULT_TYPE_URI);
michael@0 65 // TODO: change query type to RESULTS_AS_FULL_VISIT and test this
michael@0 66 //do_check_eq(node.transitionType, histsvc.TRANSITION_TYPED);
michael@0 67 }
michael@0 68 root.containerOpen = false;
michael@0 69
michael@0 70 // add another visit for the same URI, and a third visit for a different URI
michael@0 71 var testURI2 = uri("http://google.com/");
michael@0 72 yield promiseAddVisits(testURI);
michael@0 73 yield promiseAddVisits(testURI2);
michael@0 74
michael@0 75 options.maxResults = 5;
michael@0 76 options.resultType = options.RESULTS_AS_URI;
michael@0 77
michael@0 78 // test minVisits
michael@0 79 query.minVisits = 0;
michael@0 80 result = histsvc.executeQuery(query, options);
michael@0 81 result.root.containerOpen = true;
michael@0 82 do_check_eq(result.root.childCount, 2);
michael@0 83 result.root.containerOpen = false;
michael@0 84 query.minVisits = 1;
michael@0 85 result = histsvc.executeQuery(query, options);
michael@0 86 result.root.containerOpen = true;
michael@0 87 do_check_eq(result.root.childCount, 2);
michael@0 88 result.root.containerOpen = false;
michael@0 89 query.minVisits = 2;
michael@0 90 result = histsvc.executeQuery(query, options);
michael@0 91 result.root.containerOpen = true;
michael@0 92 do_check_eq(result.root.childCount, 1);
michael@0 93 query.minVisits = 3;
michael@0 94 result.root.containerOpen = false;
michael@0 95 result = histsvc.executeQuery(query, options);
michael@0 96 result.root.containerOpen = true;
michael@0 97 do_check_eq(result.root.childCount, 0);
michael@0 98 result.root.containerOpen = false;
michael@0 99
michael@0 100 // test maxVisits
michael@0 101 query.minVisits = -1;
michael@0 102 query.maxVisits = -1;
michael@0 103 result = histsvc.executeQuery(query, options);
michael@0 104 result.root.containerOpen = true;
michael@0 105 do_check_eq(result.root.childCount, 2);
michael@0 106 result.root.containerOpen = false;
michael@0 107 query.maxVisits = 0;
michael@0 108 result = histsvc.executeQuery(query, options);
michael@0 109 result.root.containerOpen = true;
michael@0 110 do_check_eq(result.root.childCount, 0);
michael@0 111 result.root.containerOpen = false;
michael@0 112 query.maxVisits = 1;
michael@0 113 result = histsvc.executeQuery(query, options);
michael@0 114 result.root.containerOpen = true;
michael@0 115 do_check_eq(result.root.childCount, 1);
michael@0 116 result.root.containerOpen = false;
michael@0 117 query.maxVisits = 2;
michael@0 118 result = histsvc.executeQuery(query, options);
michael@0 119 result.root.containerOpen = true;
michael@0 120 do_check_eq(result.root.childCount, 2);
michael@0 121 result.root.containerOpen = false;
michael@0 122 query.maxVisits = 3;
michael@0 123 result = histsvc.executeQuery(query, options);
michael@0 124 result.root.containerOpen = true;
michael@0 125 do_check_eq(result.root.childCount, 2);
michael@0 126 result.root.containerOpen = false;
michael@0 127
michael@0 128 // test annotation-based queries
michael@0 129 var annos = Cc["@mozilla.org/browser/annotation-service;1"].
michael@0 130 getService(Ci.nsIAnnotationService);
michael@0 131 annos.setPageAnnotation(uri("http://mozilla.com/"), "testAnno", 0, 0,
michael@0 132 Ci.nsIAnnotationService.EXPIRE_NEVER);
michael@0 133 query.annotation = "testAnno";
michael@0 134 result = histsvc.executeQuery(query, options);
michael@0 135 result.root.containerOpen = true;
michael@0 136 do_check_eq(result.root.childCount, 1);
michael@0 137 do_check_eq(result.root.getChild(0).uri, "http://mozilla.com/");
michael@0 138 result.root.containerOpen = false;
michael@0 139
michael@0 140 // test annotationIsNot
michael@0 141 query.annotationIsNot = true;
michael@0 142 result = histsvc.executeQuery(query, options);
michael@0 143 result.root.containerOpen = true;
michael@0 144 do_check_eq(result.root.childCount, 1);
michael@0 145 do_check_eq(result.root.getChild(0).uri, "http://google.com/");
michael@0 146 result.root.containerOpen = false;
michael@0 147
michael@0 148 // By default history is enabled.
michael@0 149 do_check_true(!histsvc.historyDisabled);
michael@0 150
michael@0 151 // test getPageTitle
michael@0 152 yield promiseAddVisits({ uri: uri("http://example.com"), title: "title" });
michael@0 153 let placeInfo = yield PlacesUtils.promisePlaceInfo(uri("http://example.com"));
michael@0 154 do_check_eq(placeInfo.title, "title");
michael@0 155
michael@0 156 // query for the visit
michael@0 157 do_check_true(uri_in_db(testURI));
michael@0 158
michael@0 159 // test for schema changes in bug 373239
michael@0 160 // get direct db connection
michael@0 161 var db = histsvc.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection;
michael@0 162 var q = "SELECT id FROM moz_bookmarks";
michael@0 163 var statement;
michael@0 164 try {
michael@0 165 statement = db.createStatement(q);
michael@0 166 } catch(ex) {
michael@0 167 do_throw("bookmarks table does not have id field, schema is too old!");
michael@0 168 }
michael@0 169 finally {
michael@0 170 statement.finalize();
michael@0 171 }
michael@0 172
michael@0 173 // bug 394741 - regressed history text searches
michael@0 174 yield promiseAddVisits(uri("http://mozilla.com"));
michael@0 175 var options = histsvc.getNewQueryOptions();
michael@0 176 //options.resultType = options.RESULTS_AS_VISIT;
michael@0 177 var query = histsvc.getNewQuery();
michael@0 178 query.searchTerms = "moz";
michael@0 179 var result = histsvc.executeQuery(query, options);
michael@0 180 var root = result.root;
michael@0 181 root.containerOpen = true;
michael@0 182 do_check_true(root.childCount > 0);
michael@0 183 root.containerOpen = false;
michael@0 184 });

mercurial