-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split two css/css-cascade tests (#34081)
- Loading branch information
1 parent
01e527f
commit 76522e2
Showing
4 changed files
with
159 additions
and
95 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
css/css-cascade/layer-cssom-order-reverse-at-property.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<!DOCTYPE html> | ||
<title>CSS Cascade Layers: @property rule invalidation on layer order changes</title> | ||
<link rel="help" href="https://drafts.csswg.org/css-cascade-5/#layering"> | ||
<link rel="author" href="mailto:xiaochengh@chromium.org"> | ||
<link rel="stylesheet" href="/fonts/ahem.css"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<style> | ||
#reference { | ||
color: green; | ||
--foo: green; | ||
} | ||
</style> | ||
|
||
<div id=target>Lorem ipsum</div> | ||
<div id=reference>Lorem ipsum</div> | ||
|
||
<script> | ||
const testCases = [ | ||
{ | ||
title: 'Insert layer invalidates @property', | ||
sheets: [ | ||
'', | ||
` | ||
@layer first { | ||
@property --foo { | ||
syntax: '<color>'; | ||
inherits: false; | ||
initial-value: green; | ||
} | ||
} | ||
@layer second { | ||
@property --foo { | ||
syntax: '<color>'; | ||
inherits: false; | ||
initial-value: red; | ||
} | ||
} | ||
`, | ||
], | ||
update: function(sheets) { | ||
sheets[0].insertRule('@layer second {}', 0); | ||
}, | ||
property: '--foo', | ||
}, | ||
{ | ||
title: 'Delete layer invalidates @property', | ||
sheets: [ | ||
'@layer second {}', | ||
` | ||
@layer first { | ||
@property --foo { | ||
syntax: '<color>'; | ||
inherits: false; | ||
initial-value: red; | ||
} | ||
} | ||
@layer second { | ||
@property --foo { | ||
syntax: '<color>'; | ||
inherits: false; | ||
initial-value: green; | ||
} | ||
} | ||
`, | ||
], | ||
update: function(sheets) { | ||
sheets[0].deleteRule(0); | ||
}, | ||
property: '--foo', | ||
}, | ||
]; | ||
|
||
for (let testCase of testCases) { | ||
test(testObj => { | ||
const styleElements = testCase.sheets.map(sheet => { | ||
const element = document.createElement('style'); | ||
element.appendChild(document.createTextNode(sheet)); | ||
document.head.appendChild(element); | ||
return element; | ||
}); | ||
testObj.add_cleanup(() => { | ||
for (let element of styleElements) | ||
element.remove(); | ||
}); | ||
|
||
const sheets = styleElements.map(element => element.sheet); | ||
testCase.update(sheets); | ||
const actual = getComputedStyle(target).getPropertyValue(testCase.property); | ||
const expected = getComputedStyle(reference).getPropertyValue(testCase.property); | ||
assert_equals(actual, expected); | ||
}, testCase.title); | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<!DOCTYPE html> | ||
<title>CSS Cascade Layers: CSSStyleSheet.replaceSync clears stale statements</title> | ||
<link rel="author" href="mailto:xiaochengh@chromium.org"> | ||
<link rel="help" href="https://www.w3.org/TR/css-cascade-5/#layering"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<div id="target"></div> | ||
<div id="reference" style="color: green"></div> | ||
|
||
<script> | ||
// In all test cases, the 'color' property value of #target should be green. | ||
|
||
const testCases = [ | ||
{ | ||
title: 'replaceSync clears stale layer statements', | ||
style: ` | ||
@layer second, first; | ||
@layer second { | ||
#target { color: green; } | ||
} | ||
@layer first { | ||
#target { color: red; } | ||
} | ||
`, | ||
operations: function(sheet) { | ||
sheet.replaceSync(` | ||
@layer first { | ||
#target { color: red; } | ||
} | ||
@layer second { | ||
#target { color: green; } | ||
} | ||
`); | ||
} | ||
}, | ||
]; | ||
|
||
const target = document.getElementById('target'); | ||
const reference = document.getElementById('reference'); | ||
|
||
for (let testCase of testCases) { | ||
test(t => { | ||
let sheet = new CSSStyleSheet(); | ||
sheet.replaceSync(testCase.style); | ||
document.adoptedStyleSheets = [sheet]; | ||
|
||
try { | ||
testCase.operations(sheet); | ||
assert_equals(getComputedStyle(target).color, getComputedStyle(reference).color); | ||
} finally { | ||
document.adoptedStyleSheets = []; | ||
} | ||
}, testCase.title); | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters