summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-anchor-position/position-fallback-tree-scoped.html
blob: 2650a32f60a20675eb97ed028dfff29143045c88 (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
<!DOCTYPE html>
<title>CSS Anchor Positioning Test: @position-fallback - tree scoped names</title>
<link rel="help" href="https://drafts.csswg.org/css-anchor-1/#fallback-rule">
<link rel="help" href="https://drafts.csswg.org/css-scoping/#shadow-names">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<style>
  body { margin: 0; }

  @position-fallback --doc {
    @try {
      left: 100px;
    }
  }

  .abs { position: absolute; }

  #doc_pf_doc { position-fallback: --doc; }
  #doc_pf_outer { position-fallback: --outer; }
  #doc_pf_inner { position-fallback: --inner; }
</style>

<div id="doc_pf_doc" class="abs"></div>
<div id="doc_pf_outer" class="abs"></div>
<div id="doc_pf_inner" class="abs"></div>
<div id="outer_host">
  <template shadowrootmode="open">
    <style>
      @position-fallback --outer {
        @try {
          left: 200px;
        }
      }

      .abs { position: absolute; }

      #outer_pf_doc { position-fallback: --doc; }
      #outer_pf_outer { position-fallback: --outer; }
      #outer_pf_inner { position-fallback: --inner; }
    </style>
    <div id="outer_pf_doc" class="abs"></div>
    <div id="outer_pf_outer" class="abs"></div>
    <div id="outer_pf_inner" class="abs"></div>
    <div id="inner_host">
      <template shadowrootmode="open">
        <style>
          @position-fallback --inner {
            @try {
              left: 300px;
            }
          }

          .abs { position: absolute; }

          #inner_pf_doc { position-fallback: --doc; }
          #inner_pf_outer { position-fallback: --outer; }
          #inner_pf_inner { position-fallback: --inner; }
        </style>
        <div id="inner_pf_doc" class="abs"></div>
        <div id="inner_pf_outer" class="abs"></div>
        <div id="inner_pf_inner" class="abs"></div>
      </template>
    </div>
  </template>
</div>


<style>
  @position-fallback --host-slot-part {
    @try {
      left: 1px;
    }
  }
  #host_slotted_part::part(part) {
    position-fallback: --host-slot-part;
  }
</style>
<div id="host_slotted_part">
  <template shadowrootmode="open">
    <style>
      @position-fallback --host-slot-part {
        @try {
          left: 2px;
        }
      }
      ::slotted(#slotted), :host {
        position: absolute;
        position-fallback: --host-slot-part;
      }
      #part {
        position: absolute;
      }
    </style>
    <div id="part" part="part"></div>
    <slot></slot>
  </template>
  <div id="slotted"></div>
</div>


<script>
  test(() => {
    assert_equals(doc_pf_doc.offsetLeft, 100);
  }, "Document position-fallback matches @position-fallback in document scope");

  test(() => {
    assert_equals(doc_pf_outer.offsetLeft, 0);
  }, "Document position-fallback does not match @position-fallback in #outer_host scope");

  test(() => {
    assert_equals(doc_pf_inner.offsetLeft, 0);
  }, "Document position-fallback does not match @position-fallback in #inner_host scope");

  const outer_root = outer_host.shadowRoot;
  const inner_root = outer_root.querySelector("#inner_host").shadowRoot;

  test(() => {
    assert_equals(outer_root.querySelector("#outer_pf_doc").offsetLeft, 100);
  }, "Outer position-fallback matches @position-fallback in document scope");

  test(() => {
    assert_equals(outer_root.querySelector("#outer_pf_outer").offsetLeft, 200);
  }, "Outer position-fallback matches @position-fallback in #outer_host scope");

  test(() => {
    assert_equals(outer_root.querySelector("#outer_pf_inner").offsetLeft, 0);
  }, "Outer position-fallback does not match @position-fallback in #inner_host scope");

  test(() => {
    assert_equals(inner_root.querySelector("#inner_pf_doc").offsetLeft, 100)
  }, "Inner position-fallback matches @position-fallback in document scope");

  test(() => {
    assert_equals(inner_root.querySelector("#inner_pf_outer").offsetLeft, 200);
  }, "Inner position-fallback matches @position-fallback in #outer_host scope");

  test(() => {
    assert_equals(inner_root.querySelector("#inner_pf_inner").offsetLeft, 300);
  }, "Inner position-fallback matches @position-fallback in #inner_host scope");

  test(() => {
    assert_equals(host_slotted_part.offsetLeft, 2);
  }, "@position-fallback from same scope as :host rule");

  test(() => {
    assert_equals(slotted.offsetLeft, 2);
  }, "@position-fallback from same scope as ::slotted() rule");

  test(() => {
    assert_equals(host_slotted_part.shadowRoot.querySelector("#part").offsetLeft, 1);
  }, "@position-fallback from same scope as ::part() rule");
</script>