Skip to content

Commit

Permalink
[css-typed-om] Add per-property test for 'opacity'.
Browse files Browse the repository at this point in the history
This patch adds tests for opacity, which only takes a <number> and whose
computed value is clamped to [0, 1]. This is the <number> property so
we had to add to the test harness.

Bug: 545318
Change-Id: I5689843188811c8c14c062a60deb0a8c580de3d9
  • Loading branch information
darrnshn authored and chromium-wpt-export-bot committed Feb 21, 2018
1 parent 3023e57 commit 8c62741
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
34 changes: 34 additions & 0 deletions css/css-typed-om/the-stylepropertymap/properties/opacity.html
@@ -0,0 +1,34 @@
<!doctype html>
<meta charset="utf-8">
<title>'opacity' property</title>
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymap-get">
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymap-set">
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#property-stle-value-normalization">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testhelper.js"></script>
<script src="resources/testsuite.js"></script>
<body>
<div id="log"></div>
<script>
'use strict';

function assert_is_equal_with_clamping(input, result) {
const number = input.to('number');

if (number.value < 0)
assert_style_value_equals(result, new CSSUnitValue(0, 'number'));
else if (number.value > 1)
assert_style_value_equals(result, new CSSUnitValue(1, 'number'));
else
assert_style_value_equals(result, input);
}

runPropertyTests('opacity', [
{
syntax: '<number>',
computed: assert_is_equal_with_clamping
},
]);

</script>
Expand Up @@ -111,6 +111,31 @@ const gTestSyntaxExamples = {
}
],
},
'<number>': {
description: 'a number',
examples: [
{
description: 'the number zero',
input: new CSSUnitValue(0, 'number')
},
{
description: 'a negative number',
input: new CSSUnitValue(-3.14, 'number')
},
{
description: 'a positive number',
input: new CSSUnitValue(3.14, 'number')
},
{
description: "a calc number",
input: new CSSMathSum(new CSSUnitValue(2, 'number'), new CSSUnitValue(3, 'number')),
defaultSpecified: (_, result) => assert_is_calc_sum(result),
defaultComputed: (_, result) => {
assert_style_value_equals(result, new CSSUnitValue(5, 'number'));
}
}
],
},
'<position>': {
description: 'a position',
examples: [
Expand Down

0 comments on commit 8c62741

Please sign in to comment.