Bug 1503696: Cache cookies in the same way we did before Firefox 63. r=mak

Previous to bug 1453751 favicons were loaded from the network by a <xul:image>
tag with validate="never". This caused us to always use any cached version if
possible. Bug 1453751 used a normal load type causing us to revalidate with the
server for each request. This switches the loader to using the cache if possible.

Differential Revision: https://phabricator.services.mozilla.com/D11402

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Dave Townsend 2018-11-15 20:46:32 +00:00
Родитель 67221429e3
Коммит 3e18f3d532
5 изменённых файлов: 80 добавлений и 1 удалений

Просмотреть файл

@ -62,3 +62,7 @@ support-files =
file_with_slow_favicon.html
blank.html
file_favicon.png
[browser_favicon_cache.js]
support-files =
cookie_favicon.sjs
cookie_favicon.html

Просмотреть файл

@ -0,0 +1,40 @@
add_task(async () => {
const testPath = "http://example.com/browser/browser/base/content/test/favicons/cookie_favicon.html";
const resetPath = "http://example.com/browser/browser/base/content/test/favicons/cookie_favicon.sjs?reset";
let tab = BrowserTestUtils.addTab(gBrowser, testPath);
gBrowser.selectedTab = tab;
let browser = tab.linkedBrowser;
let faviconPromise = waitForLinkAvailable(browser);
await BrowserTestUtils.browserLoaded(browser);
await faviconPromise;
let cookies = Services.cookies.getCookiesFromHost("example.com", browser.contentPrincipal.originAttributes);
let seenCookie = false;
for (let cookie of cookies) {
if (cookie.name == "faviconCookie") {
seenCookie = true;
is(cookie.value, 1, "Should have seen the right initial cookie.");
}
}
ok(seenCookie, "Should have seen the cookie.");
faviconPromise = waitForLinkAvailable(browser);
BrowserTestUtils.loadURI(browser, testPath);
await BrowserTestUtils.browserLoaded(browser);
await faviconPromise;
cookies = Services.cookies.getCookiesFromHost("example.com", browser.contentPrincipal.originAttributes);
seenCookie = false;
for (let cookie of cookies) {
if (cookie.name == "faviconCookie") {
seenCookie = true;
is(cookie.value, 1, "Should have seen the cached cookie.");
}
}
ok(seenCookie, "Should have seen the cookie.");
// Reset the cookie so if this test is run again it will still pass.
await fetch(resetPath);
BrowserTestUtils.removeTab(tab);
});

Просмотреть файл

@ -0,0 +1,11 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset='utf-8'>
<title>Favicon Test for caching</title>
<link rel="icon" type="image/png" href="cookie_favicon.sjs" />
</head>
<body>
Favicon!!
</body>
</html>

Просмотреть файл

@ -0,0 +1,22 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
function handleRequest(request, response) {
if (request.queryString == "reset") {
setState("cache_cookie", "0");
response.setStatusLine(request.httpVersion, 200, "Ok");
response.write("Reset");
return;
}
let state = getState("cache_cookie");
if (!state) {
state = 0;
}
response.setStatusLine(request.httpVersion, 302, "Moved Temporarily");
response.setHeader("Set-Cookie", `faviconCookie=${++state}`);
response.setHeader("Location", "http://example.com/browser/browser/base/content/test/favicons/moz.png");
setState("cache_cookie", `${state}`);
}

Просмотреть файл

@ -78,7 +78,9 @@ class FaviconLoad {
Ci.nsILoadInfo.SEC_DISALLOW_SCRIPT),
Ci.nsIContentPolicy.TYPE_INTERNAL_IMAGE_FAVICON);
this.channel.loadFlags |= Ci.nsIRequest.LOAD_BACKGROUND;
this.channel.loadFlags |= Ci.nsIRequest.LOAD_BACKGROUND |
Ci.nsIRequest.VALIDATE_NEVER |
Ci.nsIRequest.LOAD_FROM_CACHE;
// Sometimes node is a document and sometimes it is an element. This is
// the easiest single way to get to the load group in both those cases.
this.channel.loadGroup = iconInfo.node.ownerGlobal.document.documentLoadGroup;