3 <script src=
"../resources/js-test.js"></script>
7 <p id=
"description"></p>
9 <div id=
"container" style=
"height: 100px; overflow: scroll">
10 <button id=
"upper_target">Upper Target
</button>
11 <div style=
"border: 1px solid #000; height: 5000px;">5000-pixel box
</div>
12 <button id=
"lower_target">Lower Target
</button>
15 <div id=
"console"></div>
18 description("Tests that scrolling to make an element visible successfully scrolls an arbitrary HTML element that has CSS overflow set to 'scroll'.");
21 window
.container
= document
.getElementById("container");
22 var upperTarget
= document
.getElementById("upper_target");
23 var lowerTarget
= document
.getElementById("lower_target");
25 if (window
.accessibilityController
) {
27 var lowerTargetAccessibleObject
= accessibilityController
.focusedElement
;
29 var upperTargetAccessibleObject
= accessibilityController
.focusedElement
;
32 // Reset the initial scroll position (since calling focus() can scroll the page too).
33 container
.scrollTop
= 0;
34 shouldBe("container.scrollTop", "0");
36 // Scroll to make lower target visible and check.
37 if (window
.accessibilityController
)
38 lowerTargetAccessibleObject
.scrollToMakeVisible();
39 var top
= lowerTarget
.offsetTop
- container
.offsetTop
;
40 window
.minYOffset
= top
+ lowerTarget
.offsetHeight
- container
.offsetHeight
;
41 window
.maxYOffset
= top
;
42 shouldBe("container.scrollTop >= minYOffset", "true");
43 shouldBe("container.scrollTop <= maxYOffset", "true");
45 // Do it again. It shouldn't scroll.
46 if (window
.accessibilityController
)
47 lowerTargetAccessibleObject
.scrollToMakeVisible();
48 var top
= lowerTarget
.offsetTop
- container
.offsetTop
;
49 window
.minYOffset
= top
+ lowerTarget
.offsetHeight
- container
.offsetHeight
;
50 window
.maxYOffset
= top
;
51 shouldBe("container.scrollTop >= minYOffset", "true");
52 shouldBe("container.scrollTop <= maxYOffset", "true");
54 // Scroll to make upper target visible and check.
55 if (window
.accessibilityController
)
56 upperTargetAccessibleObject
.scrollToMakeVisible();
57 top
= upperTarget
.offsetTop
- container
.offsetTop
;
58 window
.minYOffset
= top
+ upperTarget
.offsetHeight
- container
.offsetHeight
;
59 window
.maxYOffset
= top
;
60 shouldBe("container.scrollTop >= minYOffset", "true");
61 shouldBe("container.scrollTop <= maxYOffset", "true");