Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <script src="../../../resources/testharness.js"></script> | |
| 3 <script src="../../../resources/testharnessreport.js"></script> | |
| 4 <style> | |
| 5 body { | |
| 6 margin: 0; | |
| 7 } | |
| 8 | |
| 9 .paddingBefore { | |
| 10 height: 150px; | |
| 11 } | |
| 12 | |
| 13 #scroller { | |
| 14 height: 100px; | |
| 15 width: 200px; | |
| 16 overflow-y: scroll; | |
| 17 } | |
| 18 | |
| 19 .paddingAfter { | |
| 20 height: 500px; | |
| 21 } | |
| 22 | |
| 23 #sticky { | |
| 24 height: 50px; | |
| 25 position: sticky; | |
| 26 top: 20px; | |
| 27 } | |
| 28 </style> | |
| 29 | |
| 30 <div id="scroller"> | |
| 31 <div class="paddingBefore"></div> | |
| 32 <div id="sticky"></div> | |
| 33 <div class="paddingAfter"></div> | |
| 34 </div> | |
| 35 | |
| 36 <script> | |
| 37 if (window.internals) { | |
| 38 internals.settings.setCSSStickyPositionEnabled(true); | |
| 39 } | |
| 40 | |
| 41 // These tests currently mimic the behavior of Firefox for the interaction | |
| 42 // between scrollIntoView() and position:sticky, where the offset location of | |
| 43 // the sticky element is used to determine how far to scroll. This means that | |
| 44 // scrollIntoView() may scroll even when the sticky is already 'in view', and | |
| 45 // attempts to scroll so that the offset position of the sticky is at the top | |
| 46 // of the screen. | |
| 47 // | |
| 48 // TODO(smcgruer): Update tests once http://crbug.com/664246 is resolved. | |
| 49 | |
| 50 test(function() { | |
| 51 var scroller = document.getElementById('scroller'); | |
| 52 var sticky = document.getElementById('sticky'); | |
| 53 scroller.scrollTop = 0; | |
| 54 | |
| 55 // Deliberately dirty layout to make sure that scrollIntoView() still works. | |
| 56 var newDiv = document.createElement('div'); | |
| 57 newDiv.style.height = '50px'; | |
| 58 scroller.append(newDiv); | |
|
flackr
2017/01/24 22:47:15
nit: insert it before the sticky element here and
smcgruer
2017/01/25 20:51:57
Done. As usual, your offhand comments cause me to
| |
| 59 | |
| 60 sticky.scrollIntoView(); | |
| 61 assert_equals(scroller.scrollTop, 150); | |
| 62 }, "scrollIntoView should scroll when sticky is not visible"); | |
| 63 | |
| 64 test(function() { | |
| 65 var scroller = document.getElementById('scroller'); | |
| 66 var sticky = document.getElementById('sticky'); | |
| 67 scroller.scrollTop = 150; | |
| 68 | |
| 69 // Deliberately dirty layout to make sure that scrollIntoView() still works. | |
| 70 var newDiv = document.createElement('div'); | |
| 71 newDiv.style.height = '50px'; | |
| 72 scroller.append(newDiv); | |
| 73 | |
| 74 sticky.scrollIntoView(); | |
| 75 assert_equals(scroller.scrollTop, 170); | |
| 76 }, "scrollIntoView should scroll when sticky is already in view"); | |
| 77 | |
| 78 test(function() { | |
| 79 var scroller = document.getElementById('scroller'); | |
| 80 var sticky = document.getElementById('sticky'); | |
| 81 scroller.scrollTop = 0; | |
| 82 | |
| 83 // Deliberately dirty layout to make sure that scrollIntoViewIfNeeded() | |
| 84 // still works. | |
| 85 var newDiv = document.createElement('div'); | |
| 86 newDiv.style.height = '50px'; | |
| 87 scroller.append(newDiv); | |
| 88 | |
| 89 sticky.scrollIntoViewIfNeeded(); | |
| 90 assert_equals(scroller.scrollTop, 125); | |
| 91 }, "scrollIntoViewIfNeeded should scroll when sticky is not visible"); | |
| 92 | |
| 93 test(function() { | |
| 94 var scroller = document.getElementById('scroller'); | |
| 95 var sticky = document.getElementById('sticky'); | |
| 96 scroller.scrollTop = 150; | |
| 97 | |
| 98 // Deliberately dirty layout to make sure that scrollIntoViewIfNeeded() | |
| 99 // still works. | |
| 100 var newDiv = document.createElement('div'); | |
| 101 newDiv.style.height = '50px'; | |
| 102 scroller.append(newDiv); | |
| 103 | |
| 104 sticky.scrollIntoViewIfNeeded(); | |
| 105 assert_equals(scroller.scrollTop, 150); | |
| 106 }, "scrollIntoViewIfNeeded should not scroll when sticky is already in view"); | |
| 107 </script> | |
| OLD | NEW |