Skip to content

Commit 67e701c

Browse files
vmpstrchromium-wpt-export-bot
authored andcommitted
Reland "STTF: Delay sttf until related pages are finalized."
Fixed the test. Original reason for revert: TextFragmentAnchorTest.AvoidScrollingIfHasOtherRelatedPages failed at https://ci.chromium.org/ui/p/chromium/builders/ci/Linux%20UBSan%20Tests/15610/overview Original change's description: > STTF: Delay sttf until related pages are finalized. > > This patch delays sttf until related pages are finalized. It also > sends the browser-authoritative bool indicating whether there are > related pages associated with this renderer. > > R=rakina@chromium.org > > Change-Id: Ifc03488451bd3d1e99c4ab447362437778ddf96d > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7629937 > Reviewed-by: Rakina Zata Amni <rakina@chromium.org> > Commit-Queue: Vladimir Levin <vmpstr@chromium.org> > Reviewed-by: Ken Buchanan <kenrb@chromium.org> > Reviewed-by: Ari Chivukula <arichiv@chromium.org> > Cr-Commit-Position: refs/heads/main@{#1625391} Bug: 457771782 Change-Id: I9a36bfc18d12af87e96880bd565e670a2c9068ff Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7818478 Commit-Queue: Vladimir Levin <vmpstr@chromium.org> Reviewed-by: Joe Mason <joenotcharles@google.com> Reviewed-by: Rakina Zata Amni <rakina@chromium.org> Cr-Commit-Position: refs/heads/main@{#1627144}
1 parent e9495ed commit 67e701c

5 files changed

Lines changed: 91 additions & 7 deletions

File tree

css/css-contain/content-visibility/resources/text-fragment-target-auto.html

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@
2828
let key = (new URL(document.location)).searchParams.get("key");
2929
stashResultsThenClose(key, results);
3030
}
31-
function doubleRafCheckScroll() {
32-
requestAnimationFrame(() => {
33-
requestAnimationFrame(() => {
34-
checkScroll();
35-
});
36-
});
31+
32+
function waitAndCheckScroll() {
33+
requestAnimationFrame(
34+
() => requestAnimationFrame(
35+
() => requestAnimationFrame(
36+
() => requestAnimationFrame(checkScroll))));
3737
}
38+
3839
</script>
3940

4041
<style>
@@ -46,7 +47,7 @@
4647
}
4748
</style>
4849

49-
<body onload="doubleRafCheckScroll()">
50+
<body onload="waitAndCheckScroll()">
5051
<div class=spacer></div>
5152
<div class=auto>
5253
<div id=text>hiddentext</div>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!doctype html>
2+
<title>Popup 1</title>
3+
<script src="/common/utils.js"></script>
4+
<script src="../stash.js"></script>
5+
6+
<script>
7+
const urlParams = new URLSearchParams(window.location.search);
8+
const key = urlParams.get("key");
9+
10+
window.onload = () => {
11+
// Navigate this window to B.com (cross-origin) with a text fragment directive
12+
const crossOriginURL = new URL("http://{{hosts[alt][www]}}:{{ports[http][0]}}/scroll-to-text-fragment/resources/target.html");
13+
crossOriginURL.searchParams.set("key", key);
14+
crossOriginURL.hash = "#:~:text=target";
15+
16+
// Simultaneously open popup2 on A.com (same-origin) to keep the browsing context group alive
17+
try {
18+
window.open(`popup2.html?key=${key}`, "_blank");
19+
} catch (e) {}
20+
21+
// Navigate popup1 to B.com
22+
requestAnimationFrame(() => {
23+
window.location.href = crossOriginURL.href;
24+
});
25+
};
26+
</script>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!doctype html>
2+
<title>Popup 2</title>
3+
<body>Popup 2</body>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!doctype html>
2+
<title>Target on B.com</title>
3+
<script src="../stash.js"></script>
4+
5+
<style>
6+
.spacer {
7+
height: 2000px;
8+
}
9+
</style>
10+
11+
<body>
12+
<div class="spacer"></div>
13+
<div id="target">target text</div>
14+
15+
<script>
16+
function checkScroll() {
17+
const did_scroll = window.scrollY > 0;
18+
const urlParams = new URLSearchParams(window.location.search);
19+
const key = urlParams.get("key");
20+
21+
stashResultsThenClose(key, { did_scroll: did_scroll });
22+
}
23+
24+
window.onload = () => {
25+
requestAnimationFrame(() => requestAnimationFrame(() => {
26+
requestAnimationFrame(() => requestAnimationFrame(checkScroll))
27+
}));
28+
};
29+
</script>
30+
</body>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!doctype html>
2+
<title>Text fragment anchor should not scroll if has other related pages</title>
3+
<meta charset=utf-8>
4+
<script src="/resources/testharness.js"></script>
5+
<script src="/resources/testharnessreport.js"></script>
6+
<script src="/resources/testdriver.js"></script>
7+
<script src="/resources/testdriver-vendor.js"></script>
8+
<script src="/common/utils.js"></script>
9+
<script src="stash.js"></script>
10+
11+
<script>
12+
async_test(t => {
13+
const key = token();
14+
15+
test_driver.bless("Open a popup on A.com", () => {
16+
window.open(`resources/popup1.sub.html?key=${key}`, "_blank", "width=300,height=300");
17+
});
18+
19+
fetchResults(key, t.step_func(data => {
20+
assert_equals(data.did_scroll, false, "scrolled to fragment");
21+
t.done();
22+
}), t.unreached_func("Stash fetch failed"));
23+
}, "Text fragment should not scroll if opened with window.open and a simultaneous navigation");
24+
</script>

0 commit comments

Comments
 (0)