0

Remove waitForCookie early timeout except when we expect no cookie

Most DBSC WPTs expect that calling `waitForCookie` will return a cookie.
Only one (not-secure-connection.html) expects to wait indefinitely for
the cookie.

This CL changes the behavior of `waitForCookie` so that it does not time
out after 1 second for all tests that expect a cookie to be returned. If
a cookie is never found, these tests will time out with the standard
configuration for WPT timeouts. The goal is to significantly reduce
flaky failures caused by the 1-second timeout being too short.

We do not change the 1-second timeout for not-secure-connection.html.
This is to avoid the test always being long-running, since the expected
result would be that the test would time out. It is possible that the
1-second timeout is too short in some cases, but in that case the test
will still silently pass rather than cause flaky failures.

Bug: 353767385
Change-Id: I8fed421fbf874b5fe195a5d65fb800c415a3d27e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6348219
Commit-Queue: thefrog <thefrog@chromium.org>
Reviewed-by: Daniel Rubery <drubery@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1431626}
This commit is contained in:
thefrog
2025-03-12 11:01:11 -07:00
committed by Chromium LUCI CQ
parent 4c84f6aa96
commit 809a881bda
15 changed files with 22 additions and 21 deletions

@ -18,7 +18,7 @@
// Prompt starting a session, and wait until registration completes.
const login_response = await fetch('login.py');
assert_equals(login_response.status, 200);
assert_true(await waitForCookie(expectedCookieAndValue));
await waitForCookie(expectedCookieAndValue, /*expectCookie=*/true);
// The server ends the session.
const end_session_response = await fetch('end_session_via_clear_site_data.py');
@ -43,7 +43,7 @@
// Prompt starting a session, and wait until registration completes.
const login_response = await fetch('login.py');
assert_equals(login_response.status, 200);
assert_true(await waitForCookie(expectedCookieAndValue));
await waitForCookie(expectedCookieAndValue, /*expectCookie=*/true);
// The server ends the session.
const end_session_response = await fetch('end_session_via_clear_site_data.py', {method: 'POST', body: '"storage"'});

@ -18,7 +18,7 @@
// Prompt starting a session, and wait until registration completes.
const login_response = await fetch('login.py');
assert_equals(login_response.status, 200);
assert_true(await waitForCookie(expectedCookieAndValue));
await waitForCookie(expectedCookieAndValue, /*expectCookie=*/true);
// Confirm that a request has the cookie set.
const auth_response = await fetch('verify_authenticated.py');

@ -25,7 +25,7 @@
// Prompt starting a session, and wait until registration completes.
const login_response = await fetch('login.py');
assert_equals(login_response.status, 200);
assert_true(await waitForCookie(expectedCookieAndValue));
await waitForCookie(expectedCookieAndValue, /*expectCookie=*/true);
// Confirm that a request has the cookie set.
const auth_response = await fetch('verify_authenticated.py');

@ -2,20 +2,21 @@ export function documentHasCookie(cookieAndValue) {
return document.cookie.split(';').some(item => item.includes(cookieAndValue));
}
export function waitForCookie(cookieAndValue) {
export async function waitForCookie(cookieAndValue, expectCookie) {
const startTime = Date.now();
return new Promise(resolve => {
const hasCookie = await new Promise(resolve => {
const interval = setInterval(() => {
if (documentHasCookie(cookieAndValue)) {
clearInterval(interval);
resolve(true);
}
if (Date.now() - startTime >= 1000) {
if (!expectCookie && Date.now() - startTime >= 1000) {
clearInterval(interval);
resolve(false);
}
}, 100);
});
assert_equals(hasCookie, expectCookie);
}
export function expireCookie(cookieAndAttributes) {

@ -18,7 +18,7 @@
// Prompt starting a session, and wait until registration completes.
const login_response = await fetch('login.py');
assert_equals(login_response.status, 200);
assert_true(await waitForCookie(expectedCookieAndValue));
await waitForCookie(expectedCookieAndValue, /*expectCookie=*/true);
// Confirm that expiring the cookie still leads to a request with the cookie set (refresh occurs).
expireCookie(expectedCookieAndAttributes);

@ -18,6 +18,6 @@
const login_response = await fetch('login.py');
assert_equals(login_response.status, 200);
// For HTTP, this call will time out, because the cookie is never set.
assert_false(await waitForCookie(expectedCookieAndValue));
await waitForCookie(expectedCookieAndValue, /*expectCookie=*/false);
}, "Try to establish a session over HTTP");
</script>

@ -21,7 +21,7 @@
// Prompt starting a session, and wait until registration completes.
const login_response = await fetch('login.py');
assert_equals(login_response.status, 200);
assert_true(await waitForCookie(expectedCookieAndValue));
await waitForCookie(expectedCookieAndValue, /*expectCookie=*/true);
// Confirm that a request has the cookie set.
const auth_response = await fetch('verify_authenticated.py');

@ -20,7 +20,7 @@
// Prompt starting a session, and wait until registration completes.
const login_response = await fetch('login.py');
assert_equals(login_response.status, 200);
assert_true(await waitForCookie(expectedCookieAndValue1));
await waitForCookie(expectedCookieAndValue1, /*expectCookie=*/true);
// Confirm that a request has the cookie set.
const auth_response = await fetch('verify_authenticated.py');

@ -21,7 +21,7 @@
// Prompt starting a session, and wait until registration completes.
const login_response = await fetch('login.py');
assert_equals(login_response.status, 200);
assert_true(await waitForCookie(expectedCookieAndValue));
await waitForCookie(expectedCookieAndValue, /*expectCookie=*/true);
// Confirm that a request has the cookie set.
const auth_response = await fetch('verify_authenticated.py');

@ -21,7 +21,7 @@
// Prompt starting a session, and wait until registration completes.
const login_response = await fetch('login.py');
assert_equals(login_response.status, 200);
assert_true(await waitForCookie(expectedCookieAndValue));
await waitForCookie(expectedCookieAndValue, /*expectCookie=*/true);
// Confirm that a request has the cookie set.
const auth_response = await fetch('verify_authenticated.py');

@ -20,7 +20,7 @@
// Prompt starting a session, and wait until registration completes.
const login_response = await fetch('login.py');
assert_equals(login_response.status, 200);
assert_true(await waitForCookie(expectedCookieAndValue));
await waitForCookie(expectedCookieAndValue, /*expectCookie=*/true);
// Confirm that a request has the cookie set.
const auth_response = await fetch('verify_authenticated.py');

@ -21,7 +21,7 @@
// The server will confirm that the authorization is sent in registration.
const login_response = await fetch('login.py');
assert_equals(login_response.status, 200);
assert_true(await waitForCookie(expectedCookieAndValue));
await waitForCookie(expectedCookieAndValue, /*expectCookie=*/true);
// Confirm that registration succeeded (cookie was set).
const auth_response = await fetch('verify_authenticated.py');

@ -22,7 +22,7 @@
// Prompt starting a session, and wait until registration completes.
const login_response = await fetch('login.py');
assert_equals(login_response.status, 200);
assert_true(await waitForCookie(expectedCookieAndValue));
await waitForCookie(expectedCookieAndValue, /*expectCookie=*/true);
// Set up a challenge in advance.
const challenge_response = await fetch('request_early_challenge.py', {
@ -57,7 +57,7 @@
// Prompt starting one session, and wait until registration completes.
const login_response1 = await fetch('login.py');
assert_equals(login_response1.status, 200);
assert_true(await waitForCookie(expectedCookieAndValue1));
await waitForCookie(expectedCookieAndValue1, /*expectCookie=*/true);
// Configure server for sending back a challenge early, and configure the second session's
// cookie.
@ -69,7 +69,7 @@
// Prompt starting second session, and wait until registration completes.
const login_response2 = await fetch('login.py');
assert_equals(login_response2.status, 200);
assert_true(await waitForCookie(expectedCookieAndValue2));
await waitForCookie(expectedCookieAndValue2, /*expectCookie=*/true);
// Set up a challenge in advance.
const challenge_response = await fetch('request_early_challenge.py', {

@ -21,7 +21,7 @@
// Prompt starting a session, and wait until registration completes.
const login_response = await fetch('login.py');
assert_equals(login_response.status, 200);
assert_true(await waitForCookie(expectedCookieAndValue));
await waitForCookie(expectedCookieAndValue, /*expectCookie=*/true);
// Confirm that a request has the cookie set.
const auth_response = await fetch('verify_authenticated.py');
@ -47,7 +47,7 @@
// Prompt starting a session, and wait until registration completes.
const login_response = await fetch('login.py');
assert_equals(login_response.status, 200);
assert_true(await waitForCookie(expectedCookieAndValue));
await waitForCookie(expectedCookieAndValue, /*expectCookie=*/true);
// Confirm that a request has the cookie set.
const auth_response = await fetch('verify_authenticated.py');

@ -48,7 +48,7 @@
// Prompt starting a session, and wait until registration completes.
const login_response = await fetch('login.py');
assert_equals(login_response.status, 200);
assert_true(await waitForCookie(expectedCookieAndValue));
await waitForCookie(expectedCookieAndValue, /*expectCookie=*/true);
async function expireCookieAndTriggerRequest(endpoint, expectRefresh) {
expireCookie(expectedCookieAndAttributes);