[iOS] Crash under -[TestRunnerWKWebView _didShowMenu] while running layout tests...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Mar 2019 23:09:40 +0000 (23:09 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Mar 2019 23:09:40 +0000 (23:09 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195810

Reviewed by Tim Horton.

Ensure that the process of resetting web view state between tests doesn't also invoke testing callbacks
registered by the previous layout test. This fixes an occasional crash when hiding the callout menu after
ending certain layout tests.

* WebKitTestRunner/cocoa/TestRunnerWKWebView.h:
* WebKitTestRunner/cocoa/TestRunnerWKWebView.mm:
(-[TestRunnerWKWebView dealloc]):
(-[TestRunnerWKWebView resetInteractionCallbacks]):

Pull logic to reset all of TestRunnerWKWebView's callback handler blocks into a separate helper method; use this
helper method when destroying the web view, and when resetting state between tests.

* WebKitTestRunner/ios/TestControllerIOS.mm:
(WTR::TestController::platformResetStateToConsistentValues):

Hide the callout menu *after* clearing out interaction callbacks registered on the web view.

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

Tools/ChangeLog
Tools/WebKitTestRunner/cocoa/TestRunnerWKWebView.h
Tools/WebKitTestRunner/cocoa/TestRunnerWKWebView.mm
Tools/WebKitTestRunner/ios/TestControllerIOS.mm

index b44d773..c9aa80f 100644 (file)
@@ -1,3 +1,27 @@
+2019-03-15  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [iOS] Crash under -[TestRunnerWKWebView _didShowMenu] while running layout tests on iOS simulator
+        https://bugs.webkit.org/show_bug.cgi?id=195810
+
+        Reviewed by Tim Horton.
+
+        Ensure that the process of resetting web view state between tests doesn't also invoke testing callbacks
+        registered by the previous layout test. This fixes an occasional crash when hiding the callout menu after
+        ending certain layout tests.
+
+        * WebKitTestRunner/cocoa/TestRunnerWKWebView.h:
+        * WebKitTestRunner/cocoa/TestRunnerWKWebView.mm:
+        (-[TestRunnerWKWebView dealloc]):
+        (-[TestRunnerWKWebView resetInteractionCallbacks]):
+
+        Pull logic to reset all of TestRunnerWKWebView's callback handler blocks into a separate helper method; use this
+        helper method when destroying the web view, and when resetting state between tests.
+
+        * WebKitTestRunner/ios/TestControllerIOS.mm:
+        (WTR::TestController::platformResetStateToConsistentValues):
+
+        Hide the callout menu *after* clearing out interaction callbacks registered on the web view.
+
 2019-03-15  Sihui Liu  <sihui_liu@apple.com>
 
         [ Mojave WK1 ] Layout Test storage/indexeddb/database-odd-names.html is failing
index 9bf4dfd..bcd62df 100644 (file)
@@ -47,6 +47,7 @@
 @property (nonatomic, copy) void (^rotationDidEndCallback)(void);
 @property (nonatomic, copy) NSString *accessibilitySpeakSelectionContent;
 
+- (void)resetInteractionCallbacks;
 - (void)zoomToScale:(double)scale animated:(BOOL)animated completionHandler:(void (^)(void))completionHandler;
 - (void)accessibilityRetrieveSpeakSelectionContentWithCompletionHandler:(void (^)(void))completionHandler;
 - (void)_didEndRotation;
index 60895ec..14d5d59 100644 (file)
@@ -88,18 +88,7 @@ IGNORE_WARNINGS_END
 {
     [[NSNotificationCenter defaultCenter] removeObserver:self];
 
-    self.didStartFormControlInteractionCallback = nil;
-    self.didEndFormControlInteractionCallback = nil;
-    self.didShowForcePressPreviewCallback = nil;
-    self.didDismissForcePressPreviewCallback = nil;
-    self.willBeginZoomingCallback = nil;
-    self.didEndZoomingCallback = nil;
-    self.didShowKeyboardCallback = nil;
-    self.didHideKeyboardCallback = nil;
-    self.didShowMenuCallback = nil;
-    self.didHideMenuCallback = nil;
-    self.didEndScrollingCallback = nil;
-    self.rotationDidEndCallback = nil;
+    [self resetInteractionCallbacks];
 
     self.zoomToScaleCompletionHandler = nil;
     self.retrieveSpeakSelectionContentCompletionHandler = nil;
@@ -140,6 +129,22 @@ IGNORE_WARNINGS_END
         self.didDismissForcePressPreviewCallback();
 }
 
+- (void)resetInteractionCallbacks
+{
+    self.didStartFormControlInteractionCallback = nil;
+    self.didEndFormControlInteractionCallback = nil;
+    self.didShowForcePressPreviewCallback = nil;
+    self.didDismissForcePressPreviewCallback = nil;
+    self.willBeginZoomingCallback = nil;
+    self.didEndZoomingCallback = nil;
+    self.didShowKeyboardCallback = nil;
+    self.didHideKeyboardCallback = nil;
+    self.didShowMenuCallback = nil;
+    self.didHideMenuCallback = nil;
+    self.didEndScrollingCallback = nil;
+    self.rotationDidEndCallback = nil;
+}
+
 - (void)zoomToScale:(double)scale animated:(BOOL)animated completionHandler:(void (^)(void))completionHandler
 {
     ASSERT(!self.zoomToScaleCompletionHandler);
index ff1d6e7..d4058f3 100644 (file)
@@ -135,7 +135,6 @@ void TestController::platformResetStateToConsistentValues(const TestOptions& opt
 {
     cocoaResetStateToConsistentValues(options);
 
-    UIMenuController.sharedMenuController.menuVisible = NO;
     [[UIApplication sharedApplication] _cancelAllTouches];
     [[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait animated:NO];
 
@@ -151,6 +150,7 @@ void TestController::platformResetStateToConsistentValues(const TestOptions& opt
         webView.overrideSafeAreaInsets = UIEdgeInsetsZero;
         [webView _clearOverrideLayoutParameters];
         [webView _clearInterfaceOrientationOverride];
+        [webView resetInteractionCallbacks];
 
         UIScrollView *scrollView = webView.scrollView;
         [scrollView _removeAllAnimations:YES];
@@ -162,6 +162,8 @@ void TestController::platformResetStateToConsistentValues(const TestOptions& opt
             shouldRestoreFirstResponder = [webView resignFirstResponder];
     }
 
+    UIMenuController.sharedMenuController.menuVisible = NO;
+
     runUntil(isDoneWaitingForKeyboardToDismiss, m_currentInvocation->shortTimeout());
     runUntil(isDoneWaitingForMenuToDismiss, m_currentInvocation->shortTimeout());