Address NSWindow sometimes using WebKitTestRunnerEvent too early
authorap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Mar 2019 15:58:36 +0000 (15:58 +0000)
committerap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Mar 2019 15:58:36 +0000 (15:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196211
rdar://problem/49110552

Reviewed by Tim Horton.

* WebKitTestRunner/TestController.cpp: (WTR::TestController::initialize):
Make sure that EventSenderProxy always exists when running tests. We used to create
it when resetting before the first test, which is a bit too late.

* WebKitTestRunner/TestController.h:
* WebKitTestRunner/cocoa/TestControllerCocoa.mm:
(WTR::TestController::platformCreateWebView):
(WTR::TestController::platformCreateOtherPage):
(WTR::TestController::finishCreatingPlatformWebView):
* WebKitTestRunner/mac/PlatformWebViewMac.mm:
(WTR::PlatformWebView::PlatformWebView):
Moved some code that made NSWindow use NSEvent during web view creation. We may
need to move more if some other case us found, but this is enough for now.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243496 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/WebKitTestRunner/TestController.cpp
Tools/WebKitTestRunner/TestController.h
Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm
Tools/WebKitTestRunner/mac/PlatformWebViewMac.mm

index e3ebc0a..aa8c956 100644 (file)
@@ -1,3 +1,25 @@
+2019-03-25  Alexey Proskuryakov  <ap@apple.com>
+
+        Address NSWindow sometimes using WebKitTestRunnerEvent too early
+        https://bugs.webkit.org/show_bug.cgi?id=196211
+        rdar://problem/49110552
+
+        Reviewed by Tim Horton.
+
+        * WebKitTestRunner/TestController.cpp: (WTR::TestController::initialize):
+        Make sure that EventSenderProxy always exists when running tests. We used to create
+        it when resetting before the first test, which is a bit too late.
+
+        * WebKitTestRunner/TestController.h:
+        * WebKitTestRunner/cocoa/TestControllerCocoa.mm:
+        (WTR::TestController::platformCreateWebView):
+        (WTR::TestController::platformCreateOtherPage):
+        (WTR::TestController::finishCreatingPlatformWebView):
+        * WebKitTestRunner/mac/PlatformWebViewMac.mm:
+        (WTR::PlatformWebView::PlatformWebView):
+        Moved some code that made NSWindow use NSEvent during web view creation. We may
+        need to move more if some other case us found, but this is enough for now.
+
 2019-03-26  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         Unreviewed. Fix typo in GLib geolocation API after r243285.
index e8908fb..3b53123 100644 (file)
@@ -458,6 +458,8 @@ void TestController::initialize(int argc, const char* argv[])
 
     WKRetainPtr<WKStringRef> pageGroupIdentifier(AdoptWK, WKStringCreateWithUTF8CString("WebKitTestRunnerPageGroup"));
     m_pageGroup.adopt(WKPageGroupCreateWithIdentifier(pageGroupIdentifier.get()));
+
+    m_eventSenderProxy = std::make_unique<EventSenderProxy>(this);
 }
 
 WKRetainPtr<WKContextConfigurationRef> TestController::generateContextConfiguration(const TestOptions::ContextOptions& options) const
index 288749d..1847172 100644 (file)
@@ -453,6 +453,10 @@ private:
     static void runModal(WKPageRef, const void* clientInfo);
     static void runModal(PlatformWebView*);
 
+#if PLATFORM(COCOA)
+    static void finishCreatingPlatformWebView(PlatformWebView*, const TestOptions&);
+#endif
+
     static const char* libraryPathForTesting();
     static const char* platformLibraryPathForTesting();
 
index 5594338..6e8d944 100644 (file)
@@ -166,6 +166,7 @@ void TestController::platformCreateWebView(WKPageConfigurationRef, const TestOpt
     }
 
     m_mainWebView = std::make_unique<PlatformWebView>(copiedConfiguration.get(), options);
+    finishCreatingPlatformWebView(m_mainWebView.get(), options);
 
     if (options.punchOutWhiteBackgroundsInDarkMode)
         m_mainWebView->setDrawsBackground(false);
@@ -178,7 +179,20 @@ PlatformWebView* TestController::platformCreateOtherPage(PlatformWebView* parent
 {
     WKWebViewConfiguration *newConfiguration = [[globalWebViewConfiguration copy] autorelease];
     newConfiguration._relatedWebView = static_cast<WKWebView*>(parentView->platformView());
-    return new PlatformWebView(newConfiguration, options);
+    PlatformWebView* view = new PlatformWebView(newConfiguration, options);
+    finishCreatingPlatformWebView(view, options);
+    return view;
+}
+
+// Code that needs to run after TestController::m_mainWebView is initialized goes into this function.
+void TestController::finishCreatingPlatformWebView(PlatformWebView* view, const TestOptions& options)
+{
+#if PLATFORM(MAC)
+    if (options.shouldShowWebView)
+        [view->platformWindow() orderFront:nil];
+    else
+        [view->platformWindow() orderBack:nil];
+#endif
 }
 
 WKContextRef TestController::platformAdjustContext(WKContextRef context, WKContextConfigurationRef contextConfiguration)
index a887082..2f4a5ea 100644 (file)
@@ -80,10 +80,6 @@ PlatformWebView::PlatformWebView(WKWebViewConfiguration* configuration, const Te
     [m_window setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameAqua]];
     [m_window setCollectionBehavior:NSWindowCollectionBehaviorStationary];
     [[m_window contentView] addSubview:m_view];
-    if (m_options.shouldShowWebView)
-        [m_window orderFront:nil];
-    else
-        [m_window orderBack:nil];
     [m_window setReleasedWhenClosed:NO];
 }