forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypedom.html
More file actions
993 lines (760 loc) · 42.2 KB
/
typedom.html
File metadata and controls
993 lines (760 loc) · 42.2 KB
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
<!DOCTYPE html>
<link rel="help" href="https://drafts.css-houdini.org/css-properties-values-api-1/#css-style-value-reification" />
<meta name="assert" content="Verifies that registered custom properties interact correctly with CSS Typed OM" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="./resources/utils.js"></script>
<style id=style>
div {}
</style>
<div id=target></div>
<script>
// Cleans style rules used for testing between every test.
add_result_callback(function(){
target.attributeStyleMap.clear();
// Clears 'div' rule in #style:
style.sheet.rules[0].styleMap.clear();
});
// In the following utility functions, the 'map' parameter (if present)
// can be any StylePropertyMap. (Not StylePropertyMapReadOnly).
// Verifies that get()/getAll() reifies the specified property to a
// CSSUnparsedValue, with a string serialization equal to 'value'.
function verify_map_get_unparsed(map, name, value) {
map.set(name, value);
let specifiedValue = map.get(name);
assert_true(specifiedValue instanceof CSSUnparsedValue);
assert_equals(specifiedValue.toString(), value);
let allSpecifiedValues = map.getAll(name);
assert_equals(allSpecifiedValues.length, 1);
assert_true(allSpecifiedValues[0] instanceof CSSUnparsedValue);
assert_equals(allSpecifiedValues[0].toString(), value);
}
// Verifies that the specified value is accepted by set().
function verify_map_set(map, name, value) {
map.set(name, value);
assert_equals(map.get(name).toString(), value.toString());
}
// Verifies that the specified value is NOT accepted by set().
function verify_map_not_set(map, name, value) {
assert_throws_js(TypeError, () => {
map.set(name, value);
});
}
// Verifies that the specified value is NOT accepted by append().
function verify_map_no_append(map, name, value) {
assert_throws_js(TypeError, () => {
map.append(name, value);
});
}
// Verifies that the property 'name' shows up on iteration, that it's reified
// as a CSSUnparsedValue, and that the string representation is equal to
// 'value'.
function verify_map_iteration_unparsed(map, name, value) {
map.set(name, value);
let result = Array.from(map).filter(e => e[0] == name)[0];
assert_equals(result.length, 2);
let iter_value = result[1];
assert_equals(iter_value.length, 1);
assert_true(iter_value[0] instanceof CSSUnparsedValue);
assert_equals(iter_value[0].toString(), value);
}
// Verifies that CSSStyleValue.parse/parseAll results in a CSSStyleValue with
// the 'expected' type.
function verify_parsed_type(prop, value, expected) {
let parse_value = CSSStyleValue.parse(prop, value);
let parse_all_value = CSSStyleValue.parseAll(prop, value);
assert_true(parse_value instanceof expected);
assert_true(parse_all_value.every(x => x instanceof expected))
}
// On the target element, verify that computed value of 'name' is an instance
// of 'expected' and not an instance of CSSUnparsedValue.
//
// If 'value' is non-null, that value is first set using the style attribute
// of the target element.
function verify_computed_type(name, value, expected) {
if (expected == CSSUnparsedValue) {
throw 'CSSUnparsedValue may not be used as expected type';
}
try {
if (value != null) {
target.style = `${name}: ${value}`;
}
let computedValue = target.computedStyleMap().get(name);
assert_false(computedValue instanceof CSSUnparsedValue);
assert_true(computedValue instanceof expected);
} finally {
if (value != null) {
target.style = '';
}
}
}
// Verifies that the property 'name' shows up on iteration, that it's reified
// to the specified type, and that the string representation is equal to 'value'.
function verify_computed_iteration_type(name, value, type) {
target.attributeStyleMap.set(name, value);
let result = Array.from(target.computedStyleMap()).filter(e => e[0] == name)[0];
assert_equals(result.length, 2);
let iter_value = result[1];
assert_equals(iter_value.length, 1);
assert_true(iter_value[0] instanceof type);
assert_equals(iter_value[0].toString(), value);
}
// Run the same test twice: once for each StylePropertyMap.
//
// https://drafts.css-houdini.org/css-typed-om-1/#stylepropertymap
function test_specified_maps(func, description) {
test(function(){
func(target.attributeStyleMap)
}, description + ' [attributeStyleMap]');
test(function(){
let rule = style.sheet.rules[0];
func(rule.styleMap)
}, description + ' [styleMap]');
}
// StylePropertyMapReadOnly.get
test(function(){
let name = generate_property('*', 'if(){}');
assert_true(target.computedStyleMap().get(name) instanceof CSSUnparsedValue);
target.attributeStyleMap.set(name, 'as{}df');
assert_true(target.computedStyleMap().get(name) instanceof CSSUnparsedValue);
target.attributeStyleMap.delete(name);
}, 'Computed * is reified as CSSUnparsedValue');
test(function(){
verify_computed_type(generate_property('<angle>'), null, CSSUnitValue);
verify_computed_type(generate_property('fail | <angle> '), '42deg', CSSUnitValue);
}, 'Computed <angle> is reified as CSSUnitValue');
test(function(){
verify_computed_type(generate_property('<color>'), null, CSSStyleValue);
verify_computed_type(generate_property('fail | <color> '), null, CSSStyleValue);
}, 'Computed <color> is reified as CSSStyleValue');
test(function(){
verify_computed_type(generate_property('<custom-ident>'), null, CSSKeywordValue);
verify_computed_type(generate_property('<custom-ident> | <length>'), 'none', CSSKeywordValue);
}, 'Computed <custom-ident> is reified as CSSKeywordValue');
test(function(){
verify_computed_type(generate_property('<image>'), null, CSSImageValue);
verify_computed_type(generate_property('fail | <image> '), 'url(thing.png)', CSSImageValue);
}, 'Computed <image> [url] is reified as CSSImageValue');
test(function(){
verify_computed_type(generate_property('<integer>'), null, CSSUnitValue);
verify_computed_type(generate_property('fail | <integer> '), '100', CSSUnitValue);
}, 'Computed <integer> is reified as CSSUnitValue');
test(function(){
verify_computed_type(generate_property('<length-percentage>'), null, CSSUnitValue);
verify_computed_type(generate_property('fail | <length-percentage> '), '10%', CSSUnitValue);
}, 'Computed <length-percentage> [%] is reified as CSSUnitValue');
test(function(){
verify_computed_type(generate_property('<length-percentage>'), null, CSSUnitValue);
verify_computed_type(generate_property('fail | <length-percentage> '), '10px', CSSUnitValue);
}, 'Computed <length-percentage> [px] is reified as CSSUnitValue');
test(function(){
verify_computed_type(generate_property({syntax: '<length-percentage>', initialValue: 'calc(10% + 10px)'}), null, CSSMathSum);
verify_computed_type(generate_property('fail | <length-percentage> '), 'calc(10px + 10%)', CSSMathSum);
}, 'Computed <length-percentage> [px + %] is reified as CSSMathSum');
test(function(){
verify_computed_type(generate_property('<length>'), null, CSSUnitValue);
verify_computed_type(generate_property('fail | <length> '), '10px', CSSUnitValue);
}, 'Computed <length> is reified as CSSUnitValue');
test(function(){
verify_computed_type(generate_property('<number>'), null, CSSUnitValue);
verify_computed_type(generate_property('fail | <number> '), '42', CSSUnitValue);
}, 'Computed <number> is reified as CSSUnitValue');
test(function(){
verify_computed_type(generate_property('<percentage>'), null, CSSUnitValue);
verify_computed_type(generate_property('fail | <percentage> '), '10%', CSSUnitValue);
}, 'Computed <percentage> is reified as CSSUnitValue');
test(function(){
verify_computed_type(generate_property('<resolution>'), null, CSSUnitValue);
verify_computed_type(generate_property('fail | <resolution> '), '300dpi', CSSUnitValue);
}, 'Computed <resolution> is reified as CSSUnitValue');
test(function(){
verify_computed_type(generate_property('<time>'), null, CSSUnitValue);
verify_computed_type(generate_property('fail | <time> '), '42s', CSSUnitValue);
}, 'Computed <time> is reified as CSSUnitValue');
test(function(){
verify_computed_type(generate_property('<url>'), null, CSSStyleValue);
verify_computed_type(generate_property('fail | <url> '), 'url(a)', CSSStyleValue);
}, 'Computed <url> is reified as CSSStyleValue');
test(function(){
verify_computed_type(generate_property('thing1 | THING2'), null, CSSKeywordValue);
verify_computed_type(generate_property('thing1 | THING2 | <url>'), 'THING2', CSSKeywordValue);
}, 'Computed ident is reified as CSSKeywordValue');
test(function(){
verify_computed_type(generate_property('<length>+'), null, CSSUnitValue);
verify_computed_type(generate_property('<length>+'), '10px 20px', CSSUnitValue);
}, 'First computed value correctly reified in space-separated list');
test(function(){
verify_computed_type(generate_property('<length>#'), null, CSSUnitValue);
verify_computed_type(generate_property('<length>#'), '10px, 20px', CSSUnitValue);
}, 'First computed value correctly reified in comma-separated list');
// StylePropertyMapReadOnly.getAll
test(function(){
let name = generate_property({syntax: '<length>+', initialValue: '10px 20px'});
assert_equals(target.computedStyleMap().getAll(name).length, 2);
assert_true(target.computedStyleMap().getAll(name).every(x => x instanceof CSSUnitValue));
target.style = `${name}: 10px 20px 30px`;
assert_equals(target.computedStyleMap().getAll(name).length, 3);
assert_true(target.computedStyleMap().getAll(name).every(x => x instanceof CSSUnitValue));
}, 'All computed values correctly reified in space-separated list');
test(function(){
let name = generate_property({syntax: '<length>#', initialValue: '10px, 20px'});
assert_equals(target.computedStyleMap().getAll(name).length, 2);
assert_true(target.computedStyleMap().getAll(name).every(x => x instanceof CSSUnitValue));
target.style = `${name}: 10px, 20px, 30px`;
assert_equals(target.computedStyleMap().getAll(name).length, 3);
assert_true(target.computedStyleMap().getAll(name).every(x => x instanceof CSSUnitValue));
}, 'All computed values correctly reified in comma-separated list');
// StylePropertyMap.get/All
test_specified_maps(function(map){
verify_map_get_unparsed(map, generate_property('*'), 'foo');
}, 'Specified * is reified as CSSUnparsedValue from get/getAll');
test_specified_maps(function(map){
verify_map_get_unparsed(map, generate_property('foo'), 'foo');
}, 'Specified foo is reified as CSSUnparsedValue from get/getAll');
test_specified_maps(function(map){
verify_map_get_unparsed(map, generate_property('<angle>'), '10deg');
}, 'Specified <angle> is reified as CSSUnparsedValue from get/getAll');
test_specified_maps(function(map){
verify_map_get_unparsed(map, generate_property('<color>'), 'green');
}, 'Specified <color> is reified as CSSUnparsedValue from get/getAll');
test_specified_maps(function(map){
verify_map_get_unparsed(map, generate_property('<custom-ident>'), 'foo');
}, 'Specified <custom-ident> is reified as CSSUnparsedValue from get/getAll');
test_specified_maps(function(map){
verify_map_get_unparsed(map, generate_property('<image>'), 'url("a")');
}, 'Specified <image> is reified as CSSUnparsedValue from get/getAll');
test_specified_maps(function(map){
verify_map_get_unparsed(map, generate_property('<integer>'), '1');
}, 'Specified <integer> is reified as CSSUnparsedValue from get/getAll');
test_specified_maps(function(map){
verify_map_get_unparsed(map, generate_property('<length-percentage>'), 'calc(10% + 10px)');
}, 'Specified <length-percentage> is reified as CSSUnparsedValue from get/getAll');
test_specified_maps(function(map){
verify_map_get_unparsed(map, generate_property('<length>'), '10px');
}, 'Specified <length> is reified as CSSUnparsedValue from get/getAll');
test_specified_maps(function(map){
verify_map_get_unparsed(map, generate_property('<number>'), '1');
}, 'Specified <number> is reified as CSSUnparsedValue from get/getAll');
test_specified_maps(function(map){
verify_map_get_unparsed(map, generate_property('<percentage>'), '10%');
}, 'Specified <percentage> is reified as CSSUnparsedValue from get/getAll');
test_specified_maps(function(map){
verify_map_get_unparsed(map, generate_property('<resolution>'), '10dpi');
}, 'Specified <resolution> is reified as CSSUnparsedValue from get/getAll');
test_specified_maps(function(map){
verify_map_get_unparsed(map, generate_property('<time>'), '1s');
}, 'Specified <time> is reified as CSSUnparsedValue from get/getAll');
test_specified_maps(function(map){
verify_map_get_unparsed(map, generate_property('<transform-function>'), 'matrix(0, 0, 0, 0, 0, 0)');
}, 'Specified <transform-function> is reified as CSSUnparsedValue from get/getAll');
test_specified_maps(function(map){
verify_map_get_unparsed(map, generate_property('<transform-list>'), 'matrix(0, 0, 0, 0, 0, 0)');
}, 'Specified <transform-list> is reified as CSSUnparsedValue from get/getAll');
test_specified_maps(function(map){
verify_map_get_unparsed(map, generate_property('<url>'), 'url("a")');
}, 'Specified <url> is reified as CSSUnparsedValue from get/getAll');
test_specified_maps(function(map){
verify_map_get_unparsed(map, generate_property('<length>+'), '10px 11px');
}, 'Specified <length>+ is reified as CSSUnparsedValue from get/getAll');
test_specified_maps(function(map){
verify_map_get_unparsed(map, generate_property('<length>#'), '10px, 11px');
}, 'Specified <length># is reified as CSSUnparsedValue from get/getAll');
// StylePropertyMap.set
// The following strings are valid for the specified syntax, and should be
// accepted by set().
test_specified_maps(function(map){
verify_map_set(map, generate_property('*'), 'foo');
}, 'Specified string "foo" accepted by set() for syntax *');
test_specified_maps(function(map){
verify_map_set(map, generate_property('foo'), 'foo');
}, 'Specified string "foo" accepted by set() for syntax foo');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<angle>'), '10deg');
}, 'Specified string "10deg" accepted by set() for syntax <angle>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<color>'), 'green');
}, 'Specified string "green" accepted by set() for syntax <color>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<custom-ident>'), 'foo');
}, 'Specified string "foo" accepted by set() for syntax <custom-ident>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<image>'), 'url("a")');
}, 'Specified string "url("a")" accepted by set() for syntax <image>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<integer>'), '1');
}, 'Specified string "1" accepted by set() for syntax <integer>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<length-percentage>'), 'calc(10% + 10px)');
}, 'Specified string "calc(10% + 10px)" accepted by set() for syntax <length-percentage>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<length>'), '10px');
}, 'Specified string "10px" accepted by set() for syntax <length>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<number>'), '1');
}, 'Specified string "1" accepted by set() for syntax <number>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<percentage>'), '10%');
}, 'Specified string "10%" accepted by set() for syntax <percentage>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<resolution>'), '10dpi');
}, 'Specified string "10dpi" accepted by set() for syntax <resolution>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<time>'), '1s');
}, 'Specified string "1s" accepted by set() for syntax <time>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<transform-function>'), 'matrix(0, 0, 0, 0, 0, 0)');
}, 'Specified string "matrix(0, 0, 0, 0, 0, 0)" accepted by set() for syntax <transform-function>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<transform-list>'), 'matrix(0, 0, 0, 0, 0, 0)');
}, 'Specified string "matrix(0, 0, 0, 0, 0, 0)" accepted by set() for syntax <transform-list>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<url>'), 'url("a")');
}, 'Specified string "url("a")" accepted by set() for syntax <url>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<length>+'), '10px 11px');
}, 'Specified string "10px 11px" accepted by set() for syntax <length>+');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<length>#'), '10px, 11px');
}, 'Specified string "10px, 11px" accepted by set() for syntax <length>#');
// The following strings are invalid for the specified syntax, but should
// should be accepted by set().
test_specified_maps(function(map){
verify_map_set(map, generate_property('foo'), 'bar');
}, 'Specified string "bar" accepted by set() for syntax foo');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<angle>'), '10px');
}, 'Specified string "10px" accepted by set() for syntax <angle>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<color>'), '10px');
}, 'Specified string "10px" accepted by set() for syntax <color>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<custom-ident>'), '10px');
}, 'Specified string "10px" accepted by set() for syntax <custom-ident>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<image>'), 'a');
}, 'Specified string "a" accepted by set() for syntax <image>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<integer>'), 'float');
}, 'Specified string "float" accepted by set() for syntax <integer>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<length-percentage>'), 'red');
}, 'Specified string "red" accepted by set() for syntax <length-percentage>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<length>'), 'red');
}, 'Specified string "red" accepted by set() for syntax <length>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<number>'), 'red');
}, 'Specified string "red" accepted by set() for syntax <number>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<percentage>'), 'var(--x)');
}, 'Specified string "var(--x)" accepted by set() for syntax <percentage>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<resolution>'), 'blue');
}, 'Specified string "blue" accepted by set() for syntax <resolution>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<time>'), '1meter');
}, 'Specified string "1meter" accepted by set() for syntax <time>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<transform-function>'), 'foo(0)');
}, 'Specified string "foo(0)" accepted by set() for syntax <transform-function>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<transform-list>'), 'bar(1)');
}, 'Specified string "bar(1)" accepted by set() for syntax <transform-list>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<url>'), 'a');
}, 'Specified string "a" accepted by set() for syntax <url>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<length>+'), 'a b');
}, 'Specified string "a b" accepted by set() for syntax <length>+');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<length>#'), 'a, b');
}, 'Specified string "a, b" accepted by set() for syntax <length>#');
// CSSUnparsedValue should always be accepted by any custom property,
// regardless of registation status.
const unparsed = CSSStyleValue.parse('--x', 'foo bar thing');
test_specified_maps(function(map){
verify_map_set(map, generate_property('*'), unparsed);
}, 'CSSUnparsedValue is accepted via set() for syntax *');
test_specified_maps(function(map){
verify_map_set(map, generate_property('foo'), unparsed);
}, 'CSSUnparsedValue is accepted via set() for syntax foo');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<angle>'), unparsed);
}, 'CSSUnparsedValue is accepted via set() for syntax <angle>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<color>'), unparsed);
}, 'CSSUnparsedValue is accepted via set() for syntax <color>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<custom-ident>'), unparsed);
}, 'CSSUnparsedValue is accepted via set() for syntax <custom-ident>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<image>'), unparsed);
}, 'CSSUnparsedValue is accepted via set() for syntax <image>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<integer>'), unparsed);
}, 'CSSUnparsedValue is accepted via set() for syntax <integer>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<length-percentage>'), unparsed);
}, 'CSSUnparsedValue is accepted via set() for syntax <length-percentage>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<length>'), unparsed);
}, 'CSSUnparsedValue is accepted via set() for syntax <length>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<number>'), unparsed);
}, 'CSSUnparsedValue is accepted via set() for syntax <number>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<percentage>'), unparsed);
}, 'CSSUnparsedValue is accepted via set() for syntax <percentage>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<resolution>'), unparsed);
}, 'CSSUnparsedValue is accepted via set() for syntax <resolution>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<time>'), unparsed);
}, 'CSSUnparsedValue is accepted via set() for syntax <time>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<transform-function>'), unparsed);
}, 'CSSUnparsedValue is accepted via set() for syntax <transform-function>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<transform-list>'), unparsed);
}, 'CSSUnparsedValue is accepted via set() for syntax <transform-list>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<url>'), unparsed);
}, 'CSSUnparsedValue is accepted via set() for syntax <url>');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<length>+'), unparsed);
}, 'CSSUnparsedValue is accepted via set() for syntax <length>+');
test_specified_maps(function(map){
verify_map_set(map, generate_property('<length>#'), unparsed);
}, 'CSSUnparsedValue is accepted via set() for syntax <length>#');
// CSSStyleValues which aren't CSSUnparsedValues aren't accepted by set(),
// even if they're a value which is compatible with the syntax.
//
// https://drafts.css-houdini.org/css-properties-values-api-1/#cssom
const zero_matrix = CSSStyleValue.parse('transform', 'matrix(0, 0, 0, 0, 0, 0)');
const image_value = CSSStyleValue.parse('background-image', 'url(a)');
test_specified_maps(function(map){
verify_map_not_set(map, generate_property('*'), new CSSKeywordValue('foo'));
}, 'CSSKeywordValue rejected by set() for syntax *');
test_specified_maps(function(map){
verify_map_not_set(map, generate_property('foo'), new CSSKeywordValue('foo'));
}, 'CSSKeywordValue rejected by set() for syntax foo');
test_specified_maps(function(map){
verify_map_not_set(map, generate_property('<angle>'), CSS.deg(10));
}, 'CSSUnitValue rejected by set() for syntax <angle>');
test_specified_maps(function(map){
verify_map_not_set(map, generate_property('<custom-ident>'), new CSSKeywordValue('foo'));
}, 'CSSKeywordValue rejected by set() for syntax <custom-ident>');
test_specified_maps(function(map){
verify_map_not_set(map, generate_property('<image>'), image_value);
}, 'CSSImageValue rejected by set() for syntax <image>');
test_specified_maps(function(map){
verify_map_not_set(map, generate_property('<integer>'), CSS.number(1));
}, 'CSSUnitValue rejected by set() for syntax <integer>');
test_specified_maps(function(map){
verify_map_not_set(map, generate_property('<length-percentage>'), CSS.px(10));
}, 'CSSUnitValue rejected by set() for syntax <length-percentage>');
test_specified_maps(function(map){
verify_map_not_set(map, generate_property('<length>'), CSS.px(10));
}, 'CSSUnitValue rejected by set() for syntax <length>');
test_specified_maps(function(map){
verify_map_not_set(map, generate_property('<number>'), CSS.number(10));
}, 'CSSUnitValue rejected by set() for syntax <number>');
test_specified_maps(function(map){
verify_map_not_set(map, generate_property('<percentage>'), CSS.percent(10));
}, 'CSSUnitValue rejected by set() for syntax <percentage>');
test_specified_maps(function(map){
verify_map_not_set(map, generate_property('<resolution>'), CSS.dpi(10));
}, 'CSSUnitValue rejected by set() for syntax <resolution>');
test_specified_maps(function(map){
verify_map_not_set(map, generate_property('<time>'), CSS.s(10));
}, 'CSSUnitValue rejected by set() for syntax <time>');
test_specified_maps(function(map){
verify_map_not_set(map, generate_property('<transform-list>'), zero_matrix);
}, 'CSSTransformValue rejected by set() for syntax <transform-list>');
test_specified_maps(function(map){
verify_map_not_set(map, generate_property('<length>+'), CSS.px(10), CSS.px(10));
}, 'CSSUnitValue rejected by set() for syntax <length>+');
test_specified_maps(function(map){
verify_map_not_set(map, generate_property('<length>#'), CSS.px(10), CSS.px(10));
}, 'CSSUnitValue rejected by set() for syntax <length>#');
// <color> has no CSSStyleValue subclass yet.
// <url> has no CSSStyleValue subclass yet.
// <transform-function> has no CSSStyleValue subclass yet.
// StylePropertyMap.append
// It is not allowed to append CSSStyleValues to custom properties, even
// when the string matches the syntax of the custom property.
test_specified_maps(function(map){
verify_map_no_append(map, generate_property('*'), 'a');
}, 'Appending a string to * is not allowed');
test_specified_maps(function(map){
verify_map_no_append(map, generate_property('foo+'), 'foo');
}, 'Appending a string to foo+ is not allowed');
test_specified_maps(function(map){
verify_map_no_append(map, generate_property('<angle>+'), '10deg');
}, 'Appending a string to <angle>+ is not allowed');
test_specified_maps(function(map){
verify_map_no_append(map, generate_property('<color>+'), 'red');
}, 'Appending a string to <color>+ is not allowed');
test_specified_maps(function(map){
verify_map_no_append(map, generate_property('<custom-ident>+'), 'foo');
}, 'Appending a string to <custom-ident>+ is not allowed');
test_specified_maps(function(map){
verify_map_no_append(map, generate_property('<image>+'), 'url(a)');
}, 'Appending a string to <image>+ is not allowed');
test_specified_maps(function(map){
verify_map_no_append(map, generate_property('<integer>+'), 'a');
}, 'Appending a string to <integer>+ is not allowed');
test_specified_maps(function(map){
verify_map_no_append(map, generate_property('<length-percentage>+'), 'calc(10*% + 10px)');
}, 'Appending a string to <length-percentage>+ is not allowed');
test_specified_maps(function(map){
verify_map_no_append(map, generate_property('<length>+'), '10px');
}, 'Appending a string to <length>+ is not allowed');
test_specified_maps(function(map){
verify_map_no_append(map, generate_property('<number>+'), '1.3');
}, 'Appending a string to <number>+ is not allowed');
test_specified_maps(function(map){
verify_map_no_append(map, generate_property('<percentage>+'), '10%');
}, 'Appending a string to <percentage>+ is not allowed');
test_specified_maps(function(map){
verify_map_no_append(map, generate_property('<resolution>+'), '10dpi');
}, 'Appending a string to <resolution>+ is not allowed');
test_specified_maps(function(map){
verify_map_no_append(map, generate_property('<time>+'), '1s');
}, 'Appending a string to <time>+ is not allowed');
test_specified_maps(function(map){
verify_map_no_append(map, generate_property('<transform-function>+'), 'matrix(0, 0, 0, 0, 0, 0)');
}, 'Appending a string to <transform-function>+ is not allowed');
test_specified_maps(function(map){
verify_map_no_append(map, generate_property('<transform-list>'), 'matrix(0, 0, 0, 0, 0, 0)');
}, 'Appending a string to <transform-list> is not allowed');
test_specified_maps(function(map){
verify_map_no_append(map, generate_property('<url>+'), 'url(a)');
}, 'Appending a string to <url>+ is not allowed');
test_specified_maps(function(map){
verify_map_no_append(map, generate_property('<length>#'), '10px');
}, 'Appending a string to <length># is not allowed');
// It is not allowed to append CSSStyleValues to custom properties, even
// when the CSSStyleValue matches the syntax of the custom property.
test_specified_maps(function(map) {
verify_map_no_append(map, generate_property('*'), new CSSKeywordValue('foo'));
}, 'Appending a CSSKeywordValue to * is not allowed');
test_specified_maps(function(map) {
verify_map_no_append(map, generate_property('foo+'), new CSSKeywordValue('foo'));
}, 'Appending a CSSKeywordValue to foo+ is not allowed');
test_specified_maps(function(map) {
verify_map_no_append(map, generate_property('<angle>+'), CSS.deg(10));
}, 'Appending a CSSUnitValue to <angle>+ is not allowed');
test_specified_maps(function(map) {
verify_map_no_append(map, generate_property('<custom-ident>+'), new CSSKeywordValue('foo'));
}, 'Appending a CSSKeywordValue to <custom-ident>+ is not allowed');
test_specified_maps(function(map) {
verify_map_no_append(map, generate_property('<image>+'), image_value);
}, 'Appending a CSSImageValue to <image>+ is not allowed');
test_specified_maps(function(map) {
verify_map_no_append(map, generate_property('<integer>+'), CSS.number(1));
}, 'Appending a CSSUnitValue to <integer>+ is not allowed');
test_specified_maps(function(map) {
verify_map_no_append(map, generate_property('<length-percentage>+'), CSS.px(10));
}, 'Appending a CSSUnitValue to <length-percentage>+ is not allowed');
test_specified_maps(function(map) {
verify_map_no_append(map, generate_property('<length>+'), CSS.px(10));
}, 'Appending a CSSUnitValue to <length>+ is not allowed');
test_specified_maps(function(map) {
verify_map_no_append(map, generate_property('<number>+'), CSS.number(10));
}, 'Appending a CSSUnitValue to <number>+ is not allowed');
test_specified_maps(function(map) {
verify_map_no_append(map, generate_property('<percentage>+'), CSS.percent(10));
}, 'Appending a CSSUnitValue to <percentage>+ is not allowed');
test_specified_maps(function(map) {
verify_map_no_append(map, generate_property('<resolution>+'), CSS.dpi(10));
}, 'Appending a CSSUnitValue to <resolution>+ is not allowed');
test_specified_maps(function(map) {
verify_map_no_append(map, generate_property('<time>+'), CSS.s(10));
}, 'Appending a CSSUnitValue to <time>+ is not allowed');
test_specified_maps(function(map) {
verify_map_no_append(map, generate_property('<transform-list>'), zero_matrix);
}, 'Appending a CSSKeywordValue to <transform-list> is not allowed');
test_specified_maps(function(map) {
verify_map_no_append(map, generate_property('<length>#'), CSS.px(10));
}, 'Appending a CSSUnitValue to <length># is not allowed');
// <color> has no CSSStyleValue subclass yet.
// <url> has no CSSStyleValue subclass yet.
// <transform-function> has no CSSStyleValue subclass yet.
// CSSStyleValue.parse/parseAll
test(function(){
verify_parsed_type(generate_property('*'), 'while(){}', CSSUnparsedValue);
}, 'CSSStyleValue.parse[All] returns CSSUnparsedValue for syntax *', CSSUnparsedValue);
test(function(){
verify_parsed_type(generate_property('<angle>'), '42deg', CSSUnparsedValue);
}, 'CSSStyleValue.parse[All] returns CSSUnparsedValue for syntax <angle>');
test(function(){
verify_parsed_type(generate_property('<color>'), '#fefefe', CSSUnparsedValue);
}, 'CSSStyleValue.parse[All] returns CSSUnparsedValue for syntax <color>');
test(function(){
verify_parsed_type(generate_property('<custom-ident> | <length>'), 'none', CSSUnparsedValue);
}, 'CSSStyleValue.parse[All] returns CSSUnparsedValue for syntax <custom-ident> | <length>');
test(function(){
verify_parsed_type(generate_property('<image>'), 'url(thing.png)', CSSUnparsedValue);
}, 'CSSStyleValue.parse[All] returns CSSUnparsedValue for syntax <image>');
test(function(){
verify_parsed_type(generate_property('<integer>'), '100', CSSUnparsedValue);
}, 'CSSStyleValue.parse[All] returns CSSUnparsedValue for syntax <integer>');
test(function(){
verify_parsed_type(generate_property('<length-percentage>'), '10%', CSSUnparsedValue);
}, 'CSSStyleValue.parse[All] returns CSSUnparsedValue for syntax <length-percentage> (10%)');
test(function(){
verify_parsed_type(generate_property('<length-percentage>'), '10px', CSSUnparsedValue);
}, 'CSSStyleValue.parse[All] returns CSSUnparsedValue for syntax <length-percentage> (10px)');
test(function(){
verify_parsed_type(generate_property('<length-percentage>'), 'calc(10px + 10%)', CSSUnparsedValue);
}, 'CSSStyleValue.parse[All] returns CSSUnparsedValue for syntax <length-percentage> (calc(10px + 10%))');
test(function(){
verify_parsed_type(generate_property('<length>'), '10px', CSSUnparsedValue);
}, 'CSSStyleValue.parse[All] returns CSSUnparsedValue for syntax <length>');
test(function(){
verify_parsed_type(generate_property('<number>'), '42', CSSUnparsedValue);
}, 'CSSStyleValue.parse[All] returns CSSUnparsedValue for syntax <number>');
test(function(){
verify_parsed_type(generate_property('<percentage>'), '10%', CSSUnparsedValue);
}, 'CSSStyleValue.parse[All] returns CSSUnparsedValue for syntax <percentage>');
test(function(){
verify_parsed_type(generate_property('<resolution>'), '300dpi', CSSUnparsedValue);
}, 'CSSStyleValue.parse[All] returns CSSUnparsedValue for syntax <resolution>');
test(function(){
verify_parsed_type(generate_property('<time>'), '42s', CSSUnparsedValue);
}, 'CSSStyleValue.parse[All] returns CSSUnparsedValue for syntax <time>');
test(function(){
verify_parsed_type(generate_property('<transform-function>'), 'matrix(0, 0, 0, 0, 0, 0)', CSSUnparsedValue);
}, 'CSSStyleValue.parse[All] returns CSSUnparsedValue for syntax <transform-function>');
test(function(){
verify_parsed_type(generate_property('<transform-list>'), 'matrix(0, 0, 0, 0, 0, 0)', CSSUnparsedValue);
}, 'CSSStyleValue.parse[All] returns CSSUnparsedValue for syntax <transform-list>');
test(function(){
verify_parsed_type(generate_property('<url>'), 'url(a)', CSSUnparsedValue);
}, 'CSSStyleValue.parse[All] returns CSSUnparsedValue for syntax <url>');
test(function(){
verify_parsed_type(generate_property('thing1 | THING2 | <url>'), 'THING2', CSSUnparsedValue);
}, 'CSSStyleValue.parse[All] returns CSSUnparsedValue for syntax thing1 | THING2 | <url>');
test(function(){
verify_parsed_type(generate_property('<length>+'), '10px 20px', CSSUnparsedValue);
}, 'CSSStyleValue.parse[All] returns CSSUnparsedValue for syntax <length>+');
test(function(){
verify_parsed_type(generate_property('<length>#'), '10px, 20px', CSSUnparsedValue);
}, 'CSSStyleValue.parse[All] returns CSSUnparsedValue for syntax <length>#');
// Direct CSSStyleValue objects:
test_specified_maps(function(map){
for (let syntax of all_syntaxes()) {
let name = generate_property(syntax);
let initialValue = target.computedStyleMap().get(name);
// We only care about direct CSSStyleValue instances in this test.
// Ultimately, in some future version of CSS TypedOM, we may have no
// direct CSSStyleValue instances at all, which is fine.
if (initialValue.constructor !== CSSStyleValue) {
continue;
}
// Verify that direct CSSStyleValues are rejected by set(). Two things
// should prevent this: 1) direct CSSStyleValues are not
// CSSUnparsedValues, and 2) direct CSSStyleValues are only valid for
// the property they were reified from.
verify_map_not_set(map, generate_property(syntax), initialValue);
}
}, 'Direct CSSStyleValue may not be set');
// StylePropertyMap iteration
test_specified_maps(function(map){
verify_map_iteration_unparsed(map, generate_property('*'), 'foo');
}, 'Specified * is reified CSSUnparsedValue by iterator');
test_specified_maps(function(map){
verify_map_iteration_unparsed(map, generate_property('foo'), 'foo');
}, 'Specified foo is reified CSSUnparsedValue by iterator');
test_specified_maps(function(map){
verify_map_iteration_unparsed(map, generate_property('<angle>'), '10deg');
}, 'Specified <angle> is reified CSSUnparsedValue by iterator');
test_specified_maps(function(map){
verify_map_iteration_unparsed(map, generate_property('<color>'), 'green');
}, 'Specified <color> is reified CSSUnparsedValue by iterator');
test_specified_maps(function(map){
verify_map_iteration_unparsed(map, generate_property('<custom-ident>'), 'foo');
}, 'Specified <custom-ident> is reified CSSUnparsedValue by iterator');
test_specified_maps(function(map){
verify_map_iteration_unparsed(map, generate_property('<image>'), 'url("a")');
}, 'Specified <image> is reified CSSUnparsedValue by iterator');
test_specified_maps(function(map){
verify_map_iteration_unparsed(map, generate_property('<integer>'), '1');
}, 'Specified <integer> is reified CSSUnparsedValue by iterator');
test_specified_maps(function(map){
verify_map_iteration_unparsed(map, generate_property('<length-percentage>'), 'calc(10% + 10px)');
}, 'Specified <length-percentage> is reified CSSUnparsedValue by iterator');
test_specified_maps(function(map){
verify_map_iteration_unparsed(map, generate_property('<length>'), '10px');
}, 'Specified <length> is reified CSSUnparsedValue by iterator');
test_specified_maps(function(map){
verify_map_iteration_unparsed(map, generate_property('<number>'), '1');
}, 'Specified <number> is reified CSSUnparsedValue by iterator');
test_specified_maps(function(map){
verify_map_iteration_unparsed(map, generate_property('<percentage>'), '10%');
}, 'Specified <percentage> is reified CSSUnparsedValue by iterator');
test_specified_maps(function(map){
verify_map_iteration_unparsed(map, generate_property('<resolution>'), '10dpi');
}, 'Specified <resolution> is reified CSSUnparsedValue by iterator');
test_specified_maps(function(map){
verify_map_iteration_unparsed(map, generate_property('<time>'), '1s');
}, 'Specified <time> is reified CSSUnparsedValue by iterator');
test_specified_maps(function(map){
verify_map_iteration_unparsed(map, generate_property('<transform-function>'), 'matrix(0, 0, 0, 0, 0, 0)');
}, 'Specified <transform-function> is reified CSSUnparsedValue by iterator');
test_specified_maps(function(map){
verify_map_iteration_unparsed(map, generate_property('<transform-list>'), 'matrix(0, 0, 0, 0, 0, 0)');
}, 'Specified <transform-list> is reified CSSUnparsedValue by iterator');
test_specified_maps(function(map){
verify_map_iteration_unparsed(map, generate_property('<url>'), 'url("a")');
}, 'Specified <url> is reified CSSUnparsedValue by iterator');
test_specified_maps(function(map){
verify_map_iteration_unparsed(map, generate_property('<length>+'), '10px 11px');
}, 'Specified <length>+ is reified CSSUnparsedValue by iterator');
test_specified_maps(function(map){
verify_map_iteration_unparsed(map, generate_property('<length>#'), '10px, 11px');
}, 'Specified <length># is reified CSSUnparsedValue by iterator');
// StylePropertyMapReadOnly iteration
test(function(){
let name = generate_property({syntax: '<length>', initialValue: '10px'});
let result = Array.from(target.computedStyleMap()).filter(e => e[0] == name)[0];
assert_true(typeof(result) !== 'undefined');
}, 'Registered property with initial value show up on iteration of computedStyleMap');
test(function(){
verify_computed_iteration_type(generate_property('*'), 'thing', CSSUnparsedValue);
}, 'Computed * is reified as CSSUnparsedValue by iterator');
test(function(){
verify_computed_iteration_type(generate_property('<angle>'), '42deg', CSSUnitValue);
}, 'Computed <angle> is reified as CSSUnitValue by iterator');
test(function(){
verify_computed_iteration_type(generate_property('<custom-ident>'), 'thing', CSSKeywordValue);
}, 'Computed <custom-ident> is reified as CSSKeywordValue by iterator');
test(function(){
verify_computed_iteration_type(generate_property('<image>'), 'url(\"a\")', CSSImageValue);
}, 'Computed <image> is reified as CSSImageValue by iterator');
test(function(){
verify_computed_iteration_type(generate_property('<integer>'), '100', CSSUnitValue);
}, 'Computed <integer> is reified as CSSUnitValue by iterator');
test(function(){
verify_computed_iteration_type(generate_property('<length>'), '10px', CSSUnitValue);
}, 'Computed <length> is reified as CSSUnitValue by iterator');
test(function(){
verify_computed_iteration_type(generate_property('<number>'), '42', CSSUnitValue);
}, 'Computed <number> is reified as CSSUnitValue by iterator');
test(function(){
verify_computed_iteration_type(generate_property('<percentage>'), '10%', CSSUnitValue);
}, 'Computed <percentage> is reified as CSSUnitValue by iterator');
test(function(){
verify_computed_iteration_type(generate_property('<resolution>'), '300dppx', CSSUnitValue);
}, 'Computed <resolution> is reified as CSSUnitValue by iterator');
test(function(){
verify_computed_iteration_type(generate_property('<time>'), '10s', CSSUnitValue);
}, 'Computed <time> is reified as CSSUnitValue by iterator');
test(function(){
verify_computed_iteration_type(generate_property('none | thing | THING'), 'THING', CSSKeywordValue);
}, 'Computed none | thing | THING is reified as CSSKeywordValue by iterator');
test(function(){
verify_computed_iteration_type(generate_property('<angle> | <length>'), '10px', CSSUnitValue);
}, 'Computed <angle> | <length> is reified as CSSUnitValue by iterator');
</script>