Bug 1783848: Stop cancelling early hints on error pages r=necko-reviewers,kershaw

***
Bug 1783848: Fixed failure due to non secure URLs

Differential Revision: https://phabricator.services.mozilla.com/D155669
This commit is contained in:
mleclair 2022-09-14 11:57:49 +00:00
parent 674ee40a3a
commit 086e24cfbb
4 changed files with 91 additions and 4 deletions

View File

@ -84,7 +84,7 @@ void EarlyHintsService::FinalResponse(uint32_t aResponseStatus) {
// We will collect telemetry mosly once for a document.
// In case of a reddirect this will be called multiple times.
CollectTelemetry(Some(aResponseStatus));
if (aResponseStatus >= 300) {
if (aResponseStatus >= 300 && aResponseStatus < 400) {
mOngoingEarlyHints->CancelAllOngoingPreloads();
mCanceled = true;
}

View File

@ -117,6 +117,11 @@ support-files =
skip-if =
os == 'linux' && bits == 64 && !debug # Bug 1744028 and Bug 1746324
[browser_103_assets.js]
skip-if =
os == 'linux' && bits == 64 && !debug # Bug 1744028 and Bug 1746324
[browser_103_no_cancel_on_error.js]
support-files =
early_hint_preload_test_helper.jsm
skip-if =
os == 'linux' && bits == 64 && !debug # Bug 1744028 and Bug 1746324
[browser_cookie_filtering_basic.js]

View File

@ -0,0 +1,79 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Services.prefs.setBoolPref("network.early-hints.enabled", true);
const { lax_request_count_checking } = ChromeUtils.import(
"resource://testing-common/early_hint_preload_test_helper.jsm"
);
// - httpCode is the response code we're testing for. This file mostly covers 400 and 500 responses
async function test_hint_completion_on_error(httpCode) {
// reset the count
let headers = new Headers();
headers.append("X-Early-Hint-Count-Start", "");
await fetch(
"https://example.com/browser/netwerk/test/browser/early_hint_pixel_count.sjs",
{ headers }
);
let requestUrl = `https://example.com/browser/netwerk/test/browser/early_hint_asset_html.sjs?as=image&code=${httpCode}`;
await BrowserTestUtils.withNewTab(
{
gBrowser,
url: requestUrl,
waitForLoad: true,
},
async function() {}
);
let gotRequestCount = await fetch(
"https://example.com/browser/netwerk/test/browser/early_hint_pixel_count.sjs"
).then(response => response.json());
// TODO: Switch to stricter counting method after fixing https://bugzilla.mozilla.org/show_bug.cgi?id=1753730#c11
await lax_request_count_checking(
`test_103_error_${httpCode}`,
gotRequestCount,
{
hinted: 1,
normal: 0,
}
);
/*
await Assert.deepEqual(
gotRequestCount,
hinted ? { hinted: 1, normal: 0 } : { hinted: 0, normal: 1 },
`${testName} (${asset}): Unexpected amount of requests made`
);
*/
}
// 400 Bad Request
add_task(async function test_complete_103_on_400() {
await test_hint_completion_on_error(400);
});
add_task(async function test_complete_103_on_401() {
await test_hint_completion_on_error(401);
});
add_task(async function test_complete_103_on_402() {
await test_hint_completion_on_error(402);
});
add_task(async function test_complete_103_on_403() {
await test_hint_completion_on_error(403);
});
add_task(async function test_complete_103_on_500() {
await test_hint_completion_on_error(500);
});
add_task(async function test_complete_103_on_501() {
await test_hint_completion_on_error(501);
});
add_task(async function test_complete_103_on_502() {
await test_hint_completion_on_error(502);
});

View File

@ -5,7 +5,7 @@ function handleRequest(request, response) {
let qs = new URLSearchParams(request.queryString);
let asset = qs.get("as");
let hinted = qs.get("hinted") !== "0";
let httpCode = qs.get("code");
// eslint-disable-next-line mozilla/use-services
let uuidGenerator = Cc["@mozilla.org/uuid-generator;1"].getService(
Ci.nsIUUIDGenerator
@ -91,8 +91,11 @@ function handleRequest(request, response) {
`;
}
// main document response
response.write("HTTP/1.1 200 OK\r\n");
if (!httpCode) {
response.write(`HTTP/1.1 ${httpCode} OK\r\n`);
} else {
response.write(`HTTP/1.1 ${httpCode} Error\r\n`);
}
response.write("Content-Type: text/html;charset=utf-8\r\n");
response.write("Cache-Control: no-cache\r\n");
response.write(`Content-Length: ${body.length}\r\n`);