Skip to content

Commit

Permalink
Await web font loading in css-scoping tests
Browse files Browse the repository at this point in the history
Some tests did not pass because the web font did not finish loading
before the rendered widths were checked. Await document.fonts.ready to
make the tests predictable.

Bug: 333457515
Change-Id: I830cc11b4ba7a4c8a5579777712085cb3f7e5a1e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5447137
Commit-Queue: Rune Lillesveen <[email protected]>
Reviewed-by: Munira Tursunova <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1287178}
  • Loading branch information
lilles authored and chromium-wpt-export-bot committed Apr 15, 2024
1 parent cde638c commit 6eb4b61
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 9 deletions.
4 changes: 3 additions & 1 deletion css/css-scoping/font-face-001.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</style>
<div id="host"><span id="in-document">1234567890</span></div>
<script>
test(function() {
promise_test(async () => {
host.attachShadow({ mode: "open" }).innerHTML = `
<style>
@font-face {
Expand All @@ -27,6 +27,8 @@
<span id="in-shadow">0123456789</span>
`;

await document.fonts.ready;

assert_not_equals(document.getElementById('in-document').offsetWidth, 160);
assert_equals(host.shadowRoot.getElementById('in-shadow').offsetWidth, 160);
}, "@font-face applies in the shadow tree")
Expand Down
4 changes: 3 additions & 1 deletion css/css-scoping/font-face-002.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</style>
<div id="host"><span id="in-document">1234567890</span></div>
<script>
test(function() {
promise_test(async () => {
host.attachShadow({ mode: "open" }).innerHTML = `
<style>
#in-shadow {
Expand All @@ -24,6 +24,8 @@
<span id="in-shadow">0123456789</span>
`;

await document.fonts.ready;

assert_not_equals(document.getElementById('in-document').offsetWidth, 160);
assert_equals(host.shadowRoot.getElementById('in-shadow').offsetWidth, 160);
}, "@font-face from the document applies in the shadow tree");
Expand Down
4 changes: 3 additions & 1 deletion css/css-scoping/font-face-003.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</style>
<div id="host"><span id="in-document">1234567890</span></div>
<script>
test(function() {
promise_test(async () => {
host.attachShadow({ mode: "open" }).innerHTML = `
<style>
:host {
Expand All @@ -24,6 +24,8 @@
<span id="in-shadow">0123456789</span>
`;

await document.fonts.ready;

assert_equals(document.getElementById('in-document').offsetWidth, 160);
assert_equals(host.shadowRoot.getElementById('in-shadow').offsetWidth, 160);
}, "@font-face from document applies to :host");
Expand Down
4 changes: 3 additions & 1 deletion css/css-scoping/font-face-004.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</style>
<div id="host"><span id="in-document">1234567890</span></div>
<script>
test(function() {
promise_test(async () => {
host.attachShadow({ mode: "open" }).innerHTML = `
<style>
::slotted(#in-document) {
Expand All @@ -25,6 +25,8 @@
<span id="in-shadow">0123456789</span>
`;

await document.fonts.ready;

assert_equals(document.getElementById('in-document').offsetWidth, 160);
assert_not_equals(host.shadowRoot.getElementById('in-shadow').offsetWidth, 160);
}, "@font-face from document applies to a slotted element");
Expand Down
4 changes: 3 additions & 1 deletion css/css-scoping/font-face-005.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</style>
<div id="host"><span id="in-document">1234567890</span></div>
<script>
test(function() {
promise_test(async () => {
host.attachShadow({ mode: "open" }).innerHTML = `
<style>
@font-face {
Expand All @@ -27,6 +27,8 @@
<span id="in-shadow">0123456789</span>
`;

await document.fonts.ready;

assert_not_equals(document.getElementById('in-document').offsetWidth, 160);
assert_equals(host.shadowRoot.getElementById('in-shadow').offsetWidth, 160);
}, "@font-face should not leak out of shadow tree.");
Expand Down
2 changes: 1 addition & 1 deletion css/css-scoping/font-face-006.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</style>
<div id="host"></div>
<script>
promise_test(async function() {
promise_test(async () => {
host.attachShadow({ mode: "open" }).innerHTML = `
<style>
:host::before, :host::after {
Expand Down
4 changes: 3 additions & 1 deletion css/css-scoping/font-face-007.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<div id="host"><span id="in-document">1234567890</span></div>
<script>
test(function() {
promise_test(async () => {
host.attachShadow({ mode: "open" }).innerHTML = `
<style>
@font-face {
Expand All @@ -22,6 +22,8 @@
<span id="in-shadow">0123456789</span>
`;

await document.fonts.ready;

assert_equals(document.getElementById('in-document').offsetWidth, 160);
assert_equals(host.shadowRoot.getElementById('in-shadow').offsetWidth, 160);
}, "@font-face from shadow applies to :host");
Expand Down
4 changes: 3 additions & 1 deletion css/css-scoping/font-face-008.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<div id="host"><span id="in-document">1234567890</span></div>
<script>
test(function() {
promise_test(async () => {
host.attachShadow({ mode: "open" }).innerHTML = `
<style>
@font-face {
Expand All @@ -23,6 +23,8 @@
<span id="in-shadow">0123456789</span>
`;

await document.fonts.ready;

assert_equals(document.getElementById('in-document').offsetWidth, 160);
assert_not_equals(host.shadowRoot.getElementById('in-shadow').offsetWidth, 160);
}, "@font-face from shadow applies to a slotted element");
Expand Down
4 changes: 3 additions & 1 deletion css/css-scoping/font-face-009.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</style>
<div id="host"></div>
<script>
test(function() {
promise_test(async () => {
host.attachShadow({ mode: "open" }).innerHTML = `
<style>
@font-face {
Expand All @@ -27,6 +27,8 @@
<slot></slot>
`;

await document.fonts.ready;

//shrinkwrapped size for a default font will be a bit more than 80-90
//if the font is applied, it will be a bit more than 160
assert_greater_than(document.getElementById('host').offsetWidth, 160);
Expand Down

0 comments on commit 6eb4b61

Please sign in to comment.