Bug 225728 - some MathML WPTs need tweaking to avoid font loading race in WebKit
Summary: some MathML WPTs need tweaking to avoid font loading race in WebKit
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Cameron McCormack (:heycam)
URL:
Keywords: InRadar
Depends on:
Blocks: 225586 225902
  Show dependency treegraph
 
Reported: 2021-05-12 18:45 PDT by Cameron McCormack (:heycam)
Modified: 2021-05-25 13:50 PDT (History)
14 users (show)

See Also:


Attachments
Patch (308.31 KB, patch)
2021-05-12 20:45 PDT, Cameron McCormack (:heycam)
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (316.66 KB, patch)
2021-05-12 23:45 PDT, Cameron McCormack (:heycam)
no flags Details | Formatted Diff | Diff
Patch (344.16 KB, patch)
2021-05-13 00:02 PDT, Cameron McCormack (:heycam)
no flags Details | Formatted Diff | Diff
Patch (366.93 KB, patch)
2021-05-13 00:19 PDT, Cameron McCormack (:heycam)
no flags Details | Formatted Diff | Diff
Patch (366.85 KB, patch)
2021-05-13 00:33 PDT, Cameron McCormack (:heycam)
no flags Details | Formatted Diff | Diff
Patch (366.27 KB, patch)
2021-05-13 16:53 PDT, Cameron McCormack (:heycam)
no flags Details | Formatted Diff | Diff
Patch (365.85 KB, patch)
2021-05-13 17:03 PDT, Cameron McCormack (:heycam)
no flags Details | Formatted Diff | Diff
Patch (377.84 KB, patch)
2021-05-14 00:45 PDT, Cameron McCormack (:heycam)
no flags Details | Formatted Diff | Diff
Patch (379.03 KB, patch)
2021-05-14 15:34 PDT, Cameron McCormack (:heycam)
no flags Details | Formatted Diff | Diff
Patch (379.13 KB, patch)
2021-05-14 16:12 PDT, Cameron McCormack (:heycam)
no flags Details | Formatted Diff | Diff
patch produced by git (380.63 KB, patch)
2021-05-14 22:52 PDT, Cameron McCormack (:heycam)
no flags Details | Formatted Diff | Diff
Patch (379.11 KB, patch)
2021-05-16 21:35 PDT, Cameron McCormack (:heycam)
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Cameron McCormack (:heycam) 2021-05-12 18:45:02 PDT
There are some MathML WPTs that rely on a web font, and they use document.fonts.ready from inside a window load event handler to wait until the font has been loaded before starting the test.  In WebKit, it looks like this is insufficient to wait for the font to be loaded, because (I'm assuming!) there is no guarantee that layout has been flushed by the time the load event handler runs, and despite relevant content being in the document that should cause a font load to start, the FontFaceSet does not wait for that flush to happen before resolving the ready Promise.  It probably should wait for that, but to avoid running into this font loading problem (since the WPTs aren't testing font loading specifically), let's tweak the way the tests wait.
Comment 1 Simon Fraser (smfr) 2021-05-12 20:38:56 PDT
But maybe also file a bug on the timing of document.fonts.ready? That should have its own WPT test, perhaps?
Comment 2 Cameron McCormack (:heycam) 2021-05-12 20:45:58 PDT
Created attachment 428452 [details]
Patch
Comment 3 EWS Watchlist 2021-05-12 20:47:48 PDT
This patch modifies the imported WPT tests. Please ensure that any changes on the tests (not coming from a WPT import) are exported to WPT. Please see https://trac.webkit.org/wiki/WPTExportProcess
Comment 4 Cameron McCormack (:heycam) 2021-05-12 20:59:04 PDT
Yes, I will file a bug about that.  WPTs for the Font Loading API unfortunately don't have great coverage.
Comment 5 Cameron McCormack (:heycam) 2021-05-12 22:17:35 PDT
After reading through the spec some more, I was wrong about the ready promise.  If there are loads in flight, then it does indeed need to wait for layout to have been flushed (so that it's no longer "pending on the environment").  But there is no requirement to replace a settled ready promise with a fresh, pending one as soon as content is inserted into the document.  The spec isn't very strict on when loads get kicked off due to content in the document, it just says:

> When a user-agent needs to load a font face, it must do so by calling the load() method of the corresponding FontFace object.

So I think by the letter of the spec, the current WebKit behavior is allowed.  In fact, it's probably not great to be replacing the ready promise every time some content in the document is changed.

That does make it hard to use the ready promise in conjunction with font loads initiated from content (as opposed to explicit load() calls).
Comment 6 Cameron McCormack (:heycam) 2021-05-12 22:27:01 PDT
And gsnedders points out in https://github.com/w3c/csswg-drafts/issues/1088#issuecomment-292997364 that "Chrome and Firefox delay the load event for a used @font-face, Safari and Edge do not".  So I do think the safe thing to do with these tests is to explicitly load() the FontFaces and wait on them to complete.
Comment 7 Cameron McCormack (:heycam) 2021-05-12 23:45:22 PDT
Created attachment 428462 [details]
Patch
Comment 8 Frédéric Wang (:fredw) 2021-05-12 23:56:54 PDT
Comment on attachment 428452 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=428452&action=review

Thanks for working on this and great to see more tests passing !

If this approach works in Firefox and Chromium too, it sounds good to do that change indeed.

(In reply to Cameron McCormack (:heycam) from comment #4)
> Yes, I will file a bug about that.  WPTs for the Font Loading API
> unfortunately don't have great coverage.

May I ask you to cc me to this bug?

> LayoutTests/imported/w3c/web-platform-tests/mathml/support/fonts.js:3
> +  return Promise.allSettled([...document.fonts].map(f => f.load()));

Can you please mention that document.fonts.ready is supposed to do that and why we don't use it (spec unclear, browsers inconsistent...)?

And also why we can't use Promise.all ?
Comment 9 Cameron McCormack (:heycam) 2021-05-13 00:02:07 PDT
Created attachment 428464 [details]
Patch
Comment 10 Cameron McCormack (:heycam) 2021-05-13 00:19:31 PDT
Created attachment 428466 [details]
Patch
Comment 11 Cameron McCormack (:heycam) 2021-05-13 00:28:21 PDT
(In reply to Frédéric Wang (:fredw) from comment #8)
> May I ask you to cc me to this bug?

I will once I file it.  Though from my comment 5, I don't think WebKit is wrong.  But the different behavior between engines is a potential compat problem (as shown by these tests), so I'll file one to track doing something.

> > LayoutTests/imported/w3c/web-platform-tests/mathml/support/fonts.js:3
> > +  return Promise.allSettled([...document.fonts].map(f => f.load()));
> 
> Can you please mention that document.fonts.ready is supposed to do that and
> why we don't use it (spec unclear, browsers inconsistent...)?

OK.

> And also why we can't use Promise.all ?

Because I plan to land this patch before the one adding operators.woff (to make it clear which expectation changes are due to which change), and the promise will be rejected if the font file isn't found.
Comment 12 Cameron McCormack (:heycam) 2021-05-13 00:33:34 PDT
Created attachment 428467 [details]
Patch
Comment 13 Cameron McCormack (:heycam) 2021-05-13 16:53:03 PDT
Created attachment 428576 [details]
Patch
Comment 14 Cameron McCormack (:heycam) 2021-05-13 17:03:46 PDT
Created attachment 428580 [details]
Patch
Comment 15 Cameron McCormack (:heycam) 2021-05-14 00:45:46 PDT
Created attachment 428609 [details]
Patch
Comment 16 Cameron McCormack (:heycam) 2021-05-14 15:34:19 PDT
Created attachment 428674 [details]
Patch
Comment 17 Cameron McCormack (:heycam) 2021-05-14 16:12:34 PDT
Created attachment 428679 [details]
Patch
Comment 18 Cameron McCormack (:heycam) 2021-05-14 22:49:19 PDT
Comment on attachment 428679 [details]
Patch

Finally got all the test expectations update right, at least for the EWS bots.  Fred, can you take a look at this?
Comment 19 Cameron McCormack (:heycam) 2021-05-14 22:52:44 PDT
Created attachment 428717 [details]
patch produced by git

It may be more instructive to look at the patch as produced by git, which has shows file moves/renames.
Comment 20 Darin Adler 2021-05-15 15:37:08 PDT
Comment on attachment 428679 [details]
Patch

I’m going to set review+ but I get the impression you want to wait to hear from Frédéric thinks.
Comment 21 Cameron McCormack (:heycam) 2021-05-15 17:38:28 PDT
(In reply to Darin Adler from comment #20)
> I’m going to set review+ but I get the impression you want to wait to hear
> from Frédéric thinks.

Thanks.  I think Frédéric's input in an earlier comment and your review is sufficient.  I'll land it on Monday so I can deal with any other expectation update fallout / rebase the bug 225586 patch while I'm at my desk.
Comment 22 Frédéric Wang (:fredw) 2021-05-15 22:47:01 PDT
Comment on attachment 428679 [details]
Patch

Yes, patch LGTM too
Comment 23 Frédéric Wang (:fredw) 2021-05-15 22:54:06 PDT
(In reply to Frédéric Wang (:fredw) from comment #22)
> Comment on attachment 428679 [details]
> Patch
> 
> Yes, patch LGTM too

Well, I forgot to say that WebKit does not have automatic sync for WPT. Our current procedure is

1) Export the WPT changes on GitHub, get them approved and land them.
2) Land the patch with the WPT change in WebKit.

For (1), it's possible to use an experimental script from Youenn so that you get auto-approval if the patch was already reviewed in WebKit. But it's likely not going to work well here, so I'd suggest you send a PR manually.
Comment 24 Cameron McCormack (:heycam) 2021-05-15 23:52:09 PDT
Some of the tests have changed upstream, but not yet been updated in our copy.  Is it OK to rework the changes so that the apply upstream, in the WPT PR, and land the patches here to the old copies of the tests?  Will that mess up any future import of upstream WPT changes?
Comment 25 Frédéric Wang (:fredw) 2021-05-16 00:17:59 PDT
(In reply to Cameron McCormack (:heycam) from comment #24)
> Some of the tests have changed upstream, but not yet been updated in our
> copy.  Is it OK to rework the changes so that the apply upstream, in the WPT
> PR, and land the patches here to the old copies of the tests?  Will that
> mess up any future import of upstream WPT changes?

cc'ing Ryosuke who knows better the status, but my understanding is that the general rule is: it is ok to rework the changes so that they apply upstream ; but not to apply changes to our copies before they are synced again.
Comment 26 Ryosuke Niwa 2021-05-16 00:58:56 PDT
(In reply to Frédéric Wang (:fredw) from comment #25)
> (In reply to Cameron McCormack (:heycam) from comment #24)
> > Some of the tests have changed upstream, but not yet been updated in our
> > copy.  Is it OK to rework the changes so that the apply upstream, in the WPT
> > PR, and land the patches here to the old copies of the tests?  Will that
> > mess up any future import of upstream WPT changes?
> 
> cc'ing Ryosuke who knows better the status, but my understanding is that the
> general rule is: it is ok to rework the changes so that they apply upstream
> ; but not to apply changes to our copies before they are synced again.

It's okay to land WebKit changes so long as the WPT changes upstream had already been landed. No need to wait for WPT re-sync into WebKit repo to happen.
Comment 27 Cameron McCormack (:heycam) 2021-05-16 14:24:42 PDT
https://github.com/web-platform-tests/wpt/pull/29011
Comment 28 EWS 2021-05-16 21:27:22 PDT
Tools/Scripts/svn-apply failed to apply attachment 428679 [details] to trunk.
Please resolve the conflicts and upload a new patch.
Comment 29 Cameron McCormack (:heycam) 2021-05-16 21:35:09 PDT
Created attachment 428809 [details]
Patch
Comment 30 EWS 2021-05-16 22:22:35 PDT
Committed r277577 (237804@main): <https://commits.webkit.org/237804@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 428809 [details].
Comment 31 Radar WebKit Bug Importer 2021-05-16 22:23:16 PDT
<rdar://problem/78091026>
Comment 32 Truitt Savell 2021-05-17 11:03:58 PDT
These two tests are failing on Big Sur across intel and Apple Silicon queues

imported/w3c/web-platform-tests/mathml/relations/css-styling/ignored-properties-001.html
  imported/w3c/web-platform-tests/mathml/relations/css-styling/padding-border-margin/padding-002.html

History;
https://results.webkit.org/?suite=layout-tests&suite=layout-tests&test=imported%2Fw3c%2Fweb-platform-tests%2Fmathml%2Frelations%2Fcss-styling%2Fpadding-border-margin%2Fpadding-002.html&test=imported%2Fw3c%2Fweb-platform-tests%2Fwebaudio%2Fthe-audio-api%2Fthe-audioworklet-interface%2Faudioworkletprocessor-process-frozen-array.https.html

I think these just need to be skipped on Big Sur overall sense there was an attempt to skip this on arm64
Comment 33 Cameron McCormack (:heycam) 2021-05-17 15:58:15 PDT
That they are failing on Big Sur across the board makes me think we shouldn't be skipping, and we should just add some Big Sur specific test expectations.
Comment 34 Darin Adler 2021-05-17 23:26:59 PDT
(In reply to Cameron McCormack (:heycam) from comment #33)
> That they are failing on Big Sur across the board makes me think we
> shouldn't be skipping, and we should just add some Big Sur specific test
> expectations.

Might do this in two parts:

1) Bot watchers could add the skip expectations to get us back to green.
2) Someone with more expertise in the area can create an appropriate test expectation and unskip. Might want a reviewer on that.
Comment 35 Cameron McCormack (:heycam) 2021-05-18 00:29:24 PDT
I have a patch up in bug 225902 for the updated expectations for these two tests, after I tested locally on my Big Sur machine.  I had planned to just land that unreviewed, if it ended up green.
Comment 36 Darin Adler 2021-05-18 00:37:22 PDT
(In reply to Cameron McCormack (:heycam) from comment #35)
> I have a patch up in bug 225902 for the updated expectations for these two
> tests, after I tested locally on my Big Sur machine.  I had planned to just
> land that unreviewed, if it ended up green.

Sounds great.
Comment 37 Sam Sneddon [:gsnedders] 2021-05-25 13:50:50 PDT
(In reply to Cameron McCormack (:heycam) from comment #5)
> After reading through the spec some more, I was wrong about the ready
> promise.  If there are loads in flight, then it does indeed need to wait for
> layout to have been flushed (so that it's no longer "pending on the
> environment").  But there is no requirement to replace a settled ready
> promise with a fresh, pending one as soon as content is inserted into the
> document.  The spec isn't very strict on when loads get kicked off due to
> content in the document, it just says:
> 
> > When a user-agent needs to load a font face, it must do so by calling the load() method of the corresponding FontFace object.
> 
> So I think by the letter of the spec, the current WebKit behavior is
> allowed.  In fact, it's probably not great to be replacing the ready promise
> every time some content in the document is changed.
> 
> That does make it hard to use the ready promise in conjunction with font
> loads initiated from content (as opposed to explicit load() calls).

It sounds like it's probably worth filing a spec bug to make this more concrete, at least?