Commit 85210a9b authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

[css-typed-om] Clean up CSSKeywordValue tests.

This patch:
- Creates separate test file for CSSKeywordValue.value.
- Make code style consistent.

Bug: 774887
Change-Id: I46322556d4f39fd33cffd91bfad82f5a001e48b5
Reviewed-on: https://chromium-review.googlesource.com/954563Reviewed-by: default avatarnainar <nainar@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543313}
parent 27c3af9c
......@@ -14,10 +14,4 @@ test(() => {
assert_throws(new TypeError(), () => new CSSKeywordValue(''));
}, 'Constructing CSSKeywordValue with an empty string throws a TypeError');
test(() => {
let result = new CSSKeywordValue('lemon');
assert_throws(new TypeError(), () => result.value = '');
assert_equals(result.value, 'lemon');
}, 'Updating CSSKeywordValue.value with an empty string throws a TypeError');
</script>
<!doctype html>
<meta charset="utf-8">
<title>CSSKeywordValue.value</title>
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#dom-csskeywordvalue-value">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<div id="log"></div>
<script>
'use strict';
const gTestArguments = [
{ keyword: 'initial', description: 'a CSS wide keyword' },
{ keyword: 'auto', description: 'a CSS keyword' },
{ keyword: 'lemon', description: 'an unsupported CSS keyword' },
{ keyword: '3! + 4@', description: 'a string containing multiple tokens' },
{ keyword: '', description: 'a unicode string' },
];
for (const args of gTestArguments) {
test(() => {
const result = new CSSKeywordValue(args.keyword);
assert_not_equals(result, null, 'a CSSKeywordValue is created');
assert_equals(result.value, args.keyword, 'value reflects new value');
}, `CSSKeywordValue.value can be updated to ${args.description}`);
}
test(() => {
let result = new CSSKeywordValue('lemon');
assert_throws(new TypeError(), () => result.value = '');
assert_equals(result.value, 'lemon', 'value does not change');
}, 'Updating CSSKeywordValue.value with an empty string throws a TypeError');
</script>
<!doctype html>
<meta charset="utf-8">
<title>CSSKeywordValue</title>
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#csskeywordvalue">
<meta name="assert" content="Test CSSKeywordValue constructor and attributes" />
<title>CSSKeywordValue Constructor</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>
<body>
<div id="log">
<div id="log"></div>
<script>
'use strict';
......@@ -18,23 +17,13 @@ const gTestArguments = [
{ keyword: '', description: 'a unicode string' },
];
for (const {keyword, description} of gTestArguments) {
for (const args of gTestArguments) {
test(() => {
const result = new CSSKeywordValue(keyword);
assert_not_equals(result, null,
'A CSSKeywordValue should be created');
assert_equals(result.value, keyword,
'Value attribute should be same as passed in the constructor');
}, 'CSSKeywordValue can be constructed from ' + description);
test(() => {
let result = new CSSKeywordValue('auto');
result.value = keyword;
assert_equals(result.value, keyword,
'Value attribute should be same as passed in the setter');
}, 'CSSKeywordValue.value can be updated to ' + description);
const result = new CSSKeywordValue(args.keyword);
assert_not_equals(result, null, 'a CSSKeywordValue is created');
assert_equals(result.value, args.keyword,
'value is same as given by constructor');
}, `CSSKeywordValue can be constructed from ${args.description}`);
}
</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