Commit f372e37d authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

[css-typed-om] Add tests for CSSKeywordValue constructor

Spec: https://drafts.css-houdini.org/css-typed-om-1/#keywordvalue-objects

There are no failing tests.

Bug: 774887
Change-Id: If78a3e490c406e8743eb591f1e9bdcb28f9fb3a5
Reviewed-on: https://chromium-review.googlesource.com/720582
Commit-Queue: Darren Shen <shend@chromium.org>
Reviewed-by: default avatarRenée Wright <rjwright@chromium.org>
Cr-Commit-Position: refs/heads/master@{#509711}
parent c8804494
...@@ -3,10 +3,6 @@ ...@@ -3,10 +3,6 @@
<script src='../resources/testharnessreport.js'></script> <script src='../resources/testharnessreport.js'></script>
<script> <script>
test(function() {
assert_throws(TypeError(), function() { new CSSKeywordValue("") });
}, "Constructor should throw an error if given an empty string");
test(function() { test(function() {
assert_equals(new CSSKeywordValue('initial').toString(), 'initial'); assert_equals(new CSSKeywordValue('initial').toString(), 'initial');
assert_equals(new CSSKeywordValue('center').toString(), 'center'); assert_equals(new CSSKeywordValue('center').toString(), 'center');
...@@ -16,14 +12,6 @@ test(function() { ...@@ -16,14 +12,6 @@ test(function() {
}, 'toString() returns a string with a format similar to CSS.escape. This test also ' + }, 'toString() returns a string with a format similar to CSS.escape. This test also ' +
'implies that toCSSValue supports all keywords including custom identifiers'); 'implies that toCSSValue supports all keywords including custom identifiers');
test(function() {
assert_equals(new CSSKeywordValue('initial').value, 'initial');
assert_equals(new CSSKeywordValue('center').value, 'center');
assert_equals(new CSSKeywordValue('customLemon').value, 'customLemon');
assert_equals(new CSSKeywordValue(' Hello World').value, ' Hello World');
assert_equals(new CSSKeywordValue('3').value, '3');
}, 'value returns a string equal to the string used in the constructor');
test(function() { test(function() {
let keywordValue = new CSSKeywordValue('foo'); let keywordValue = new CSSKeywordValue('foo');
assert_equals(keywordValue.value, 'foo'); assert_equals(keywordValue.value, 'foo');
......
<!doctype html>
<meta charset="utf-8">
<title>CSSKeywordValue constructor tests</title>
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#dom-csskeywordvalue-csskeywordvalue">
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script>
'use strict';
const gValidTestValues = [
{ value: 'initial', desc: 'a CSS keyword' },
{ value: 'customLemon', desc: 'an unsupported CSS keyword' },
{ value: '3! + 4@', desc: 'a string containing multiple tokens' },
{ value: '', desc: 'a unicode string' },
{ value: [3], desc: 'an object that serializes to a nonempty string' }
];
for (const {value, desc} of gValidTestValues) {
test(() => {
const result = new CSSKeywordValue(value);
assert_equals(result.value, value.toString());
}, 'CSSKeywordValue can be constructed from ' + desc);
}
const gInvalidTestValues = [
{ value: '', desc: 'an empty string' },
{ value: [], desc: 'an object that serializes to empty string' },
];
for (const {value, desc} of gInvalidTestValues) {
test(() => {
assert_throws(new TypeError(), () => new CSSKeywordValue(value));
}, 'Constructing CSSKeywordValue with ' + desc + ' throws a TypeError');
}
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment