Skip to content

Commit

Permalink
[css-cascade] parsing tests for 'all' property
Browse files Browse the repository at this point in the history
  • Loading branch information
ericwilligers committed Jun 29, 2018
1 parent e347325 commit 5ecb1f7
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
24 changes: 24 additions & 0 deletions css/css-cascade/parsing/all-invalid.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSS Cascading and Inheritance Level 3: parsing all with invalid values</title>
<link rel="author" title="Eric Willigers" href="mailto:ericwilligers@chromium.org">
<link rel="help" href="https://drafts.csswg.org/css-cascade-3/#propdef-all">
<meta name="assert" content="all supports only the grammar 'initial | inherit | unset'.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/parsing-testcommon.js"></script>
</head>
<body>
<script>
test_invalid_value("all", "auto");
test_invalid_value("all", "none");
test_invalid_value("all", "filter");
test_invalid_value("all", "unset inherit");
test_invalid_value("all", "inherit initial");
test_invalid_value("all", "initial unset");
test_invalid_value("all", "opacity transform");
</script>
</body>
</html>
20 changes: 20 additions & 0 deletions css/css-cascade/parsing/all-valid.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSS Cascading and Inheritance Level 3: parsing all with valid values</title>
<link rel="author" title="Eric Willigers" href="mailto:ericwilligers@chromium.org">
<link rel="help" href="https://drafts.csswg.org/css-cascade-3/#propdef-all">
<meta name="assert" content="all supports the full grammar 'initial | inherit | unset'.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/parsing-testcommon.js"></script>
</head>
<body>
<script>
test_valid_value("all", "initial");
test_valid_value("all", "inherit");
test_valid_value("all", "unset");
</script>
</body>
</html>
39 changes: 39 additions & 0 deletions css/css-cascade/parsing/support/parsing-testcommon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';

// serializedValue can be the expected serialization of value,
// or an array of permitted serializations,
// or omitted if value should serialize as value.
function test_valid_value(property, value, serializedValue) {
if (arguments.length < 3)
serializedValue = value;

var stringifiedValue = JSON.stringify(value);

test(function(){
var div = document.createElement('div');
div.style[property] = value;
assert_not_equals(div.style.getPropertyValue(property), "", "property should be set");

var div = document.createElement('div');
div.style[property] = value;
var readValue = div.style.getPropertyValue(property);
if (serializedValue instanceof Array)
assert_in_array(readValue, serializedValue, "serialization should be sound");
else
assert_equals(readValue, serializedValue, "serialization should be canonical");

div.style[property] = readValue;
assert_equals(div.style.getPropertyValue(property), readValue, "serialization should round-trip");

}, "e.style['" + property + "'] = " + stringifiedValue + " should set the property value");
}

function test_invalid_value(property, value) {
var stringifiedValue = JSON.stringify(value);

test(function(){
var div = document.createElement('div');
div.style[property] = value;
assert_equals(div.style.getPropertyValue(property), "");
}, "e.style['" + property + "'] = " + stringifiedValue + " should not set the property value");
}

0 comments on commit 5ecb1f7

Please sign in to comment.