Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[css-typed-om] Clean up StylePropertyMap.delete tests. #9080

Merged
merged 1 commit into from
Jan 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions css/css-typed-om/resources/testhelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ function createDivWithStyle(test, cssText) {
// Creates a new div element with inline style |cssText| and returns
// its inline style property map.
function createInlineStyleMap(test, cssText) {
return createDivWithStyle(test, cssText).attributeStyleMap;
return createElementWithInlineStyleMap(test, cssText)[1]
}
// Same as createInlineStyleMap but also returns the element itself.
function createElementWithInlineStyleMap(test, cssText) {
let elem = createDivWithStyle(test, cssText);
return [elem, elem.attributeStyleMap];
}

// Creates a new div element with inline style |cssText| and returns
Expand All @@ -117,13 +122,17 @@ function createComputedStyleMap(test, cssText) {
// Creates a new style element with a rule |cssText| and returns
// its declared style property map.
function createDeclaredStyleMap(test, cssText) {
return createRuleWithDeclaredStyleMap(test, cssText)[1];
}
// Same as createDeclaredStyleMap but also returns the rule itself.
function createRuleWithDeclaredStyleMap(test, cssText) {
const style = document.createElement('style');
document.head.appendChild(style);
const rule = style.sheet.cssRules[style.sheet.insertRule('#test { ' + cssText + '}')];
test.add_cleanup(() => {
style.remove();
});
return rule.attributeStyleMap;
return [rule, rule.attributeStyleMap];
}

// Creates a new element with background image set to |imageValue|
Expand Down
18 changes: 18 additions & 0 deletions css/css-typed-om/the-stylepropertymap/declared/delete-invalid.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!doctype html>
<meta charset="utf-8">
<title>Declared StylePropertyMap.delete Error Handling</title>
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#delete-a-stylepropertymap">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testhelper.js"></script>
<body>
<div id="log">
<script>
'use strict';

test(t => {
let styleMap = createDeclaredStyleMap(t, '');
assert_throws(new TypeError(), () => styleMap.delete('lemon'));
}, 'Deleting an unsupported property name throws a TypeError');

</script>
56 changes: 56 additions & 0 deletions css/css-typed-om/the-stylepropertymap/declared/delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!doctype html>
<meta charset="utf-8">
<title>Declared StylePropertyMap.delete</title>
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#delete-a-stylepropertymap">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testhelper.js"></script>
<body>
<div id="log">
<script>
'use strict';

test(t => {
let [rule, styleMap] = createRuleWithDeclaredStyleMap(t, '');
assert_equals(rule.style.getPropertyValue('width'), '');

styleMap.delete('width');
assert_equals(rule.style.getPropertyValue('width'), '');
}, 'Deleting a property not in the css rule is a no-op');

test(t => {
let [rule, styleMap] = createRuleWithDeclaredStyleMap(t, 'width: 10px');
assert_not_equals(rule.style.getPropertyValue('width'), '');

styleMap.delete('width');
assert_equals(rule.style.getPropertyValue('width'), '');
}, 'Deleting a property in the css rule removes it from the css rule');

test(t => {
let [rule, styleMap] = createRuleWithDeclaredStyleMap(t, '--Foo: 10px');
assert_not_equals(rule.style.getPropertyValue('--Foo'), '');

styleMap.delete('--Foo');
assert_equals(rule.style.getPropertyValue('--Foo'), '');
}, 'Deleting a custom property in the css rule removes it from the ' +
'css rule');

test(t => {
let [rule, styleMap] = createRuleWithDeclaredStyleMap(t,
'transition-duration: 1s, 2s');
assert_not_equals(rule.style.getPropertyValue('transition-duration'), '');

styleMap.delete('transition-duration');
assert_equals(rule.style.getPropertyValue('transition-duration'), '');
}, 'Deleting a list-valued property in the css rule removes it from ' +
'the css rule');

test(t => {
let [rule, styleMap] = createRuleWithDeclaredStyleMap(t, 'width: 10px');
assert_not_equals(rule.style.getPropertyValue('width'), '');

styleMap.delete('wIdTh');
assert_equals(rule.style.getPropertyValue('width'), '');
}, 'Declared StylePropertyMap.delete is not case-sensitive');

</script>
18 changes: 18 additions & 0 deletions css/css-typed-om/the-stylepropertymap/inline/delete-invalid.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!doctype html>
<meta charset="utf-8">
<title>Inline StylePropertyMap.delete Error Handling</title>
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#delete-a-stylepropertymap">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testhelper.js"></script>
<body>
<div id="log">
<script>
'use strict';

test(t => {
let styleMap = createInlineStyleMap(t, '');
assert_throws(new TypeError(), () => styleMap.delete('lemon'));
}, 'Deleting an unsupported property name throws a TypeError');

</script>
56 changes: 56 additions & 0 deletions css/css-typed-om/the-stylepropertymap/inline/delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!doctype html>
<meta charset="utf-8">
<title>Inline StylePropertyMap.delete</title>
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#delete-a-stylepropertymap">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testhelper.js"></script>
<body>
<div id="log">
<script>
'use strict';

test(t => {
let [elem, styleMap] = createElementWithInlineStyleMap(t, '');
assert_equals(elem.style.getPropertyValue('width'), '');

styleMap.delete('width');
assert_equals(elem.style.getPropertyValue('width'), '');
}, 'Deleting a property not in the inline style is a no-op');

test(t => {
let [elem, styleMap] = createElementWithInlineStyleMap(t, 'width: 10px');
assert_not_equals(elem.style.getPropertyValue('width'), '');

styleMap.delete('width');
assert_equals(elem.style.getPropertyValue('width'), '');
}, 'Deleting a property in the inline style removes it from the inline style');

test(t => {
let [elem, styleMap] = createElementWithInlineStyleMap(t, '--Foo: 10px');
assert_not_equals(elem.style.getPropertyValue('--Foo'), '');

styleMap.delete('--Foo');
assert_equals(elem.style.getPropertyValue('--Foo'), '');
}, 'Deleting a custom property in the inline style removes it from the ' +
'inline style');

test(t => {
let [elem, styleMap] = createElementWithInlineStyleMap(t,
'transition-duration: 1s, 2s');
assert_not_equals(elem.style.getPropertyValue('transition-duration'), '');

styleMap.delete('transition-duration');
assert_equals(elem.style.getPropertyValue('transition-duration'), '');
}, 'Deleting a list-valued property in the inline style removes it from ' +
'the inline style');

test(t => {
let [elem, styleMap] = createElementWithInlineStyleMap(t, 'width: 10px');
assert_not_equals(elem.style.getPropertyValue('width'), '');

styleMap.delete('wIdTh');
assert_equals(elem.style.getPropertyValue('width'), '');
}, 'Inline StylePropertyMap.delete is not case-sensitive');

</script>
41 changes: 0 additions & 41 deletions css/css-typed-om/the-stylepropertymap/inline/delete.tentative.html

This file was deleted.