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
|
<!doctype html>
<title>Container Relative Units: fall back to small viewport</title>
<link rel="help" href="https://drafts.csswg.org/css-contain-3/#container-lengths">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/cq-testcommon.js"></script>
<style>
iframe {
width: 200px;
height: 40px;
}
</style>
<iframe id=iframe srcdoc="
<style>
#container {
container-type: inline-size;
width: 70px;
height: 30px;
}
#target {
left: 10cqw;
top: 10cqh;
right: 10cqi;
bottom: 10cqb;
margin-left: 10cqmax;
margin-right: 10cqmin;
}
</style>
<div id=container>
<div id=target></div>
</div>
"></iframe>
<script>
setup(() => assert_implements_container_queries());
function waitForLoad(w) {
return new Promise(resolve => w.addEventListener('load', resolve));
}
promise_test(async () => {
await waitForLoad(window);
let inner_target = iframe.contentDocument.querySelector('#target');
// Since there's an inline-size container, cqw/cqi should evaluate against
// that.
assert_equals(getComputedStyle(inner_target).left, '7px'); // 10cqw
assert_equals(getComputedStyle(inner_target).right, '7px'); // 10cqi
// However, there is no size container, so cqh/cqb should evaluate against
// the small viewport size.
assert_equals(getComputedStyle(inner_target).top, '4px'); // 10cqh
assert_equals(getComputedStyle(inner_target).bottom, '4px'); // 10cqb
assert_equals(getComputedStyle(inner_target).marginLeft, '7px'); // 10cqmax
assert_equals(getComputedStyle(inner_target).marginRight, '4px'); // 10cqmin
iframe.style = 'width:400px;height:80px';
// Not affected by resize:
assert_equals(getComputedStyle(inner_target).left, '7px'); // 10cqw
assert_equals(getComputedStyle(inner_target).right, '7px'); // 10cqi
// Affected:
assert_equals(getComputedStyle(inner_target).top, '8px'); // 10cqh
assert_equals(getComputedStyle(inner_target).bottom, '8px'); // 10cqb
assert_equals(getComputedStyle(inner_target).marginLeft, '8px'); // 10cqmax
assert_equals(getComputedStyle(inner_target).marginRight, '7px'); // 10cqmin
}, 'Use small viewport size as fallback');
</script>
|