Chromium Code Reviews| 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 var instantScrolls = [ | |
|
Ian Vollick
2014/02/06 16:02:31
If you make an object for the behavior test case,
| |
| 10 {js: "instant", css: "instant", index: 2}, | |
| 11 {js: "instant", css: "smooth", index: 3}, | |
| 12 {js: "auto", css: "instant", index: 4}, | |
| 13 {js: "", css: "instant", index: 5} | |
| 14 ]; | |
| 15 | |
| 16 var smoothScrolls = [ | |
| 17 {js: "smooth", css: "instant", waitForEnd: true, index: 15}, | |
| 18 {js: "smooth", css: "smooth", waitForEnd: true, index: 20}, | |
| 19 {js: "auto", css: "smooth", waitForEnd: true, index: 30}, | |
| 20 {js: "", css: "smooth", waitForEnd: true, index: 35}, | |
| 21 {js: "smooth", css: "instant", waitForEnd: false, index: 410}, | |
| 22 {js: "smooth", css: "smooth", waitForEnd: false, index: 20}, | |
| 23 {js: "auto", css: "smooth", waitForEnd: false, index: 400}, | |
| 24 {js: "", css: "smooth", waitForEnd: false, index: 5}, | |
| 25 ]; | |
| 26 | |
| 27 function runTestCase(testCase) | |
| 28 { | |
| 29 var element = document.getElementById("listbox"); | |
| 30 if (testCase.js) | |
| 31 element.scrollTop = {y: testCase.y, behavior: testCase.js}; | |
| 32 else | |
| 33 element.scrollTop = testCase.y; | |
| 34 } | |
| 35 | |
| 36 function endX(testCase, startX) | |
| 37 { | |
| 38 return startX; | |
| 39 } | |
| 40 | |
| 41 function endY(testCase) | |
| 42 { | |
| 43 return testCase.y; | |
| 44 } | |
| 45 | |
| 46 function initializeContents(listbox) | |
| 47 { | |
| 48 for (var i = 0; i < numItems; i++) { | |
| 49 var option = document.createElement("option"); | |
| 50 option.appendChild(document.createTextNode(i)); | |
| 51 listbox.appendChild(option); | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 function initializeTestCases(listbox) | |
| 56 { | |
| 57 var itemHeight = (listbox.scrollHeight - listbox.clientHeight) / (numItems - listbox.size); | |
| 58 for (var i = 0; i < instantScrolls.length; i++) { | |
| 59 instantScrolls[i].y = instantScrolls[i].index * itemHeight; | |
| 60 } | |
| 61 for (var i = 0; i < smoothScrolls.length; i++) { | |
| 62 smoothScrolls[i].y = smoothScrolls[i].index * itemHeight; | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 function doTest() | |
| 67 { | |
| 68 var element = document.getElementById("listbox"); | |
| 69 initializeContents(element); | |
| 70 initializeTestCases(element); | |
| 71 runScrollBehaviorTests(element, | |
| 72 element, | |
| 73 instantScrolls, | |
| 74 smoothScrolls, | |
| 75 runTestCase, | |
| 76 endX, | |
| 77 endY); | |
| 78 } | |
| 79 | |
| 80 window.addEventListener('load', doTest, false); | |
| 81 </script> | |
| 82 </head> | |
| 83 | |
| 84 <body> | |
| 85 <p>Test that setting scrollTop on a listbox works with both scroll behaviors</ p> | |
| 86 <select size="4" id="listbox"></select> | |
| 87 </body> | |
| 88 </html> | |
| OLD | NEW |