Changeset 255826 in webkit


Ignore:
Timestamp:
Feb 5, 2020 10:08:54 AM (4 years ago)
Author:
Chris Dumez
Message:

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):

Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r255813 r255826  
     12020-02-05  Chris Dumez  <cdumez@apple.com>
     2
     3        REGRESSION(r255595): page not closed after beforeunload handler returns true
     4        https://bugs.webkit.org/show_bug.cgi?id=207189
     5        <rdar://problem/59149593>
     6
     7        Reviewed by Youenn Fablet.
     8
     9        Add API test coverage for fix landed in r255677.
     10
     11        * TestWebKitAPI/Tests/WebKitCocoa/ModalAlerts.mm:
     12        (-[SlowBeforeUnloadPromptUIDelegate _webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:completionHandler:]):
     13        (TEST):
     14
    1152020-02-05  Jonathan Bedard  <jbedard@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ModalAlerts.mm

    r255595 r255826  
    146146#if PLATFORM(MAC)
    147147
    148 static bool didRejectTryClose = false;
     148static bool shouldRejectClosingViaPrompt = false;
     149static bool didRespondToPrompt = false;
    149150
    150151@interface SlowBeforeUnloadPromptUIDelegate : NSObject <WKUIDelegate>
     
    156157{
    157158    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
    158         completionHandler(NO);
    159         didRejectTryClose = true;
     159        completionHandler(shouldRejectClosingViaPrompt ? NO : YES);
     160        didRespondToPrompt = true;
    160161    });
    161162}
     
    168169@end
    169170
    170 TEST(WebKit, SlowBeforeUnloadPrompt)
     171TEST(WebKit, SlowBeforeUnloadPromptReject)
    171172{
    172173    auto slowBeforeUnloadPromptUIDelegate = adoptNS([[SlowBeforeUnloadPromptUIDelegate alloc] init]);
     
    182183    TestWebKitAPI::Util::spinRunLoop(10);
    183184
     185    shouldRejectClosingViaPrompt = true;
    184186    [webView _tryClose];
    185187
    186     TestWebKitAPI::Util::run(&didRejectTryClose);
     188    TestWebKitAPI::Util::run(&didRespondToPrompt);
    187189    EXPECT_FALSE([webView _isClosed]);
    188190
    189191    TestWebKitAPI::Util::sleep(0.1);
    190192    EXPECT_FALSE([webView _isClosed]);
     193}
     194
     195TEST(WebKit, SlowBeforeUnloadPromptAllow)
     196{
     197    auto slowBeforeUnloadPromptUIDelegate = adoptNS([[SlowBeforeUnloadPromptUIDelegate alloc] init]);
     198    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
     199    [webView setUIDelegate:slowBeforeUnloadPromptUIDelegate.get()];
     200    [webView synchronouslyLoadTestPageNamed:@"beforeunload"];
     201
     202    TestWebKitAPI::Util::spinRunLoop(10);
     203
     204    // Need a user gesture on the page before being allowed to show the beforeunload prompt.
     205    [webView sendClicksAtPoint:NSMakePoint(5, 5) numberOfClicks:1];
     206
     207    TestWebKitAPI::Util::spinRunLoop(10);
     208
     209    shouldRejectClosingViaPrompt = false;
     210    [webView _tryClose];
     211
     212    TestWebKitAPI::Util::run(&didRespondToPrompt);
     213
     214    while (![webView _isClosed])
     215        TestWebKitAPI::Util::sleep(0.1);
    191216}
    192217
Note: See TracChangeset for help on using the changeset viewer.