Backed out changeset a6dadf64c1e0 (bug 1819529) for causing bug 1827669

This commit is contained in:
Sandor Molnar 2023-04-14 16:59:32 +03:00
parent a3c219bee7
commit 0f674185af
6 changed files with 48 additions and 366 deletions

View File

@ -37,7 +37,6 @@ add_task(async function test() {
await setupDownloads();
await setupFormHistory();
await setupHistory();
await setUpCookies();
await onHistoryReady();
});
@ -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);
@ -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();
@ -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();
@ -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();
@ -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();
@ -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();
@ -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();
@ -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) {
@ -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",
@ -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(
@ -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();
@ -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 = [];

View File

@ -808,26 +808,7 @@ 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)
@ -835,8 +816,7 @@ 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;
}
@ -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);

View File

@ -131,58 +131,6 @@ interface nsICookieManager : nsISupports
in int32_t aSameSite,
in nsICookie_schemeType aSchemeMap);
/**
* Add a cookie with a custom creation time, purpose is for test cases only.
*
* @param aHost
* the host or domain for which the cookie is set. presence of a
* leading dot indicates a domain cookie; otherwise, the cookie
* is treated as a non-domain cookie (see RFC2109). The host string
* will be normalized to ASCII or ACE; any trailing dot will be
* stripped. To be a domain cookie, the host must have at least two
* subdomain parts (e.g. '.foo.com', not '.com'), otherwise an
* exception will be thrown. An empty string is acceptable
* (e.g. file:// URI's).
* @param aPath
* path within the domain for which the cookie is valid
* @param aName
* cookie name
* @param aValue
* cookie data
* @param aIsSecure
* true if the cookie should only be sent over a secure connection.
* @param aIsHttpOnly
* true if the cookie should only be sent to, and can only be
* modified by, an http connection.
* @param aIsSession
* true if the cookie should exist for the current session only.
* see aExpiry.
* @param aExpiry
* expiration date, in seconds since midnight (00:00:00), January 1,
* 1970 UTC. note that expiry time will also be honored for session cookies;
* in this way, the more restrictive of the two will take effect.
* @param aOriginAttributes
* the originAttributes of this cookie.
* @param aSameSite
* the SameSite attribute.
* @param aCreationTimeOverrideUsec
* custom creation time that will be set on the cookie,
* passing -1 indicates that no custom creation time is provided.
*/
[implicit_jscontext]
void addForTest(in AUTF8String aHost,
in AUTF8String aPath,
in ACString aName,
in AUTF8String aValue,
in boolean aIsSecure,
in boolean aIsHttpOnly,
in boolean aIsSession,
in int64_t aExpiry,
in jsval aOriginAttributes,
in int32_t aSameSite,
in nsICookie_schemeType aSchemeMap,
in int64_t aCreationTimeOverrideUsec);
[notxpcom]
nsresult addNative(in AUTF8String aHost,
in AUTF8String aPath,
@ -194,8 +142,7 @@ interface nsICookieManager : nsISupports
in int64_t aExpiry,
in OriginAttributesPtr aOriginAttributes,
in int32_t aSameSite,
in nsICookie_schemeType aSchemeMap,
in int64_t aCreationTimeOverrideUsec);
in nsICookie_schemeType aSchemeMap);
/**
* Find whether a given cookie already exists.

View File

@ -757,42 +757,39 @@ TEST(TestCookie, TestCookieMain)
// first, ensure a clean slate
EXPECT_NS_SUCCEEDED(cookieMgr->RemoveAll());
// add some cookies
EXPECT_TRUE(NS_SUCCEEDED(
cookieMgr2->AddNative("cookiemgr.test"_ns, // domain
"/foo"_ns, // path
"test1"_ns, // name
"yes"_ns, // value
false, // is secure
false, // is httponly
true, // is session
INT64_MAX, // expiry time
&attrs, // originAttributes
nsICookie::SAMESITE_NONE, nsICookie::SCHEME_HTTPS,
-1))); // do not overwrite creation time
EXPECT_TRUE(NS_SUCCEEDED(
cookieMgr2->AddNative("cookiemgr.test"_ns, // domain
"/foo"_ns, // path
"test2"_ns, // name
"yes"_ns, // value
false, // is secure
true, // is httponly
true, // is session
PR_Now() / PR_USEC_PER_SEC + 2, // expiry time
&attrs, // originAttributes
nsICookie::SAMESITE_NONE, nsICookie::SCHEME_HTTPS,
-1))); // do not overwrite creation time
EXPECT_TRUE(NS_SUCCEEDED(
cookieMgr2->AddNative("new.domain"_ns, // domain
"/rabbit"_ns, // path
"test3"_ns, // name
"yes"_ns, // value
false, // is secure
false, // is httponly
true, // is session
INT64_MAX, // expiry time
&attrs, // originAttributes
nsICookie::SAMESITE_NONE, nsICookie::SCHEME_HTTPS,
-1))); // do not overwrite creation time
EXPECT_TRUE(NS_SUCCEEDED(cookieMgr2->AddNative("cookiemgr.test"_ns, // domain
"/foo"_ns, // path
"test1"_ns, // name
"yes"_ns, // value
false, // is secure
false, // is httponly
true, // is session
INT64_MAX, // expiry time
&attrs, // originAttributes
nsICookie::SAMESITE_NONE,
nsICookie::SCHEME_HTTPS)));
EXPECT_TRUE(NS_SUCCEEDED(cookieMgr2->AddNative(
"cookiemgr.test"_ns, // domain
"/foo"_ns, // path
"test2"_ns, // name
"yes"_ns, // value
false, // is secure
true, // is httponly
true, // is session
PR_Now() / PR_USEC_PER_SEC + 2, // expiry time
&attrs, // originAttributes
nsICookie::SAMESITE_NONE, nsICookie::SCHEME_HTTPS)));
EXPECT_TRUE(NS_SUCCEEDED(cookieMgr2->AddNative("new.domain"_ns, // domain
"/rabbit"_ns, // path
"test3"_ns, // name
"yes"_ns, // value
false, // is secure
false, // is httponly
true, // is session
INT64_MAX, // expiry time
&attrs, // originAttributes
nsICookie::SAMESITE_NONE,
nsICookie::SCHEME_HTTPS)));
// confirm using enumerator
nsTArray<RefPtr<nsICookie>> cookies;
EXPECT_NS_SUCCEEDED(cookieMgr->GetCookies(cookies));

View File

@ -81,9 +81,6 @@ export var SiteDataTestUtils = {
* set cookie for.
* @param {String} [options.name] - Cookie name
* @param {String} [options.value] - Cookie value
* @param {Number} [optins.creationTime] - Optional custom creation time in usec that will be set on the cookie.
* If creationTime is not provided the cookieService will set the current time
* as the cookies creation time instead.
*/
addToCookies({
origin,
@ -92,7 +89,6 @@ export var SiteDataTestUtils = {
originAttributes = {},
name = "foo",
value = "bar",
creationTime = -1,
}) {
if (origin) {
let principal = Services.scriptSecurityManager.createContentPrincipalFromOrigin(
@ -104,7 +100,8 @@ export var SiteDataTestUtils = {
? originAttributes
: principal.originAttributes;
}
Services.cookies.addForTest(
Services.cookies.add(
host,
path,
name,
@ -115,8 +112,7 @@ export var SiteDataTestUtils = {
Math.floor(Date.now() / 1000) + 24 * 60 * 60,
originAttributes,
Ci.nsICookie.SAMESITE_NONE,
Ci.nsICookie.SCHEME_UNSET,
creationTime
Ci.nsICookie.SCHEME_UNSET
);
},

View File

@ -326,7 +326,7 @@ nsresult nsCookieInjector::InjectCookiesFromRules(
rv = cookieManager->AddNative(
c.Host(), c.Path(), c.Name(), c.Value(), c.IsSecure(), c.IsHttpOnly(),
c.IsSession(), c.Expiry(), &aOriginAttributes, c.SameSite(),
static_cast<nsICookie::schemeType>(c.SchemeMap()), -1);
static_cast<nsICookie::schemeType>(c.SchemeMap()));
NS_ENSURE_SUCCESS(rv, rv);
aHasInjectedCookie = true;