| <!DOCTYPE HTML> |
| <html> |
| <head> |
| <style> |
| html { |
| scroll-snap-type: x proximity; |
| } |
| .horizontalGallery { |
| width: 600vw; |
| height: 100vh; |
| margin: 0; |
| padding: 0; |
| } |
| .colorBox { |
| height: 100vh; |
| width: 100vw; |
| float: left; |
| scroll-snap-align: start; |
| } |
| #item0 { background-color: red; } |
| #item1 { background-color: green; } |
| #item2 { background-color: blue; } |
| #item3 { background-color: aqua; } |
| #item4 { background-color: yellow; } |
| #item5 { background-color: fuchsia; } |
| </style> |
| <script src="../../../resources/js-test.js"></script> |
| <script src="../../../resources/ui-helper.js"></script> |
| <script> |
| window.jsTestIsAsync = true; |
| |
| async function runTests() |
| { |
| if (window.internals) |
| internals.settings.setScrollAnimatorEnabled(false); |
| try { |
| await UIHelper.delayFor(0); |
| |
| let scrollPositionBeforeSnap = document.scrollingElement.scrollLeft; |
| eventSender.keyDown("rightArrow"); |
| eventSender.keyDown("rightArrow"); |
| eventSender.keyDown("rightArrow"); |
| var betweenFirstScrollPositionAndSecond = |
| document.scrollingElement.scrollLeft > scrollPositionBeforeSnap |
| && document.scrollingElement.scrollLeft < window.innerWidth; |
| expectTrue(betweenFirstScrollPositionAndSecond, "arrow keys didn't scroll to second div."); |
| |
| // We reset the scrolling position because changing the DOM when we are not on |
| // a snap point can reset our scroll position. |
| document.scrollingElement.scrollLeft = scrollPositionBeforeSnap; |
| eventSender.keyDown("rightArrow"); |
| eventSender.keyDown("rightArrow"); |
| eventSender.keyDown("rightArrow"); |
| eventSender.keyDown("leftArrow"); |
| |
| // Reversing directions should snap back. |
| expectTrue(document.scrollingElement.scrollLeft == scrollPositionBeforeSnap, "left arrow snapped back."); |
| } catch (e) { |
| console.log(e); |
| } finally { |
| finishJSTest(); |
| } |
| } |
| |
| function onLoad() |
| { |
| if (window.eventSender) { |
| runTests(); |
| } else { |
| var messageLocation = document.getElementById('item0'); |
| var message = document.createElement('div'); |
| message.innerHTML = "<p>To run this test manually, scroll the page horizontally with the keyboard.</p>"; |
| messageLocation.appendChild(message); |
| } |
| } |
| </script> |
| </head> |
| <body onload="onLoad();" class="horizontalGallery"> |
| <div id="item0" class="colorBox"><div id="console"></div></div> |
| <div id="item1" class="colorBox"></div> |
| <div id="item2" class="colorBox"></div> |
| <div id="item3" class="colorBox"></div> |
| <div id="item4" class="colorBox"></div> |
| <div id="item5" class="colorBox"></div> |
| </body> |
| </html> |