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

Load Ahem as a web font in css-shapes tests. #19577

Merged
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
12 changes: 10 additions & 2 deletions css/css-shapes/shape-outside/values/shape-margin-001.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/parsing-utils.js"></script>
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" />
</head>
<body>
<div id="log"></div>
<script type="text/javascript">
setup({explicit_done: true});
var shape_margin_valid_unit_tests = [];
ParsingUtils.validUnits.forEach(function(unit) {
test = "10"+unit;
Expand All @@ -25,10 +27,16 @@
testCase["expected_computed"] = test;
shape_margin_valid_unit_tests.push(testCase);
});

generate_tests( ParsingUtils.testShapeMarginInlineStyle,
ParsingUtils.buildTestCases(shape_margin_valid_unit_tests, "inline"), true);
generate_tests( ParsingUtils.testShapeMarginComputedStyle,
ParsingUtils.buildTestCases(shape_margin_valid_unit_tests, "computed"), true);
ParsingUtils.setupFonts();
document.fonts.ready.then(()=> {
generate_tests( ParsingUtils.testShapeMarginComputedStyle,
ParsingUtils.buildTestCases(shape_margin_valid_unit_tests, "computed"), true);
ParsingUtils.restoreFonts();
done();
});
</script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/parsing-utils.js"></script>
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" />
</head>
<body>
<div id="log"></div>
<script type="text/javascript">
setup({explicit_done: true});
generate_tests( ParsingUtils.testInlineStyle,
ParsingUtils.buildPositionTests("circle", true, 'lengthUnit + inline', ParsingUtils.validUnits) );
generate_tests( ParsingUtils.testComputedStyle,
ParsingUtils.buildPositionTests("circle", true, 'lengthUnit + computed', ParsingUtils.validUnits) );
ParsingUtils.setupFonts();
document.fonts.ready.then(()=> {
generate_tests( ParsingUtils.testComputedStyle,
ParsingUtils.buildPositionTests("circle", true, 'lengthUnit + computed', ParsingUtils.validUnits) );
ParsingUtils.restoreFonts();
done();
});
</script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/parsing-utils.js"></script>
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" />
</head>
<body>
<div id="log"></div>
<script type="text/javascript">
setup({explicit_done: true});
generate_tests(ParsingUtils.testInlineStyle, ParsingUtils.buildRadiiTests('circle', 'lengthUnit + inline', ParsingUtils.validUnits));
generate_tests(ParsingUtils.testComputedStyle, ParsingUtils.buildRadiiTests('circle', 'lengthUnit + computed', ParsingUtils.validUnits));
ParsingUtils.setupFonts();
document.fonts.ready.then(()=> {
generate_tests(ParsingUtils.testComputedStyle, ParsingUtils.buildRadiiTests('circle', 'lengthUnit + computed', ParsingUtils.validUnits));
ParsingUtils.restoreFonts();
done();
});
</script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/parsing-utils.js"></script>
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" />
</head>
<body>
<div id="log"></div>
<script type="text/javascript">
setup({explicit_done: true});
generate_tests( ParsingUtils.testInlineStyle,
ParsingUtils.buildPositionTests("ellipse", true, 'lengthUnit + inline', ParsingUtils.validUnits) );
generate_tests( ParsingUtils.testComputedStyle,
ParsingUtils.buildPositionTests("ellipse", true, 'lengthUnit + computed', ParsingUtils.validUnits) );
ParsingUtils.setupFonts();
document.fonts.ready.then(()=> {
generate_tests( ParsingUtils.testComputedStyle,
ParsingUtils.buildPositionTests("ellipse", true, 'lengthUnit + computed', ParsingUtils.validUnits) );
ParsingUtils.restoreFonts();
done();
});
</script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/parsing-utils.js"></script>
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" />
</head>
<body>
<div id="log"></div>
<script type="text/javascript">
setup({explicit_done: true});
generate_tests(ParsingUtils.testInlineStyle, ParsingUtils.buildRadiiTests('ellipse', 'lengthUnit + inline', ParsingUtils.validUnits));
generate_tests(ParsingUtils.testComputedStyle, ParsingUtils.buildRadiiTests('ellipse', 'lengthUnit + computed', ParsingUtils.validUnits));
ParsingUtils.setupFonts();
document.fonts.ready.then(()=> {
generate_tests(ParsingUtils.testComputedStyle,
ParsingUtils.buildRadiiTests('ellipse', 'lengthUnit + computed', ParsingUtils.validUnits));
ParsingUtils.restoreFonts();
done();
});
</script>
</body>
</html>
11 changes: 9 additions & 2 deletions css/css-shapes/shape-outside/values/shape-outside-inset-003.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,22 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/parsing-utils.js"></script>
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" />
</head>
<body>
<div id="log"></div>
<script type="text/javascript">
setup({explicit_done: true});
ParsingUtils.validUnits.forEach(function(unit) {
generate_tests(ParsingUtils.testInlineStyle, ParsingUtils.generateInsetRoundCases(unit, 'inline'));
});
ParsingUtils.validUnits.forEach(function(unit) {
generate_tests(ParsingUtils.testComputedStyle, ParsingUtils.generateInsetRoundCases(unit, 'computed'));
ParsingUtils.setupFonts();
document.fonts.ready.then(()=> {
ParsingUtils.validUnits.forEach(function(unit) {
generate_tests(ParsingUtils.testComputedStyle, ParsingUtils.generateInsetRoundCases(unit, 'computed'));
});
ParsingUtils.restoreFonts();
done();
});
</script>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/parsing-utils.js"></script>
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" />
</head>
<body>
<div id="log"></div>
<script type="text/javascript">
setup({explicit_done: true});
var arg_length_units_tests = [
['%', 'px', 'px'],
['px', '%', 'px'],
Expand All @@ -31,8 +33,13 @@
];
generate_tests( ParsingUtils.testInlineStyle,
ParsingUtils.buildPolygonTests(arg_length_units_tests, 'inline') );
generate_tests( ParsingUtils.testComputedStyle,
ParsingUtils.buildPolygonTests(arg_length_units_tests, 'computed') );
ParsingUtils.setupFonts();
document.fonts.ready.then(()=> {
generate_tests( ParsingUtils.testComputedStyle,
ParsingUtils.buildPolygonTests(arg_length_units_tests, 'computed') );
ParsingUtils.restoreFonts();
done();
});
</script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/parsing-utils.js"></script>
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" />
</head>
<body>
<div id="log"></div>
Expand All @@ -21,6 +22,7 @@
// fixed units: cm, mm, in, px, pt, pc
// percentage unit: %
// zero length: 0
setup({explicit_done: true});
var basic_shape_args_tests = [
{
"name": "0-valued",
Expand Down Expand Up @@ -53,10 +55,17 @@
"expected_computed": "polygon(1% 2%)"
}
];

generate_tests( ParsingUtils.testInlineStyle,
ParsingUtils.buildTestCases(basic_shape_args_tests, "inline") );
generate_tests( ParsingUtils.testComputedStyle,
ParsingUtils.buildTestCases(basic_shape_args_tests, "computed") );
ParsingUtils.setupFonts();
document.fonts.ready.then(()=> {
generate_tests( ParsingUtils.testComputedStyle,
ParsingUtils.buildTestCases(basic_shape_args_tests, "computed") );
ParsingUtils.restoreFonts();
done();
});

</script>
</body>
</html>
56 changes: 29 additions & 27 deletions css/css-shapes/shape-outside/values/support/parsing-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,31 +446,32 @@ function each(object, func) {
}
}

function setupFonts(func) {
return function () {
var fontProperties = {
'font-family': 'Ahem',
'font-size': '16px',
'line-height': '1'
};
var savedValues = { };
each(fontProperties, function (key, value) {
savedValues[key] = document.body.style.getPropertyValue(key);
/// For saving and restoring font properties
var savedFontValues = { };

function setupFonts() {
var fontProperties = {
'font-family': 'Ahem',
'font-size': '16px',
'line-height': '1'
};
savedFontValues = { };
each(fontProperties, function (key, value) {
savedFontValues[key] = document.body.style.getPropertyValue(key);
document.body.style.setProperty(key, value);
});
}

function restoreFonts() {
each(savedFontValues, function (key, value) {
if (value) {
document.body.style.setProperty(key, value);
});
try {
func.apply(this, arguments);
} finally {
each(savedValues, function (key, value) {
if (value) {
document.body.style.setProperty(key, value);
}
else {
document.body.style.removeProperty(key);
}
});
}
};
else {
document.body.style.removeProperty(key);
}
});
savedFontValues = { };
}

var validUnits = [
Expand Down Expand Up @@ -819,11 +820,11 @@ var calcTestValues = [

return {
testInlineStyle: testInlineStyle,
testComputedStyle: setupFonts(testComputedStyle),
testComputedStyle: testComputedStyle,
testShapeMarginInlineStyle: testShapeMarginInlineStyle,
testShapeMarginComputedStyle: setupFonts(testShapeMarginComputedStyle),
testShapeMarginComputedStyle: testShapeMarginComputedStyle,
testShapeThresholdInlineStyle: testShapeThresholdInlineStyle,
testShapeThresholdComputedStyle: setupFonts(testShapeThresholdComputedStyle),
testShapeThresholdComputedStyle: testShapeThresholdComputedStyle,
buildTestCases: buildTestCases,
buildRadiiTests: buildRadiiTests,
buildPositionTests: buildPositionTests,
Expand All @@ -834,6 +835,7 @@ return {
validUnits: validUnits,
calcTestValues: calcTestValues,
roundResultStr: roundResultStr,
setupFonts: setupFonts
setupFonts: setupFonts,
restoreFonts: restoreFonts,
}
})();