Bug 1587188 [wpt PR 19577] - Load Ahem as a web font in css-shapes tests., a=testonly

Automatic update from web-platform-tests
Load Ahem as a web font in css-shapes tests. (#19577)

This makes font setup/restoration explicit rather than per-subtest.
This allows us to setup Ahem usage, then wait for fonts to load, and
then run all computed tests as a discrete block.

The previous method (which dynamically inserted Ahem prior to a subtest
and removed it immediately after) didn't allow us to wait for the web
fonts to be loaded because the test page would have no Ahem usage
present at the time we waited for the fonts.ready event.
--

wpt-commits: 4c1bbd4b27cfa527485d4f56609895c9df55212b
wpt-pr: 19577
This commit is contained in:
Luke Zielinski 2019-10-22 09:26:41 +00:00 коммит произвёл James Graham
Родитель 486e97beb0
Коммит eef4a421ce
9 изменённых файлов: 104 добавлений и 42 удалений

Просмотреть файл

@ -10,10 +10,12 @@
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script src="support/parsing-utils.js"></script> <script src="support/parsing-utils.js"></script>
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" />
</head> </head>
<body> <body>
<div id="log"></div> <div id="log"></div>
<script type="text/javascript"> <script type="text/javascript">
setup({explicit_done: true});
var shape_margin_valid_unit_tests = []; var shape_margin_valid_unit_tests = [];
ParsingUtils.validUnits.forEach(function(unit) { ParsingUtils.validUnits.forEach(function(unit) {
test = "10"+unit; test = "10"+unit;
@ -25,10 +27,16 @@
testCase["expected_computed"] = test; testCase["expected_computed"] = test;
shape_margin_valid_unit_tests.push(testCase); shape_margin_valid_unit_tests.push(testCase);
}); });
generate_tests( ParsingUtils.testShapeMarginInlineStyle, generate_tests( ParsingUtils.testShapeMarginInlineStyle,
ParsingUtils.buildTestCases(shape_margin_valid_unit_tests, "inline"), true); ParsingUtils.buildTestCases(shape_margin_valid_unit_tests, "inline"), true);
ParsingUtils.setupFonts();
document.fonts.ready.then(()=> {
generate_tests( ParsingUtils.testShapeMarginComputedStyle, generate_tests( ParsingUtils.testShapeMarginComputedStyle,
ParsingUtils.buildTestCases(shape_margin_valid_unit_tests, "computed"), true); ParsingUtils.buildTestCases(shape_margin_valid_unit_tests, "computed"), true);
ParsingUtils.restoreFonts();
done();
});
</script> </script>
</body> </body>
</html> </html>

Просмотреть файл

@ -13,14 +13,21 @@
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script src="support/parsing-utils.js"></script> <script src="support/parsing-utils.js"></script>
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" />
</head> </head>
<body> <body>
<div id="log"></div> <div id="log"></div>
<script type="text/javascript"> <script type="text/javascript">
setup({explicit_done: true});
generate_tests( ParsingUtils.testInlineStyle, generate_tests( ParsingUtils.testInlineStyle,
ParsingUtils.buildPositionTests("circle", true, 'lengthUnit + inline', ParsingUtils.validUnits) ); ParsingUtils.buildPositionTests("circle", true, 'lengthUnit + inline', ParsingUtils.validUnits) );
ParsingUtils.setupFonts();
document.fonts.ready.then(()=> {
generate_tests( ParsingUtils.testComputedStyle, generate_tests( ParsingUtils.testComputedStyle,
ParsingUtils.buildPositionTests("circle", true, 'lengthUnit + computed', ParsingUtils.validUnits) ); ParsingUtils.buildPositionTests("circle", true, 'lengthUnit + computed', ParsingUtils.validUnits) );
ParsingUtils.restoreFonts();
done();
});
</script> </script>
</body> </body>
</html> </html>

Просмотреть файл

@ -12,12 +12,19 @@
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script src="support/parsing-utils.js"></script> <script src="support/parsing-utils.js"></script>
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" />
</head> </head>
<body> <body>
<div id="log"></div> <div id="log"></div>
<script type="text/javascript"> <script type="text/javascript">
setup({explicit_done: true});
generate_tests(ParsingUtils.testInlineStyle, ParsingUtils.buildRadiiTests('circle', 'lengthUnit + inline', ParsingUtils.validUnits)); generate_tests(ParsingUtils.testInlineStyle, ParsingUtils.buildRadiiTests('circle', 'lengthUnit + inline', ParsingUtils.validUnits));
ParsingUtils.setupFonts();
document.fonts.ready.then(()=> {
generate_tests(ParsingUtils.testComputedStyle, ParsingUtils.buildRadiiTests('circle', 'lengthUnit + computed', ParsingUtils.validUnits)); generate_tests(ParsingUtils.testComputedStyle, ParsingUtils.buildRadiiTests('circle', 'lengthUnit + computed', ParsingUtils.validUnits));
ParsingUtils.restoreFonts();
done();
});
</script> </script>
</body> </body>
</html> </html>

Просмотреть файл

@ -13,14 +13,21 @@
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script src="support/parsing-utils.js"></script> <script src="support/parsing-utils.js"></script>
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" />
</head> </head>
<body> <body>
<div id="log"></div> <div id="log"></div>
<script type="text/javascript"> <script type="text/javascript">
setup({explicit_done: true});
generate_tests( ParsingUtils.testInlineStyle, generate_tests( ParsingUtils.testInlineStyle,
ParsingUtils.buildPositionTests("ellipse", true, 'lengthUnit + inline', ParsingUtils.validUnits) ); ParsingUtils.buildPositionTests("ellipse", true, 'lengthUnit + inline', ParsingUtils.validUnits) );
ParsingUtils.setupFonts();
document.fonts.ready.then(()=> {
generate_tests( ParsingUtils.testComputedStyle, generate_tests( ParsingUtils.testComputedStyle,
ParsingUtils.buildPositionTests("ellipse", true, 'lengthUnit + computed', ParsingUtils.validUnits) ); ParsingUtils.buildPositionTests("ellipse", true, 'lengthUnit + computed', ParsingUtils.validUnits) );
ParsingUtils.restoreFonts();
done();
});
</script> </script>
</body> </body>
</html> </html>

Просмотреть файл

@ -12,12 +12,20 @@
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script src="support/parsing-utils.js"></script> <script src="support/parsing-utils.js"></script>
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" />
</head> </head>
<body> <body>
<div id="log"></div> <div id="log"></div>
<script type="text/javascript"> <script type="text/javascript">
setup({explicit_done: true});
generate_tests(ParsingUtils.testInlineStyle, ParsingUtils.buildRadiiTests('ellipse', 'lengthUnit + inline', ParsingUtils.validUnits)); 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> </script>
</body> </body>
</html> </html>

Просмотреть файл

@ -13,16 +13,23 @@
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script src="support/parsing-utils.js"></script> <script src="support/parsing-utils.js"></script>
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" />
</head> </head>
<body> <body>
<div id="log"></div> <div id="log"></div>
<script type="text/javascript"> <script type="text/javascript">
setup({explicit_done: true});
ParsingUtils.validUnits.forEach(function(unit) { ParsingUtils.validUnits.forEach(function(unit) {
generate_tests(ParsingUtils.testInlineStyle, ParsingUtils.generateInsetRoundCases(unit, 'inline')); generate_tests(ParsingUtils.testInlineStyle, ParsingUtils.generateInsetRoundCases(unit, 'inline'));
}); });
ParsingUtils.setupFonts();
document.fonts.ready.then(()=> {
ParsingUtils.validUnits.forEach(function(unit) { ParsingUtils.validUnits.forEach(function(unit) {
generate_tests(ParsingUtils.testComputedStyle, ParsingUtils.generateInsetRoundCases(unit, 'computed')); generate_tests(ParsingUtils.testComputedStyle, ParsingUtils.generateInsetRoundCases(unit, 'computed'));
}); });
ParsingUtils.restoreFonts();
done();
});
</script> </script>
</body> </body>
</html> </html>

Просмотреть файл

@ -13,10 +13,12 @@
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script src="support/parsing-utils.js"></script> <script src="support/parsing-utils.js"></script>
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" />
</head> </head>
<body> <body>
<div id="log"></div> <div id="log"></div>
<script type="text/javascript"> <script type="text/javascript">
setup({explicit_done: true});
var arg_length_units_tests = [ var arg_length_units_tests = [
['%', 'px', 'px'], ['%', 'px', 'px'],
['px', '%', 'px'], ['px', '%', 'px'],
@ -31,8 +33,13 @@
]; ];
generate_tests( ParsingUtils.testInlineStyle, generate_tests( ParsingUtils.testInlineStyle,
ParsingUtils.buildPolygonTests(arg_length_units_tests, 'inline') ); ParsingUtils.buildPolygonTests(arg_length_units_tests, 'inline') );
ParsingUtils.setupFonts();
document.fonts.ready.then(()=> {
generate_tests( ParsingUtils.testComputedStyle, generate_tests( ParsingUtils.testComputedStyle,
ParsingUtils.buildPolygonTests(arg_length_units_tests, 'computed') ); ParsingUtils.buildPolygonTests(arg_length_units_tests, 'computed') );
ParsingUtils.restoreFonts();
done();
});
</script> </script>
</body> </body>
</html> </html>

Просмотреть файл

@ -13,6 +13,7 @@
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script src="support/parsing-utils.js"></script> <script src="support/parsing-utils.js"></script>
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" />
</head> </head>
<body> <body>
<div id="log"></div> <div id="log"></div>
@ -21,6 +22,7 @@
// fixed units: cm, mm, in, px, pt, pc // fixed units: cm, mm, in, px, pt, pc
// percentage unit: % // percentage unit: %
// zero length: 0 // zero length: 0
setup({explicit_done: true});
var basic_shape_args_tests = [ var basic_shape_args_tests = [
{ {
"name": "0-valued", "name": "0-valued",
@ -53,10 +55,17 @@
"expected_computed": "polygon(1% 2%)" "expected_computed": "polygon(1% 2%)"
} }
]; ];
generate_tests( ParsingUtils.testInlineStyle, generate_tests( ParsingUtils.testInlineStyle,
ParsingUtils.buildTestCases(basic_shape_args_tests, "inline") ); ParsingUtils.buildTestCases(basic_shape_args_tests, "inline") );
ParsingUtils.setupFonts();
document.fonts.ready.then(()=> {
generate_tests( ParsingUtils.testComputedStyle, generate_tests( ParsingUtils.testComputedStyle,
ParsingUtils.buildTestCases(basic_shape_args_tests, "computed") ); ParsingUtils.buildTestCases(basic_shape_args_tests, "computed") );
ParsingUtils.restoreFonts();
done();
});
</script> </script>
</body> </body>
</html> </html>

Просмотреть файл

@ -446,22 +446,24 @@ function each(object, func) {
} }
} }
function setupFonts(func) { /// For saving and restoring font properties
return function () { var savedFontValues = { };
function setupFonts() {
var fontProperties = { var fontProperties = {
'font-family': 'Ahem', 'font-family': 'Ahem',
'font-size': '16px', 'font-size': '16px',
'line-height': '1' 'line-height': '1'
}; };
var savedValues = { }; savedFontValues = { };
each(fontProperties, function (key, value) { each(fontProperties, function (key, value) {
savedValues[key] = document.body.style.getPropertyValue(key); savedFontValues[key] = document.body.style.getPropertyValue(key);
document.body.style.setProperty(key, value); document.body.style.setProperty(key, value);
}); });
try { }
func.apply(this, arguments);
} finally { function restoreFonts() {
each(savedValues, function (key, value) { each(savedFontValues, function (key, value) {
if (value) { if (value) {
document.body.style.setProperty(key, value); document.body.style.setProperty(key, value);
} }
@ -469,8 +471,7 @@ function setupFonts(func) {
document.body.style.removeProperty(key); document.body.style.removeProperty(key);
} }
}); });
} savedFontValues = { };
};
} }
var validUnits = [ var validUnits = [
@ -819,11 +820,11 @@ var calcTestValues = [
return { return {
testInlineStyle: testInlineStyle, testInlineStyle: testInlineStyle,
testComputedStyle: setupFonts(testComputedStyle), testComputedStyle: testComputedStyle,
testShapeMarginInlineStyle: testShapeMarginInlineStyle, testShapeMarginInlineStyle: testShapeMarginInlineStyle,
testShapeMarginComputedStyle: setupFonts(testShapeMarginComputedStyle), testShapeMarginComputedStyle: testShapeMarginComputedStyle,
testShapeThresholdInlineStyle: testShapeThresholdInlineStyle, testShapeThresholdInlineStyle: testShapeThresholdInlineStyle,
testShapeThresholdComputedStyle: setupFonts(testShapeThresholdComputedStyle), testShapeThresholdComputedStyle: testShapeThresholdComputedStyle,
buildTestCases: buildTestCases, buildTestCases: buildTestCases,
buildRadiiTests: buildRadiiTests, buildRadiiTests: buildRadiiTests,
buildPositionTests: buildPositionTests, buildPositionTests: buildPositionTests,
@ -834,6 +835,7 @@ return {
validUnits: validUnits, validUnits: validUnits,
calcTestValues: calcTestValues, calcTestValues: calcTestValues,
roundResultStr: roundResultStr, roundResultStr: roundResultStr,
setupFonts: setupFonts setupFonts: setupFonts,
restoreFonts: restoreFonts,
} }
})(); })();