Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Errors
- This test failed 4 times in the preceding 30 days. quicksearch this test
- Manifest: layout/base/tests/mochitest.toml
<!DOCTYPE HTML>
<html>
<!--
-->
<head>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body onload="run()">
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
function assert_fully_in_view(element) {
let rect = element.getBoundingClientRect();
ok(rect.top >= 0, `${element.id} top`);
ok(rect.bottom <= window.innerHeight, `${element.id} bottom`);
}
function run() {
is(window.scrollY, 0, "window should initially be at top");
let first = document.getElementById("first");
let second = document.getElementById("second");
let third = document.getElementById("third");
first.focus();
let firstOffset = window.scrollY;
isnot(firstOffset, 0, "we scrolled to first anchor");
ok(firstOffset + window.innerHeight > 4000,
"we scrolled enough to show the anchor");
assert_fully_in_view(first);
window.scrollTo(0, 0);
second.focus();
let secondOffset = window.scrollY;
assert_fully_in_view(second);
window.scrollTo(0, 0);
third.focus();
let thirdOffset = window.scrollY;
assert_fully_in_view(third);
ok(secondOffset > firstOffset, "we scrolled the second line of the anchor into view");
ok(thirdOffset > secondOffset, "we scrolled the second line of the anchor into view");
window.scrollTo(0, 0); // make the results visible
SimpleTest.finish();
}
</script>
</pre>
<div style="height:4000px"></div>
<div style="height:4000px"></div>
</body>
</html>