Commit 8e8c88b3 authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

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

This patch:
- Adds mutation tests for CSSUnitValue.value.
- Clean up code style.

Bug: 774887
Change-Id: I5a6398c4a4a2ad86f60165780ee8d48bb3d8b0a1
Reviewed-on: https://chromium-review.googlesource.com/954642
Commit-Queue: Darren Shen <shend@chromium.org>
Reviewed-by: default avatarnainar <nainar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543959}
parent 29b26a4b
This is a testharness.js-based test. This is a testharness.js-based test.
PASS Constructing CSSUnitValue with an empty string as the unit throws a TypeError PASS Constructing CSSUnitValue with an unknown unit throws a TypeError
PASS Constructing CSSUnitValue with an invalid unit as the unit throws a TypeError PASS Constructing CSSUnitValue with a empty string unit throws a TypeError
PASS CSSUnitValue can be constructed with number PASS CSSUnitValue can be constructed with number
PASS CSSUnitValue can be constructed with percent PASS CSSUnitValue can be constructed with percent
PASS CSSUnitValue can be constructed with em PASS CSSUnitValue can be constructed with em
......
<!doctype html>
<meta charset="utf-8">
<title>CSSUnitValue.value</title>
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#cssunitvalue">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<div id="log"></div>
<script>
'use strict';
test(() => {
const result = new CSSUnitValue(-3.14, 'px');
result.value = 3.14;
assert_equals(result.value, 3.14, 'value reflects new value');
assert_equals(result.unit, 'px', 'unit does not change');
}, 'CSSUnitValue.value can be updated to a different value');
</script>
<!doctype html> <!doctype html>
<meta charset="utf-8"> <meta charset="utf-8">
<title>CSSUnitValue tests</title> <title>CSSUnitValue Constructor</title>
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#simple-numeric"> <link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#dom-cssunitvalue-cssunitvalue">
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testhelper.js"></script> <script src="../../resources/testhelper.js"></script>
<body>
<div id="log"></div>
<script> <script>
'use strict'; 'use strict';
const gInvalidTestUnits = [ test(() => {
{ unit: '', desc: 'an empty string' }, assert_throws(new TypeError(), () => new CSSUnitValue(0, 'lemon'));
{ unit: 'lemon', desc: 'an invalid unit' }, }, 'Constructing CSSUnitValue with an unknown unit throws a TypeError');
];
for (const {unit, desc} of gInvalidTestUnits) { test(() => {
test(() => { assert_throws(new TypeError(), () => new CSSUnitValue(0, ''));
assert_throws(new TypeError(), () => new CSSUnitValue(0, unit)); }, 'Constructing CSSUnitValue with a empty string unit throws a TypeError');
}, 'Constructing CSSUnitValue with ' + desc + ' as the unit throws a TypeError');
}
for (const unit of gValidUnits) { for (const unit of gValidUnits) {
test(() => { test(() => {
const result = new CSSUnitValue(-3.14, unit); const result = new CSSUnitValue(-3.14, unit);
assert_equals(result.value, -3.14); assert_not_equals(result, null, 'a CSSUnitValue is created');
assert_equals(result.unit, unit.toLowerCase()); assert_equals(result.value, -3.14,
'value is same as given by constructor');
assert_equals(result.unit, unit.toLowerCase(),
'unit is same as given by constructor');
}, 'CSSUnitValue can be constructed with ' + unit); }, 'CSSUnitValue can be constructed with ' + unit);
} }
......
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