18 background-color: #ace;
24 ::-webkit-scrollbar-thumb {
32 <div id=
"spacer"></div>
33 <div id=
"focusable" tabindex=
"-1"></div>
35 <script src=
"../../resources/js-test.js"></script>
38 description('Tests that scrollable areas are scrolled to the correct location '
39 + 'when an element is focused.');
41 var container
= document
.querySelector('#container');
42 var focusable
= document
.querySelector('#focusable');
44 function runTest(elemRect
, initialScroll
, expectedFinalScroll
) {
45 focusable
.style
.left
= elemRect
.x
+ 'px';
46 focusable
.style
.top
= elemRect
.y
+ 'px';
47 focusable
.style
.width
= elemRect
.w
+ 'px';
48 focusable
.style
.height
= elemRect
.h
+ 'px';
50 container
.scrollLeft
= initialScroll
.x
;
51 container
.scrollTop
= initialScroll
.y
;
56 shouldBe('container.scrollLeft', String(expectedFinalScroll
.x
));
57 shouldBe('container.scrollTop', String(expectedFinalScroll
.y
));
60 // Smaller fully offscreen element is centered when focused.
61 runTest({x
: 20, y
: 20, w
: 280, h
: 280}, {x
: 690, y
: 690}, {x
: 10, y
: 10});
62 runTest({x
: 700, y
: 700, w
: 280, h
: 280}, {x
: 10, y
: 10}, {x
: 690, y
: 690});
64 // Larger fully offscreen element is centered when focused.
65 runTest({x
: 10, y
: 10, w
: 320, h
: 320}, {x
: 690, y
: 690}, {x
: 20, y
: 20});
66 runTest({x
: 670, y
: 670, w
: 320, h
: 320}, {x
: 10, y
: 10}, {x
: 680, y
: 680});
68 // Smaller fully onscreen element does not scroll when focused.
69 runTest({x
: 10, y
: 10, w
: 100, h
: 100}, {x
: 10, y
: 10}, {x
: 10, y
: 10});
70 runTest({x
: 210, y
: 210, w
: 100, h
: 100}, {x
: 10, y
: 10}, {x
: 10, y
: 10});
72 // Larger fully overlapping element does not scroll when focused.
73 runTest({x
: 10, y
: 10, w
: 310, h
: 310}, {x
: 20, y
: 20}, {x
: 20, y
: 20});
74 runTest({x
: 20, y
: 20, w
: 310, h
: 310}, {x
: 20, y
: 20}, {x
: 20, y
: 20});
76 // Smaller overlapping element scrolls to nearest edge when focused.
77 runTest({x
: 20, y
: 20, w
: 280, h
: 280}, {x
: 290, y
: 290}, {x
: 20, y
: 20});
78 runTest({x
: 700, y
: 700, w
: 280, h
: 280}, {x
: 410, y
: 410}, {x
: 680, y
: 680});
80 // Larger overlapping element scrolls to nearest edge when focused.
81 runTest({x
: 10, y
: 10, w
: 320, h
: 320}, {x
: 320, y
: 320}, {x
: 30, y
: 30});
82 runTest({x
: 670, y
: 670, w
: 320, h
: 320}, {x
: 380, y
: 380}, {x
: 670, y
: 670});
84 if (window
.testRunner
)
85 testRunner
.dumpAsText();