Commit 11c9826a authored by Zhuoyu Qian's avatar Zhuoyu Qian Committed by Commit Bot

Background-size should not accept negative values.

Follow the spec[1], negative values are not allowed.
We should reject the negative values of background-size during parsing.

[1]: https://drafts.csswg.org/css-backgrounds/#background-size

Bug: 825549
Signed-off-by: default avatarZhuoyu Qian <zhuoyu.qian@samsung.com>
Change-Id: Ib260bafa421249aed471ff801c8b49a4b97aba1e
Reviewed-on: https://chromium-review.googlesource.com/989529Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#572149}
parent d8269be5
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSS Backgrounds and Borders Test: background-size - negative value</title>
<link rel="author" title="Zhuoyu Qian" href="mailto:zhuoyu.qian@samsung.com">
<link rel="help" href="http://www.w3.org/TR/css3-background/#the-background-size" title="3.9. Sizing Images: the 'background-size' property">
<link rel="match" href="reference/background-size-002-ref.html">
<meta name="flags" content="image">
<meta name="assert" content="Check if 'background-size' has the negative values, then such values are not allowed and they will be assumed to be 'auto'.">
<style>
#ref-overlapped-red {
background-color: red;
height: 45px;
width: 45px;
}
#test-overlapping-green {
background-image: url(support/60x60-green.png);
background-repeat: no-repeat;
background-size: -1px -1px;
bottom: 45px;
height: 100px;
position: relative;
width: 100px;
}
</style>
</head>
<body>
<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>
<div id="ref-overlapped-red"></div>
<div id="test-overlapping-green"></div>
</body>
</html>
This is a testharness.js-based test.
FAIL e.style['background-size'] = "-1px" should not set the property value assert_equals: expected "" but got "-1px"
FAIL e.style['background-size'] = "2% -3%" should not set the property value assert_equals: expected "" but got "2% -3%"
PASS e.style['background-size'] = "1px 2px 3px" should not set the property value
Harness: the test ran to completion.
...@@ -750,14 +750,7 @@ CSSPrimitiveValue* ConsumeLengthOrPercentCountNegative( ...@@ -750,14 +750,7 @@ CSSPrimitiveValue* ConsumeLengthOrPercentCountNegative(
CSSPrimitiveValue* result = CSSPrimitiveValue* result =
ConsumeLengthOrPercent(range, context.Mode(), kValueRangeNonNegative, ConsumeLengthOrPercent(range, context.Mode(), kValueRangeNonNegative,
CSSPropertyParserHelpers::UnitlessQuirk::kForbid); CSSPropertyParserHelpers::UnitlessQuirk::kForbid);
if (result || !negative_size) if (!result && negative_size)
return result;
result =
ConsumeLengthOrPercent(range, context.Mode(), kValueRangeAll,
CSSPropertyParserHelpers::UnitlessQuirk::kForbid);
if (result)
context.Count(*negative_size); context.Count(*negative_size);
return result; return result;
} }
...@@ -777,6 +770,8 @@ CSSValue* ConsumeBackgroundSize(CSSParserTokenRange& range, ...@@ -777,6 +770,8 @@ CSSValue* ConsumeBackgroundSize(CSSParserTokenRange& range,
horizontal = horizontal =
ConsumeLengthOrPercentCountNegative(range, context, negative_size); ConsumeLengthOrPercentCountNegative(range, context, negative_size);
} }
if (!horizontal)
return nullptr;
CSSValue* vertical = nullptr; CSSValue* vertical = nullptr;
if (!range.AtEnd()) { if (!range.AtEnd()) {
......
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