Title: [276912] trunk/Tools
Revision
276912
Author
[email protected]
Date
2021-05-03 11:35:23 -0700 (Mon, 03 May 2021)

Log Message

editing/selection/ios/become-key-window-when-focusing-editable-area.html is timing out
https://bugs.webkit.org/show_bug.cgi?id=225274
rdar://77042575

Reviewed by Tim Horton.

This test is timing out on recent versions of iOS because the `-becomeKeyWindow` subclassing hook is no longer
invoked when calling `-makeKeyWindow`, in the case where the `UIWindow` was already the key window. The iOS
version of WebKitTestRunner on iOS was dependent on this behavior because `setWindowIsKey(false)` on
`PlatformWebView` did not actually cause the test runner window to resign from being the key window. Instead, it
only set the boolean flag `PlatformWebView::m_windowIsKey`, which `WebKitTestRunnerWindow` then uses to override
the value of `-[WebKitTestRunnerWindow isKeyWindow]` (effectively side-stepping platform key window state).

We can fix this by refactoring `PlatformWebView::setWindowIsKey` to actually make the `WebKitTestRunnerWindow`
resign key window when calling `setWindowIsKey(false)`. Compared to macOS, doing this on iOS is a bit tricky
since `-[UIWindow resignKeyWindow]` is purely a subclassing hook that is invoked when the window loses its
status as the key window. However, we can work around this limitation by creating a separate `UIWindow` and
making that window key instead (which implicitly makes our current `WebKitTestRunnerWindow` resign key window).

* WebKitTestRunner/PlatformWebView.h:
* WebKitTestRunner/ios/PlatformWebViewIOS.mm:
(WTR::PlatformWebView::setWindowIsKey):

Install the other `UIWindow` and make it key in order to resign the current key window. Note that this window is
placed just offscreen, so that simulated taps and other gestures will continue to go to the original window.

(-[WebKitTestRunnerWindow isKeyWindow]): Deleted.

Stop overriding the platform key window state with the simulated test runner state, since we now correctly
update platform key window state when setting `m_windowIsKey`. This adjustment is also necessary to ensure that
we actually end up in the `!isKey && m_window.keyWindow` case above.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (276911 => 276912)


--- trunk/Tools/ChangeLog	2021-05-03 18:22:27 UTC (rev 276911)
+++ trunk/Tools/ChangeLog	2021-05-03 18:35:23 UTC (rev 276912)
@@ -1,3 +1,37 @@
+2021-05-03  Wenson Hsieh  <[email protected]>
+
+        editing/selection/ios/become-key-window-when-focusing-editable-area.html is timing out
+        https://bugs.webkit.org/show_bug.cgi?id=225274
+        rdar://77042575
+
+        Reviewed by Tim Horton.
+
+        This test is timing out on recent versions of iOS because the `-becomeKeyWindow` subclassing hook is no longer
+        invoked when calling `-makeKeyWindow`, in the case where the `UIWindow` was already the key window. The iOS
+        version of WebKitTestRunner on iOS was dependent on this behavior because `setWindowIsKey(false)` on
+        `PlatformWebView` did not actually cause the test runner window to resign from being the key window. Instead, it
+        only set the boolean flag `PlatformWebView::m_windowIsKey`, which `WebKitTestRunnerWindow` then uses to override
+        the value of `-[WebKitTestRunnerWindow isKeyWindow]` (effectively side-stepping platform key window state).
+
+        We can fix this by refactoring `PlatformWebView::setWindowIsKey` to actually make the `WebKitTestRunnerWindow`
+        resign key window when calling `setWindowIsKey(false)`. Compared to macOS, doing this on iOS is a bit tricky
+        since `-[UIWindow resignKeyWindow]` is purely a subclassing hook that is invoked when the window loses its
+        status as the key window. However, we can work around this limitation by creating a separate `UIWindow` and
+        making that window key instead (which implicitly makes our current `WebKitTestRunnerWindow` resign key window).
+
+        * WebKitTestRunner/PlatformWebView.h:
+        * WebKitTestRunner/ios/PlatformWebViewIOS.mm:
+        (WTR::PlatformWebView::setWindowIsKey):
+
+        Install the other `UIWindow` and make it key in order to resign the current key window. Note that this window is
+        placed just offscreen, so that simulated taps and other gestures will continue to go to the original window.
+
+        (-[WebKitTestRunnerWindow isKeyWindow]): Deleted.
+
+        Stop overriding the platform key window state with the simulated test runner state, since we now correctly
+        update platform key window state when setting `m_windowIsKey`. This adjustment is also necessary to ensure that
+        we actually end up in the `!isKey && m_window.keyWindow` case above.
+
 2021-05-03  Jonathan Bedard  <[email protected]>
 
         [webkitcorepy] Pass logging level to child processes

Modified: trunk/Tools/WebKitTestRunner/PlatformWebView.h (276911 => 276912)


--- trunk/Tools/WebKitTestRunner/PlatformWebView.h	2021-05-03 18:22:27 UTC (rev 276911)
+++ trunk/Tools/WebKitTestRunner/PlatformWebView.h	2021-05-03 18:35:23 UTC (rev 276912)
@@ -33,6 +33,7 @@
 #include <wtf/RetainPtr.h>
 OBJC_CLASS NSView;
 OBJC_CLASS UIView;
+OBJC_CLASS UIWindow;
 OBJC_CLASS TestRunnerWKWebView;
 OBJC_CLASS WKWebViewConfiguration;
 OBJC_CLASS WebKitTestRunnerWindow;
@@ -133,6 +134,9 @@
     PlatformWindow m_window;
     bool m_windowIsKey;
     const TestOptions m_options;
+#if PLATFORM(IOS_FAMILY)
+    RetainPtr<UIWindow> m_otherWindow;
+#endif
 #if PLATFORM(GTK)
     GtkWidget* m_otherWindow { nullptr };
 #endif

Modified: trunk/Tools/WebKitTestRunner/ios/PlatformWebViewIOS.mm (276911 => 276912)


--- trunk/Tools/WebKitTestRunner/ios/PlatformWebViewIOS.mm	2021-05-03 18:22:27 UTC (rev 276911)
+++ trunk/Tools/WebKitTestRunner/ios/PlatformWebViewIOS.mm	2021-05-03 18:35:23 UTC (rev 276912)
@@ -91,11 +91,6 @@
     [super dealloc];
 }
 
-- (BOOL)isKeyWindow
-{
-    return [super isKeyWindow] && (_platformWebView ? _platformWebView->windowIsKey() : YES);
-}
-
 - (void)setFrameOrigin:(CGPoint)point
 {
     _fakeOrigin = point;
@@ -240,8 +235,24 @@
 void PlatformWebView::setWindowIsKey(bool isKey)
 {
     m_windowIsKey = isKey;
-    if (isKey && !m_window.keyWindow)
+
+    if (isKey && !m_window.keyWindow) {
+        [m_otherWindow setHidden:YES];
         [m_window makeKeyWindow];
+        return;
+    }
+
+    if (!isKey && m_window.keyWindow) {
+        if (!m_otherWindow) {
+            m_otherWindow = adoptNS([[UIWindow alloc] initWithWindowScene:m_window.windowScene]);
+            [m_otherWindow setFrame:CGRectMake(-1, -1, 1, 1)];
+        }
+        // On iOS, there's no API to force a UIWindow to resign key window. However, we can instead
+        // cause the test runner window to resign key window by making a different window (in this
+        // case, m_otherWindow) the key window.
+        [m_otherWindow setHidden:NO];
+        [m_otherWindow makeKeyWindow];
+    }
 }
 
 void PlatformWebView::addToWindow()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to