Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: LayoutTests/fast/scroll-behavior/listbox-interrupted-scroll.html

Issue 782793002: Update Element API for CSSOM smooth scrolling to match the spec (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../resources/testharness.js"></script>
5 <script src="../../resources/testharnessreport.js"></script>
6 <script src="resources/scroll-interruption-test.js"></script>
7 <script type="text/javascript">
8 const numItems = 500;
9
10 function jsScroll(y) {
11 document.getElementById('listbox').scrollTop = {y: y, behavior: 'smooth'};
12 }
13
14 function initializeContents(listbox) {
15 for (var i = 0; i < numItems; i++) {
16 var option = document.createElement('option');
17 option.appendChild(document.createTextNode(i));
18 listbox.appendChild(option);
19 }
20 }
21
22 function convertIndexToScrollOffset(index, listbox, approximateItemHeight) {
23 var scrollOffset = Math.floor(index * approximateItemHeight);
24
25 // The scroll offset set on a list box can get rounded to the nearest whol e-item
26 // offset. We set and then readback the scroll offset to get the rounded v alue
27 // (so that the scroll offsets used during the test won't be subject to fu rther
28 // rounding).
29 listbox.scrollTop = scrollOffset;
30 scrollOffset = listbox.scrollTop;
31 return scrollOffset;
32 }
33
34 function initializeTest(indexTargets, targets, innerPoint, listbox) {
35 var approximateItemHeight = listbox.clientHeight / listbox.size;
36
37 // Convert from listbox item index to scroll offset.
38 targets.y_min = convertIndexToScrollOffset(indexTargets.index_min, listbox , approximateItemHeight);
39 targets.y_mid = convertIndexToScrollOffset(indexTargets.index_mid, listbox , approximateItemHeight);
40 targets.y_max = convertIndexToScrollOffset(indexTargets.index_max, listbox , approximateItemHeight);
41
42 var boundingRect = listbox.getBoundingClientRect();
43 innerPoint.x = (boundingRect.left + boundingRect.right)/2;
44 innerPoint.y = (boundingRect.top + boundingRect.bottom)/2;
45 }
46
47 function doTest() {
48 var indexTargets = {index_min: 3, index_mid: 200, index_max: 400};
49 var targets = {};
50 var innerPoint = {};
51 var element = document.getElementById('listbox');
52 initializeContents(element);
53 initializeTest(indexTargets, targets, innerPoint, element);
54 var scrollInterruptionTest = new SmoothScrollInterruptionTest(element,
55 innerPoint,
56 targets,
57 jsScroll);
58 scrollInterruptionTest.run();
59 }
60
61 window.addEventListener('load', doTest, false);
62 </script>
63 </head>
64
65 <body>
66 <p>Test that interrupting a smooth scroll on a listbox works with both scroll behaviors and with input</p>
67 <select size="4" id="listbox"></select>
68 </body>
69 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698