haikuwebkit/LayoutTests/fast/loader/resources
Brady Eidson 911fb39b7f Font loads quickly followed by navigations may fail indefinitely
<rdar://problem/65560550> and https://bugs.webkit.org/show_bug.cgi?id=215435

Reviewed by Myles C. Maxfield.

Source/WebCore:

Second take at this.

Myles took the first swipe at this, but a conflict with SuspendableTimer caused issues
in the form of layout test asserts with
http/tests/security/navigate-when-restoring-cached-page.html

His original ChangeLog entry:

Font loads are coalesced using a zero-delay timer. However, that zero-delay timer
can fire while the page is in the middle of a navigation, which will cause the font
loads to fail. Then, the second page can request those same fonts, which are marked
as failed, and as such will never actually load/use the desired web font.

This patch just stops the zero-delay timer during navigations, and resumes it
when resuming the document. This means:

1. The second page in the above story will not see that the font has failed, or
even started, and will then re-request the font and load it successfully
2. If the user goes "back" to the previous page, the zero-delay timer is restarted,
the CachedFont realizes it's already succeeded, and the previous page is rendered
as expected.

Test: fast/loader/font-load-timer.html

---

Now the explanation of the failure it caused:
The font loading timer was a SuspendableTimer, which is an ActiveDOMObject.

An ActiveDOMObject was used to make sure the delayed font loads play well with the
page cache, which is still necessary.

But we also still need to suspend the timer manually when "stopLoading()" is called,
which doesn't play well with ActiveDOMObject's automatic suspend/resume.

My solution:
- Make the timer "just a normal timer"
- Make CSSFontSelector itself the ActiveDOMObject
- Let DocumentLoader explicitly pause the font load timer
- Rely on ActiveDOMObject to resume the timer

These keep the bug fixed and resolve the layout test ASSERT seen with
http/tests/security/navigate-when-restoring-cached-page.html

* css/CSSFontSelector.cpp:
(WebCore::CSSFontSelector::CSSFontSelector):
(WebCore::CSSFontSelector::clearDocument):
(WebCore::CSSFontSelector::beginLoadingFontSoon):
(WebCore::CSSFontSelector::suspendFontLoadingTimer):
(WebCore::CSSFontSelector::fontLoadingTimerFired):
(WebCore::CSSFontSelector::stop):
(WebCore::CSSFontSelector::suspend):
(WebCore::CSSFontSelector::resume):
(WebCore::CSSFontSelector::beginLoadTimerFired): Deleted.
* css/CSSFontSelector.h:
* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::stopLoading):

LayoutTests:

1) The page has some content that has “font-family: WebFont” but there are no @font-face blocks on the page
2) In script, after the page has loaded, add an @font-face rule to the page with “font-family: WebFont” and some valid font URL
3) Synchronously, within the same turn of the run loop, trigger a synchronous layout of the element (using offsetWidth or something). This will add the font to the 0-delay time work list.
4) Synchronously, within the same turn of the run loop, navigate to a second page that doesn’t use the web font.
5) The second page waits some small-but-positive amount of time. This will cause the 0-delay timer to fire, but because the page is in the middle of navigating, the font load should fail.
6) The second page adds the same @font-face rule to itself using script. This should pull the same (failed) CachedResource object out of the memory cache.
7) Use the CSS Font Loading API to wait for the font load to complete
8) Make sure that the font is used on the second page (as a reference test). Today, the second page’s font load will fail because it pulled the failed font out of the memory cache. The test makes sure the second page’s font load succeeds.

* fast/loader/font-load-timer-expected.html: Added.
* fast/loader/font-load-timer.html: Added.
* fast/loader/resources/font-load-timer-navigation-destination.html: Added.


Canonical link: https://commits.webkit.org/228618@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266148 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-08-25 22:08:51 +00:00
..
animated-image-subframe.html
animated-image.html
animated-image2.html
animated-image3.html
click-fragment-link.html
document-destruction-within-unload-iframe.html
document-destruction-within-unload.svg
document-with-fragment-url-test.html
early-load-cancel-inner.html
empty-document-goes-back.html
empty-script.js
empty-subframe.html
external-script-URL-location.js
fail-and-notify-done.html
font-load-timer-navigation-destination.html Font loads quickly followed by navigations may fail indefinitely 2020-08-25 22:08:51 +00:00
form-state-restore-with-frames-1.html
form-state-restore-with-locked-back-forward-list-2.html
form-state-restore-with-locked-back-forward-list-3.html
form-submission-before-load-page2.html
form-submission-before-load-page3.html
fragment-navigation-base-blank.html
frame-creation-removal-iframe.html
iframe-meta-refresh-base-blank.html
iframe-set-location-base-blank.html
iframe-with-beforeunload.html
image space.png
image@test.png
invalid-charset-on-script-crashes-loader.js
location-change-aborts-parsing-fail.html
location-change-aborts-parsing-pass.html
location-port-iframe.html
meta-redirect-to-notify-done.html
notify-done-with-window-count.html
notify-done.html
onunload-form-submit-failure.html
onunload-form-submit-success.html
page-dismissal-modal-dialogs-iframe.html
parent-of-redirect.html
pass-and-notify-done.html
ping-error-frame.html
ping-error-window.html
plain-text-document.txt
refresh-iframe-base-blank-frame.html
simultaneous-reloads-assert-frame.html
stylesheet.css
subframe-navigate-during-main-frame-load2.html
subframe-notify-done.html
subframe-self-close.html
subframe-success.html
subframe-that-removes-itself.html
subframe-with-subsubframe-with-unload-handler.html
subframe-with-unload-handler.html
submit-form-while-parsing-subframe.html
submit-form-while-parsing-success.html
success.js
text-document-wrapping.txt
unload-hyperlink-targeted-subframe.html
unschedule-relayout-after-unload-target.html
user-style-sheet.css
window-clearing2.html