File: registered-property-cssom.html

package info (click to toggle)
firefox 143.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,617,328 kB
  • sloc: cpp: 7,478,492; javascript: 6,417,157; ansic: 3,720,058; python: 1,396,372; xml: 627,523; asm: 438,677; java: 186,156; sh: 63,477; makefile: 19,171; objc: 13,059; perl: 12,983; yacc: 4,583; cs: 3,846; pascal: 3,405; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (91 lines) | stat: -rw-r--r-- 3,737 bytes parent folder | download | duplicates (20)
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
<!DOCTYPE HTML>
<link rel="help" href="https://drafts.css-houdini.org/css-properties-values-api/#dom-css-registerproperty" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<style>
#inner {
  --length: 10px;
  --color: red;
}
#outer {
  --length: 77px;
  --color: blue;
}
</style>

<div id=outer>
  <div id=inner></div>
</div>

<script>
var computedStyle = getComputedStyle(inner);
var inlineStyle = inner.style;
var sheetStyle = document.styleSheets[0].cssRules[0].style;

test(function() {
  // Nothing registered yet, whatever you specify works
  assert_equals(computedStyle.getPropertyValue('--length'), '10px');
  assert_equals(computedStyle.getPropertyValue('--color'), 'red');
}, "Initially unregistered values from stylesheet");

test(function() {
  inlineStyle.setProperty('--length', '5');
  inlineStyle.setProperty('--color', 'hello');

  assert_equals(inlineStyle.getPropertyValue('--length'), '5');
  assert_equals(inlineStyle.getPropertyValue('--color'), 'hello');
  assert_equals(computedStyle.getPropertyValue('--length'), '5');
  assert_equals(computedStyle.getPropertyValue('--color'), 'hello');
}, "CSSOM setters function as expected for unregistered properties");

test(function() {
  CSS.registerProperty({name: '--length', syntax: '<length>', initialValue: '0px', inherits: false});
  CSS.registerProperty({name: '--color', syntax: '<color>', initialValue: 'white', inherits: true});
}, "CSS.registerProperty");

test(function() {
  assert_equals(inlineStyle.getPropertyValue('--length'), '5');
  assert_equals(inlineStyle.getPropertyValue('--color'), 'hello');
  assert_equals(computedStyle.getPropertyValue('--length'), '0px');
  assert_equals(computedStyle.getPropertyValue('--color'), 'rgb(0, 0, 255)');
}, "Formerly valid values are still readable from inline styles but are computed as the unset value");

test(function() {
  inlineStyle.setProperty('--length', 'hi');
  inlineStyle.setProperty('--color', '20');
  assert_equals(inlineStyle.getPropertyValue('--length'), 'hi');
  assert_equals(inlineStyle.getPropertyValue('--color'), '20');
}, "Values not matching the registered type can still be set");

test(function() {
  inlineStyle.removeProperty('--length');
  inlineStyle.setProperty('--color', '');
  assert_equals(inlineStyle.getPropertyValue('--length'), '');
  assert_equals(inlineStyle.getPropertyValue('--color'), '');
  assert_equals(computedStyle.getPropertyValue('--length'), '10px');
  assert_equals(computedStyle.getPropertyValue('--color'), 'rgb(255, 0, 0)');
}, "Values can be removed from inline styles");

test(function() {
  // 'banana' is not a valid <length>, but still accepted.
  sheetStyle.setProperty('--length', 'banana');
  assert_equals(computedStyle.getPropertyValue('--length'), '0px');
  sheetStyle.setProperty('--length', '20px');
  assert_equals(computedStyle.getPropertyValue('--length'), '20px');
  sheetStyle.setProperty('--length', 'initial');
  assert_equals(computedStyle.getPropertyValue('--length'), '0px');
}, "Stylesheets can be modified by CSSOM");

test(function() {
  inlineStyle.setProperty('--length', '30px');
  inlineStyle.setProperty('--color', 'pink');
  assert_equals(inlineStyle.getPropertyValue('--length'), '30px');
  assert_equals(inlineStyle.getPropertyValue('--color'), 'pink');
  assert_equals(computedStyle.getPropertyValue('--length'), '30px');
  assert_equals(computedStyle.getPropertyValue('--color'), 'rgb(255, 192, 203)');
  inlineStyle.setProperty('--color', 'inherit');
  assert_equals(inlineStyle.getPropertyValue('--color'), 'inherit');
  assert_equals(computedStyle.getPropertyValue('--color'), 'rgb(0, 0, 255)');
}, "Valid values can be set on inline styles");
</script>