Bug 1853116 - Early Hints: don't preload fonts when gfx.downloadable_fonts.enabled false r=necko-reviewers,kershaw

Differential Revision: https://phabricator.services.mozilla.com/D188231
This commit is contained in:
Manuel Bucher 2023-09-21 15:35:52 +00:00
parent e4b8a30013
commit 438123356a
3 changed files with 54 additions and 7 deletions

View file

@ -10,6 +10,7 @@
#include "HttpChannelParent.h"
#include "MainThreadUtils.h"
#include "NeckoCommon.h"
#include "gfxPlatform.h"
#include "mozilla/CORSMode.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/nsCSPContext.h"
@ -219,6 +220,11 @@ void EarlyHintPreloader::MaybeCreateAndInsertPreload(
return;
}
if (destination == ASDestination::DESTINATION_FONT &&
!gfxPlatform::GetPlatform()->DownloadableFontsEnabled()) {
return;
}
nsCOMPtr<nsIURI> uri;
NS_ENSURE_SUCCESS_VOID(
NS_NewURI(getter_AddRefs(uri), aLinkHeader.mHref, nullptr, aBaseURI));

View file

@ -11,13 +11,10 @@ Services.prefs.setBoolPref(
false
);
const {
request_count_checking,
test_hint_preload_internal,
test_hint_preload,
} = ChromeUtils.importESModule(
"resource://testing-common/early_hint_preload_test_helper.sys.mjs"
);
const { request_count_checking, test_preload_url, test_hint_preload } =
ChromeUtils.importESModule(
"resource://testing-common/early_hint_preload_test_helper.sys.mjs"
);
// TODO testing:
// * Abort main document load while early hint is still loading -> early hint should be aborted
@ -34,6 +31,22 @@ add_task(async function test_103_preload_disabled() {
Services.prefs.setBoolPref("network.early-hints.enabled", true);
});
add_task(async function test_103_font_disabled() {
let url =
"https://example.com/browser/netwerk/test/browser/early_hint_asset_html.sjs?hinted=1&as=font";
Services.prefs.setBoolPref("gfx.downloadable_fonts.enabled", false);
await test_preload_url("font_loading_disabled", url, {
hinted: 0,
normal: 0,
});
Services.prefs.setBoolPref("gfx.downloadable_fonts.enabled", true);
await test_preload_url("font_loading_enabled", url, {
hinted: 1,
normal: 0,
});
Services.prefs.clearUserPref("gfx.downloadable_fonts.enabled");
});
// Preload with same origin in secure context with mochitest http proxy
add_task(async function test_103_preload_https() {
await test_hint_preload(

View file

@ -129,3 +129,31 @@ export async function test_preload_hint_and_request(input, expected_results) {
gBrowser.removeCurrentTab();
Services.cache2.clear();
}
// simple loading of one url and then checking the request count against the
// passed expected count
export async function test_preload_url(testName, url, expectedRequestCount) {
// reset the count
let headers = new Headers();
headers.append("X-Early-Hint-Count-Start", "");
await fetch(
"http://example.com/browser/netwerk/test/browser/early_hint_pixel_count.sjs",
{ headers }
);
await BrowserTestUtils.withNewTab(
{
gBrowser,
url,
waitForLoad: true,
},
async function () {}
);
let gotRequestCount = await fetch(
"http://example.com/browser/netwerk/test/browser/early_hint_pixel_count.sjs"
).then(response => response.json());
await request_count_checking(testName, gotRequestCount, expectedRequestCount);
Services.cache2.clear();
}