Skip to content

Commit

Permalink
REGRESSION(275943@main) TestWebKitAPI tests timing out
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=270875
rdar://124475961

Reviewed by Ben Nham and Chris Dumez.

TestWebKitAPI, when running against iOS, is not a "real" UI application. As such, the UIWindows
it creates are not associated with any UIWindowScene. This breaks the foreground/background checking
logic in ApplicationStateTracker.

Update ApplicationStateTracker to treat the view as "not background" if it has a UIWindow but no
UIScene.

* Source/WebKit/UIProcess/ApplicationStateTracker.mm:
(WebKit::ApplicationStateTracker::setScene):

Canonical link: https://commits.webkit.org/276009@main
  • Loading branch information
jernoble authored and cdumez committed Mar 12, 2024
1 parent 3134d8e commit c5fa77c
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions Source/WebKit/UIProcess/ApplicationStateTracker.mm
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,21 @@ ApplicationType applicationType(UIWindow *window)

void ApplicationStateTracker::setScene(UIScene *scene)
{
if (m_scene.get() == scene)
auto isWindowAndSceneInBackground = [] (const auto& window, const auto& scene) {
if (!scene) {
// TestWebKitAPI will create a WKWebView and place it into a UIWindow that
// has no UIWindowScene. For the purposes of keeping tests passing, treat
// the combination of a window without a windowScene as not in the background:
return !window;
}

return [scene activationState] == UISceneActivationStateBackground || [scene activationState] == UISceneActivationStateUnattached;
};

if (m_scene.get() == scene) {
m_isInBackground = isWindowAndSceneInBackground(m_window, m_scene);
return;
}

NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];

Expand All @@ -239,13 +252,11 @@ ApplicationType applicationType(UIWindow *window)
}

m_scene = scene;
m_isInBackground = isWindowAndSceneInBackground(m_window, m_scene);

if (!m_scene) {
m_isInBackground = true;
if (!m_scene)
return;
}

m_isInBackground = scene.activationState == UISceneActivationStateBackground || scene.activationState == UISceneActivationStateUnattached;
RELEASE_LOG(ViewState, "%p - ApplicationStateTracker::ApplicationStateTracker(): m_isInBackground=%d", this, m_isInBackground);

m_didEnterBackgroundObserver = [notificationCenter addObserverForName:UISceneDidEnterBackgroundNotification object:scene queue:nil usingBlock:[this](NSNotification *notification) {
Expand Down

0 comments on commit c5fa77c

Please sign in to comment.