10 border-top: 20px solid black;
11 border-bottom: 10px solid black;
12 border-left: 15px solid black;
13 border-right: 9px solid black;
15 -webkit-overflow-scrolling: touch;
16 -webkit-scroll-snap-points-x: repeat(100%);
17 -webkit-scroll-snap-type: mandatory;
19 .horizontalGalleryDrawer {
26 display: inline-block;
29 border-top: 20px solid black;
30 border-bottom: 10px solid black;
31 border-left: 15px solid black;
32 border-right: 9px solid black;
34 -webkit-overflow-scrolling: touch;
35 -webkit-scroll-snap-points-y: repeat(100%);
36 -webkit-scroll-snap-type: mandatory;
38 .verticalGalleryDrawer {
47 #itemH0, #itemV0 { background-color: red; }
48 #itemH1, #itemV1 { background-color: green; }
49 #itemH2, #itemV2 { background-color: blue; }
50 #itemH3, #itemV3 { background-color: aqua; }
51 #itemH4, #itemV4 { background-color: yellow; }
52 #itemH5, #itemV5 { background-color: fuchsia; }
54 <script src="../../../resources/js-test.js"></script>
56 window.jsTestIsAsync = true;
58 var divScrollPositionBeforeGlide;
59 var divScrollPositionBeforeSnap;
61 function locationInWindowCoordinates(element)
64 position.x = element.offsetLeft;
65 position.y = element.offsetTop;
67 while (element.offsetParent) {
68 position.x = position.x + element.offsetParent.offsetLeft;
69 position.y = position.y + element.offsetParent.offsetTop;
70 if (element == document.getElementsByTagName("body")[0])
73 element = element.offsetParent;
79 function checkForScrollSnap(targetLabel)
81 var divTarget = document.getElementById(targetLabel);
83 var actualPosition = divTarget.scrollTop;
84 if (targetLabel == 'horizontalTarget')
85 actualPosition = divTarget.scrollLeft;
87 // The div should have snapped back to the previous position
88 if (actualPosition != divScrollPositionBeforeSnap)
89 testFailed("div did not snap back to proper location for " + targetLabel +". Expected " + divScrollPositionBeforeSnap + ", but got " + actualPosition);
91 testPassed("div honored snap points.");
93 if (targetLabel == 'horizontalTarget')
94 setTimeout(function() { scrollGlideTest('verticalTarget') }, 0);
99 function scrollSnapTest(targetLabel)
101 debug("Testing scroll-snap snap for " + targetLabel + ":");
102 var divTarget = document.getElementById(targetLabel);
106 if (targetLabel == 'horizontalTarget') {
107 divScrollPositionBeforeSnap = divTarget.scrollLeft;
110 divScrollPositionBeforeSnap = divTarget.scrollTop;
114 var windowPosition = locationInWindowCoordinates(divTarget);
116 var startPosX = windowPosition.x + 0.5 * divTarget.clientWidth;
117 var startPosY = windowPosition.y + 0.5 * divTarget.clientHeight;
118 eventSender.mouseMoveTo(startPosX, startPosY); // Make sure we are just outside the iFrame
119 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, dy, 'began', 'none');
120 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, 2*dy, 'changed', 'none');
121 eventSender.mouseScrollByWithWheelAndMomentumPhases(0, 0, 'ended', 'none');
122 eventSender.callAfterScrollingCompletes(function() { return checkForScrollSnap(targetLabel); });
125 function checkForScrollGlide(targetLabel)
127 var divTarget = document.getElementById(targetLabel);
129 var actualPosition = divTarget.scrollTop;
130 var expectedPosition = divTarget.clientHeight;
131 if (targetLabel == 'horizontalTarget') {
132 actualPosition = divTarget.scrollLeft;
133 expectedPosition = divTarget.clientWidth;
136 // The div should have scrolled (glided) to the next snap point.
137 if (actualPosition == expectedPosition)
138 testPassed("div scrolled to next window.");
140 testFailed("div did not honor snap points. Expected " + expectedPosition + ", but got " + actualPosition);
142 setTimeout(function() { scrollSnapTest(targetLabel) }, 0);
145 function scrollGlideTest(targetLabel)
147 debug("Testing scroll-snap glide for " + targetLabel + ":");
148 var divTarget = document.getElementById(targetLabel);
152 if (targetLabel == 'horizontalTarget') {
153 divScrollPositionBeforeGlide = divTarget.scrollLeft;
156 divScrollPositionBeforeGlide = divTarget.scrollTop;
160 var windowPosition = locationInWindowCoordinates(divTarget);
162 var startPosX = windowPosition.x + divTarget.clientWidth - 10;
163 var startPosY = windowPosition.y + 50;
164 eventSender.mouseMoveTo(startPosX, startPosY);
165 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, dy, 'began', 'none');
166 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, 3*dy, 'changed', 'none');
167 eventSender.mouseScrollByWithWheelAndMomentumPhases(0, 0, 'ended', 'none');
168 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, dy, 'none', 'begin');
169 eventSender.mouseScrollByWithWheelAndMomentumPhases(dx, 2*dy, 'none', 'continue');
170 eventSender.mouseScrollByWithWheelAndMomentumPhases(0, 0, 'none', 'end');
171 eventSender.callAfterScrollingCompletes(function() { return checkForScrollGlide(targetLabel); });
176 if (window.eventSender) {
177 eventSender.monitorWheelEvents();
178 setTimeout(function() { scrollGlideTest('horizontalTarget') }, 0);
180 var messageLocationH = document.getElementById('itemH0');
181 var message = document.createElement('div');
182 message.innerHTML = "<p>This test is better run under DumpRenderTree.<br/>To manually test it, place the mouse pointer<br/>"
183 + "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"
184 + "small swipe gesture with<br/>some momentum.<br/><br/>"
185 + "The region should scroll to show a green region.<br/><br/>"
186 + "Next, perform a small scroll gesture that does<br/>not involve momentum. You should begin to<br/>see one of the colors "
187 + "to the side of the current<br/>green box. When you release the wheel, the<br/>region should scroll back to a single color.";
188 messageLocationH.appendChild(message);
190 var messageLocationV = document.getElementById('itemV0');
191 var message = document.createElement('div');
192 message.innerHTML = "<p>You should also be able to repeat these tests steps for this vertical region.<br/>"
193 messageLocationV.appendChild(message);
198 <body onload="onLoad();">
199 <div style="position: relative; width: 300px">
200 <div>Tests that the scroll-snap feature works properly in overflow regions.</div>
201 <div class="horizontalGallery" id="horizontalTarget">
202 <div class="horizontalGalleryDrawer">
203 <div id="itemH0" class="colorBox"></div>
204 <div id="itemH1" class="colorBox"></div>
205 <div id="itemH2" class="colorBox"></div>
206 <div id="itemH3" class="colorBox"></div>
207 <div id="itemH4" class="colorBox"></div>
208 <div id="itemH5" class="colorBox"></div>
211 <div class="verticalGallery" id="verticalTarget">
212 <div class="verticalGalleryDrawer">
213 <div id="itemV0" class="colorBox"></div>
214 <div id="itemV1" class="colorBox"></div>
215 <div id="itemV2" class="colorBox"></div>
216 <div id="itemV3" class="colorBox"></div>
217 <div id="itemV4" class="colorBox"></div>
218 <div id="itemV5" class="colorBox"></div>
221 <div id="console"></div>