summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-properties-values-api/at-property-cssom.html
blob: 27041c2ad0c8043edd9b202bde615e0dd72d2be9 (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
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
182
183
184
185
186
187
188
189
190
191
<!DOCTYPE html>
<link rel="help" href="https://drafts.css-houdini.org/css-properties-values-api-1/#cssom">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
  @property --valid {
    syntax: "<color> | none";
    inherits: false;
    initial-value: red;
  }
  @property --valid-reverse {
    initial-value: 0px;
    inherits: true;
    syntax: "<length>";
  }
  @property --valid-universal {
    syntax: "*";
    inherits: false;
  }
  @property --valid-whitespace {
    syntax: " <color># ";
    inherits: false;
    initial-value: red, blue;
  }
  @property --vALId {
    syntax: "<color> | none";
    inherits: false;
    initial-value: red;
  }
  @property --no-descriptors {

  }
  @property --no-syntax {
    inherits: false;
    initial-value: red;
  }
  @property --no-inherits {
    syntax: "<color> | none";
    initial-value: red;
  }
  @property --no-initial-color-value {
    syntax: "<color> | none";
    inherits: false;
  }
  @property --no-initial-universal-value {
    syntax: "*";
    inherits: false;
  }
  @property --syntax-only {
    syntax: "<color> | none";
  }
  @property --inherits-only {
    inherits: true;
  }
  @property --initial-value-only {
    initial-value: red;
  }
  /* U+0009 CHARACTER TABULATION */
  @property --tab\9 tab {
    syntax: "*";
    inherits: true;
  }
</style>
<script>

function find_at_property_rule(name) {
  for (let rule of document.styleSheets[0].cssRules) {
    if (rule.constructor.name != "CSSPropertyRule")
      continue;
    if (rule.name == name)
      return rule;
  }
  return null;
}

function test_invalid(name) {
  test(() => {
    let rule = find_at_property_rule(name);
    assert_true(!rule);
  }, `Rule for ${name} is invalid`);
}

function test_css_text(name, expected) {
  test(() => {
    let rule = find_at_property_rule(name);
    assert_true(!!rule);
    assert_equals(rule.cssText, expected);
  }, `Rule for ${name} has expected cssText`);
}

function test_name(name) {
  test(() => {
    let rule = find_at_property_rule(name);
    assert_true(!!rule);
    assert_equals(rule.name, name);
  }, `Rule for ${name} returns expected value for CSSPropertyRule.name`);
}

function test_syntax(name, expected) {
  test(() => {
    let rule = find_at_property_rule(name);
    assert_true(!!rule);
    assert_equals(rule.syntax, expected);
  }, `Rule for ${name} returns expected value for CSSPropertyRule.syntax`);
}

function test_inherits(name, expected) {
  test(() => {
    let rule = find_at_property_rule(name);
    assert_true(!!rule);
    assert_equals(rule.inherits, expected);
  }, `Rule for ${name} returns expected value for CSSPropertyRule.inherits`);
}

function test_initial_value(name, expected) {
  test(() => {
    let rule = find_at_property_rule(name);
    assert_true(!!rule);
    assert_equals(rule.initialValue, expected);
  }, `Rule for ${name} returns expected value for CSSPropertyRule.initialValue`);
}

// Invalid @property rules.
test_invalid('--no-descriptors');
test_invalid('--no-syntax');
test_invalid('--no-inherits');
test_invalid('--no-initial-color-value');
test_invalid('--syntax-only', '@property --syntax-only { syntax: "<color> | none"; }');
test_invalid('--inherits-only', '@property --inherits-only { inherits: true; }');
test_invalid('--initial-value-only', '@property --initial-value-only { initial-value: red; }');

// CSSPropertyRule.cssText

test_css_text('--valid', '@property --valid { syntax: "<color> | none"; inherits: false; initial-value: red; }');
test_css_text('--valid-reverse', '@property --valid-reverse { syntax: "<length>"; inherits: true; initial-value: 0px; }');
test_css_text('--valid-universal', '@property --valid-universal { syntax: "*"; inherits: false; }');
test_css_text('--valid-whitespace', '@property --valid-whitespace { syntax: " <color># "; inherits: false; initial-value: red, blue; }');
test_css_text('--vALId', '@property --vALId { syntax: "<color> | none"; inherits: false; initial-value: red; }');

test_css_text('--no-initial-universal-value', '@property --no-initial-universal-value { syntax: "*"; inherits: false; }');

test_css_text('--tab\ttab', '@property --tab\\9 tab { syntax: "*"; inherits: true; }');

// CSSRule.type

test(() => {
  let rule = find_at_property_rule('--valid');
  assert_equals(rule.type, 0);
}, 'CSSRule.type returns 0');

// CSSPropertyRule.name

test_name('--valid');
test_name('--valid-reverse');
test_name('--valid-universal');
test_name('--valid-whitespace');
test_name('--vALId');

test_name('--no-initial-universal-value');

// CSSPropertyRule.syntax

test_syntax('--valid', '<color> | none');
test_syntax('--valid-reverse', '<length>');
test_syntax('--valid-universal', '*');
test_syntax('--valid-whitespace', ' <color># ');
test_syntax('--vALId', '<color> | none');

test_syntax('--no-initial-universal-value', '*');

// CSSPropertyRule.inherits

test_inherits('--valid', false);
test_inherits('--valid-reverse', true);
test_inherits('--valid-universal', false);
test_inherits('--valid-whitespace', false);
test_inherits('--vALId', false);

test_inherits('--no-initial-universal-value', false);

// CSSPropertyRule.initialValue

test_initial_value('--valid', 'red');
test_initial_value('--valid-reverse', '0px');
test_initial_value('--valid-universal', null);
test_initial_value('--valid-whitespace', 'red, blue');
test_initial_value('--vALId', 'red');

test_initial_value('--no-initial-universal-value', null);

</script>