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: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : |
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 | /** |
michael@0 | 8 | * What this is aimed to test: |
michael@0 | 9 | * |
michael@0 | 10 | * bh.removeAllPages should expire everything but bookmarked pages and valid |
michael@0 | 11 | * annos. |
michael@0 | 12 | */ |
michael@0 | 13 | |
michael@0 | 14 | let hs = PlacesUtils.history; |
michael@0 | 15 | let bs = PlacesUtils.bookmarks; |
michael@0 | 16 | let as = PlacesUtils.annotations; |
michael@0 | 17 | |
michael@0 | 18 | /** |
michael@0 | 19 | * Creates an aged annotation. |
michael@0 | 20 | * |
michael@0 | 21 | * @param aIdentifier Either a page url or an item id. |
michael@0 | 22 | * @param aIdentifier Name of the annotation. |
michael@0 | 23 | * @param aValue Value for the annotation. |
michael@0 | 24 | * @param aExpirePolicy Expiration policy of the annotation. |
michael@0 | 25 | * @param aAgeInDays Age in days of the annotation. |
michael@0 | 26 | * @param [optional] aLastModifiedAgeInDays Age in days of the annotation, for lastModified. |
michael@0 | 27 | */ |
michael@0 | 28 | let now = Date.now(); |
michael@0 | 29 | function add_old_anno(aIdentifier, aName, aValue, aExpirePolicy, |
michael@0 | 30 | aAgeInDays, aLastModifiedAgeInDays) { |
michael@0 | 31 | let expireDate = (now - (aAgeInDays * 86400 * 1000)) * 1000; |
michael@0 | 32 | let lastModifiedDate = 0; |
michael@0 | 33 | if (aLastModifiedAgeInDays) |
michael@0 | 34 | lastModifiedDate = (now - (aLastModifiedAgeInDays * 86400 * 1000)) * 1000; |
michael@0 | 35 | |
michael@0 | 36 | let sql; |
michael@0 | 37 | if (typeof(aIdentifier) == "number") { |
michael@0 | 38 | // Item annotation. |
michael@0 | 39 | as.setItemAnnotation(aIdentifier, aName, aValue, 0, aExpirePolicy); |
michael@0 | 40 | // Update dateAdded for the last added annotation. |
michael@0 | 41 | sql = "UPDATE moz_items_annos SET dateAdded = :expire_date, lastModified = :last_modified " + |
michael@0 | 42 | "WHERE id = ( " + |
michael@0 | 43 | "SELECT a.id FROM moz_items_annos a " + |
michael@0 | 44 | "JOIN moz_anno_attributes n ON n.id = a.anno_attribute_id " + |
michael@0 | 45 | "WHERE a.item_id = :id " + |
michael@0 | 46 | "AND n.name = :anno_name " + |
michael@0 | 47 | "ORDER BY a.dateAdded DESC LIMIT 1 " + |
michael@0 | 48 | ")"; |
michael@0 | 49 | } |
michael@0 | 50 | else if (aIdentifier instanceof Ci.nsIURI){ |
michael@0 | 51 | // Page annotation. |
michael@0 | 52 | as.setPageAnnotation(aIdentifier, aName, aValue, 0, aExpirePolicy); |
michael@0 | 53 | // Update dateAdded for the last added annotation. |
michael@0 | 54 | sql = "UPDATE moz_annos SET dateAdded = :expire_date, lastModified = :last_modified " + |
michael@0 | 55 | "WHERE id = ( " + |
michael@0 | 56 | "SELECT a.id FROM moz_annos a " + |
michael@0 | 57 | "JOIN moz_anno_attributes n ON n.id = a.anno_attribute_id " + |
michael@0 | 58 | "JOIN moz_places h on h.id = a.place_id " + |
michael@0 | 59 | "WHERE h.url = :id " + |
michael@0 | 60 | "AND n.name = :anno_name " + |
michael@0 | 61 | "ORDER BY a.dateAdded DESC LIMIT 1 " + |
michael@0 | 62 | ")"; |
michael@0 | 63 | } |
michael@0 | 64 | else |
michael@0 | 65 | do_throw("Wrong identifier type"); |
michael@0 | 66 | |
michael@0 | 67 | let stmt = DBConn().createStatement(sql); |
michael@0 | 68 | stmt.params.id = (typeof(aIdentifier) == "number") ? aIdentifier |
michael@0 | 69 | : aIdentifier.spec; |
michael@0 | 70 | stmt.params.expire_date = expireDate; |
michael@0 | 71 | stmt.params.last_modified = lastModifiedDate; |
michael@0 | 72 | stmt.params.anno_name = aName; |
michael@0 | 73 | try { |
michael@0 | 74 | stmt.executeStep(); |
michael@0 | 75 | } |
michael@0 | 76 | finally { |
michael@0 | 77 | stmt.finalize(); |
michael@0 | 78 | } |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | function run_test() { |
michael@0 | 82 | run_next_test(); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | add_task(function test_removeAllPages() { |
michael@0 | 86 | // Set interval to a large value so we don't expire on it. |
michael@0 | 87 | setInterval(3600); // 1h |
michael@0 | 88 | |
michael@0 | 89 | // Expire all expirable pages. |
michael@0 | 90 | setMaxPages(0); |
michael@0 | 91 | |
michael@0 | 92 | // Add some bookmarked page with visit and annotations. |
michael@0 | 93 | for (let i = 0; i < 5; i++) { |
michael@0 | 94 | let pageURI = uri("http://item_anno." + i + ".mozilla.org/"); |
michael@0 | 95 | // This visit will be expired. |
michael@0 | 96 | yield promiseAddVisits({ uri: pageURI, visitDate: now++ }); |
michael@0 | 97 | let id = bs.insertBookmark(bs.unfiledBookmarksFolder, pageURI, |
michael@0 | 98 | bs.DEFAULT_INDEX, null); |
michael@0 | 99 | // Will persist because it's an EXPIRE_NEVER item anno. |
michael@0 | 100 | as.setItemAnnotation(id, "persist", "test", 0, as.EXPIRE_NEVER); |
michael@0 | 101 | // Will persist because the page is bookmarked. |
michael@0 | 102 | as.setPageAnnotation(pageURI, "persist", "test", 0, as.EXPIRE_NEVER); |
michael@0 | 103 | // All EXPIRE_SESSION annotations are expected to expire on clear history. |
michael@0 | 104 | as.setItemAnnotation(id, "expire_session", "test", 0, as.EXPIRE_SESSION); |
michael@0 | 105 | as.setPageAnnotation(pageURI, "expire_session", "test", 0, as.EXPIRE_SESSION); |
michael@0 | 106 | // Annotations with timed policy will expire regardless bookmarked status. |
michael@0 | 107 | add_old_anno(id, "expire_days", "test", as.EXPIRE_DAYS, 8); |
michael@0 | 108 | add_old_anno(id, "expire_weeks", "test", as.EXPIRE_WEEKS, 31); |
michael@0 | 109 | add_old_anno(id, "expire_months", "test", as.EXPIRE_MONTHS, 181); |
michael@0 | 110 | add_old_anno(pageURI, "expire_days", "test", as.EXPIRE_DAYS, 8); |
michael@0 | 111 | add_old_anno(pageURI, "expire_weeks", "test", as.EXPIRE_WEEKS, 31); |
michael@0 | 112 | add_old_anno(pageURI, "expire_months", "test", as.EXPIRE_MONTHS, 181); |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | // Add some visited page and annotations for each. |
michael@0 | 116 | let now = Date.now() * 1000; |
michael@0 | 117 | for (let i = 0; i < 5; i++) { |
michael@0 | 118 | // All page annotations related to these expired pages are expected to |
michael@0 | 119 | // expire as well. |
michael@0 | 120 | let pageURI = uri("http://page_anno." + i + ".mozilla.org/"); |
michael@0 | 121 | yield promiseAddVisits({ uri: pageURI, visitDate: now++ }); |
michael@0 | 122 | as.setPageAnnotation(pageURI, "expire", "test", 0, as.EXPIRE_NEVER); |
michael@0 | 123 | as.setPageAnnotation(pageURI, "expire_session", "test", 0, as.EXPIRE_SESSION); |
michael@0 | 124 | add_old_anno(pageURI, "expire_days", "test", as.EXPIRE_DAYS, 8); |
michael@0 | 125 | add_old_anno(pageURI, "expire_weeks", "test", as.EXPIRE_WEEKS, 31); |
michael@0 | 126 | add_old_anno(pageURI, "expire_months", "test", as.EXPIRE_MONTHS, 181); |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | // Expire all visits for the bookmarks. This does the same thing as the |
michael@0 | 130 | // promiseClearHistory helper, but it is made explicit here because |
michael@0 | 131 | // removeAllPages is the function we are testing. |
michael@0 | 132 | let promise = |
michael@0 | 133 | promiseTopicObserved(PlacesUtils.TOPIC_EXPIRATION_FINISHED); |
michael@0 | 134 | hs.QueryInterface(Ci.nsIBrowserHistory).removeAllPages(); |
michael@0 | 135 | yield promise; |
michael@0 | 136 | |
michael@0 | 137 | ["expire_days", "expire_weeks", "expire_months", "expire_session", |
michael@0 | 138 | "expire"].forEach(function(aAnno) { |
michael@0 | 139 | let pages = as.getPagesWithAnnotation(aAnno); |
michael@0 | 140 | do_check_eq(pages.length, 0); |
michael@0 | 141 | }); |
michael@0 | 142 | |
michael@0 | 143 | ["expire_days", "expire_weeks", "expire_months", "expire_session", |
michael@0 | 144 | "expire"].forEach(function(aAnno) { |
michael@0 | 145 | let items = as.getItemsWithAnnotation(aAnno); |
michael@0 | 146 | do_check_eq(items.length, 0); |
michael@0 | 147 | }); |
michael@0 | 148 | |
michael@0 | 149 | ["persist"].forEach(function(aAnno) { |
michael@0 | 150 | let pages = as.getPagesWithAnnotation(aAnno); |
michael@0 | 151 | do_check_eq(pages.length, 5); |
michael@0 | 152 | }); |
michael@0 | 153 | |
michael@0 | 154 | ["persist"].forEach(function(aAnno) { |
michael@0 | 155 | let items = as.getItemsWithAnnotation(aAnno); |
michael@0 | 156 | do_check_eq(items.length, 5); |
michael@0 | 157 | items.forEach(function(aItemId) { |
michael@0 | 158 | // Check item exists. |
michael@0 | 159 | bs.getItemIndex(aItemId); |
michael@0 | 160 | }); |
michael@0 | 161 | }); |
michael@0 | 162 | }); |