OLD | NEW |
(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-behavior-test.js"></script> |
| 7 <script type="text/javascript"> |
| 8 const numItems = 500; |
| 9 |
| 10 function getEndPosition(testCase, startPosition) { |
| 11 var endPosition = {}; |
| 12 endPosition.x = startPosition.x; |
| 13 endPosition.y = testCase.y; |
| 14 return endPosition; |
| 15 } |
| 16 |
| 17 function jsScroll(testCase) { |
| 18 var element = document.getElementById("listbox"); |
| 19 if (testCase.js) { |
| 20 element.scrollTop = {y: testCase.y, behavior: testCase.js}; |
| 21 } else { |
| 22 element.scrollTop = testCase.y; |
| 23 } |
| 24 } |
| 25 |
| 26 var testScrolls = [ |
| 27 {js: "instant", css: "instant", index: 2}, |
| 28 {js: "instant", css: "smooth", index: 3}, |
| 29 {js: "auto", css: "instant", index: 4}, |
| 30 {js: "", css: "instant", index: 5}, |
| 31 {js: "smooth", css: "instant", waitForEnd: true, index: 15}, |
| 32 {js: "smooth", css: "smooth", waitForEnd: true, index: 20}, |
| 33 {js: "auto", css: "smooth", waitForEnd: true, index: 30}, |
| 34 {js: "", css: "smooth", waitForEnd: true, index: 35}, |
| 35 {js: "smooth", css: "instant", waitForEnd: false, index: 410}, |
| 36 {js: "smooth", css: "smooth", waitForEnd: false, index: 20}, |
| 37 {js: "auto", css: "smooth", waitForEnd: false, index: 400}, |
| 38 {js: "", css: "smooth", waitForEnd: false, index: 5}, |
| 39 ]; |
| 40 |
| 41 function initializeContents(listbox) |
| 42 { |
| 43 for (var i = 0; i < numItems; i++) { |
| 44 var option = document.createElement("option"); |
| 45 option.appendChild(document.createTextNode(i)); |
| 46 listbox.appendChild(option); |
| 47 } |
| 48 } |
| 49 |
| 50 function doTest() |
| 51 { |
| 52 var element = document.getElementById("listbox"); |
| 53 initializeContents(element); |
| 54 var itemHeight = (listbox.scrollHeight - listbox.clientHeight) / (numItems
- listbox.size); |
| 55 |
| 56 var testCases = []; |
| 57 for (var i = 0; i < testScrolls.length; i++) { |
| 58 // Convert from list box item index to a scroll offset. |
| 59 testScrolls[i].y = testScrolls[i].index * itemHeight; |
| 60 testScrolls[i].x = 0; |
| 61 testCases.push(new ScrollBehaviorTestCase(testScrolls[i])); |
| 62 } |
| 63 |
| 64 var scrollBehaviorTest = new ScrollBehaviorTest(element, |
| 65 element, |
| 66 testCases, |
| 67 getEndPosition, |
| 68 jsScroll); |
| 69 scrollBehaviorTest.run(); |
| 70 } |
| 71 |
| 72 window.addEventListener('load', doTest, false); |
| 73 </script> |
| 74 </head> |
| 75 |
| 76 <body> |
| 77 <p>Test that setting scrollTop on a listbox works with both scroll behaviors</
p> |
| 78 <select size="4" id="listbox"></select> |
| 79 </body> |
| 80 </html> |
OLD | NEW |