preventScroll-nested-scroll-elements.html (2504B)
1 <!doctype html> 2 <title>focus(options) - preventScroll on nested scroll elements</title> 3 <script src=/resources/testharness.js></script> 4 <script src=/resources/testharnessreport.js></script> 5 <style> 6 .scrollBox { width: 400px; height: 300px; border: 1px solid } 7 .bigbox { width: 380px; height: 300px; border: 1px solid } 8 .box { width: 380px; height: 150px; border: 1px solid } 9 </style> 10 <div class="scrollBox" style="overflow-y: scroll;"> 11 <div class="bigbox" id="1" style="overflow-y: scroll;" tabindex=1> 12 <div class="box" id="1_1" tabindex=1>1_1</div> 13 <div class="box" id="1_2" tabindex=1>1_2</div> 14 <div class="box" id="1_3" tabindex=1>1_3</div> 15 </div> 16 <div class="bigbox" id="2" style="overflow-y: scroll;" tabindex=1> 17 <div class="box" id="2_1" tabindex=1>2_1</div> 18 <div class="box" id="2_2" tabindex=1>2_2</div> 19 <div class="box" id="2_3" tabindex=1>2_3</div> 20 </div> 21 <div class="bigbox" id="3" style="overflow-y: scroll;" tabindex=1> 22 <div class="box" id="3_1" tabindex=1>3_1</div> 23 <div class="box" id="3_2" tabindex=1>3_2</div> 24 <div class="box" id="3_3" tabindex=1>3_3</div> 25 </div> 26 </div> 27 <script> 28 promise_test(async function(t) { 29 await new Promise(resolve => window.addEventListener("load", resolve)); 30 let div2_2 = document.getElementById("2_2"); 31 div2_2.focus({ preventScroll: true }); 32 33 await new Promise(resolve => { 34 requestAnimationFrame(() => requestAnimationFrame(resolve)); 35 }); 36 37 assert_equals(document.activeElement, div2_2, `box 2_2: should have been focused`); 38 assert_equals(div2_2.scrollTop, 0, "box 2_2: should not have scrolled"); 39 assert_equals(div2_2.parentNode.scrollTop, 0, "box 2_2: should not have scrolled ancestor"); 40 41 // Reset focus 42 let div1_1 = document.getElementById("1_1"); 43 div1_1.focus(); 44 45 await new Promise(resolve => { 46 requestAnimationFrame(() => requestAnimationFrame(resolve)); 47 }); 48 assert_equals(document.activeElement, div1_1, `box 1_1: should have been focused`); 49 50 let div2 = document.getElementById("2"); 51 div2.focus({ preventScroll: true }); 52 53 await new Promise(resolve => { 54 requestAnimationFrame(() => requestAnimationFrame(resolve)); 55 }); 56 57 assert_equals(document.activeElement, div2, `box 2: should have been focused`); 58 assert_equals(div2.scrollTop, 0, "box 2: should not have scrolled"); 59 assert_equals(div2_2.scrollTop, 0, "box 2_2: should not have scrolled"); 60 assert_equals(div2.parentNode.scrollTop, 0, "box 2: should not have scrolled ancestor"); 61 }); 62 </script>