File: preventScroll-nested-scroll-elements.html

package info (click to toggle)
firefox 149.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,767,760 kB
  • sloc: cpp: 7,416,064; javascript: 6,752,859; ansic: 3,774,850; python: 1,250,473; xml: 641,578; asm: 439,191; java: 186,617; sh: 56,634; makefile: 18,856; objc: 13,092; perl: 12,763; pascal: 5,960; yacc: 4,583; cs: 3,846; lex: 1,720; ruby: 1,002; php: 436; lisp: 258; awk: 105; sql: 66; sed: 53; csh: 10; exp: 6
file content (62 lines) | stat: -rw-r--r-- 2,504 bytes parent folder | download | duplicates (22)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!doctype html>
<title>focus(options) - preventScroll on nested scroll elements</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<style>
  .scrollBox { width: 400px; height: 300px; border: 1px solid }
  .bigbox { width: 380px; height: 300px; border: 1px solid }
  .box { width: 380px; height: 150px; border: 1px solid }
</style>
<div class="scrollBox" style="overflow-y: scroll;">
  <div class="bigbox" id="1" style="overflow-y: scroll;" tabindex=1>
    <div class="box" id="1_1" tabindex=1>1_1</div>
    <div class="box" id="1_2" tabindex=1>1_2</div>
    <div class="box" id="1_3" tabindex=1>1_3</div>
  </div>
  <div class="bigbox" id="2" style="overflow-y: scroll;" tabindex=1>
    <div class="box" id="2_1" tabindex=1>2_1</div>
    <div class="box" id="2_2" tabindex=1>2_2</div>
    <div class="box" id="2_3" tabindex=1>2_3</div>
  </div>
  <div class="bigbox" id="3" style="overflow-y: scroll;" tabindex=1>
    <div class="box" id="3_1" tabindex=1>3_1</div>
    <div class="box" id="3_2" tabindex=1>3_2</div>
    <div class="box" id="3_3" tabindex=1>3_3</div>
  </div>
</div>
<script>
promise_test(async function(t) {
  await new Promise(resolve => window.addEventListener("load", resolve));
  let div2_2 = document.getElementById("2_2");
  div2_2.focus({ preventScroll: true });

  await new Promise(resolve => {
    requestAnimationFrame(() => requestAnimationFrame(resolve));
  });

  assert_equals(document.activeElement, div2_2, `box 2_2: should have been focused`);
  assert_equals(div2_2.scrollTop, 0, "box 2_2: should not have scrolled");
  assert_equals(div2_2.parentNode.scrollTop, 0, "box 2_2: should not have scrolled ancestor");

  // Reset focus
  let div1_1 = document.getElementById("1_1");
  div1_1.focus();

  await new Promise(resolve => {
    requestAnimationFrame(() => requestAnimationFrame(resolve));
  });
  assert_equals(document.activeElement, div1_1, `box 1_1: should have been focused`);

  let div2 = document.getElementById("2");
  div2.focus({ preventScroll: true });

  await new Promise(resolve => {
    requestAnimationFrame(() => requestAnimationFrame(resolve));
  });

  assert_equals(document.activeElement, div2, `box 2: should have been focused`);
  assert_equals(div2.scrollTop, 0, "box 2: should not have scrolled");
  assert_equals(div2_2.scrollTop, 0, "box 2_2: should not have scrolled");
  assert_equals(div2.parentNode.scrollTop, 0, "box 2: should not have scrolled ancestor");
});
</script>