Bug 1892047 - Fix Intermittent netwerk/test/browser/browser_dns_prefetch_link_header.js r=necko-reviewers,kershaw

While not possible to reproduce locally, from the logs it appears that the dns-prefetch request may race the pageload event.
We will wait for the prefetch record before testing it.

Differential Revision: https://phabricator.services.mozilla.com/D210178
This commit is contained in:
Andrew Creskey 2024-05-14 13:39:05 +00:00
parent 5e12349e05
commit 8a6e0cff6f

View file

@ -78,11 +78,13 @@ add_task(async function test_https_dns_prefetch() {
async function () {}
);
Assert.ok(await isRecordFound("example.com"), "Host record should be found");
Assert.ok(
await isRecordFound("example.org"),
"Prefetched dns record should be found"
await TestUtils.waitForCondition(() => {
return isRecordFound("example.org");
}),
"Record from link rel=dns-prefetch element should be found"
);
Assert.ok(await isRecordFound("example.com"), "Host record should be found");
});
// Test dns-prefetch on http
@ -98,11 +100,13 @@ add_task(async function test_http_dns_prefetch() {
async function () {}
);
Assert.ok(await isRecordFound("example.com"), "Host record should be found");
Assert.ok(
await isRecordFound("example.org"),
"Prefetched dns record should be found"
await TestUtils.waitForCondition(() => {
return isRecordFound("example.org");
}),
"Record from link rel=dns-prefetch element should be found"
);
Assert.ok(await isRecordFound("example.com"), "Host record should be found");
});
// Test dns-prefetch on https with the feature disabled
@ -124,7 +128,7 @@ add_task(async function test_https_dns_prefetch_disabled() {
Assert.ok(await isRecordFound("example.com"), "Host record should be found");
Assert.ok(
!(await isRecordFound("example.org")),
"Prefetched dns record should not be found with disablePrefetchFromHTTPS set"
"Record from link rel=dns-prefetch element should not be found with disablePrefetchFromHTTPS set"
);
Services.prefs.clearUserPref("network.dns.disablePrefetchFromHTTPS");
@ -146,11 +150,13 @@ add_task(async function test_http_dns_prefetch_disabled() {
async function () {}
);
Assert.ok(await isRecordFound("example.com"), "Host record should be found");
Assert.ok(
await isRecordFound("example.org"),
"Prefetched dns record should still be found on http page with disablePrefetchFromHTTPS set"
await TestUtils.waitForCondition(() => {
return isRecordFound("example.org");
}),
"Record from link rel=dns-prefetch element should be found on http page with disablePrefetchFromHTTPS set"
);
Assert.ok(await isRecordFound("example.com"), "Host record should be found");
Services.prefs.clearUserPref("network.dns.disablePrefetchFromHTTPS");
});
@ -165,17 +171,16 @@ add_task(async function test_https_anchor_speculative_dns_prefetch() {
url: https_requestUrl,
waitForLoad: true,
},
async function () {}
);
Assert.ok(await isRecordFound("example.com"), "Host record should be found");
Assert.ok(
await isRecordFound("example.org"),
"Prefetched dns record should still be found on http page with disablePrefetchFromHTTPS set"
);
Assert.ok(
!(await isRecordFound("www.mozilla.org")),
"By default we do not speculatively prefetch dns for anchor elements on https documents"
async function () {
Assert.ok(
await isRecordFound("example.com"),
"Host record should be found"
);
Assert.ok(
!(await isRecordFound("www.mozilla.org")),
"By default we do not speculatively prefetch dns for anchor elements on https documents"
);
}
);
// And enable the pref to verify that it works
@ -192,24 +197,17 @@ add_task(async function test_https_anchor_speculative_dns_prefetch() {
waitForLoad: true,
},
async function () {
// The anchor element prefetchs are sent after pageload event; wait for them
Assert.ok(
await TestUtils.waitForCondition(() => {
return isRecordFound("www.mozilla.org");
}),
"Speculatively prefetch dns for anchor elements on https documents"
);
Assert.ok(
await isRecordFound("example.com"),
"Host record should be found"
);
Assert.ok(
await isRecordFound("example.org"),
"Prefetched dns record should still be found on http page with disablePrefetchFromHTTPS set"
);
// The anchor element prefetchs are sent after pageload event; wait for them
await TestUtils.waitForCondition(() => {
return isRecordFound("www.mozilla.org");
});
Assert.ok(
await isRecordFound("www.mozilla.org"),
"Speculatively prefetch dns for anchor elements on https documents"
);
}
);
@ -228,22 +226,23 @@ add_task(async function test_http_anchor_speculative_dns_prefetch() {
},
async function () {
Assert.ok(
await isRecordFound("example.com"),
"Host record should be found"
);
Assert.ok(
await isRecordFound("example.org"),
"Prefetched dns record should still be found on http page with disablePrefetchFromHTTPS set"
await TestUtils.waitForCondition(() => {
return isRecordFound("example.org");
}),
"Record from link rel=dns-prefetch element should be found"
);
// The anchor element prefetchs are sent after pageload event; wait for them
await TestUtils.waitForCondition(() => {
return isRecordFound("www.mozilla.org");
});
Assert.ok(
await TestUtils.waitForCondition(() => {
return isRecordFound("www.mozilla.org");
}),
"By default we speculatively prefetch dns for anchor elements on http documents"
);
Assert.ok(
await isRecordFound("www.mozilla.org"),
"By default we speculatively prefetch dns for anchor elements on http documents"
await isRecordFound("example.com"),
"Host record should be found"
);
}
);
@ -263,17 +262,19 @@ add_task(async function test_http_anchor_speculative_dns_prefetch() {
},
async function () {
Assert.ok(
await isRecordFound("example.com"),
"Host record should be found"
);
Assert.ok(
await isRecordFound("example.org"),
"Prefetched dns record should still be found on http page with disablePrefetchFromHTTPS set"
await TestUtils.waitForCondition(() => {
return isRecordFound("example.org");
}),
"Record from link rel=dns-prefetch element should be found"
);
Assert.ok(
!(await isRecordFound("www.mozilla.org")),
"We disabled speculative prefetch dns for anchor elements on http documents"
);
Assert.ok(
await isRecordFound("example.com"),
"Host record should be found"
);
}
);