toolkit/components/places/tests/queries/test_415716.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 function modHistoryTypes(val){
michael@0 8 switch(val % 8) {
michael@0 9 case 0:
michael@0 10 case 1:
michael@0 11 return TRANSITION_LINK;
michael@0 12 case 2:
michael@0 13 return TRANSITION_TYPED;
michael@0 14 case 3:
michael@0 15 return TRANSITION_BOOKMARK;
michael@0 16 case 4:
michael@0 17 return TRANSITION_EMBED;
michael@0 18 case 5:
michael@0 19 return TRANSITION_REDIRECT_PERMANENT;
michael@0 20 case 6:
michael@0 21 return TRANSITION_REDIRECT_TEMPORARY;
michael@0 22 case 7:
michael@0 23 return TRANSITION_DOWNLOAD;
michael@0 24 case 8:
michael@0 25 return TRANSITION_FRAMED_LINK;
michael@0 26 }
michael@0 27 return TRANSITION_TYPED;
michael@0 28 }
michael@0 29
michael@0 30 function run_test()
michael@0 31 {
michael@0 32 run_next_test();
michael@0 33 }
michael@0 34
michael@0 35 /**
michael@0 36 * Builds a test database by hand using various times, annotations and
michael@0 37 * visit numbers for this test
michael@0 38 */
michael@0 39 add_task(function test_buildTestDatabase()
michael@0 40 {
michael@0 41 // This is the set of visits that we will match - our min visit is 2 so that's
michael@0 42 // why we add more visits to the same URIs.
michael@0 43 let testURI = uri("http://www.foo.com");
michael@0 44 let places = [];
michael@0 45
michael@0 46 for (let i = 0; i < 12; ++i) {
michael@0 47 places.push({
michael@0 48 uri: testURI,
michael@0 49 transition: modHistoryTypes(i),
michael@0 50 visitDate: today
michael@0 51 });
michael@0 52 }
michael@0 53
michael@0 54 testURI = uri("http://foo.com/youdontseeme.html");
michael@0 55 let testAnnoName = "moz-test-places/testing123";
michael@0 56 let testAnnoVal = "test";
michael@0 57 for (let i = 0; i < 12; ++i) {
michael@0 58 places.push({
michael@0 59 uri: testURI,
michael@0 60 transition: modHistoryTypes(i),
michael@0 61 visitDate: today
michael@0 62 });
michael@0 63 }
michael@0 64
michael@0 65 yield promiseAddVisits(places);
michael@0 66
michael@0 67 PlacesUtils.annotations.setPageAnnotation(testURI, testAnnoName,
michael@0 68 testAnnoVal, 0, 0);
michael@0 69 });
michael@0 70
michael@0 71 /**
michael@0 72 * This test will test Queries that use relative Time Range, minVists, maxVisits,
michael@0 73 * annotation.
michael@0 74 * The Query:
michael@0 75 * Annotation == "moz-test-places/testing123" &&
michael@0 76 * TimeRange == "now() - 2d" &&
michael@0 77 * minVisits == 2 &&
michael@0 78 * maxVisits == 10
michael@0 79 */
michael@0 80 add_task(function test_execute()
michael@0 81 {
michael@0 82 let query = PlacesUtils.history.getNewQuery();
michael@0 83 query.annotation = "moz-test-places/testing123";
michael@0 84 query.beginTime = daybefore * 1000;
michael@0 85 query.beginTimeReference = PlacesUtils.history.TIME_RELATIVE_NOW;
michael@0 86 query.endTime = today * 1000;
michael@0 87 query.endTimeReference = PlacesUtils.history.TIME_RELATIVE_NOW;
michael@0 88 query.minVisits = 2;
michael@0 89 query.maxVisits = 10;
michael@0 90
michael@0 91 // Options
michael@0 92 let options = PlacesUtils.history.getNewQueryOptions();
michael@0 93 options.sortingMode = options.SORT_BY_DATE_DESCENDING;
michael@0 94 options.resultType = options.RESULTS_AS_VISIT;
michael@0 95
michael@0 96 // Results
michael@0 97 let root = PlacesUtils.history.executeQuery(query, options).root;
michael@0 98 root.containerOpen = true;
michael@0 99 let cc = root.childCount;
michael@0 100 dump("----> cc is: " + cc + "\n");
michael@0 101 for(let i = 0; i < root.childCount; ++i) {
michael@0 102 let resultNode = root.getChild(i);
michael@0 103 let accesstime = Date(resultNode.time / 1000);
michael@0 104 dump("----> result: " + resultNode.uri + " Date: " + accesstime.toLocaleString() + "\n");
michael@0 105 }
michael@0 106 do_check_eq(cc,0);
michael@0 107 root.containerOpen = false;
michael@0 108 });

mercurial