[css-typed-om] Allow mutations of CSSUnparsedValue.
This patch allows CSSUnparsedValue items to be mutated/appended.
See https://github.com/w3c/css-houdini-drafts/issues/664
Bug: 812919
Change-Id: I3e3c1d91fa9bfaa3a1a4adde45202c36c9bdb37f
Reviewed-on: https://chromium-review.googlesource.com/923670
Reviewed-by: nainar <nainar@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537691}
diff --git a/css/css-typed-om/stylevalue-subclasses/cssUnparsedValue.html b/css/css-typed-om/stylevalue-subclasses/cssUnparsedValue.html
index 8af27e1..f337032 100644
--- a/css/css-typed-om/stylevalue-subclasses/cssUnparsedValue.html
+++ b/css/css-typed-om/stylevalue-subclasses/cssUnparsedValue.html
@@ -5,6 +5,7 @@
<meta name="assert" content="Test CSSUnparsedValue constructor and members">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
+<script src="../resources/testhelper.js"></script>
<body>
<div id="log">
<script>
@@ -47,4 +48,44 @@
}, 'CSSUnparsedValue can be constructed from ' + description);
}
+test(() => {
+ let result = new CSSUnparsedValue([new CSSVariableReferenceValue('--foo')]);
+
+ result[0] = 'A';
+ assert_equals(result[0], 'A', 'Item should be updated to new value');
+}, 'Can update item in CSSUnparsedValue to a string');
+
+test(() => {
+ let result = new CSSUnparsedValue(['foo']);
+
+ result[0] = new CSSVariableReferenceValue('--A');
+ assert_style_value_equals(result[0], new CSSVariableReferenceValue('--A'),
+ 'Item should be updated to new value');
+}, 'Can update item in CSSUnparsedValue to a variable reference');
+
+test(() => {
+ let result = new CSSUnparsedValue([]);
+
+ result[0] = new CSSVariableReferenceValue('--A');
+ assert_equals(result.length, 1,
+ 'Length of CSSUnparsedValue should have increased');
+ assert_style_value_equals(result[0], new CSSVariableReferenceValue('--A'),
+ 'New item should be appended');
+
+ result[1] = 'foo';
+ assert_equals(result.length, 2,
+ 'Length of CSSUnparsedValue should have increased');
+ assert_equals(result[1], 'foo', 'New item should be appended');
+}, 'Can append items to CSSUnparsedValue');
+
+test(() => {
+ const result = new CSSUnparsedValue(['foo', 'bar']);
+ assert_equals(result[3], undefined);
+}, 'Getting invalid index in CSSUnparsedValue returns undefined');
+
+test(() => {
+ let result = new CSSUnparsedValue(['foo', 'bar']);
+ assert_throws(new RangeError(), () => result[3] = 'foo');
+}, 'Setting invalid index in CSSUnparsedValue throws RangeError');
+
</script>