summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/cssom-view/scrollLeftTop.html
blob: 55b4013600727a3dcae0ab2c286a38801cdd8426 (plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<!DOCTYPE html>
<title>CSSOM View - scrollLeft/scrollTop considers writing-mode and css direction</title>
<meta charset="utf-8">
<link rel="author" title="Cathie Chen" href="mailto:cathiechen@igalia.com">
<link rel="help" href="https://drafts.csswg.org/cssom-view/#scrolling-area-origin">
<link rel="help" href="https://drafts.csswg.org/cssom-view/#scroll-an-element">
<meta name="assert" content="This test verifies the assigned and extreme values of the scroll positions of an element.">

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<head>
  <style>
    .scroller {
        overflow: scroll;
        width: 150px;
        height: 100px;
    }
    .content {
        width: 300px;
        height: 400px;
    }
    .horizontal-tb {
      writing-mode: horizontal-tb;
    }
    .vertical-lr {
      writing-mode: vertical-lr;
    }
    .vertical-rl {
      writing-mode: vertical-rl;
    }
    .rtl {
      direction: rtl;
    }
  </style>
</head>

<body>
  <h1>scrollLeft/scrollTop</h1>
  <h2>writing-mode: horizontal-tb;</h2>
  <div id="target_scroller" class="scroller horizontal-tb ltr">
    <div id="target_content" class="content"></div>
  </div>
  <div class="scroller horizontal-tb rtl">
    <div class="content"></div>
  </div>
  <h2>writing-mode: vertical-lr;</h2>
  <div class="scroller vertical-lr ltr">
    <div class="content"></div>
  </div>
  <div class="scroller vertical-lr rtl">
    <div class="content"></div>
  </div>
  <h2>writing-mode: vertical-rl;</h2>
  <div class="scroller vertical-rl ltr">
    <div class="content"></div>
  </div>
  <div class="scroller vertical-rl rtl">
    <div class="content"></div>
  </div>

  <script>
  var scroller = document.querySelector("#target_scroller");
  var content = document.querySelector("#target_content");
  var scrollbar_width = scroller.offsetWidth - scroller.clientWidth;
  var scroller_width = scroller.offsetWidth;
  var scroller_height = scroller.offsetHeight;
  var content_width = content.offsetWidth;
  var content_height = content.offsetHeight;

  expectedScrollTop = content_height - scroller_height + scrollbar_width;
  expectedScrollLeft = content_width - scroller_width + scrollbar_width;

  const epsilon = 0.5;
  test(() => {
    var scroller = document.querySelector(".horizontal-tb.ltr");
    assert_approx_equals(scroller.scrollLeft, 0, epsilon, "initial scrollLeft");
    assert_approx_equals(scroller.scrollTop, 0, epsilon, "initial scrollTop");
    scroller.scrollLeft = 2*content_width;
    scroller.scrollTop = 2*content_height;
    assert_approx_equals(scroller.scrollLeft, expectedScrollLeft, epsilon, "ending scrollLeft");
    assert_approx_equals(scroller.scrollTop, expectedScrollTop, epsilon, "ending scrollTop");
  }, `writing-mode:horizontal-tb; direction:ltr`);

  test(() => {
    var scroller = document.querySelector(".horizontal-tb.rtl");
    assert_approx_equals(scroller.scrollLeft, 0, epsilon, "initial scrollLeft");
    assert_approx_equals(scroller.scrollTop, 0, epsilon, "initial scrollTop");
    scroller.scrollLeft = -2*content_width;
    scroller.scrollTop = 2*content_height;
    assert_approx_equals(scroller.scrollLeft, -expectedScrollLeft, epsilon, "ending scrollLeft");
    assert_approx_equals(scroller.scrollTop, expectedScrollTop, epsilon, "ending scrollTop");
  }, `writing-mode:horizontal-tb; direction:rtl`);

  test(() => {
    var scroller = document.querySelector(".vertical-lr.ltr");
    assert_approx_equals(scroller.scrollLeft, 0, epsilon, "initial scrollLeft");
    assert_approx_equals(scroller.scrollTop, 0, epsilon, "initial scrollTop");
    scroller.scrollLeft = 2*content_width;
    scroller.scrollTop = 2*content_height;
    assert_approx_equals(scroller.scrollLeft, expectedScrollLeft, epsilon, "ending scrollLeft");
    assert_approx_equals(scroller.scrollTop, expectedScrollTop, epsilon, "ending scrollTop");
  }, `writing-mode:vertical-lr; direction:ltr`);

  test(() => {
    var scroller = document.querySelector(".vertical-lr.rtl");
    assert_approx_equals(scroller.scrollLeft, 0, epsilon, "initial scrollLeft");
    assert_approx_equals(scroller.scrollTop, 0, epsilon, "initial scrollTop");
    scroller.scrollLeft = 2*content_width;
    scroller.scrollTop = -2*content_height;
    assert_approx_equals(scroller.scrollLeft, expectedScrollLeft, epsilon, "ending scrollLeft");
    assert_approx_equals(scroller.scrollTop, -expectedScrollTop, epsilon, "ending scrollTop");
  }, `writing-mode:vertical-lr; direction:rtl`);

  test(() => {
    var scroller = document.querySelector(".vertical-rl.ltr");
    assert_approx_equals(scroller.scrollLeft, 0, epsilon, "initial scrollLeft");
    assert_approx_equals(scroller.scrollTop, 0, epsilon, "initial scrollTop");
    scroller.scrollLeft = -2*content_width;
    scroller.scrollTop = 2*content_height;
    assert_approx_equals(scroller.scrollLeft, -expectedScrollLeft, epsilon, "ending scrollLeft");
    assert_approx_equals(scroller.scrollTop, expectedScrollTop, epsilon, "ending scrollTop");
  }, `writing-mode:vertical-rl; direction:ltr`);

  test(() => {
    var scroller = document.querySelector(".vertical-rl.rtl");
    assert_approx_equals(scroller.scrollLeft, 0, epsilon, "initial scrollLeft");
    assert_approx_equals(scroller.scrollTop, 0, epsilon, "initial scrollTop");
    scroller.scrollLeft = -2*content_width;
    scroller.scrollTop = -2*content_height;
    assert_approx_equals(scroller.scrollLeft, -expectedScrollLeft, epsilon, "ending scrollLeft");
    assert_approx_equals(scroller.scrollTop, -expectedScrollTop, epsilon, "ending scrollTop");
  }, `writing-mode:vertical-rl; direction:rtl`);
  </script>
</body>
</html>