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 windowPosition = locationInWindowCoordinates(divTarget);
110 var startPosX = windowPosition.x + 0.5 * divTarget.clientWidth;
111 var startPosY = windowPosition.y + 0.5 * divTarget.clientHeight;
112 eventSender.mouseMoveTo(startPosX, startPosY); // Make sure we are just outside the iFrame
113 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, dy, 'began', 'none', false);
114 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, dy, 'changed', 'none', false);
115 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, dy, 'changed', 'none', false);
116 eventSender.mouseScrollByWithWheelAndMomentumPhases(0, 0, 'ended', 'none', false);
117 eventSender.callAfterScrollingCompletes(function() { return checkForScrollSnap(targetLabel); });
120 function checkForScrollGlide(targetLabel)
122 var divTarget = document.getElementById(targetLabel);
124 var actualPosition = divTarget.scrollTop;
125 var expectedPosition = divTarget.clientHeight;
126 if (targetLabel == 'horizontalTarget') {
127 actualPosition = divTarget.scrollLeft;
128 expectedPosition = divTarget.clientWidth;
131 // The div should have scrolled (glided) to the next snap point.
132 if (actualPosition == expectedPosition)
133 testPassed("div scrolled to next window.");
135 testFailed("div did not honor snap points. Expected " + expectedPosition + ", but got " + actualPosition);
137 setTimeout(scrollSnapTest(targetLabel), 0);
140 function scrollGlideTest(targetLabel)
142 debug("Testing scroll-snap glide for " + targetLabel + ":");
143 var divTarget = document.getElementById(targetLabel);
147 if (targetLabel == 'horizontalTarget') {
148 divScrollPositionBeforeGlide = divTarget.scrollLeft;
151 divScrollPositionBeforeGlide = divTarget.scrollTop;
155 var windowPosition = locationInWindowCoordinates(divTarget);
157 var startPosX = windowPosition.x + 0.5 * divTarget.clientWidth;
158 var startPosY = windowPosition.y + 0.5 * divTarget.clientHeight;
159 eventSender.mouseMoveTo(startPosX, startPosY);
160 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, dy, 'began', 'none', false);
161 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, dy, 'changed', 'none', false);
162 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, dy, 'changed', 'none', false);
163 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, dy, 'changed', 'none', false);
164 eventSender.mouseScrollByWithWheelAndMomentumPhases(0, 0, 'ended', 'none', false);
165 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, dy, 'none', 'begin', false);
166 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, dy, 'none', 'continue', false);
167 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, dy, 'none', 'continue', false);
168 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, dy, 'none', 'continue', false);
169 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, dy, 'none', 'continue', false);
170 eventSender.mouseScrollByWithWheelAndMomentumPhases(0, 0, 'none', 'end', false);
171 eventSender.callAfterScrollingCompletes(function() { return checkForScrollGlide(targetLabel); });
176 if (window.eventSender) {
177 window.jsTestIsAsync = true;
178 testRunner.dumpAsText();
179 testRunner.waitUntilDone();
181 eventSender.monitorWheelEvents();
182 setTimeout(scrollGlideTest('horizontalTarget'), 0);
184 var messageLocationH = document.getElementById('itemH0');
185 var message = document.createElement('div');
186 message.innerHTML = "<p>This test is better run under DumpRenderTree.<br/>To manually test it, place the mouse pointer<br/>"
187 + "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"
188 + "small swipe gesture with<br/>some momentum.<br/><br/>"
189 + "The region should scroll to show a green region.<br/><br/>"
190 + "Next, perform a small scroll gesture that does<br/>not involve momentum. You should begin to<br/>see one of the colors "
191 + "to the side of the current<br/>green box. When you release the wheel, the<br/>region should scroll back to a single color.";
192 messageLocationH.appendChild(message);
194 var messageLocationV = document.getElementById('itemV0');
195 var message = document.createElement('div');
196 message.innerHTML = "<p>You should also be able to repeat these tests steps for this vertical region.<br/>"
197 messageLocationV.appendChild(message);
202 <body onload="onLoad();">
203 <div style="position: relative; width: 300px">
204 <div>Tests that the scroll-snap feature works properly in overflow regions.</div>
205 <div class="horizontalGallery" id="horizontalTarget">
206 <div class="horizontalGalleryDrawer">
207 <div id="itemH0" class="colorBox"></div>
208 <div id="itemH1" class="colorBox"></div>
209 <div id="itemH2" class="colorBox"></div>
210 <div id="itemH3" class="colorBox"></div>
211 <div id="itemH4" class="colorBox"></div>
212 <div id="itemH5" class="colorBox"></div>
215 <div class="verticalGallery" id="verticalTarget">
216 <div class="verticalGalleryDrawer">
217 <div id="itemV0" class="colorBox"></div>
218 <div id="itemV1" class="colorBox"></div>
219 <div id="itemV2" class="colorBox"></div>
220 <div id="itemV3" class="colorBox"></div>
221 <div id="itemV4" class="colorBox"></div>
222 <div id="itemV5" class="colorBox"></div>
225 <div id="console"></div>
227 <script src="../../../../../resources/js-test-post.js"></script>