File: position-computed.tentative.html

package info (click to toggle)
thunderbird 1%3A143.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,703,968 kB
  • sloc: cpp: 7,770,492; javascript: 5,943,842; ansic: 3,918,754; python: 1,418,263; xml: 653,354; asm: 474,045; java: 183,079; sh: 111,238; makefile: 20,410; perl: 14,359; objc: 13,059; yacc: 4,583; pascal: 3,405; lex: 1,720; ruby: 999; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 69; csh: 10
file content (188 lines) | stat: -rw-r--r-- 6,236 bytes parent folder | download | duplicates (3)
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSS Values and Units Module Level 5: computed values for &lt;position&gt;</title>
<link rel="author" title="Sam Weinig" href="mailto:sam@webkit.org">
<link rel="help" href="https://drafts.csswg.org/css-values-5/#position">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/css/support/computed-testcommon.js"></script>
</head>
<body>
<div id="container">
<div id="target"></div>
</div>
<script>
const property = "object-position";

test_computed_value(property, "10% center", "10% 50%");
test_computed_value(property, "right 30% top 60px", "70% 60px");
test_computed_value(property, "-20% -30px");
test_computed_value(property, "30px center", "30px 50%");
test_computed_value(property, "40px top", "40px 0%");
test_computed_value(property, "right 20% bottom 10%", "80% 90%");
test_computed_value(property, "right bottom", "100% 100%");
test_computed_value(property, "center 50px", "50% 50px");
test_computed_value(property, "center bottom", "50% 100%");
test_computed_value(property, "left center", "0% 50%");
test_computed_value(property, "left bottom", "0% 100%");
test_computed_value(property, "right 40%", "100% 40%");
test_computed_value(property, "center top", "50% 0%");
test_computed_value(property, "center", "50% 50%");
test_computed_value(property, "center center", "50% 50%");
test_computed_value(property, "right 20px bottom 10px", "calc(100% - 20px) calc(100% - 10px)");

test_computed_value(property, "x-start", "0% 50%");
test_computed_value(property, "x-start 10px", "0% 10px");
test_computed_value(property, "x-start 10% top 20px", "10% 20px");
test_computed_value(property, "x-end", "100% 50%");
test_computed_value(property, "x-end 10%", "100% 10%");
test_computed_value(property, "x-end 10px top 20px", "calc(100% - 10px) 20px");
test_computed_value(property, "y-start", "50% 0%");
test_computed_value(property, "10px y-start", "10px 0%");
test_computed_value(property, "left 10px y-start 20%", "10px 20%");
test_computed_value(property, "y-end", "50% 100%");
test_computed_value(property, "10px y-end", "10px 100%");
test_computed_value(property, "left 10px y-end 20%", "10px 80%");

function test_writing_modes(property) {
  const writing_modes = [
    {
      styles: [
        {"writing-mode": "horizontal-tb", "direction": "ltr"},
      ],
      mappings: [
        { "x-start": "left" },
        { "x-end": "right" },
        { "y-start": "top" },
        { "y-end": "bottom" },
      ]
    },
    {
      styles: [
        {"writing-mode": "horizontal-tb", "direction": "rtl"},
      ],
      mappings: [
        { "x-start": "right" },
        { "x-end": "left" },
        { "y-start": "top" },
        { "y-end": "bottom" },
      ]
    },
    {
      styles: [
        {"writing-mode": "vertical-rl", "direction": "rtl"},
        {"writing-mode": "sideways-rl", "direction": "rtl"},
      ],
      mappings: [
        { "x-start": "right" },
        { "x-end": "left" },
        { "y-start": "bottom" },
        { "y-end": "top" },
      ]
    },
    {
      styles: [
        {"writing-mode": "vertical-rl", "direction": "ltr"},
        {"writing-mode": "sideways-rl", "direction": "ltr"},
      ],
      mappings: [
        { "x-start": "right" },
        { "x-end": "left" },
        { "y-start": "top" },
        { "y-end": "bottom" },
      ]
    },
    {
      styles: [
        {"writing-mode": "vertical-lr", "direction": "rtl"},
      ],
      mappings: [
        { "x-start": "left" },
        { "x-end": "right" },
        { "y-start": "bottom" },
        { "y-end": "top" },
      ]
    },
    {
      styles: [
        {"writing-mode": "sideways-lr", "direction": "ltr"},
      ],
      mappings: [
        { "x-start": "left" },
        { "x-end": "right" },
        { "y-start": "bottom" },
        { "y-end": "top" },
      ]
    },
    {
      styles: [
        {"writing-mode": "vertical-lr", "direction": "ltr"},
      ],
      mappings: [
        { "x-start": "left" },
        { "x-end": "right" },
        { "y-start": "top" },
        { "y-end": "bottom" },
      ]
    },
    {
      styles: [
        {"writing-mode": "sideways-lr", "direction": "rtl"},
      ],
      mappings: [
        { "x-start": "left" },
        { "x-end": "right" },
        { "y-start": "top" },
        { "y-end": "bottom" },
      ]
    },
  ];

  function inner_test(property, specified, expected_to_match, container_styles) {
    test(() => {
      const target = document.getElementById('target');
      assert_true(property in getComputedStyle(target), "'" + property + "' is a supported property for the computed style");
      assert_true(CSS.supports(property, specified), "'" + specified + "' is a supported value for " + property + ".");

      target.style[property] = '';
      target.style[property] = expected_to_match;
      let expectedValue = getComputedStyle(target)[property];

      target.style[property] = '';
      target.style[property] = specified;
      let readValue = getComputedStyle(target)[property];
      assert_equals(readValue, expectedValue, `'${specified}' is equal to the computed value of ''${expected_to_match}' which is '${expectedValue}'`);
      if (readValue !== specified) {
        target.style[property] = '';
        target.style[property] = readValue;
        assert_equals(getComputedStyle(target)[property], readValue,
                      'computed value should round-trip');
      }
    }, `Property ${property} value '${specified}' in mode '${container_styles.join(', ')}'`);
  }

  const container = document.getElementById('container');
  for (let writing_mode of writing_modes) {
    for (let style of writing_mode.styles) {
      var container_styles = [];
      for (let container_property in style) {
        container.style[container_property] = style[container_property];
        container_styles.push(`${container_property}: ${style[container_property]}`);
      }

      for (let mapping of writing_mode.mappings) {
        for (let key in mapping) {
          inner_test(property, key, mapping[key], container_styles);
        }
      }
    }
  }
}

test_writing_modes(property);

</script>
</body>
</html>