3 <script src=
"../resources/js-test.js"></script>
7 <p id=
"description"></p>
9 <div id=
"container" style=
"width: 100px; overflow: scroll">
10 <div style=
"border: 1px solid #000; width: 1000px; height: 5000px;">5000-pixel box
</div>
11 <button id=
"target1">Target
</button>
12 <button id=
"target2">Target
</button>
13 <button id=
"target3">Target
</button>
14 <div style=
"border: 1px solid #000; width: 1000px; height: 5000px;">5000-pixel box
</div>
17 <div id=
"console"></div>
20 description("Tests that scrolling to make an element visible works when the inner scroll container doesn't need to be scrolled, but the other one does.");
23 window
.container
= document
.getElementById("container");
24 window
.target1
= document
.getElementById("target1");
25 window
.target2
= document
.getElementById("target2");
26 window
.target3
= document
.getElementById("target3");
28 if (window
.accessibilityController
) {
30 var target1AccessibleObject
= accessibilityController
.focusedElement
;
32 var target2AccessibleObject
= accessibilityController
.focusedElement
;
34 var target3AccessibleObject
= accessibilityController
.focusedElement
;
37 // Reset the initial scroll positions (since calling focus() can scroll the page too).
38 window
.scrollTo(0, 0);
39 container
.scrollTop
= 0;
40 shouldBe("window.pageYOffset", "0");
41 shouldBe("container.scrollTop", "0");
42 shouldBeGreaterThanOrEqual("target1.getBoundingClientRect().top", "5000");
44 // Scroll to make the middle target visible.
45 if (window
.accessibilityController
)
46 target2AccessibleObject
.scrollToMakeVisible();
48 // Instead of testing the exact scroll offsets of the two containers, just test that
49 // the new absolute position of the target is on-screen.
50 shouldBeGreaterThanOrEqual("window.innerHeight", "target2.getBoundingClientRect().bottom");
52 // Make sure that calling scrollToMakeVisible on target1 and target3 don't result in any
53 // scrolling, because they should already be within the viewport.
54 window
.target2top
= target2
.getBoundingClientRect().top
;
55 if (window
.accessibilityController
)
56 target1AccessibleObject
.scrollToMakeVisible();
57 shouldBe("target2top", "target2.getBoundingClientRect().top");
58 if (window
.accessibilityController
)
59 target3AccessibleObject
.scrollToMakeVisible();
60 shouldBe("target2top", "target2.getBoundingClientRect().top");