Skip to content

Commit

Permalink
Backed out changeset a6dadf64c1e0 (bug 1819529) for causing bug 1827669
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandor Molnar committed Apr 14, 2023
1 parent ab5e73a commit 6a89bba
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 366 deletions.
242 changes: 4 additions & 238 deletions browser/base/content/test/sanitize/browser_sanitize-timespans.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ add_task(async function test() {
await setupDownloads();
await setupFormHistory();
await setupHistory();
await setUpCookies();
await onHistoryReady();
});

Expand All @@ -54,11 +53,14 @@ async function onHistoryReady() {
var hoursSinceMidnight = new Date().getHours();
var minutesSinceMidnight = hoursSinceMidnight * 60 + new Date().getMinutes();

// Should test cookies here, but nsICookieManager/nsICookieService
// doesn't let us fake creation times. bug 463127

var itemPrefs = Services.prefs.getBranch("privacy.cpd.");
itemPrefs.setBoolPref("history", true);
itemPrefs.setBoolPref("downloads", true);
itemPrefs.setBoolPref("cache", false);
itemPrefs.setBoolPref("cookies", true);
itemPrefs.setBoolPref("cookies", false);
itemPrefs.setBoolPref("formdata", true);
itemPrefs.setBoolPref("offlineApps", false);
itemPrefs.setBoolPref("passwords", false);
Expand Down Expand Up @@ -198,46 +200,6 @@ async function onHistoryReady() {
);
}

// cookies
ok(
!SiteDataTestUtils.hasCookies("https://10minutes.com/"),
"Cookie from 10 minutes ago should be deleted"
);
ok(
SiteDataTestUtils.hasCookies("https://1hour.com"),
"Cookie from 1 hour ago should still be present"
);
ok(
SiteDataTestUtils.hasCookies("https://1hour10mins.com"),
"Cookie from 1 hour 10 minutes ago should still be present"
);
ok(
SiteDataTestUtils.hasCookies("https://2hour.com"),
"Cookie from 2 hours ago should still be present"
);
ok(
SiteDataTestUtils.hasCookies("https://2hour10mins.com"),
"Cookie from 2 hours 10 minutes ago should still be present"
);
ok(
SiteDataTestUtils.hasCookies("https://4hour.com"),
"Cookie from 4 hours ago should still be present"
);
ok(
SiteDataTestUtils.hasCookies("https://4hour10mins.com"),
"Cookie from 4 hours 10 minutes ago should still be present"
);
if (hoursSinceMidnight > 1) {
ok(
SiteDataTestUtils.hasCookies("https://today.com"),
"Cookie from today should still be present"
);
}
ok(
SiteDataTestUtils.hasCookies("https://last-year.com"),
"Cookie from last year should still be present"
);

downloadPromise = promiseDownloadRemoved(publicList);
formHistoryPromise = promiseFormHistoryRemoved();

Expand Down Expand Up @@ -350,42 +312,6 @@ async function onHistoryReady() {
);
}

// cookies
ok(
!SiteDataTestUtils.hasCookies("https://1hour.com"),
"Cookie from 1 hour ago should be deleted"
);
ok(
SiteDataTestUtils.hasCookies("https://1hour10mins.com"),
"Cookie from 1 hour 10 minutes ago should still be present"
);
ok(
SiteDataTestUtils.hasCookies("https://2hour.com"),
"Cookie from 2 hours ago should still be present"
);
ok(
SiteDataTestUtils.hasCookies("https://2hour10mins.com"),
"Cookie from 2 hours 10 minutes ago should still be present"
);
ok(
SiteDataTestUtils.hasCookies("https://4hour.com"),
"Cookie from 4 hours ago should still be present"
);
ok(
SiteDataTestUtils.hasCookies("https://4hour10mins.com"),
"Cookie from 4 hours 10 minutes ago should still be present"
);
if (hoursSinceMidnight > 1) {
ok(
SiteDataTestUtils.hasCookies("https://today.com"),
"Cookie from today should still be present"
);
}
ok(
SiteDataTestUtils.hasCookies("https://last-year.com"),
"Cookie from last year should still be present"
);

downloadPromise = promiseDownloadRemoved(publicList);
formHistoryPromise = promiseFormHistoryRemoved();

Expand Down Expand Up @@ -488,38 +414,6 @@ async function onHistoryReady() {
);
}

// cookies
ok(
!SiteDataTestUtils.hasCookies("https://1hour10mins.com"),
"Cookie from 1 hour 10 minutes ago should be deleted"
);
ok(
SiteDataTestUtils.hasCookies("https://2hour.com"),
"Cookie from 2 hours ago should still be present"
);
ok(
SiteDataTestUtils.hasCookies("https://2hour10mins.com"),
"Cookie from 2 hours 10 minutes ago should still be present"
);
ok(
SiteDataTestUtils.hasCookies("https://4hour.com"),
"Cookie from 4 hours ago should still be present"
);
ok(
SiteDataTestUtils.hasCookies("https://4hour10mins.com"),
"Cookie from 4 hours 10 minutes ago should still be present"
);
if (minutesSinceMidnight > 70) {
ok(
SiteDataTestUtils.hasCookies("https://today.com"),
"Cookie from today should still be present"
);
}
ok(
SiteDataTestUtils.hasCookies("https://last-year.com"),
"Cookie from last year should still be present"
);

downloadPromise = promiseDownloadRemoved(publicList);
formHistoryPromise = promiseFormHistoryRemoved();

Expand Down Expand Up @@ -609,34 +503,6 @@ async function onHistoryReady() {
);
}

// cookies
ok(
!SiteDataTestUtils.hasCookies("https://2hour.com"),
"Cookie from 2 hours ago should be deleted"
);
ok(
SiteDataTestUtils.hasCookies("https://2hour10mins.com"),
"Cookie from 2 hours 10 minutes ago should still be present"
);
ok(
SiteDataTestUtils.hasCookies("https://4hour.com"),
"Cookie from 4 hours ago should still be present"
);
ok(
SiteDataTestUtils.hasCookies("https://4hour10mins.com"),
"Cookie from 4 hours 10 minutes ago should still be present"
);
if (hoursSinceMidnight > 2) {
ok(
SiteDataTestUtils.hasCookies("https://today.com"),
"Cookie from today should still be present"
);
}
ok(
SiteDataTestUtils.hasCookies("https://last-year.com"),
"Cookie from last year should still be present"
);

downloadPromise = promiseDownloadRemoved(publicList);
formHistoryPromise = promiseFormHistoryRemoved();

Expand Down Expand Up @@ -717,30 +583,6 @@ async function onHistoryReady() {
);
}

// cookies
ok(
!SiteDataTestUtils.hasCookies("https://2hour10mins.com"),
"Cookie from 2 hours 10 minutes ago should be deleted"
);
ok(
SiteDataTestUtils.hasCookies("https://4hour.com"),
"Cookie from 4 hours ago should still be present"
);
ok(
SiteDataTestUtils.hasCookies("https://4hour10mins.com"),
"Cookie from 4 hours 10 minutes ago should still be present"
);
if (minutesSinceMidnight > 130) {
ok(
SiteDataTestUtils.hasCookies("https://today.com"),
"Cookie from today should still be present"
);
}
ok(
SiteDataTestUtils.hasCookies("https://last-year.com"),
"Cookie from last year should still be present"
);

downloadPromise = promiseDownloadRemoved(publicList);
formHistoryPromise = promiseFormHistoryRemoved();

Expand Down Expand Up @@ -808,26 +650,6 @@ async function onHistoryReady() {
);
}

// cookies
ok(
!SiteDataTestUtils.hasCookies("https://4hour.com"),
"Cookie from 4 hours ago should be deleted"
);
ok(
SiteDataTestUtils.hasCookies("https://4hour10mins.com"),
"Cookie from 4 hours 10 minutes ago should still be present"
);
if (hoursSinceMidnight > 4) {
ok(
SiteDataTestUtils.hasCookies("https://today.com"),
"Cookie from today should still be present"
);
}
ok(
SiteDataTestUtils.hasCookies("https://last-year.com"),
"Cookie from last year should still be present"
);

downloadPromise = promiseDownloadRemoved(publicList);
formHistoryPromise = promiseFormHistoryRemoved();

Expand Down Expand Up @@ -886,22 +708,6 @@ async function onHistoryReady() {
);
}

// cookies
ok(
!SiteDataTestUtils.hasCookies("https://4hour10mins.com"),
"Cookie from 4 hours 10 minutes ago should be deleted"
);
if (minutesSinceMidnight > 250) {
ok(
SiteDataTestUtils.hasCookies("https://today.com"),
"Cookie from today should still be present"
);
}
ok(
SiteDataTestUtils.hasCookies("https://last-year.com"),
"Cookie from last year should still be present"
);

// The 'Today' download might have been already deleted, in which case we
// should not wait for a download removal notification.
if (minutesSinceMidnight > 250) {
Expand All @@ -915,7 +721,6 @@ async function onHistoryReady() {
Services.prefs.setIntPref(Sanitizer.PREF_TIMESPAN, 4);
let progress = await Sanitizer.sanitize(null, { ignoreTimespan: false });
Assert.deepEqual(progress, {
cookies: "cleared",
history: "cleared",
formdata: "cleared",
downloads: "cleared",
Expand Down Expand Up @@ -945,10 +750,6 @@ async function onHistoryReady() {
!(await downloadExists(publicList, "fakefile-today")),
"'Today' download should now be deleted"
);
ok(
!SiteDataTestUtils.hasCookies("https://today.com"),
"Cookie from today should be deleted"
);
}

ok(
Expand All @@ -964,10 +765,6 @@ async function onHistoryReady() {
await downloadExists(publicList, "fakefile-old"),
"Year old download should still be present"
);
ok(
SiteDataTestUtils.hasCookies("https://last-year.com"),
"Cookie from last year should still be present"
);

downloadPromise = promiseDownloadRemoved(publicList);
formHistoryPromise = promiseFormHistoryRemoved();
Expand All @@ -994,39 +791,8 @@ async function onHistoryReady() {
!(await downloadExists(publicList, "fakefile-old")),
"Year old download should now be deleted"
);
ok(
!SiteDataTestUtils.hasCookies("https://last-year.com"),
"Cookie from last year should be deleted"
);
}

async function setUpCookies() {
let today = new Date();
today.setHours(0);
today.setMinutes(0);
today.setSeconds(0);
today.setMilliseconds(1);
let lastYear = new Date();
lastYear.setFullYear(lastYear.getFullYear() - 1);
let origins = {
"https://10minutes.com/": now_uSec - 9 * kUsecPerMin,
"https://1hour.com/": now_uSec - 45 * kUsecPerMin,
"https://1hour10mins.com/": now_uSec - 69 * kUsecPerMin,
"https://2hour.com/": now_uSec - 90 * kUsecPerMin,
"https://2hour10mins.com/": now_uSec - 129 * kUsecPerMin,
"https://4hour.com/": now_uSec - 180 * kUsecPerMin,
"https://4hour10mins.com/": now_uSec - 249 * kUsecPerMin,
"https://today.com/": today.getTime() * 1000,
"https://last-year.com/": lastYear.getTime() * 1000,
};
for (let [url, time] of Object.entries(origins)) {
SiteDataTestUtils.addToCookies({
origin: url,
creationTime: time,
});
ok(SiteDataTestUtils.hasCookies(url), "we have cookies for " + url);
}
}
async function setupHistory() {
let places = [];

Expand Down
36 changes: 6 additions & 30 deletions netwerk/cookie/CookieService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,35 +808,15 @@ CookieService::Add(const nsACString& aHost, const nsACString& aPath,
}

return AddNative(aHost, aPath, aName, aValue, aIsSecure, aIsHttpOnly,
aIsSession, aExpiry, &attrs, aSameSite, aSchemeMap, -1);
}

NS_IMETHODIMP
CookieService::AddForTest(const nsACString& aHost, const nsACString& aPath,
const nsACString& aName, const nsACString& aValue,
bool aIsSecure, bool aIsHttpOnly, bool aIsSession,
int64_t aExpiry,
JS::Handle<JS::Value> aOriginAttributes,
int32_t aSameSite, nsICookie::schemeType aSchemeMap,
int64_t aCreationTimeOverrideUsec, JSContext* aCx) {
OriginAttributes attrs;

if (!aOriginAttributes.isObject() || !attrs.Init(aCx, aOriginAttributes)) {
return NS_ERROR_INVALID_ARG;
}

return AddNative(aHost, aPath, aName, aValue, aIsSecure, aIsHttpOnly,
aIsSession, aExpiry, &attrs, aSameSite, aSchemeMap,
aCreationTimeOverrideUsec);
aIsSession, aExpiry, &attrs, aSameSite, aSchemeMap);
}

NS_IMETHODIMP_(nsresult)
CookieService::AddNative(const nsACString& aHost, const nsACString& aPath,
const nsACString& aName, const nsACString& aValue,
bool aIsSecure, bool aIsHttpOnly, bool aIsSession,
int64_t aExpiry, OriginAttributes* aOriginAttributes,
int32_t aSameSite, nsICookie::schemeType aSchemeMap,
int64_t aCreationTimeOverrideUsec) {
int32_t aSameSite, nsICookie::schemeType aSchemeMap) {
if (NS_WARN_IF(!aOriginAttributes)) {
return NS_ERROR_FAILURE;
}
Expand All @@ -856,18 +836,14 @@ CookieService::AddNative(const nsACString& aHost, const nsACString& aPath,
rv = CookieCommons::GetBaseDomainFromHost(mTLDService, host, baseDomain);
NS_ENSURE_SUCCESS(rv, rv);

int64_t currentTimeInUsec;
currentTimeInUsec = Cookie::GenerateUniqueCreationTime(PR_Now());
// Test callers may override creation time.
if (aCreationTimeOverrideUsec > 0) {
currentTimeInUsec = aCreationTimeOverrideUsec;
}
int64_t currentTimeInUsec = PR_Now();
CookieKey key = CookieKey(baseDomain, *aOriginAttributes);

CookieStruct cookieData(nsCString(aName), nsCString(aValue), nsCString(aHost),
nsCString(aPath), aExpiry, currentTimeInUsec,
currentTimeInUsec, aIsHttpOnly, aIsSession, aIsSecure,
aSameSite, aSameSite, aSchemeMap);
Cookie::GenerateUniqueCreationTime(currentTimeInUsec),
aIsHttpOnly, aIsSession, aIsSecure, aSameSite,
aSameSite, aSchemeMap);

RefPtr<Cookie> cookie = Cookie::Create(cookieData, key.mOriginAttributes);
MOZ_ASSERT(cookie);
Expand Down
Loading

0 comments on commit 6a89bba

Please sign in to comment.