Commit a83f42ce authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

[css-typed-om] Update CSSVariableReferenceValue.

The new spec made attributes of CSSVariableReferenceValue mutable.
This also allows us to simplify the test helper to create
CSSVariableReferenceValues.

Spec: https://drafts.css-houdini.org/css-typed-om-1/#cssvariablereferencevalue

Bug: 545318
Change-Id: I9f7571e7b50b646423e4a6dc44cfb6c95c3fc5dd
Reviewed-on: https://chromium-review.googlesource.com/802664
Commit-Queue: Darren Shen <shend@chromium.org>
Reviewed-by: default avatarRenée Wright <rjwright@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521936}
parent 20c3c417
...@@ -139,6 +139,8 @@ CONSOLE MESSAGE: line 147: interface CSSVariableReferenceValue ...@@ -139,6 +139,8 @@ CONSOLE MESSAGE: line 147: interface CSSVariableReferenceValue
CONSOLE MESSAGE: line 147: getter fallback CONSOLE MESSAGE: line 147: getter fallback
CONSOLE MESSAGE: line 147: getter variable CONSOLE MESSAGE: line 147: getter variable
CONSOLE MESSAGE: line 147: method constructor CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: setter fallback
CONSOLE MESSAGE: line 147: setter variable
CONSOLE MESSAGE: line 147: interface CountQueuingStrategy CONSOLE MESSAGE: line 147: interface CountQueuingStrategy
CONSOLE MESSAGE: line 147: method constructor CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: method size CONSOLE MESSAGE: line 147: method size
...@@ -434,6 +436,8 @@ CONSOLE MESSAGE: line 147: interface CSSVariableReferenceValue ...@@ -434,6 +436,8 @@ CONSOLE MESSAGE: line 147: interface CSSVariableReferenceValue
CONSOLE MESSAGE: line 147: getter fallback CONSOLE MESSAGE: line 147: getter fallback
CONSOLE MESSAGE: line 147: getter variable CONSOLE MESSAGE: line 147: getter variable
CONSOLE MESSAGE: line 147: method constructor CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: setter fallback
CONSOLE MESSAGE: line 147: setter variable
CONSOLE MESSAGE: line 147: interface CountQueuingStrategy CONSOLE MESSAGE: line 147: interface CountQueuingStrategy
CONSOLE MESSAGE: line 147: method constructor CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: method size CONSOLE MESSAGE: line 147: method size
......
// Compares two CSSStyleValues to check if they're the same type // Compares two CSSStyleValues to check if they're the same type
// and have the same attributes. // and have the same attributes.
function assert_style_value_equals(a, b) { function assert_style_value_equals(a, b) {
if (a == null || b == null) {
assert_equals(a, b);
return;
}
assert_equals(a.constructor.name, b.constructor.name); assert_equals(a.constructor.name, b.constructor.name);
const className = a.constructor.name; const className = a.constructor.name;
switch (className) { switch (className) {
...@@ -21,6 +26,13 @@ function assert_style_value_equals(a, b) { ...@@ -21,6 +26,13 @@ function assert_style_value_equals(a, b) {
case 'CSSMathNegate': case 'CSSMathNegate':
assert_style_value_equals(a.value, b.value); assert_style_value_equals(a.value, b.value);
break; break;
case 'CSSUnparsedValue':
assert_style_value_array_equals(a, b);
break;
case 'CSSVariableReferenceValue':
assert_equals(a.variable, b.variable);
assert_style_value_equals(a.fallback, b.fallback);
break;
} }
} }
...@@ -52,10 +64,9 @@ const gValidUnits = [ ...@@ -52,10 +64,9 @@ const gValidUnits = [
// Hacky way of creating a CSSVariableReferenceValue // Hacky way of creating a CSSVariableReferenceValue
// since it doesn't expose a constructor. // since it doesn't expose a constructor.
function createReferenceValue(variable, fallback) { function createReferenceValue(variable, fallback) {
const varExpr = fallback ? const varExpr = 'var(' + variable + ')';
'var(' + variable + ', ' + fallback + ')' :
'var(' + variable + ')';
const unparsedValue = newDivWithStyle('color:' + varExpr).attributeStyleMap.get('color'); const unparsedValue = newDivWithStyle('color:' + varExpr).attributeStyleMap.get('color');
return unparsedValue[0]; let referenceValue = unparsedValue[0];
referenceValue.fallback = fallback;
return referenceValue;
} }
This is a testharness.js-based test.
FAIL Setting CSSVariableReferenceValue.variable to an invalid variable name throws SyntaxError assert_throws: function "() => result.variable = 'bar'" did not throw
PASS CSSVariableReferenceValue.variable can updated to a valid variable name
PASS CSSVariableReferenceValue.fallback can updated to null
PASS CSSVariableReferenceValue.fallback can updated to a CSSUnparsedValue
Harness: the test ran to completion.
<!doctype html>
<meta charset="utf-8">
<title>CSSVariableReferenceValue tests</title>
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#cssvariablereferencevalue">
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../resources/testhelper.js"></script>
<script>
'use strict';
test(() => {
let result = createReferenceValue('--foo', null);
assert_throws(new SyntaxError(), () => result.variable = 'bar');
assert_equals(result.variable, '--foo');
assert_throws(new SyntaxError(), () => result.variable = '');
assert_equals(result.variable, '--foo');
}, 'Setting CSSVariableReferenceValue.variable to an invalid variable name throws SyntaxError');
test(() => {
let result = createReferenceValue('--foo', null);
result.variable = '--bar';
assert_equals(result.variable, '--bar');
}, 'CSSVariableReferenceValue.variable can updated to a valid variable name');
test(() => {
let result = createReferenceValue('--foo', new CSSUnparsedValue());
result.fallback = null;
assert_equals(result.fallback, null);
}, 'CSSVariableReferenceValue.fallback can updated to null');
test(() => {
let result = createReferenceValue('--foo', null);
result.fallback = new CSSUnparsedValue('foo');
assert_style_value_equals(result.fallback, new CSSUnparsedValue('foo'));
}, 'CSSVariableReferenceValue.fallback can updated to a CSSUnparsedValue');
</script>
...@@ -874,6 +874,8 @@ interface CSSVariableReferenceValue ...@@ -874,6 +874,8 @@ interface CSSVariableReferenceValue
getter fallback getter fallback
getter variable getter variable
method constructor method constructor
setter fallback
setter variable
interface CSSViewportRule : CSSRule interface CSSViewportRule : CSSRule
attribute @@toStringTag attribute @@toStringTag
getter style getter style
......
...@@ -21,17 +21,16 @@ class CORE_EXPORT CSSStyleVariableReferenceValue final ...@@ -21,17 +21,16 @@ class CORE_EXPORT CSSStyleVariableReferenceValue final
public: public:
virtual ~CSSStyleVariableReferenceValue() = default; virtual ~CSSStyleVariableReferenceValue() = default;
static CSSStyleVariableReferenceValue* Create( static CSSStyleVariableReferenceValue* Create(const String& variable,
const String& variable, CSSUnparsedValue* fallback) {
const CSSUnparsedValue* fallback) {
return new CSSStyleVariableReferenceValue(variable, fallback); return new CSSStyleVariableReferenceValue(variable, fallback);
} }
const String& variable() const { return variable_; } const String& variable() const { return variable_; }
void setVariable(const String& value) { variable_ = value; }
CSSUnparsedValue* fallback() { CSSUnparsedValue* fallback() { return fallback_.Get(); }
return const_cast<CSSUnparsedValue*>(fallback_.Get()); void setFallback(CSSUnparsedValue* value) { fallback_ = value; }
}
void Trace(blink::Visitor* visitor) override { void Trace(blink::Visitor* visitor) override {
visitor->Trace(fallback_); visitor->Trace(fallback_);
...@@ -40,11 +39,11 @@ class CORE_EXPORT CSSStyleVariableReferenceValue final ...@@ -40,11 +39,11 @@ class CORE_EXPORT CSSStyleVariableReferenceValue final
protected: protected:
CSSStyleVariableReferenceValue(const String& variable, CSSStyleVariableReferenceValue(const String& variable,
const CSSUnparsedValue* fallback) CSSUnparsedValue* fallback)
: variable_(variable), fallback_(fallback) {} : variable_(variable), fallback_(fallback) {}
String variable_; String variable_;
Member<const CSSUnparsedValue> fallback_; Member<CSSUnparsedValue> fallback_;
private: private:
DISALLOW_COPY_AND_ASSIGN(CSSStyleVariableReferenceValue); DISALLOW_COPY_AND_ASSIGN(CSSStyleVariableReferenceValue);
......
...@@ -9,6 +9,6 @@ ...@@ -9,6 +9,6 @@
RuntimeEnabled=CSSTypedOM, RuntimeEnabled=CSSTypedOM,
ImplementedAs=CSSStyleVariableReferenceValue ImplementedAs=CSSStyleVariableReferenceValue
] interface CSSVariableReferenceValue { ] interface CSSVariableReferenceValue {
readonly attribute DOMString variable; attribute DOMString variable;
readonly attribute CSSUnparsedValue fallback; attribute CSSUnparsedValue? fallback;
}; };
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