File: select-size-scrolling-and-sizing.optional.html

package info (click to toggle)
firefox-esr 115.14.0esr-1~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,659,200 kB
  • sloc: cpp: 6,676,648; javascript: 5,690,850; ansic: 3,328,545; python: 1,120,605; asm: 397,163; xml: 180,531; java: 178,838; sh: 68,930; makefile: 20,999; perl: 12,595; objc: 12,561; yacc: 4,583; cs: 3,846; pascal: 2,840; lex: 1,720; ruby: 1,079; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (137 lines) | stat: -rw-r--r-- 5,196 bytes parent folder | download | duplicates (15)
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
137
<!doctype html>
<link rel="author" title="Tim Nguyen" href="https://github.com/nt1m">
<link rel="help" href="https://html.spec.whatwg.org/#the-select-element">
<link rel="help" href="https://drafts.csswg.org/css-writing-modes-4/#block-flow">
<link rel="help" href="https://drafts.csswg.org/cssom-view/#scrolling-area">
<title>Test &lt;select&gt; size attribute scroll progression and sizing</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<select size="5"></select>
<script>
const select = document.querySelector("select");
for (let i = 0; i < 100; i++) {
    const option = document.createElement("option");
    option.textContent = `Option ${i + 1}`;
    select.appendChild(option);
}

for (const writingMode of ["horizontal-tb", "vertical-lr", "vertical-rl", "sideways-lr", "sideways-rl"]) {
    if (!CSS.supports(`writing-mode: ${writingMode}`))
        continue;

    const scrollBlockAxis = (() => {
        switch (writingMode) {
        case "horizontal-tb":
            return "scrollTop";
        case "vertical-lr":
        case "sideways-lr":
        case "vertical-rl":
        case "sideways-rl":
            return "scrollLeft";
        }
    })();
    const scrollInlineAxis = scrollBlockAxis === "scrollTop" ? "scrollLeft" : "scrollTop";

    const isHorizontal = writingMode === "horizontal-tb";
    const clientBlock = isHorizontal ? "clientHeight" : "clientWidth";
    const clientInline = isHorizontal ? "clientWidth" : "clientHeight";
    const scrollBlock = isHorizontal ? "scrollHeight" : "scrollWidth";
    const scrollInline = isHorizontal ? "scrollWidth" : "scrollHeight";

    const select = document.querySelector("select");

    test(t => {
        select.scrollTop = select.scrollLeft = 0;
        select.style.writingMode = writingMode;
        t.add_cleanup(() => {
            select.removeAttribute("style");
            select.scrollTop = select.scrollLeft = 0;
        });

        assert_true(
            select[scrollBlock] > select[clientBlock],
            "select should be scrollable in block axis"
        );
        assert_equals(
            select[scrollInline], select[clientInline],
            "select should not be scrollable in inline axis"
        );

        assert_equals(
            select[scrollBlockAxis], 0,
            `scrolling is initially at block start for writing-mode: ${writingMode}`
        );

        const isReversedBlockFlowDirection = writingMode.endsWith("-rl");
        select[scrollBlockAxis] = 100;
        if (!isReversedBlockFlowDirection) {
            assert_true(
                select[scrollBlockAxis] > 0,
                `Setting ${scrollBlockAxis} to a positive value of the list works for writing-mode: ${writingMode}`
            );
        } else {
            assert_equals(
                select[scrollBlockAxis], 0,
                `Setting ${scrollBlockAxis} to a positive value of the list does not work for writing-mode: ${writingMode}`
            );
        }

        select[scrollBlockAxis] = -100;
        if (isReversedBlockFlowDirection) {
            assert_true(
                select[scrollBlockAxis] < 0,
                `Setting ${scrollBlockAxis} to a negative value of the list works for writing-mode: ${writingMode}`
            );
        } else {
            assert_equals(
                select[scrollBlockAxis], 0,
                `Setting ${scrollBlockAxis} to a negative value of the list does not work for writing-mode: ${writingMode}`
            );
        }

        select[scrollInlineAxis] = 100;
        assert_equals(
            select[scrollInlineAxis], 0,
            `setting ${scrollInlineAxis} to a positive value should not scroll for writing-mode: ${writingMode}`
        );
        select[scrollInlineAxis] = -100;
        assert_equals(
            select[scrollInlineAxis], 0,
            `setting ${scrollInlineAxis} to a negative value should not scroll for writing-mode: ${writingMode}`
        );
    }, `select[size][style="writing-mode: ${writingMode}"] scrolls correctly`);

    test(t => {
        select.style.writingMode = writingMode;
        t.add_cleanup(() => {
            select.removeAttribute("style");
            select.size = 5;
        });

        let prevBlockSize = select[clientBlock];
        let prevInlineSize = select[clientInline];
        select.size = 10;
        assert_true(
            select[clientBlock] > prevBlockSize,
            `${clientBlock} increased when increasing size`
        );
        assert_equals(
            select[clientInline], prevInlineSize,
            `${clientInline} did not change when increasing size`
        );

        prevBlockSize = select[clientBlock];
        prevInlineSize = select[clientInline];
        select.size = 8;
        assert_true(
            select[clientBlock] < prevBlockSize,
            `${clientBlock} decreased when decreasing size`
        );
        assert_equals(
            select[clientInline], prevInlineSize,
            `${clientInline} did not change when decreasing size`
        );
    }, `select[size][style="writing-mode: ${writingMode}"] sizing works correctly`);
};
</script>