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
  
     | 
    
      <!DOCTYPE html>
<title>Pseudo-elements allowed after ::part()</title>
<link rel="help" href="https://drafts.csswg.org/css-shadow-parts/">
<meta name="flags" content="ahem">
<link rel="stylesheet" href="/fonts/ahem.css">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../support/parsing-testcommon.js"></script>
<body>
<span style="font-family: Ahem">X</span>
<script>
"use strict";
test_invalid_selector("::part(mypart)::part(anotherpart)");
test_invalid_selector("::part(mypart)::notarealpseudoelement");
test_valid_selector("::part(mypart)::after");
test_valid_selector("::part(mypart)::backdrop");
test_valid_selector("::part(mypart)::before");
test_valid_selector("::part(mypart)::cue");
test_valid_selector("::part(mypart)::details-content");
test_valid_selector("::part(mypart)::file-selector-button");
test_valid_selector("::part(mypart)::first-letter");
test_valid_selector("::part(mypart)::first-line");
test_valid_selector("::part(mypart)::grammar-error");
test_valid_selector("::part(mypart)::highlight(myhighlight)");
test_valid_selector("::part(mypart)::marker");
test_valid_selector("::part(mypart)::placeholder");
test_valid_selector("::part(mypart)::search-text");
test_valid_selector("::part(mypart)::selection");
test_valid_selector("::part(mypart)::spelling-error");
test_valid_selector("::part(mypart)::target-text");
test_valid_selector("::part(mypart)::view-transition");
test_valid_selector("::part(mypart)::view-transition-group(*)");
test_valid_selector("::part(mypart)::view-transition-image-pair(*)");
test_valid_selector("::part(mypart)::view-transition-new(*)");
test_valid_selector("::part(mypart)::view-transition-old(*)");
// to be used inside of a promise_test() function.
async function run_part_test(t, style_rules, part_html, assertion) {
  let container = document.createElement("div");
  let shadow = container.attachShadow({mode: "open"});
  shadow.innerHTML = `
    ${part_html}
    <slot></slot>
  `;
  document.body.append(container);
  let style = document.createElement("style");
  style.innerText = style_rules;
  document.head.append(style);
  t.add_cleanup(() => {
    container.remove();
    style.remove();
  });
  await assertion(container, shadow.firstElementChild);
}
function test_with_part(style_rules, part_html, assertion) {
  promise_test(async (t) => {
    await run_part_test(t, style_rules, part_html, assertion);
  }, `::part styles with ${style_rules} and ${part_html}`);
}
// Generate a random-looking color using the string input as a "seed"
// (so different tests use different colors).
function generate_color(str) {
  let sum = Array.from(str).reduce((sum, char) => sum + char.charCodeAt(0), 0);
  return `rgb(${sum % 255}, ${(sum * 2 + 17) % 255}, ${(sum * 3 + 139) % 255})`;
}
function test_pseudo_computed_style(pseudo_element, tag, attributes) {
  promise_test(async (t) => {
    let our_color = generate_color(pseudo_element);
    await run_part_test(t,
                        `::part(mypart)${pseudo_element} {
                           background: ${our_color};
                         }`,
                        `<${tag} ${attributes} part='mypart'></${tag}>`,
                        async (container, part) => {
                          assert_equals(getComputedStyle(part, pseudo_element).backgroundColor, our_color);
                        });
  }, `computed style for ::part()${pseudo_element}`);
}
test_pseudo_computed_style("::after", "div", "");
test_pseudo_computed_style("::backdrop", "div", "popover='auto'");
test_pseudo_computed_style("::before", "div", "");
// NOTE: not testing :cue at all.
test_pseudo_computed_style("::details-content", "details", "");
test_pseudo_computed_style("::file-selector-button", "input", "type='file'");
test_pseudo_computed_style("::first-letter", "div", "");
test_pseudo_computed_style("::first-line", "div", "");
test_pseudo_computed_style("::grammar-error", "div", "");
test_pseudo_computed_style("::highlight(myhighlight)", "div", "");
test_pseudo_computed_style("::placeholder", "input", "type='text' placeholder='enter text'");
test_pseudo_computed_style("::search-text", "div", "");
test_pseudo_computed_style("::selection", "div", "");
test_pseudo_computed_style("::spelling-error", "div", "");
test_pseudo_computed_style("::target-text", "div", "");
// NOTE: Not yet testing computed style for view transition
// pseudo-elements since they currently only apply to the root element
// (but are intended to apply to others later).
test_with_part(`::part(mypart)::after {
                  display: block;
                  content: "";
                  height: 77px;
                }`,
               `<div part='mypart'></div>`,
               async (container, part) => {
                 assert_equals(container.getBoundingClientRect().height, 77);
               });
test_with_part(`::part(mypart)::before {
                  display: block;
                  content: "";
                  height: 46px;
                }`,
               `<div part='mypart'></div>`,
               async (container, part) => {
                 assert_equals(container.getBoundingClientRect().height, 46);
               });
test_with_part(`::part(mypart)::details-content {
                  height: 371px;
                }`,
               `<details part='mypart'><summary style="height:47px">summary</summary>details</details>`,
               async (container, part) => {
                 assert_equals(container.getBoundingClientRect().height, 371 + 47);
               });
test_with_part(`::part(mypart)::file-selector-button {
                  height: 94px;
                  padding: 0;
                  margin: 0;
                  border: none;
                  appearance: none;
                }`,
               `<input type=file part=mypart>`,
               async (container, part) => {
                 assert_equals(container.getBoundingClientRect().height, 94);
               });
test_with_part(`::part(mypart) {
                  font: 20px/1 Ahem;
                }
                ::part(mypart)::first-letter {
                  font-size: 86px;
                }`,
               `<div part=mypart>X<br>X</div>`,
               async (container, part) => {
                 await document.fonts.ready;
                 assert_equals(container.getBoundingClientRect().height, 86 + 20);
               });
test_with_part(`::part(mypart) {
                  font: 20px/1 Ahem;
                }
                ::part(mypart)::first-line {
                  font-size: 86px;
                }`,
               `<div part=mypart>X<br>X</div>`,
               async (container, part) => {
                 await document.fonts.ready;
                 assert_equals(container.getBoundingClientRect().height, 86 + 20);
               });
test_with_part(`::part(mypart)::marker {
                  font: 63px/1.0 Ahem;
                  content: "X";
                }`,
               `<li style="list-style-position: inside" part="mypart"></li>`,
               async (container, part) => {
                 await document.fonts.ready;
                 assert_equals(container.getBoundingClientRect().height, 63);
               });
</script>
 
     |