Changeset 204243 in webkit


Ignore:
Timestamp:
Aug 7, 2016 12:08:01 PM (8 years ago)
Author:
Chris Dumez
Message:

Write API test to cover crash fix in r204135
https://bugs.webkit.org/show_bug.cgi?id=160587

Reviewed by Darin Adler.

Source/WebKit2:

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::terminateProcess):
Stop calling resetStateAfterProcessExited() after calling
requestTermination() because requestTermination() now calls
didClose() which calls processDidCrash() which already calls
resetStateAfterProcessExited(). Because the processDidCrash()
delegates may start new loads, we really do not want to
reset the state again after calling the delegates.

  • UIProcess/WebProcessProxy.cpp:

(WebKit::WebProcessProxy::requestTermination):

  • Call didClose() in WebProcessProxy::requestTermination() so that the processDidCrash() delegates get called in API tests whenever a WebContent process is terminated to simulate a crash.
  • Stop calling shutDown() and webConnection()->didClose() because didClose() already does this for us.

Tools:

Add API test to cover crash fix in r204135. This reproduces the crash
by destroying a related WKWebView in the webViewWebContentProcessDidTerminate
callback.

  • TestWebKitAPI/Tests/WebKit2Cocoa/Navigation.mm:

(-[NavigationDelegate webViewWebContentProcessDidTerminate:]):
(TEST):

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r204238 r204243  
     12016-08-07  Chris Dumez  <cdumez@apple.com>
     2
     3        Write API test to cover crash fix in r204135
     4        https://bugs.webkit.org/show_bug.cgi?id=160587
     5
     6        Reviewed by Darin Adler.
     7
     8        * UIProcess/WebPageProxy.cpp:
     9        (WebKit::WebPageProxy::terminateProcess):
     10        Stop calling resetStateAfterProcessExited() after calling
     11        requestTermination() because requestTermination() now calls
     12        didClose() which calls processDidCrash() which already calls
     13        resetStateAfterProcessExited(). Because the processDidCrash()
     14        delegates may start new loads, we really do not want to
     15        reset the state again after calling the delegates.
     16
     17        * UIProcess/WebProcessProxy.cpp:
     18        (WebKit::WebProcessProxy::requestTermination):
     19        - Call didClose() in WebProcessProxy::requestTermination() so that
     20          the processDidCrash() delegates get called in API tests whenever
     21          a WebContent process is terminated to simulate a crash.
     22        - Stop calling shutDown() and webConnection()->didClose() because
     23          didClose() already does this for us.
     24
    1252016-08-06  Chris Dumez  <cdumez@apple.com>
    226
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp

    r204135 r204243  
    23542354
    23552355    m_process->requestTermination();
    2356     resetStateAfterProcessExited();
    23572356}
    23582357
  • trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp

    r204238 r204243  
    805805    ChildProcessProxy::terminate();
    806806
    807     if (webConnection())
    808         webConnection()->didClose();
    809 
    810     shutDown();
     807    didClose(*connection());
    811808}
    812809
  • trunk/Tools/ChangeLog

    r204238 r204243  
     12016-08-07  Chris Dumez  <cdumez@apple.com>
     2
     3        Write API test to cover crash fix in r204135
     4        https://bugs.webkit.org/show_bug.cgi?id=160587
     5
     6        Reviewed by Darin Adler.
     7
     8        Add API test to cover crash fix in r204135. This reproduces the crash
     9        by destroying a related WKWebView in the webViewWebContentProcessDidTerminate
     10        callback.
     11
     12        * TestWebKitAPI/Tests/WebKit2Cocoa/Navigation.mm:
     13        (-[NavigationDelegate webViewWebContentProcessDidTerminate:]):
     14        (TEST):
     15
    1162016-08-06  Chris Dumez  <cdumez@apple.com>
    217
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/Navigation.mm

    r204238 r204243  
    2828#import <WebKit/WKNavigationPrivate.h>
    2929#import <WebKit/WKNavigationDelegate.h>
     30#import <WebKit/WKProcessPoolPrivate.h>
    3031#import <WebKit/WKWebView.h>
     32#import <WebKit/WKWebViewConfigurationPrivate.h>
     33#import <WebKit/WKWebViewPrivate.h>
     34#import <WebKit/_WKProcessPoolConfiguration.h>
    3135#import <wtf/RetainPtr.h>
    3236#import "PlatformUtilities.h"
     
    3640
    3741static bool isDone;
     42static std::function<void()> crashHandler;
    3843static RetainPtr<WKNavigation> currentNavigation;
    3944
     
    5964
    6065    isDone = true;
     66}
     67
     68- (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView
     69{
     70    crashHandler();
    6171}
    6272
     
    188198}
    189199
     200TEST(WKNavigation, WebContentProcessDidTerminate)
     201{
     202    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     203    RetainPtr<_WKProcessPoolConfiguration> poolConfiguration = adoptNS([[_WKProcessPoolConfiguration alloc] init]);
     204    poolConfiguration.get().maximumProcessCount = 1;
     205    RetainPtr<WKProcessPool> processPool = adoptNS([[WKProcessPool alloc] _initWithConfiguration:poolConfiguration.get()]);
     206
     207    RetainPtr<WKWebViewConfiguration> configuration1 = adoptNS([[WKWebViewConfiguration alloc] init]);
     208    configuration1.get().processPool = processPool.get();
     209    RetainPtr<WKWebView> webView1 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration1.get()]);
     210
     211    RetainPtr<NavigationDelegate> delegate1 = adoptNS([[NavigationDelegate alloc] init]);
     212    [webView1 setNavigationDelegate:delegate1.get()];
     213
     214    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,1"]];
     215
     216    isDone = false;
     217    currentNavigation = [webView1 loadRequest:request];
     218    TestWebKitAPI::Util::run(&isDone);
     219
     220    RetainPtr<WKWebViewConfiguration> configuration2 = adoptNS([[WKWebViewConfiguration alloc] init]);
     221    configuration2.get().processPool = processPool.get();
     222    configuration2.get()._relatedWebView = webView1.get();
     223    RetainPtr<WKWebView> webView2 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration2.get()]);
     224
     225    RetainPtr<NavigationDelegate> delegate2 = adoptNS([[NavigationDelegate alloc] init]);
     226    [webView2 setNavigationDelegate:delegate2.get()];
     227
     228    isDone = false;
     229    currentNavigation = [webView2 loadRequest:request];
     230    TestWebKitAPI::Util::run(&isDone);
     231
     232    bool didTerminate = false;
     233    crashHandler = [&] {
     234        webView1 = nullptr;
     235        webView2 = nullptr;
     236        [pool drain]; // Make sure the views get deallocated.
     237        didTerminate = true;
     238    };
     239
     240    [webView2 _killWebContentProcessAndResetState];
     241    TestWebKitAPI::Util::run(&didTerminate);
     242}
     243
    190244#endif
Note: See TracChangeset for help on using the changeset viewer.