Title: [256403] branches/safari-609-branch/Tools
Revision
256403
Author
[email protected]
Date
2020-02-11 16:59:33 -0800 (Tue, 11 Feb 2020)

Log Message

Cherry-pick r255826. rdar://problem/59299115

    REGRESSION(r255595): page not closed after beforeunload handler returns true
    https://bugs.webkit.org/show_bug.cgi?id=207189
    <rdar://problem/59149593>

    Reviewed by Youenn Fablet.

    Add API test coverage for fix landed in r255677.

    * TestWebKitAPI/Tests/WebKitCocoa/ModalAlerts.mm:
    (-[SlowBeforeUnloadPromptUIDelegate _webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:completionHandler:]):
    (TEST):

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

Modified Paths

Diff

Modified: branches/safari-609-branch/Tools/ChangeLog (256402 => 256403)


--- branches/safari-609-branch/Tools/ChangeLog	2020-02-12 00:59:29 UTC (rev 256402)
+++ branches/safari-609-branch/Tools/ChangeLog	2020-02-12 00:59:33 UTC (rev 256403)
@@ -1,5 +1,37 @@
 2020-02-11  Alan Coon  <[email protected]>
 
+        Cherry-pick r255826. rdar://problem/59299115
+
+    REGRESSION(r255595): page not closed after beforeunload handler returns true
+    https://bugs.webkit.org/show_bug.cgi?id=207189
+    <rdar://problem/59149593>
+    
+    Reviewed by Youenn Fablet.
+    
+    Add API test coverage for fix landed in r255677.
+    
+    * TestWebKitAPI/Tests/WebKitCocoa/ModalAlerts.mm:
+    (-[SlowBeforeUnloadPromptUIDelegate _webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:completionHandler:]):
+    (TEST):
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@255826 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-02-05  Chris Dumez  <[email protected]>
+
+            REGRESSION(r255595): page not closed after beforeunload handler returns true
+            https://bugs.webkit.org/show_bug.cgi?id=207189
+            <rdar://problem/59149593>
+
+            Reviewed by Youenn Fablet.
+
+            Add API test coverage for fix landed in r255677.
+
+            * TestWebKitAPI/Tests/WebKitCocoa/ModalAlerts.mm:
+            (-[SlowBeforeUnloadPromptUIDelegate _webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:completionHandler:]):
+            (TEST):
+
+2020-02-11  Alan Coon  <[email protected]>
+
         Cherry-pick r255595. rdar://problem/59298183
 
     Regression(r253224) WKUIDelegate.webViewDidClose may get called twice after calling _tryClose on the WKWebView

Modified: branches/safari-609-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ModalAlerts.mm (256402 => 256403)


--- branches/safari-609-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ModalAlerts.mm	2020-02-12 00:59:29 UTC (rev 256402)
+++ branches/safari-609-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ModalAlerts.mm	2020-02-12 00:59:33 UTC (rev 256403)
@@ -145,7 +145,8 @@
 
 #if PLATFORM(MAC)
 
-static bool didRejectTryClose = false;
+static bool shouldRejectClosingViaPrompt = false;
+static bool didRespondToPrompt = false;
 
 @interface SlowBeforeUnloadPromptUIDelegate : NSObject <WKUIDelegate>
 @end
@@ -155,8 +156,8 @@
 - (void)_webView:(WKWebView *)webView runBeforeUnloadConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler
 {
     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
-        completionHandler(NO);
-        didRejectTryClose = true;
+        completionHandler(shouldRejectClosingViaPrompt ? NO : YES);
+        didRespondToPrompt = true;
     });
 }
 
@@ -167,7 +168,7 @@
 
 @end
 
-TEST(WebKit, SlowBeforeUnloadPrompt)
+TEST(WebKit, SlowBeforeUnloadPromptReject)
 {
     auto slowBeforeUnloadPromptUIDelegate = adoptNS([[SlowBeforeUnloadPromptUIDelegate alloc] init]);
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
@@ -181,9 +182,10 @@
 
     TestWebKitAPI::Util::spinRunLoop(10);
 
+    shouldRejectClosingViaPrompt = true;
     [webView _tryClose];
 
-    TestWebKitAPI::Util::run(&didRejectTryClose);
+    TestWebKitAPI::Util::run(&didRespondToPrompt);
     EXPECT_FALSE([webView _isClosed]);
 
     TestWebKitAPI::Util::sleep(0.1);
@@ -190,6 +192,29 @@
     EXPECT_FALSE([webView _isClosed]);
 }
 
+TEST(WebKit, SlowBeforeUnloadPromptAllow)
+{
+    auto slowBeforeUnloadPromptUIDelegate = adoptNS([[SlowBeforeUnloadPromptUIDelegate alloc] init]);
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+    [webView setUIDelegate:slowBeforeUnloadPromptUIDelegate.get()];
+    [webView synchronouslyLoadTestPageNamed:@"beforeunload"];
+
+    TestWebKitAPI::Util::spinRunLoop(10);
+
+    // Need a user gesture on the page before being allowed to show the beforeunload prompt.
+    [webView sendClicksAtPoint:NSMakePoint(5, 5) numberOfClicks:1];
+
+    TestWebKitAPI::Util::spinRunLoop(10);
+
+    shouldRejectClosingViaPrompt = false;
+    [webView _tryClose];
+
+    TestWebKitAPI::Util::run(&didRespondToPrompt);
+
+    while (![webView _isClosed])
+        TestWebKitAPI::Util::sleep(0.1);
+}
+
 static bool webViewDidCloseCalled = false;
 static unsigned viewDidCloseCallCount = 0;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to