File: CSSStyleSheet-constructable-invalidation.html

package info (click to toggle)
thunderbird 1%3A140.4.0esr-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,609,432 kB
  • sloc: cpp: 7,672,442; javascript: 5,901,613; ansic: 3,898,954; python: 1,413,343; xml: 653,997; asm: 462,286; java: 180,927; sh: 113,489; makefile: 20,460; perl: 14,288; objc: 13,059; yacc: 4,583; pascal: 3,352; lex: 1,720; ruby: 1,222; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 70; csh: 10
file content (49 lines) | stat: -rw-r--r-- 2,499 bytes parent folder | download | duplicates (14)
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
<!doctype html>
<meta charset="utf-8">
<title>CSSStyleSheet rule mutation invalidation</title>
<link rel="author" href="mailto:wpt@keithcirkel.co.uk" title="Keith Cirkel">
<link rel="help" href="https://drafts.csswg.org/cssom/#extensions-to-the-document-or-shadow-root-interface">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<span id="span1">Should be green.</span>
<span id="span2">Should be green.</span>
<script>
promise_test(async function(t) {
  const sheet = new CSSStyleSheet();
  sheet.replaceSync('span {color:var(--color, red);}');
  document.adoptedStyleSheets = [sheet];
  t.add_cleanup(() => {
    document.adoptedStyleSheets = [];
  })
  assert_equals(getComputedStyle(span1).color, "rgb(255, 0, 0)", "Sheet should apply");
  sheet.rules[0].style.setProperty('--color', 'green');
  assert_equals(getComputedStyle(span1).color, "rgb(0, 128, 0)", "Sheet should invalidate style");
  document.adoptedStyleSheets = [];
  assert_equals(getComputedStyle(span1).color, "rgb(0, 0, 0)", "Removing sheet should apply");
}, "mutating constructed CSSStyleSheet applied to root invalidates styles");

promise_test(async function() {
  span1.attachShadow({mode:'open'})
  span1.shadowRoot.append(document.createElement('slot'))
  const sheet = new CSSStyleSheet();
  sheet.replaceSync(':host {color:var(--color, red);}');
  span1.shadowRoot.adoptedStyleSheets = [sheet];
  assert_equals(getComputedStyle(span1).color, "rgb(255, 0, 0)", "Sheet should apply");
  sheet.rules[0].style.setProperty('--color', 'green');
  assert_equals(getComputedStyle(span1).color, "rgb(0, 128, 0)", "Sheet should invalidate style");
}, "mutating constructed CSSStyleSheet applied to shadowdom invalidates styles");

promise_test(async function() {
  span2.attachShadow({mode:'open'})
  span2.shadowRoot.append(document.createElement('slot'))
  const sheet1 = new CSSStyleSheet();
  const sheet2 = new CSSStyleSheet();
  sheet1.replaceSync(':host {color:var(--color, hotpink);}');
  sheet2.replaceSync(':host {--color: blue}');
  const style2 = sheet2.rules[0].style;
  span2.shadowRoot.adoptedStyleSheets = [sheet1, sheet2];
  assert_equals(getComputedStyle(span2).color, "rgb(0, 0, 255)", "Sheet should apply");
  style2.setProperty('--color', 'green');
  assert_equals(getComputedStyle(span2).color, "rgb(0, 128, 0)", "Sheet should invalidate style");
}, "mutating dependent constructed CSSStyleSheet applied to shadowdom invalidates styles");
</script>