Skip to content

Commit

Permalink
Fix meta refresh test
Browse files Browse the repository at this point in the history
This fixes the less-than ideal test for <meta> refresh I wrote.
I don't think it needs a long timeout, but just had to wait for
the iframe to load completely, which is when, as per the spec, the
refresh timer should start.
(Single, tiny HTML file in this case, really shouldn't take long but I
guess the browser is pretty busy when all the tests are run at once?)
I can only go off of my local test results for this currently
but I hope that this fixes the failures that came up.

Spec:
Step 13 of the shared declarative refresh steps:
https://html.spec.whatwg.org/#shared-declarative-refresh-steps

Bug: 333976551
Change-Id: I134348aac4f97b321875b37a7c179432585bd3fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5488199
Reviewed-by: Kent Tamura <[email protected]>
Reviewed-by: Mason Freed <[email protected]>
Commit-Queue: Kent Tamura <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1356250}
  • Loading branch information
Psychpsyo authored and chromium-wpt-export-bot committed Sep 17, 2024
1 parent 4b27fc7 commit 633e522
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 41 deletions.
56 changes: 25 additions & 31 deletions html/meta/refresh-time.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,40 @@

<body>
<script>
async function sleep(ms, test) {
return new Promise(resolve => {test.step_timeout(resolve, ms)});
}

promise_test(async test => {
async function measureRefreshTime(src) {
const frame = document.createElement("iframe");
document.body.appendChild(frame);
frame.src = "resources/refresh1.html";
await sleep(500, test);
assert_equals(frame.contentWindow.document.title, "refresh 1");
await sleep(1000, test);
assert_equals(frame.contentWindow.document.title, "got refreshed");
}, "Ensure that refresh is observed");

const loadPromise = new Promise(resolve => {
frame.addEventListener("load", () => {
resolve(performance.now());
});
});
frame.src = src;
const startTime = await loadPromise;

const unloadPromise = new Promise(resolve => {
frame.contentWindow.addEventListener("beforeunload", () => {
resolve(performance.now());
});
});
const endTime = await unloadPromise;
return endTime - startTime;
}

promise_test(async test => {
const frame = document.createElement("iframe");
document.body.appendChild(frame);
frame.src = "resources/refresh.99.html";
await sleep(500, test);
assert_equals(frame.contentWindow.document.title, "got refreshed");
}, "Ensure that fractions in refresh time are ignored");
const refreshTime = await measureRefreshTime("resources/refresh1.html");
assert_greater_than(refreshTime, 900);
}, "Ensure that refresh is observed");

promise_test(async test => {
const frame = document.createElement("iframe");
document.body.appendChild(frame);
frame.src = "resources/refresh1.99.html";
await sleep(500, test);
assert_equals(frame.contentWindow.document.title, "refresh 1.99");
await sleep(1000, test);
assert_equals(frame.contentWindow.document.title, "got refreshed");
const refreshTime = await measureRefreshTime("resources/refresh1.99.html");
assert_greater_than(refreshTime, 900);
}, "Ensure that non-fractional part in refresh time does not get discarded");

promise_test(async test => {
const frame = document.createElement("iframe");
document.body.appendChild(frame);
frame.src = "resources/refresh1dotdot5dot.html";
await sleep(500, test);
assert_equals(frame.contentWindow.document.title, "refresh 1..5.");
await sleep(750, test);
assert_equals(frame.contentWindow.document.title, "got refreshed");
const refreshTime = await measureRefreshTime("resources/refresh1dotdot9dot.html");
assert_greater_than(refreshTime, 900);
}, "Ensure that multiple periods in refresh time just get ignored");
</script>
</body>
5 changes: 0 additions & 5 deletions html/meta/resources/refresh.99.html

This file was deleted.

5 changes: 0 additions & 5 deletions html/meta/resources/refresh1dotdot5dot.html

This file was deleted.

5 changes: 5 additions & 0 deletions html/meta/resources/refresh1dotdot9dot.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>refresh 1..9.</title>

<meta http-equiv="refresh" content="1..9.;url=gotRefreshed.html">

0 comments on commit 633e522

Please sign in to comment.