Sat, 03 Jan 2015 20:18:00 +0100
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 | /* ***** BEGIN LICENSE BLOCK ***** |
michael@0 | 4 | Any copyright is dedicated to the Public Domain. |
michael@0 | 5 | http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 6 | * ***** END LICENSE BLOCK ***** */ |
michael@0 | 7 | var beginTime = Date.now(); |
michael@0 | 8 | var testData = [ |
michael@0 | 9 | { |
michael@0 | 10 | isVisit: true, |
michael@0 | 11 | title: "page 0", |
michael@0 | 12 | uri: "http://mozilla.com/", |
michael@0 | 13 | transType: Ci.nsINavHistoryService.TRANSITION_TYPED |
michael@0 | 14 | }, |
michael@0 | 15 | { |
michael@0 | 16 | isVisit: true, |
michael@0 | 17 | title: "page 1", |
michael@0 | 18 | uri: "http://google.com/", |
michael@0 | 19 | transType: Ci.nsINavHistoryService.TRANSITION_DOWNLOAD |
michael@0 | 20 | }, |
michael@0 | 21 | { |
michael@0 | 22 | isVisit: true, |
michael@0 | 23 | title: "page 2", |
michael@0 | 24 | uri: "http://microsoft.com/", |
michael@0 | 25 | transType: Ci.nsINavHistoryService.TRANSITION_DOWNLOAD |
michael@0 | 26 | }, |
michael@0 | 27 | { |
michael@0 | 28 | isVisit: true, |
michael@0 | 29 | title: "page 3", |
michael@0 | 30 | uri: "http://en.wikipedia.org/", |
michael@0 | 31 | transType: Ci.nsINavHistoryService.TRANSITION_BOOKMARK |
michael@0 | 32 | }, |
michael@0 | 33 | { |
michael@0 | 34 | isVisit: true, |
michael@0 | 35 | title: "page 4", |
michael@0 | 36 | uri: "http://fr.wikipedia.org/", |
michael@0 | 37 | transType: Ci.nsINavHistoryService.TRANSITION_DOWNLOAD |
michael@0 | 38 | }, |
michael@0 | 39 | { |
michael@0 | 40 | isVisit: true, |
michael@0 | 41 | title: "page 5", |
michael@0 | 42 | uri: "http://apple.com/", |
michael@0 | 43 | transType: Ci.nsINavHistoryService.TRANSITION_TYPED |
michael@0 | 44 | }, |
michael@0 | 45 | { |
michael@0 | 46 | isVisit: true, |
michael@0 | 47 | title: "page 6", |
michael@0 | 48 | uri: "http://campus-bike-store.com/", |
michael@0 | 49 | transType: Ci.nsINavHistoryService.TRANSITION_DOWNLOAD |
michael@0 | 50 | }, |
michael@0 | 51 | { |
michael@0 | 52 | isVisit: true, |
michael@0 | 53 | title: "page 7", |
michael@0 | 54 | uri: "http://uwaterloo.ca/", |
michael@0 | 55 | transType: Ci.nsINavHistoryService.TRANSITION_TYPED |
michael@0 | 56 | }, |
michael@0 | 57 | { |
michael@0 | 58 | isVisit: true, |
michael@0 | 59 | title: "page 8", |
michael@0 | 60 | uri: "http://pugcleaner.com/", |
michael@0 | 61 | transType: Ci.nsINavHistoryService.TRANSITION_BOOKMARK |
michael@0 | 62 | }, |
michael@0 | 63 | { |
michael@0 | 64 | isVisit: true, |
michael@0 | 65 | title: "page 9", |
michael@0 | 66 | uri: "http://de.wikipedia.org/", |
michael@0 | 67 | transType: Ci.nsINavHistoryService.TRANSITION_TYPED |
michael@0 | 68 | }, |
michael@0 | 69 | { |
michael@0 | 70 | isVisit: true, |
michael@0 | 71 | title: "arewefastyet", |
michael@0 | 72 | uri: "http://arewefastyet.com/", |
michael@0 | 73 | transType: Ci.nsINavHistoryService.TRANSITION_DOWNLOAD |
michael@0 | 74 | }, |
michael@0 | 75 | { |
michael@0 | 76 | isVisit: true, |
michael@0 | 77 | title: "arewefastyet", |
michael@0 | 78 | uri: "http://arewefastyet.com/", |
michael@0 | 79 | transType: Ci.nsINavHistoryService.TRANSITION_BOOKMARK |
michael@0 | 80 | }]; |
michael@0 | 81 | // sets of indices of testData array by transition type |
michael@0 | 82 | var testDataTyped = [0, 5, 7, 9]; |
michael@0 | 83 | var testDataDownload = [1, 2, 4, 6, 10]; |
michael@0 | 84 | var testDataBookmark = [3, 8, 11]; |
michael@0 | 85 | |
michael@0 | 86 | /** |
michael@0 | 87 | * run_test is where the magic happens. This is automatically run by the test |
michael@0 | 88 | * harness. It is where you do the work of creating the query, running it, and |
michael@0 | 89 | * playing with the result set. |
michael@0 | 90 | */ |
michael@0 | 91 | function run_test() |
michael@0 | 92 | { |
michael@0 | 93 | run_next_test(); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | add_task(function test_transitions() |
michael@0 | 97 | { |
michael@0 | 98 | let timeNow = Date.now(); |
michael@0 | 99 | for each (let item in testData) { |
michael@0 | 100 | yield promiseAddVisits({ |
michael@0 | 101 | uri: uri(item.uri), |
michael@0 | 102 | transition: item.transType, |
michael@0 | 103 | visitDate: timeNow++ * 1000, |
michael@0 | 104 | title: item.title |
michael@0 | 105 | }); |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | //dump_table("moz_places"); |
michael@0 | 109 | //dump_table("moz_historyvisits"); |
michael@0 | 110 | |
michael@0 | 111 | var numSortFunc = function (a,b) { return (a - b); }; |
michael@0 | 112 | var arrs = testDataTyped.concat(testDataDownload).concat(testDataBookmark) |
michael@0 | 113 | .sort(numSortFunc); |
michael@0 | 114 | |
michael@0 | 115 | // Four tests which compare the result of a query to an expected set. |
michael@0 | 116 | var data = arrs.filter(function (index) { |
michael@0 | 117 | return (testData[index].uri.match(/arewefastyet\.com/) && |
michael@0 | 118 | testData[index].transType == |
michael@0 | 119 | Ci.nsINavHistoryService.TRANSITION_DOWNLOAD); |
michael@0 | 120 | }); |
michael@0 | 121 | |
michael@0 | 122 | compareQueryToTestData("place:domain=arewefastyet.com&transition=" + |
michael@0 | 123 | Ci.nsINavHistoryService.TRANSITION_DOWNLOAD, |
michael@0 | 124 | data.slice()); |
michael@0 | 125 | |
michael@0 | 126 | compareQueryToTestData("place:transition=" + |
michael@0 | 127 | Ci.nsINavHistoryService.TRANSITION_DOWNLOAD, |
michael@0 | 128 | testDataDownload.slice()); |
michael@0 | 129 | |
michael@0 | 130 | compareQueryToTestData("place:transition=" + |
michael@0 | 131 | Ci.nsINavHistoryService.TRANSITION_TYPED, |
michael@0 | 132 | testDataTyped.slice()); |
michael@0 | 133 | |
michael@0 | 134 | compareQueryToTestData("place:transition=" + |
michael@0 | 135 | Ci.nsINavHistoryService.TRANSITION_DOWNLOAD + |
michael@0 | 136 | "&transition=" + |
michael@0 | 137 | Ci.nsINavHistoryService.TRANSITION_BOOKMARK, |
michael@0 | 138 | data); |
michael@0 | 139 | |
michael@0 | 140 | // Tests the live update property of transitions. |
michael@0 | 141 | var query = {}; |
michael@0 | 142 | var options = {}; |
michael@0 | 143 | PlacesUtils.history. |
michael@0 | 144 | queryStringToQueries("place:transition=" + |
michael@0 | 145 | Ci.nsINavHistoryService.TRANSITION_DOWNLOAD, |
michael@0 | 146 | query, {}, options); |
michael@0 | 147 | query = (query.value)[0]; |
michael@0 | 148 | options = PlacesUtils.history.getNewQueryOptions(); |
michael@0 | 149 | var result = PlacesUtils.history.executeQuery(query, options); |
michael@0 | 150 | var root = result.root; |
michael@0 | 151 | root.containerOpen = true; |
michael@0 | 152 | do_check_eq(testDataDownload.length, root.childCount); |
michael@0 | 153 | yield promiseAddVisits({ |
michael@0 | 154 | uri: uri("http://getfirefox.com"), |
michael@0 | 155 | transition: TRANSITION_DOWNLOAD |
michael@0 | 156 | }); |
michael@0 | 157 | do_check_eq(testDataDownload.length + 1, root.childCount); |
michael@0 | 158 | root.containerOpen = false; |
michael@0 | 159 | }); |
michael@0 | 160 | |
michael@0 | 161 | /* |
michael@0 | 162 | * Takes a query and a set of indices. The indices correspond to elements |
michael@0 | 163 | * of testData that are the result of the query. |
michael@0 | 164 | */ |
michael@0 | 165 | function compareQueryToTestData(queryStr, data) { |
michael@0 | 166 | var query = {}; |
michael@0 | 167 | var options = {}; |
michael@0 | 168 | PlacesUtils.history.queryStringToQueries(queryStr, query, {}, options); |
michael@0 | 169 | query = query.value[0]; |
michael@0 | 170 | options = options.value; |
michael@0 | 171 | var result = PlacesUtils.history.executeQuery(query, options); |
michael@0 | 172 | var root = result.root; |
michael@0 | 173 | for (var i = 0; i < data.length; i++) { |
michael@0 | 174 | data[i] = testData[data[i]]; |
michael@0 | 175 | data[i].isInQuery = true; |
michael@0 | 176 | } |
michael@0 | 177 | compareArrayToResult(data, root); |
michael@0 | 178 | } |