Commit 9646ae2d authored by Anders Hartvoll Ruud's avatar Anders Hartvoll Ruud Committed by Commit Bot

[css-properties-values-api] CSS.supports(property, value) behavior.

The two-parameter version of CSS.supports should return false if the
value does not parse for the registered syntax of the property.

BUG=641877
R=futhark@chromium.org

Change-Id: I7a3ccbbd8ad465132bb44348919db19e837b5dd7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1604268Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659919}
parent 2464e572
......@@ -33,6 +33,7 @@
#include "third_party/blink/renderer/core/css/css_property_value_set.h"
#include "third_party/blink/renderer/core/css/parser/css_parser.h"
#include "third_party/blink/renderer/core/css/properties/css_property.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
......@@ -49,8 +50,10 @@ bool DOMWindowCSS::supports(const ExecutionContext* execution_context,
MutableCSSPropertyValueSet* dummy_style =
MutableCSSPropertyValueSet::Create(kHTMLStandardMode);
bool is_animation_tainted = false;
const Document& document = To<Document>(*execution_context);
const PropertyRegistry* registry = document.GetPropertyRegistry();
return CSSParser::ParseValueForCustomProperty(
dummy_style, "--valid", nullptr, value, false,
dummy_style, AtomicString(property), registry, value, false,
execution_context->GetSecureContextMode(), nullptr,
is_animation_tainted)
.did_parse;
......
<!DOCTYPE html>
<link rel="help" href="https://drafts.css-houdini.org/css-properties-values-api-1/#conditional-rules" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
CSS.registerProperty({
name: '--length',
syntax: '<length>',
initialValue: '0px',
inherits: false
});
</script>
<style>
#target { color: red; }
@supports(--length: green) {
#target { color: rgb(1, 2, 3); }
}
</style>
<div id=target></div>
<script>
test(function() {
let cs = getComputedStyle(target);
assert_equals(cs.getPropertyValue('color'), 'rgb(1, 2, 3)');
}, '@supports should ignore registered syntax');
test(function() {
assert_true(CSS.supports('--length: red'));
assert_true(CSS.supports('--length: 10px'));
assert_true(CSS.supports('--length: anything, really'));
}, 'CSS.supports(conditionText) should ignore registered syntax');
test(function() {
assert_false(CSS.supports('--length', 'red'));
assert_true(CSS.supports('--length', '10px'));
}, 'CSS.supports(property, value) should parse against registered syntax');
</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