cfleizach@apple.com | ed9796c | 2015-08-29 07:41:46 +0000 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <head> |
| 3 | <script src="../resources/js-test.js"></script> |
| 4 | </head> |
| 5 | <body> |
| 6 | |
| 7 | <p id="description"></p> |
| 8 | |
| 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> |
| 13 | </div> |
| 14 | |
| 15 | <div id="console"></div> |
| 16 | |
| 17 | <script> |
| 18 | description("Tests that scrolling to make an element visible successfully scrolls an arbitrary HTML element that has CSS overflow set to 'scroll'."); |
| 19 | |
| 20 | function runTest() { |
| 21 | window.container = document.getElementById("container"); |
| 22 | var upperTarget = document.getElementById("upper_target"); |
| 23 | var lowerTarget = document.getElementById("lower_target"); |
| 24 | |
| 25 | var lowerTargetAccessibleObject; |
| 26 | var upperTargetAccessibleObject; |
| 27 | if (window.accessibilityController) { |
| 28 | lowerTarget.focus(); |
| 29 | lowerTargetAccessibleObject = accessibilityController.focusedElement; |
| 30 | upperTarget.focus(); |
| 31 | upperTargetAccessibleObject = accessibilityController.focusedElement; |
| 32 | } |
| 33 | |
| 34 | // Reset the initial scroll position (since calling focus() can scroll the page too). |
| 35 | container.scrollTop = 0; |
| 36 | shouldBeZero("container.scrollTop"); |
| 37 | |
| 38 | // Scroll to make lower target visible and check. |
| 39 | if (window.accessibilityController) |
| 40 | lowerTargetAccessibleObject.scrollToMakeVisible(); |
| 41 | var top = lowerTarget.offsetTop - container.offsetTop; |
| 42 | window.minYOffset = top + lowerTarget.offsetHeight - container.offsetHeight; |
| 43 | window.maxYOffset = top; |
| 44 | shouldBeTrue("container.scrollTop >= minYOffset"); |
| 45 | shouldBeTrue("container.scrollTop <= maxYOffset"); |
| 46 | |
| 47 | // Do it again. It shouldn't scroll. |
| 48 | if (window.accessibilityController) |
| 49 | lowerTargetAccessibleObject.scrollToMakeVisible(); |
| 50 | var top = lowerTarget.offsetTop - container.offsetTop; |
| 51 | window.minYOffset = top + lowerTarget.offsetHeight - container.offsetHeight; |
| 52 | window.maxYOffset = top; |
| 53 | shouldBeTrue("container.scrollTop >= minYOffset"); |
| 54 | shouldBeTrue("container.scrollTop <= maxYOffset"); |
| 55 | |
| 56 | // Scroll to make upper target visible and check. |
| 57 | if (window.accessibilityController) |
| 58 | upperTargetAccessibleObject.scrollToMakeVisible(); |
| 59 | top = upperTarget.offsetTop - container.offsetTop; |
| 60 | window.minYOffset = top + upperTarget.offsetHeight - container.offsetHeight; |
| 61 | window.maxYOffset = top; |
| 62 | shouldBe("container.scrollTop >= minYOffset", "true"); |
| 63 | shouldBe("container.scrollTop <= maxYOffset", "true"); |
| 64 | |
| 65 | finishJSTest(); |
| 66 | } |
| 67 | |
| 68 | runTest(); |
| 69 | |
| 70 | </script> |
| 71 | |
| 72 | </body> |
| 73 | </html> |