summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-position/position-absolute-replaced-minmax.html
blob: 5a76277092bf9e84605fbb8e1fd64e17259e3f44 (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
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
<!DOCTYPE html>
<title>CSS Position: absolute position, replaced elements, and minmax</title>
<link rel="author" title="mailto:atotic@google.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="https://www.w3.org/TR/CSS2/visudet.html#min-max-widths">
<meta name="assert" content="Min/max width and height interact properly with abspos replaced elements">
<style>
.container {
  position: relative;
  display: inline-block;
  width: 400px;
  height: 200px;
  border: 1px solid black;
}
.target {
  position: absolute;
  padding: 10px;
  bottom: 0;
  right: 0;
  border-width: 3px 7px 9px 11px;
  border-color: yellow;
  border-style: solid;
  margin: 1px 3px 7px 9px;
}
</style>
<!-- test all combinations of minmax from section 10.4 table at
  https://www.w3.org/TR/CSS2/visudet.html#min-max-widths -->

<!-- IFRAME tests -->
<!-- iframe: intrinsic size is 300x150, no aspect ratio -->
<div class="container">
  <iframe class="target"
  data-expected-width="338" data-expected-height="182" data-offset-y="11" data-offset-x="59"
  >
  </iframe>
</div>
<!-- spec 1: w > max-width -->
<div class="container">
  <iframe class="target" style="max-width:100px"
  data-expected-width="138" data-expected-height="182" data-offset-y="11" data-offset-x="259"
  >
  </iframe>
</div>
<!-- spec 2: w < min-width -->
<div class="container">
  <iframe class="target" style="min-width: 350px"
  data-expected-width="388" data-expected-height="182" data-offset-y="11" data-offset-x="9"
  >
  </iframe>
</div>
<!-- spec 3: h > max-height -->
<div class="container">
  <iframe class="target" style="max-height: 150px"
  data-expected-width="338" data-expected-height="182" data-offset-y="11" data-offset-x="59"
  >
  </iframe>
</div>
<!-- spec 4: h < min-height -->
<div class="container">
  <iframe class="target" style="min-height: 165px"
  data-expected-width="338" data-expected-height="197" data-offset-y="-4" data-offset-x="59"
  >
  </iframe>
</div>
<!-- spec 5: (w > max-width) and (h > max-height), where (max-width/w ≤ max-height/h) -->
<div class="container">
  <iframe class="target" style="max-width: 240px; max-height: 135px"
  data-expected-width="278" data-expected-height="167" data-offset-y="26" data-offset-x="119"
  >
  </iframe>
</div>
<!-- spec 6: (w > max-width) and (h > max-height), where (max-width/w > max-height/h) -->
<div class="container">
  <iframe class="target" style="max-width: 270px; max-height: 120px"
  data-expected-width="308" data-expected-height="152" data-offset-y="41" data-offset-x="89"
  >
  </iframe>
</div>
<!-- spec 7: (w < min-width) and (h < min-height), where (min-width/w  min-height/h) -->
<div class="container">
  <iframe class="target" style="min-width: 360px; min-height: 165px"
  data-expected-width="398" data-expected-height="197" data-offset-y="-4" data-offset-x="-1"
  >
  </iframe>
</div>
<!-- spec 8: (w < min-width) and (h < min-height), where (min-width/w > min-height/h) -->
<div class="container">
  <iframe class="target" style="min-width: 330px; min-height: 180px"
  data-expected-width="368" data-expected-height="212" data-offset-y="-19" data-offset-x="29"
  >
  </iframe>
</div>
<!-- spec 9: (w < min-width) and (h > max-height) -->
<div class="container">
  <iframe class="target" style="min-width: 330px; max-height: 135px"
  data-expected-width="368" data-expected-height="167" data-offset-y="26" data-offset-x="29"
  >
  </iframe>
</div>
<!-- spec 10: (w > max-width) and (h < min-height) -->
<div class="container">
  <iframe class="target" style="max-width: 240px; min-height: 165px"
  data-expected-width="278" data-expected-height="197" data-offset-y="-4" data-offset-x="119"
  >
  </iframe>
</div>

<!-- IMG png tests -->
<!-- image dimensions: 200x150. images has intrinic size and aspect ratio -->
<div class="container">
  <img class="target png"
  data-expected-width="238" data-expected-height="182" data-offset-y="11" data-offset-x="159"
  >
</div>
<!-- spec 1: w > max-width -->
<div class="container">
  <img class="target png" style="max-width: 180px"
  data-expected-width="218" data-expected-height="167" data-offset-y="26" data-offset-x="179"
  >
</div>
<!-- spec 2: w < min-width -->
<div class="container">
  <img class="target png" style="min-width: 220px"
  data-expected-width="258" data-expected-height="197" data-offset-y="-4" data-offset-x="139"
  >
</div>

<!-- spec 3: h > max-height -->
<div class="container">
  <img class="target png" style="max-height: 135px"
  data-expected-width="218" data-expected-height="167" data-offset-y="26" data-offset-x="179"
  >
</div>
<!-- spec 4: h < min-height -->
<div class="container">
  <img class="target png" style="min-height: 165px"
  data-expected-width="258" data-expected-height="197" data-offset-y="-4" data-offset-x="139"
  >
</div>
<!-- spec 5: (w > max-width) and (h > max-height), where (max-width/w ≤ max-height/h) -->
<div class="container">
  <img class="target png" style="max-width: 160px; max-height: 135px"
  data-expected-width="198" data-expected-height="152" data-offset-y="41" data-offset-x="199"
  >
</div>
<!-- spec 6: (w > max-width) and (h > max-height), where (max-width/w > max-height/h) -->
<div class="container">
  <img class="target png" style="max-width: 180px; max-height: 120px"
  data-expected-width="198" data-expected-height="152" data-offset-y="41" data-offset-x="199"
  >
</div>
<!-- spec 7: (w < min-width) and (h < min-height), where (min-width/w  min-height/h) -->
<div class="container">
  <img class="target png" style="min-width: 240px;min-height: 165px"
  data-expected-width="278" data-expected-height="212" data-offset-y="-19" data-offset-x="119"
  >
</div>
<!-- spec 8: (w < min-width) and (h < min-height), where (min-width/w > min-height/h) -->
<div class="container">
  <img class="target png" style="min-width: 220px;min-height: 180px"
  data-expected-width="278" data-expected-height="212" data-offset-y="-19" data-offset-x="119"
  >
</div>
<!-- spec 9: (w < min-width) and (h > max-height) -->
<div class="container">
  <img class="target png" style="min-width: 220px; max-height: 130px"
  data-expected-width="258" data-expected-height="162" data-offset-y="31" data-offset-x="139"
  >
</div>
<!-- spec 10: (w > max-width) and (h < min-height) -->
<div class="container">
  <img class="target png" style="max-width: 180px; min-height: 165px"
  data-expected-width="218" data-expected-height="197" data-offset-y="-4" data-offset-x="179"
  >
</div>
<!-- IMG SVG tests -->
<!-- image dimensions: 200x150. images has no intrinic size and no aspect ratio -->
<div class="container">
  <img class="target svg"
  data-expected-width="338" data-expected-height="182" data-offset-y="11" data-offset-x="59"
  >
</div>
<!-- spec 1: w > max-width -->
<div class="container">
  <img class="target svg" style="max-width: 180px"
  data-expected-width="218" data-expected-height="182" data-offset-y="11" data-offset-x="179"
  >
</div>
<!-- spec 2: w < min-width -->
<div class="container">
  <img class="target svg" style="min-width: 220px"
  data-expected-width="338" data-expected-height="182" data-offset-y="11" data-offset-x="59"
  >
</div>

<!-- spec 3: h > max-height -->
<div class="container">
  <img class="target svg" style="max-height: 135px"
  data-expected-width="338" data-expected-height="167" data-offset-y="26" data-offset-x="59"
  >
</div>
<!-- spec 4: h < min-height -->
<div class="container">
  <img class="target svg" style="min-height: 165px"
  data-expected-width="338" data-expected-height="197" data-offset-y="-4" data-offset-x="59"
  >
</div>
<!-- spec 5: (w > max-width) and (h > max-height), where (max-width/w ≤ max-height/h) -->
<div class="container">
  <img class="target svg" style="max-width: 160px; max-height: 135px"
  data-expected-width="198" data-expected-height="167" data-offset-y="26" data-offset-x="199"
  >
</div>
<!-- spec 6: (w > max-width) and (h > max-height), where (max-width/w > max-height/h) -->
<div class="container">
  <img class="target svg" style="max-width: 180px; max-height: 120px"
  data-expected-width="218" data-expected-height="152" data-offset-y="41" data-offset-x="179"
  >
</div>
<!-- spec 7: (w < min-width) and (h < min-height), where (min-width/w  min-height/h) -->
<div class="container">
  <img class="target svg" style="min-width: 240px;min-height: 165px"
  data-expected-width="338" data-expected-height="197" data-offset-y="-4" data-offset-x="59"
  >
</div>
<!-- spec 8: (w < min-width) and (h < min-height), where (min-width/w > min-height/h) -->
<div class="container">
  <img class="target svg" style="min-width: 220px;min-height: 180px"
  data-expected-width="338" data-expected-height="212" data-offset-y="-19" data-offset-x="59"
  >
</div>
<!-- spec 9: (w < min-width) and (h > max-height) -->
<div class="container">
  <img class="target svg" style="min-width: 220px; max-height: 130px"
  data-expected-width="338" data-expected-height="162" data-offset-y="31" data-offset-x="59"
  >
</div>
<!-- spec 10: (w > max-width) and (h < min-height) -->
<div class="container">
  <img class="target svg" style="max-width: 180px; min-height: 165px"
  data-expected-width="218" data-expected-height="197" data-offset-y="-4" data-offset-x="179"
  >
</div>
<!-- SVG tests -->
<!-- SVGs are special: any combination of intrinsic_size and aspect_ratio
  can happen. -->
<!-- Just viewbox. Has intrinsic aspect ratio, but no width/height -->
<div class="container">
  <img class="target" src="data:image/svg+xml,%3Csvg  xmlns='http://www.w3.org/2000/svg' %3E%3Crect width='100%' height='100%' style='fill:rgb(0,255,0);'/%3E%3C/svg%3E" style=""
  data-expected-width="338" data-expected-height="182" data-offset-y="11" data-offset-x="59"
  >
</div>
<!-- Just viewbox. Has aspect_ratio, but no intrinsic size
 inline_width defaults to container width -->
<div class="container">
  <img class="target" src="data:image/svg+xml,%3Csvg viewBox='0 0 100 10' xmlns='http://www.w3.org/2000/svg' %3E%3Crect width='100%' height='100%' style='fill:rgb(0,255,0);'/%3E%3C/svg%3E"
  data-expected-width="388" data-expected-height="67" data-offset-y="126" data-offset-x="9"
  >
</div>
<!-- Just viewbox. Has aspect_ratio, but no intrinsic size
 inline_width is constrained by left/right, height computed proportionally -->
<div class="container">
  <img class="target" style="left:100px;right:100px;" src="data:image/svg+xml,%3Csvg viewBox='0 0 100 10' xmlns='http://www.w3.org/2000/svg' %3E%3Crect width='100%' height='100%' style='fill:rgb(0,255,0);'/%3E%3C/svg%3E"
  data-expected-width="188" data-expected-height="47" data-offset-y="146" data-offset-x="109"
  >
</div>
<!-- Same as previous test, but with max-width:fit-content. crbug.com/1010798
  -->
<div class="container">
  <img class="target" style="left:100px;right:100px;max-width:fit-content" src="data:image/svg+xml,%3Csvg viewBox='0 0 100 10' xmlns='http://www.w3.org/2000/svg' %3E%3Crect width='100%' height='100%' style='fill:rgb(0,255,0);'/%3E%3C/svg%3E"
  data-expected-width="188" data-expected-height="47" data-offset-y="146" data-offset-x="109"
  >
</div>
<!-- Viewbox + svg width. Has aspect_ratio and width. Height is scaled -->
<div class="container">
  <img class="target" src="data:image/svg+xml,%3Csvg viewBox='0 0 100 10' width='100px' xmlns='http://www.w3.org/2000/svg' %3E%3Crect width='100%' height='100%' style='fill:rgb(0,255,0);'/%3E%3C/svg%3E"
  data-expected-width="138" data-expected-height="42" data-offset-y="151" data-offset-x="259"
  >
</div>
<!-- Viewbox + svg height. Has aspect_ratio and height. Width is scaled -->
<div class="container">
  <img class="target" src="data:image/svg+xml,%3Csvg viewBox='0 0 100 10' height='20px' xmlns='http://www.w3.org/2000/svg' %3E%3Crect width='100%' height='100%' style='fill:rgb(0,255,0);'/%3E%3C/svg%3E"
  data-expected-width="238" data-expected-height="52" data-offset-y="141" data-offset-x="159"
  >
</div>
<!-- Viewbox + css height. Has aspect_ratio and height. Width is scaled -->
<div class="container">
  <img class="target" style="height:20px" src="data:image/svg+xml,%3Csvg viewBox='0 0 100 10' xmlns='http://www.w3.org/2000/svg' %3E%3Crect width='100%' height='100%' style='fill:rgb(0,255,0);'/%3E%3C/svg%3E"
  data-expected-width="238" data-expected-height="52" data-offset-y="141" data-offset-x="159"
  >
</div>
<!-- Viewbox + css width. Has aspect_ratio and width. Height is scaled -->
<div class="container">
  <img class="target" style="width:238px" src="data:image/svg+xml,%3Csvg viewBox='0 0 100 10' xmlns='http://www.w3.org/2000/svg' %3E%3Crect width='100%' height='100%' style='fill:rgb(0,255,0);'/%3E%3C/svg%3E"
  data-expected-width="276" data-expected-height="56" data-offset-y="137" data-offset-x="121"
  >
</div>
<script>
  // initialize png images with  200x150 green png
  let pngSrc="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAACWAQMAAAChElVaAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABlBMVEUAgAD///8UPy9PAAAAAWJLR0QB/wIt3gAAAAd0SU1FB+MBDwkdA1Cz/EMAAAAbSURBVEjH7cGBAAAAAMOg+VPf4ARVAQAAAM8ADzwAAeM8wQsAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTktMDEtMTVUMTc6Mjk6MDMtMDg6MDCYDy9IAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE5LTAxLTE1VDE3OjI5OjAzLTA4OjAw6VKX9AAAAABJRU5ErkJggg=="
;
  let images = document.querySelectorAll("img.png");
  for (let i=0; i<images.length; ++i) {
    images[i].src = pngSrc;
  }

  // SVG with no intrinsic width/height
  let svgSrc="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' %3E%3Crect width='100%' height='100%' style='fill:rgb(0,255,0);'/%3E%3C/svg%3E ";
  images = document.querySelectorAll("img.svg");
  for (let i=0; i<images.length; ++i) {
    images[i].src = svgSrc;
  }

  function makeTest(el) {
    return function() {
      if (!el.getAttribute("data-expected-width")) {
        // This code is used to generate reference data for the tests.
        let text = `data-expected-width="${el.offsetWidth}" data-expected-height="${el.offsetHeight}" data-offset-y="${el.offsetTop}" data-offset-x="${el.offsetLeft}"`;
        el.parentElement.innerText = text;
        return;
      }
      assert_equals(el.offsetWidth + "", el.getAttribute("data-expected-width"), "incorrect offsetWidth");
      assert_equals(el.offsetHeight + "", el.getAttribute("data-expected-height"), "incorrect offsetHeight");
      assert_equals(el.offsetTop + "", el.getAttribute("data-offset-y"), "incorrect offsetTop");
      assert_equals(el.offsetLeft + "", el.getAttribute("data-offset-x"), "incorrect offsetLeft");
    }
  };


  let testNameIndex = 1;
  function getTestName(el) {
    let svg = el.classList.contains("svg") ? " svg" : "";
    return "minmax replaced " + el.nodeName + svg + " " + testNameIndex++;
  };

  function testAfterImageLoads(img, test) {
    let asyncTest = async_test(getTestName(img));
    img.addEventListener("load", _ => {
      asyncTest.step(test);
      asyncTest.done();
    });
  };

  let testElements = document.querySelectorAll(".target");

  for (let i=0; i<testElements.length; ++i) {
    let myTest = makeTest(testElements[i]);
    if (testElements[i].nodeName == "IMG" && !testElements[i].complete) {
      testAfterImageLoads(testElements[i], myTest);
    } else {
      test(myTest, getTestName(testElements[i]));
    }
  }
</script>