Commit 18fc5e4a authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

[css-typed-om] Add property test for font-weight.

font-weight is clamped to [0, 1000], so we have to change the out of
range code to handle upperbounds too.

Test failure because we seem to be rounding the font weight, but the
spec doesn't say we should.

Bug: 774887
Change-Id: I75d283dc32d37e04633133fe420817d02953d4e3
Reviewed-on: https://chromium-review.googlesource.com/936722Reviewed-by: default avatarnainar <nainar@chromium.org>
Commit-Queue: nainar <nainar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#539117}
parent c089b569
This is a testharness.js-based test.
PASS Can set 'font-weight' to CSS-wide keywords
PASS Can set 'font-weight' to the 'normal' keyword
PASS Can set 'font-weight' to the 'bold' keyword
PASS Can set 'font-weight' to the 'bolder' keyword
PASS Can set 'font-weight' to the 'lighter' keyword
FAIL Can set 'font-weight' to a number assert_approx_equals: expected -3.14 +/- 0.000001 but got -3
PASS Setting 'font-weight' to a length throws TypeError
PASS Setting 'font-weight' to a percent throws TypeError
PASS Setting 'font-weight' to a time throws TypeError
PASS Setting 'font-weight' to a position throws TypeError
PASS Setting 'font-weight' to a transform throws TypeError
Harness: the test ran to completion.
<!doctype html>
<meta charset="utf-8">
<title>'font-weight' 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_font_weight(weight, result) {
assert_style_value_equals(result, new CSSUnitValue(weight, 'number'));
}
runPropertyTests('font-weight', [
{
syntax: 'normal',
computed: (_, result) => assert_is_font_weight(400, result)
},
{
syntax: 'bold',
computed: (_, result) => assert_is_font_weight(700, result)
},
{
syntax: 'bolder',
computed: (_, result) => assert_is_unit('number', result)
},
{
syntax: 'lighter',
computed: (_, result) => assert_is_unit('number', result)
},
{
syntax: '<number>',
specified: (input, result) => {
if (input instanceof CSSUnitValue &&
(input.value < 0 || input.value > 1000))
assert_style_value_equals(result, new CSSMathSum(input));
else
assert_style_value_equals(result, input);
}
},
]);
</script>
......@@ -562,6 +562,8 @@
name_for_methods: "Weight",
converter: "ConvertFontWeight",
priority: "High",
keywords: ["normal", "bold", "bolder", "lighter"],
typedom_types: ["Number"]
},
{
name: "font-feature-settings",
......
......@@ -34,6 +34,23 @@ CSSPrimitiveValue::UnitType ToCanonicalUnitIfPossible(
return canonical_unit;
}
bool IsValueOutOfRangeForProperty(CSSPropertyID property_id, double value) {
// FIXME: Avoid this CSSProperty::Get call as it can be costly.
// The caller often has a CSSProperty already, so we can just pass it here.
if (LengthPropertyFunctions::GetValueRange(CSSProperty::Get(property_id)) ==
kValueRangeNonNegative &&
value < 0)
return true;
// For non-length properties and special cases.
switch (property_id) {
case CSSPropertyFontWeight:
return value < 0 || value > 1000;
default:
return false;
}
}
} // namespace
CSSUnitValue* CSSUnitValue::Create(double value,
......@@ -121,11 +138,7 @@ const CSSPrimitiveValue* CSSUnitValue::ToCSSValue() const {
const CSSPrimitiveValue* CSSUnitValue::ToCSSValueWithProperty(
CSSPropertyID property_id) const {
// FIXME: Avoid this CSSProperty::Get call as it can be costly.
// The caller often has a CSSProperty already, so we can just pass it here.
if (LengthPropertyFunctions::GetValueRange(CSSProperty::Get(property_id)) ==
kValueRangeNonNegative &&
value_ < 0) {
if (IsValueOutOfRangeForProperty(property_id, value_)) {
// Wrap out of range values with a calc.
CSSCalcExpressionNode* node = ToCalcExpressionNode();
node->SetIsNestedCalc();
......
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