11 -webkit-scroll-snap-points-x: repeat(100%);
12 -webkit-scroll-snap-type: mandatory;
14 .horizontalGalleryDrawer {
21 display: inline-block;
25 -webkit-scroll-snap-points-y: repeat(100%);
26 -webkit-scroll-snap-type: mandatory;
28 .verticalGalleryDrawer {
37 #itemH0, #itemV0 { background-color: red; }
38 #itemH1, #itemV1 { background-color: green; }
39 #itemH2, #itemV2 { background-color: blue; }
40 #itemH3, #itemV3 { background-color: aqua; }
41 #itemH4, #itemV4 { background-color: yellow; }
42 #itemH5, #itemV5 { background-color: fuchsia; }
44 <script src="../../../../../resources/js-test-pre.js"></script>
46 var divScrollPositionBeforeGlide;
47 var divScrollPositionBeforeSnap;
49 function locationInWindowCoordinates(element)
52 position.x = element.offsetLeft;
53 position.y = element.offsetTop;
55 while (element.offsetParent) {
56 position.x = position.x + element.offsetParent.offsetLeft;
57 position.y = position.y + element.offsetParent.offsetTop;
58 if (element == document.getElementsByTagName("body")[0])
61 element = element.offsetParent;
70 testRunner.notifyDone();
73 function checkForScrollSnap(targetLabel)
75 var divTarget = document.getElementById(targetLabel);
77 var actualPosition = divTarget.scrollTop;
78 if (targetLabel == 'horizontalTarget')
79 actualPosition = divTarget.scrollLeft;
81 // The div should have snapped back to the previous position
82 if (actualPosition != divScrollPositionBeforeSnap)
83 testFailed("div did not snap back to proper location for " + targetLabel +". Expected " + divScrollPositionBeforeSnap + ", but got " + actualPosition);
85 testPassed("div honored snap points.");
87 if (targetLabel == 'horizontalTarget')
88 setTimeout(scrollGlideTest('verticalTarget'), 0);
93 function scrollSnapTest(targetLabel)
95 debug("Testing scroll-snap snap for " + targetLabel + ":");
96 var divTarget = document.getElementById(targetLabel);
100 if (targetLabel == 'horizontalTarget') {
101 divScrollPositionBeforeSnap = divTarget.scrollLeft;
104 divScrollPositionBeforeSnap = divTarget.scrollTop;
108 var startPosX = divTarget.offsetLeft + 20;
109 var startPosY = divTarget.offsetTop + 20;
110 eventSender.mouseMoveTo(startPosX, startPosY); // Make sure we are just outside the iFrame
111 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, dy, 'began', 'none', false);
112 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, dy, 'changed', 'none', false);
113 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, dy, 'changed', 'none', false);
114 eventSender.mouseScrollByWithWheelAndMomentumPhases(0, 0, 'ended', 'none', false);
115 eventSender.callAfterScrollingCompletes(function() { return checkForScrollSnap(targetLabel); });
118 function checkForScrollGlide(targetLabel)
120 var divTarget = document.getElementById(targetLabel);
122 var actualPosition = divTarget.scrollTop;
123 var expectedPosition = divTarget.clientHeight;
124 if (targetLabel == 'horizontalTarget') {
125 actualPosition = divTarget.scrollLeft;
126 expectedPosition = divTarget.clientWidth;
129 // The div should have scrolled (glided) to the next snap point.
130 if (actualPosition == expectedPosition)
131 testPassed("div scrolled to next window.");
133 testFailed("div did not honor snap points. Expected " + expectedPosition + ", but got " + actualPosition);
135 setTimeout(scrollSnapTest(targetLabel), 0);
138 function scrollGlideTest(targetLabel)
140 debug("Testing scroll-snap glide for " + targetLabel + ":");
141 var divTarget = document.getElementById(targetLabel);
145 if (targetLabel == 'horizontalTarget') {
146 divScrollPositionBeforeGlide = divTarget.scrollLeft;
149 divScrollPositionBeforeGlide = divTarget.scrollTop;
153 var windowPosition = locationInWindowCoordinates(divTarget);
155 var startPosX = windowPosition.x + divTarget.clientWidth - 10;
156 var startPosY = windowPosition.y + 50;
157 eventSender.mouseMoveTo(startPosX, startPosY);
158 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, dy, 'began', 'none', false);
159 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, dy, 'changed', 'none', false);
160 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, dy, 'changed', 'none', false);
161 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, dy, 'changed', 'none', false);
162 eventSender.mouseScrollByWithWheelAndMomentumPhases(0, 0, 'ended', 'none', false);
163 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, dy, 'none', 'begin', false);
164 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, dy, 'none', 'continue', false);
165 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, dy, 'none', 'continue', false);
166 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, dy, 'none', 'continue', false);
167 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, dy, 'none', 'continue', false);
168 eventSender.mouseScrollByWithWheelAndMomentumPhases(0, 0, 'none', 'end', false);
169 eventSender.callAfterScrollingCompletes(function() { return checkForScrollGlide(targetLabel); });
174 if (window.eventSender) {
175 window.jsTestIsAsync = true;
176 testRunner.dumpAsText();
177 testRunner.waitUntilDone();
179 eventSender.monitorWheelEvents();
180 setTimeout(scrollGlideTest('horizontalTarget'), 0);
182 var messageLocationH = document.getElementById('itemH0');
183 var message = document.createElement('div');
184 message.innerHTML = "<p>This test is better run under DumpRenderTree.<br/>To manually test it, place the mouse pointer<br/>"
185 + "inside the red region at the top of the page,<br/>and then use the mouse wheel or a two-finger<br/>swipe to make a"
186 + "small swipe gesture with<br/>some momentum.<br/><br/>"
187 + "The region should scroll to show a green region.<br/><br/>"
188 + "Next, perform a small scroll gesture that does<br/>not involve momentum. You should begin to<br/>see one of the colors "
189 + "to the side of the current<br/>green box. When you release the wheel, the<br/>region should scroll back to a single color.";
190 messageLocationH.appendChild(message);
192 var messageLocationV = document.getElementById('itemV0');
193 var message = document.createElement('div');
194 message.innerHTML = "<p>You should also be able to repeat these tests steps for this vertical region.<br/>"
195 messageLocationV.appendChild(message);
200 <body onload="onLoad();">
201 <div style="position: relative; width: 300px">
202 <div>Tests that the scroll-snap feature works properly in overflow regions.</div>
203 <div class="horizontalGallery" id="horizontalTarget">
204 <div class="horizontalGalleryDrawer">
205 <div id="itemH0" class="colorBox"></div>
206 <div id="itemH1" class="colorBox"></div>
207 <div id="itemH2" class="colorBox"></div>
208 <div id="itemH3" class="colorBox"></div>
209 <div id="itemH4" class="colorBox"></div>
210 <div id="itemH5" class="colorBox"></div>
213 <div class="verticalGallery" id="verticalTarget">
214 <div class="verticalGalleryDrawer">
215 <div id="itemV0" class="colorBox"></div>
216 <div id="itemV1" class="colorBox"></div>
217 <div id="itemV2" class="colorBox"></div>
218 <div id="itemV3" class="colorBox"></div>
219 <div id="itemV4" class="colorBox"></div>
220 <div id="itemV5" class="colorBox"></div>
223 <div id="console"></div>
225 <script src="../../../../../resources/js-test-post.js"></script>