Title: [231645] branches/safari-605-branch
Revision
231645
Author
[email protected]
Date
2018-05-10 10:43:48 -0700 (Thu, 10 May 2018)

Log Message

Apply patch. rdar://problem/39987479

    Load hangs if the WebProcess fails to launch https://bugs.webkit.org/show_bug.cgi?id=185225 <rdar://problem/38249058>

    Reviewed by Geoff Garen.

    Source/WebKit:

    When a process fails to launch, ChildProcessProxy::didFinishLaunching() gets called with an
    invalid connection identifier. While NetworkProcessProxy::didFinishLaunching() properly deals with
    this situation, WebProcessProxy::didFinishLaunching() does not. As a result, we do not attempt to
    relaunch the process, we do not notify the client and WebPageProxy::m_isValid stays true.

    This patch thus updates WebProcessProxy::didFinishLaunching() to check if the connection identifier
    is valid and treats it as a crash. As a result, the WebPageProxies properly reset their state and
    the client gets notified of the crash so that it can attempt to reload.

    * UIProcess/API/Cocoa/WKProcessPool.mm:
    (-[WKProcessPool _makeNextWebProcessLaunchFailForTesting]):
    * UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
    * UIProcess/Launcher/ProcessLauncher.h:
    * UIProcess/Launcher/mac/ProcessLauncherMac.mm:
    (WebKit::ProcessLauncher::launchProcess):
    Add SPI to make the next WebProcess launch fail, for the purpose of API testing.

    * UIProcess/WebProcessPool.h:
    * UIProcess/WebProcessProxy.cpp:
    (WebKit::WebProcessProxy::getLaunchOptions):
    (WebKit::WebProcessProxy::didClose):
    (WebKit::WebProcessProxy::processDidTerminateOrFailedToLaunch):
    (WebKit::WebProcessProxy::didFinishLaunching):
    * UIProcess/WebProcessProxy.h:

    Tools:

    Add API test coverage.

    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
    * TestWebKitAPI/Tests/WebKitCocoa/WebContentProcessDidTerminate.mm: Added.
    (-[CrashOnStartNavigationDelegate _webView:webContentProcessDidTerminateWithReason:]):
    (-[CrashOnStartNavigationDelegate webView:didFinishNavigation:]):
    (-[CrashRecoveryScriptMessageHandler userContentController:didReceiveScriptMessage:]):
    (TEST):

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

Modified Paths

Added Paths

Diff

Modified: branches/safari-605-branch/Source/WebKit/ChangeLog (231644 => 231645)


--- branches/safari-605-branch/Source/WebKit/ChangeLog	2018-05-10 17:37:43 UTC (rev 231644)
+++ branches/safari-605-branch/Source/WebKit/ChangeLog	2018-05-10 17:43:48 UTC (rev 231645)
@@ -1,3 +1,84 @@
+2018-05-10  Jason Marcell  <[email protected]>
+
+        Apply patch. rdar://problem/39987479
+
+    Load hangs if the WebProcess fails to launch https://bugs.webkit.org/show_bug.cgi?id=185225 <rdar://problem/38249058>
+    
+    Reviewed by Geoff Garen.
+    
+    Source/WebKit:
+    
+    When a process fails to launch, ChildProcessProxy::didFinishLaunching() gets called with an
+    invalid connection identifier. While NetworkProcessProxy::didFinishLaunching() properly deals with
+    this situation, WebProcessProxy::didFinishLaunching() does not. As a result, we do not attempt to
+    relaunch the process, we do not notify the client and WebPageProxy::m_isValid stays true.
+    
+    This patch thus updates WebProcessProxy::didFinishLaunching() to check if the connection identifier
+    is valid and treats it as a crash. As a result, the WebPageProxies properly reset their state and
+    the client gets notified of the crash so that it can attempt to reload.
+    
+    * UIProcess/API/Cocoa/WKProcessPool.mm:
+    (-[WKProcessPool _makeNextWebProcessLaunchFailForTesting]):
+    * UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
+    * UIProcess/Launcher/ProcessLauncher.h:
+    * UIProcess/Launcher/mac/ProcessLauncherMac.mm:
+    (WebKit::ProcessLauncher::launchProcess):
+    Add SPI to make the next WebProcess launch fail, for the purpose of API testing.
+    
+    * UIProcess/WebProcessPool.h:
+    * UIProcess/WebProcessProxy.cpp:
+    (WebKit::WebProcessProxy::getLaunchOptions):
+    (WebKit::WebProcessProxy::didClose):
+    (WebKit::WebProcessProxy::processDidTerminateOrFailedToLaunch):
+    (WebKit::WebProcessProxy::didFinishLaunching):
+    * UIProcess/WebProcessProxy.h:
+    
+    Tools:
+    
+    Add API test coverage.
+    
+    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+    * TestWebKitAPI/Tests/WebKitCocoa/WebContentProcessDidTerminate.mm: Added.
+    (-[CrashOnStartNavigationDelegate _webView:webContentProcessDidTerminateWithReason:]):
+    (-[CrashOnStartNavigationDelegate webView:didFinishNavigation:]):
+    (-[CrashRecoveryScriptMessageHandler userContentController:didReceiveScriptMessage:]):
+    (TEST):
+    
+    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@231321 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2018-05-03  Chris Dumez  <[email protected]>
+
+            Load hangs if the WebProcess fails to launch
+            https://bugs.webkit.org/show_bug.cgi?id=185225
+            <rdar://problem/38249058>
+
+            Reviewed by Geoff Garen.
+
+            When a process fails to launch, ChildProcessProxy::didFinishLaunching() gets called with an
+            invalid connection identifier. While NetworkProcessProxy::didFinishLaunching() properly deals with
+            this situation, WebProcessProxy::didFinishLaunching() does not. As a result, we do not attempt to
+            relaunch the process, we do not notify the client and WebPageProxy::m_isValid stays true.
+
+            This patch thus updates WebProcessProxy::didFinishLaunching() to check if the connection identifier
+            is valid and treats it as a crash. As a result, the WebPageProxies properly reset their state and
+            the client gets notified of the crash so that it can attempt to reload.
+
+            * UIProcess/API/Cocoa/WKProcessPool.mm:
+            (-[WKProcessPool _makeNextWebProcessLaunchFailForTesting]):
+            * UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
+            * UIProcess/Launcher/ProcessLauncher.h:
+            * UIProcess/Launcher/mac/ProcessLauncherMac.mm:
+            (WebKit::ProcessLauncher::launchProcess):
+            Add SPI to make the next WebProcess launch fail, for the purpose of API testing.
+
+            * UIProcess/WebProcessPool.h:
+            * UIProcess/WebProcessProxy.cpp:
+            (WebKit::WebProcessProxy::getLaunchOptions):
+            (WebKit::WebProcessProxy::didClose):
+            (WebKit::WebProcessProxy::processDidTerminateOrFailedToLaunch):
+            (WebKit::WebProcessProxy::didFinishLaunching):
+            * UIProcess/WebProcessProxy.h:
+
 2018-05-09  Jason Marcell  <[email protected]>
 
         Apply patch. rdar://problem/39839226

Modified: branches/safari-605-branch/Source/WebKit/Platform/IPC/Connection.h (231644 => 231645)


--- branches/safari-605-branch/Source/WebKit/Platform/IPC/Connection.h	2018-05-10 17:37:43 UTC (rev 231644)
+++ branches/safari-605-branch/Source/WebKit/Platform/IPC/Connection.h	2018-05-10 17:43:48 UTC (rev 231645)
@@ -101,6 +101,7 @@
 #if USE(UNIX_DOMAIN_SOCKETS)
     typedef int Identifier;
     static bool identifierIsNull(Identifier identifier) { return identifier == -1; }
+    static bool identifierIsValid(Identifier identifier) { return identifier != -1; }
 
     struct SocketPair {
         int client;
@@ -135,6 +136,7 @@
         OSObjectPtr<xpc_connection_t> xpcConnection;
     };
     static bool identifierIsNull(Identifier identifier) { return identifier.port == MACH_PORT_NULL; }
+    static bool identifierIsValid(Identifier identifier) { return MACH_PORT_VALID(identifier.port); }
     xpc_connection_t xpcConnection() const { return m_xpcConnection.get(); }
     bool getAuditToken(audit_token_t&);
     pid_t remoteProcessID() const;
@@ -142,6 +144,7 @@
     typedef HANDLE Identifier;
     static bool createServerAndClientIdentifiers(Identifier& serverIdentifier, Identifier& clientIdentifier);
     static bool identifierIsNull(Identifier identifier) { return !identifier; }
+    static bool identifierIsValid(Identifier identifier) { return !!identifier; }
 #endif
 
     static Ref<Connection> createServerConnection(Identifier, Client&);

Modified: branches/safari-605-branch/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm (231644 => 231645)


--- branches/safari-605-branch/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm	2018-05-10 17:37:43 UTC (rev 231644)
+++ branches/safari-605-branch/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm	2018-05-10 17:43:48 UTC (rev 231645)
@@ -452,6 +452,11 @@
     return _processPool->processes().size();
 }
 
+- (void)_makeNextWebProcessLaunchFailForTesting
+{
+    _processPool->setShouldMakeNextWebProcessLaunchFailForTesting(true);
+}
+
 - (size_t)_webPageContentProcessCount
 {
     auto allWebProcesses = _processPool->processes();

Modified: branches/safari-605-branch/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h (231644 => 231645)


--- branches/safari-605-branch/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h	2018-05-10 17:37:43 UTC (rev 231644)
+++ branches/safari-605-branch/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h	2018-05-10 17:43:48 UTC (rev 231645)
@@ -84,6 +84,7 @@
 - (size_t)_webProcessCount WK_API_AVAILABLE(macosx(10.13), ios(11.0));
 - (size_t)_pluginProcessCount WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 - (void)_syncNetworkProcessCookies WK_API_AVAILABLE(macosx(10.13), ios(11.0));
+- (void)_makeNextWebProcessLaunchFailForTesting WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 // Test only. Returns web processes running web pages (does not include web processes running service workers)
 - (size_t)_webPageContentProcessCount WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));

Modified: branches/safari-605-branch/Source/WebKit/UIProcess/Launcher/ProcessLauncher.h (231644 => 231645)


--- branches/safari-605-branch/Source/WebKit/UIProcess/Launcher/ProcessLauncher.h	2018-05-10 17:37:43 UTC (rev 231644)
+++ branches/safari-605-branch/Source/WebKit/UIProcess/Launcher/ProcessLauncher.h	2018-05-10 17:43:48 UTC (rev 231645)
@@ -60,6 +60,7 @@
         ProcessType processType;
         WebCore::ProcessIdentifier processIdentifier;
         HashMap<String, String> extraInitializationData;
+        bool shouldMakeProcessLaunchFailForTesting { false };
 
 #if ENABLE(DEVELOPER_MODE) && (PLATFORM(GTK) || PLATFORM(WPE))
         String processCmdPrefix;

Modified: branches/safari-605-branch/Source/WebKit/UIProcess/Launcher/mac/ProcessLauncherMac.mm (231644 => 231645)


--- branches/safari-605-branch/Source/WebKit/UIProcess/Launcher/mac/ProcessLauncherMac.mm	2018-05-10 17:37:43 UTC (rev 231644)
+++ branches/safari-605-branch/Source/WebKit/UIProcess/Launcher/mac/ProcessLauncherMac.mm	2018-05-10 17:43:48 UTC (rev 231645)
@@ -192,8 +192,8 @@
     xpc_dictionary_set_value(bootstrapMessage.get(), "extra-initialization-data", extraInitializationData.get());
 
     auto weakProcessLauncher = m_weakPtrFactory.createWeakPtr(*this);
-    xpc_connection_set_event_handler(m_xpcConnection.get(), [weakProcessLauncher, listeningPort](xpc_object_t event) {
-        ASSERT(xpc_get_type(event) == XPC_TYPE_ERROR);
+    auto errorHandler = [weakProcessLauncher, listeningPort](xpc_object_t event) {
+        ASSERT(!event || xpc_get_type(event) == XPC_TYPE_ERROR);
 
         auto processLauncher = weakProcessLauncher.get();
         if (!processLauncher)
@@ -213,10 +213,19 @@
         processLauncher->m_xpcConnection = nullptr;
 
         processLauncher->didFinishLaunchingProcess(0, IPC::Connection::Identifier());
-    });
+    };
 
+    xpc_connection_set_event_handler(m_xpcConnection.get(), errorHandler);
+
     xpc_connection_resume(m_xpcConnection.get());
 
+    if (UNLIKELY(m_launchOptions.shouldMakeProcessLaunchFailForTesting)) {
+        RunLoop::main().dispatch([errorHandler = WTFMove(errorHandler)] {
+            errorHandler(nullptr);
+        });
+        return;
+    }
+
     ref();
     xpc_connection_send_message_with_reply(m_xpcConnection.get(), bootstrapMessage.get(), dispatch_get_main_queue(), ^(xpc_object_t reply) {
         // Errors are handled in the event handler.

Modified: branches/safari-605-branch/Source/WebKit/UIProcess/WebProcessPool.h (231644 => 231645)


--- branches/safari-605-branch/Source/WebKit/UIProcess/WebProcessPool.h	2018-05-10 17:37:43 UTC (rev 231644)
+++ branches/safari-605-branch/Source/WebKit/UIProcess/WebProcessPool.h	2018-05-10 17:43:48 UTC (rev 231645)
@@ -269,6 +269,9 @@
 
     void syncNetworkProcessCookies();
 
+    void setShouldMakeNextWebProcessLaunchFailForTesting(bool value) { m_shouldMakeNextWebProcessLaunchFailForTesting = value; }
+    bool shouldMakeNextWebProcessLaunchFailForTesting() const { return m_shouldMakeNextWebProcessLaunchFailForTesting; }
+
     void reportWebContentCPUTime(Seconds cpuTime, uint64_t activityState);
 
     void allowSpecificHTTPSCertificateForHost(const WebCertificateInfo*, const String& host);
@@ -607,6 +610,7 @@
     bool m_javaScriptConfigurationFileEnabled { false };
     bool m_alwaysRunsAtBackgroundPriority;
     bool m_shouldTakeUIBackgroundAssertion;
+    bool m_shouldMakeNextWebProcessLaunchFailForTesting { false };
 
     UserObservablePageCounter m_userObservablePageCounter;
     ProcessSuppressionDisabledCounter m_processSuppressionDisabledForPageCounter;

Modified: branches/safari-605-branch/Source/WebKit/UIProcess/WebProcessProxy.cpp (231644 => 231645)


--- branches/safari-605-branch/Source/WebKit/UIProcess/WebProcessProxy.cpp	2018-05-10 17:37:43 UTC (rev 231644)
+++ branches/safari-605-branch/Source/WebKit/UIProcess/WebProcessProxy.cpp	2018-05-10 17:43:48 UTC (rev 231645)
@@ -167,6 +167,11 @@
         }
         launchOptions.extraInitializationData.add(ASCIILiteral("OverrideLanguages"), languageString.toString());
     }
+
+    if (processPool().shouldMakeNextWebProcessLaunchFailForTesting()) {
+        processPool().setShouldMakeNextWebProcessLaunchFailForTesting(false);
+        launchOptions.shouldMakeProcessLaunchFailForTesting = true;
+    }
 }
 
 void WebProcessProxy::connectionWillOpen(IPC::Connection& connection)
@@ -644,11 +649,17 @@
 
 void WebProcessProxy::didClose(IPC::Connection&)
 {
+    processDidTerminateOrFailedToLaunch();
+}
+
+void WebProcessProxy::processDidTerminateOrFailedToLaunch()
+{
     // Protect ourselves, as the call to disconnect() below may otherwise cause us
     // to be deleted before we can finish our work.
     Ref<WebProcessProxy> protect(*this);
 
-    webConnection()->didClose();
+    if (auto* webConnection = this->webConnection())
+        webConnection->didClose();
 
     auto pages = copyToVectorOf<RefPtr<WebPageProxy>>(m_pageMap.values());
 
@@ -725,6 +736,11 @@
 {
     ChildProcessProxy::didFinishLaunching(launcher, connectionIdentifier);
 
+    if (!IPC::Connection::identifierIsValid(connectionIdentifier)) {
+        processDidTerminateOrFailedToLaunch();
+        return;
+    }
+
     for (WebPageProxy* page : m_pageMap.values()) {
         ASSERT(this == &page->process());
         page->processDidFinishLaunching();

Modified: branches/safari-605-branch/Source/WebKit/UIProcess/WebProcessProxy.h (231644 => 231645)


--- branches/safari-605-branch/Source/WebKit/UIProcess/WebProcessProxy.h	2018-05-10 17:37:43 UTC (rev 231644)
+++ branches/safari-605-branch/Source/WebKit/UIProcess/WebProcessProxy.h	2018-05-10 17:43:48 UTC (rev 231645)
@@ -252,6 +252,8 @@
 
     void updateBackgroundResponsivenessTimer();
 
+    void processDidTerminateOrFailedToLaunch();
+
     // IPC::Connection::Client
     friend class WebConnectionToWebProcess;
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;

Modified: branches/safari-605-branch/Tools/ChangeLog (231644 => 231645)


--- branches/safari-605-branch/Tools/ChangeLog	2018-05-10 17:37:43 UTC (rev 231644)
+++ branches/safari-605-branch/Tools/ChangeLog	2018-05-10 17:43:48 UTC (rev 231645)
@@ -1,3 +1,68 @@
+2018-05-10  Jason Marcell  <[email protected]>
+
+        Apply patch. rdar://problem/39987479
+
+    Load hangs if the WebProcess fails to launch https://bugs.webkit.org/show_bug.cgi?id=185225 <rdar://problem/38249058>
+    
+    Reviewed by Geoff Garen.
+    
+    Source/WebKit:
+    
+    When a process fails to launch, ChildProcessProxy::didFinishLaunching() gets called with an
+    invalid connection identifier. While NetworkProcessProxy::didFinishLaunching() properly deals with
+    this situation, WebProcessProxy::didFinishLaunching() does not. As a result, we do not attempt to
+    relaunch the process, we do not notify the client and WebPageProxy::m_isValid stays true.
+    
+    This patch thus updates WebProcessProxy::didFinishLaunching() to check if the connection identifier
+    is valid and treats it as a crash. As a result, the WebPageProxies properly reset their state and
+    the client gets notified of the crash so that it can attempt to reload.
+    
+    * UIProcess/API/Cocoa/WKProcessPool.mm:
+    (-[WKProcessPool _makeNextWebProcessLaunchFailForTesting]):
+    * UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
+    * UIProcess/Launcher/ProcessLauncher.h:
+    * UIProcess/Launcher/mac/ProcessLauncherMac.mm:
+    (WebKit::ProcessLauncher::launchProcess):
+    Add SPI to make the next WebProcess launch fail, for the purpose of API testing.
+    
+    * UIProcess/WebProcessPool.h:
+    * UIProcess/WebProcessProxy.cpp:
+    (WebKit::WebProcessProxy::getLaunchOptions):
+    (WebKit::WebProcessProxy::didClose):
+    (WebKit::WebProcessProxy::processDidTerminateOrFailedToLaunch):
+    (WebKit::WebProcessProxy::didFinishLaunching):
+    * UIProcess/WebProcessProxy.h:
+    
+    Tools:
+    
+    Add API test coverage.
+    
+    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+    * TestWebKitAPI/Tests/WebKitCocoa/WebContentProcessDidTerminate.mm: Added.
+    (-[CrashOnStartNavigationDelegate _webView:webContentProcessDidTerminateWithReason:]):
+    (-[CrashOnStartNavigationDelegate webView:didFinishNavigation:]):
+    (-[CrashRecoveryScriptMessageHandler userContentController:didReceiveScriptMessage:]):
+    (TEST):
+    
+    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@231321 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2018-05-03  Chris Dumez  <[email protected]>
+
+            Load hangs if the WebProcess fails to launch
+            https://bugs.webkit.org/show_bug.cgi?id=185225
+            <rdar://problem/38249058>
+
+            Reviewed by Geoff Garen.
+
+            Add API test coverage.
+
+            * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+            * TestWebKitAPI/Tests/WebKitCocoa/WebContentProcessDidTerminate.mm: Added.
+            (-[CrashOnStartNavigationDelegate _webView:webContentProcessDidTerminateWithReason:]):
+            (-[CrashOnStartNavigationDelegate webView:didFinishNavigation:]):
+            (-[CrashRecoveryScriptMessageHandler userContentController:didReceiveScriptMessage:]):
+            (TEST):
+
 2018-04-17  Kocsen Chung  <[email protected]>
 
         Apply patch. rdar://problem/39305046

Modified: branches/safari-605-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (231644 => 231645)


--- branches/safari-605-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2018-05-10 17:37:43 UTC (rev 231644)
+++ branches/safari-605-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2018-05-10 17:43:48 UTC (rev 231645)
@@ -530,6 +530,7 @@
 		7CD4C26E1E2C0E6E00929470 /* StringConcatenate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CD4C26C1E2C0E6E00929470 /* StringConcatenate.cpp */; };
 		7CEFA9661AC0B9E200B910FD /* _WKUserContentExtensionStore.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7CEFA9641AC0B9E200B910FD /* _WKUserContentExtensionStore.mm */; };
 		7CFBCAE51743238F00B2BFCF /* WillLoad_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CFBCAE31743238E00B2BFCF /* WillLoad_Bundle.cpp */; };
+		830F2E0C209A6A8E00D36FF1 /* WebContentProcessDidTerminate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 830F2E0B209A6A7400D36FF1 /* WebContentProcessDidTerminate.mm */; };
 		834138C7203261CA00F26960 /* AsyncPolicyForNavigationResponse.mm in Sources */ = {isa = PBXBuildFile; fileRef = 834138C6203261B900F26960 /* AsyncPolicyForNavigationResponse.mm */; };
 		8349D3C21DB96DDE004A9F65 /* ContextMenuDownload.mm in Sources */ = {isa = PBXBuildFile; fileRef = 8349D3C11DB96DDA004A9F65 /* ContextMenuDownload.mm */; };
 		8349D3C41DB9728E004A9F65 /* link-with-download-attribute.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 8349D3C31DB9724F004A9F65 /* link-with-download-attribute.html */; };
@@ -1522,6 +1523,7 @@
 		7CFBCADD1743234F00B2BFCF /* WillLoad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WillLoad.cpp; sourceTree = "<group>"; };
 		7CFBCAE31743238E00B2BFCF /* WillLoad_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WillLoad_Bundle.cpp; sourceTree = "<group>"; };
 		81B50192140F232300D9EB58 /* StringBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringBuilder.cpp; sourceTree = "<group>"; };
+		830F2E0B209A6A7400D36FF1 /* WebContentProcessDidTerminate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebContentProcessDidTerminate.mm; sourceTree = "<group>"; };
 		834138C6203261B900F26960 /* AsyncPolicyForNavigationResponse.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AsyncPolicyForNavigationResponse.mm; sourceTree = "<group>"; };
 		8349D3C11DB96DDA004A9F65 /* ContextMenuDownload.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ContextMenuDownload.mm; sourceTree = "<group>"; };
 		8349D3C31DB9724F004A9F65 /* link-with-download-attribute.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "link-with-download-attribute.html"; sourceTree = "<group>"; };
@@ -2162,6 +2164,7 @@
 				93E943F11CD3E87E00AC08C2 /* VideoControlsManager.mm */,
 				6356FB211EC4E0BA0044BF18 /* VisibleContentRect.mm */,
 				83779C371F82FEB0007CDA8A /* VisitedLinkStore.mm */,
+				830F2E0B209A6A7400D36FF1 /* WebContentProcessDidTerminate.mm */,
 				5C973F5B1F58EF0A00359C27 /* WebGLPolicy.mm */,
 				51714EB61CF8C7A4004723C4 /* WebProcessKillIDBCleanup.mm */,
 				5120C83C1E6750790025B250 /* WebsiteDataStoreCustomPaths.mm */,
@@ -3642,6 +3645,7 @@
 				83779C381F82FECE007CDA8A /* VisitedLinkStore.mm in Sources */,
 				0F139E771A423A5B00F590F5 /* WeakObjCPtr.mm in Sources */,
 				7CCE7F191A411AE600447C4C /* WebArchive.cpp in Sources */,
+				830F2E0C209A6A8E00D36FF1 /* WebContentProcessDidTerminate.mm in Sources */,
 				7C83E04C1D0A641800FEBCF3 /* WebCoreNSURLSession.mm in Sources */,
 				7CCE7F1A1A411AE600447C4C /* WebCoreStatisticsWithNoWebProcess.cpp in Sources */,
 				5C973F5C1F58EF8B00359C27 /* WebGLPolicy.mm in Sources */,

Added: branches/safari-605-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebContentProcessDidTerminate.mm (0 => 231645)


--- branches/safari-605-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebContentProcessDidTerminate.mm	                        (rev 0)
+++ branches/safari-605-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebContentProcessDidTerminate.mm	2018-05-10 17:43:48 UTC (rev 231645)
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if WK_API_ENABLED
+
+#import "PlatformUtilities.h"
+#import "Test.h"
+#import <WebKit/WKNavigationDelegatePrivate.h>
+#import <WebKit/WKNavigationPrivate.h>
+#import <WebKit/WKProcessPoolPrivate.h>
+#import <WebKit/WKWebView.h>
+#import <wtf/RetainPtr.h>
+
+static bool didCrash;
+static _WKProcessTerminationReason expectedCrashReason;
+static bool finishedLoad;
+static bool shouldLoadAgainOnCrash;
+static bool receivedScriptMessage;
+
+static NSString *testHTML = @"<script>window.webkit.messageHandlers.testHandler.postMessage('LOADED');</script>";
+
+@interface CrashOnStartNavigationDelegate : NSObject <WKNavigationDelegate>
+@end
+
+@implementation CrashOnStartNavigationDelegate
+
+- (void)_webView:(WKWebView *)webView webContentProcessDidTerminateWithReason:(_WKProcessTerminationReason)reason
+{
+    EXPECT_FALSE(didCrash);
+    didCrash = true;
+    EXPECT_EQ(expectedCrashReason, reason);
+    EXPECT_EQ(0, webView._webProcessIdentifier);
+
+    // Attempt the load again.
+    if (shouldLoadAgainOnCrash)
+        [webView loadHTMLString:testHTML baseURL:nil];
+}
+
+- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
+{
+    finishedLoad = true;
+}
+
+@end
+
+@interface CrashRecoveryScriptMessageHandler : NSObject <WKScriptMessageHandler>
+@end
+
+@implementation CrashRecoveryScriptMessageHandler
+
+- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
+{
+    EXPECT_STREQ([(NSString *)[message body] UTF8String], "LOADED");
+    receivedScriptMessage = true;
+}
+
+@end
+
+TEST(WKNavigation, FailureToStartWebProcessRecovery)
+{
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    auto handler = adoptNS([[CrashRecoveryScriptMessageHandler alloc] init]);
+    [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"testHandler"];
+
+    [configuration.get().processPool _makeNextWebProcessLaunchFailForTesting];
+
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+    auto delegate = adoptNS([[CrashOnStartNavigationDelegate alloc] init]);
+    [webView setNavigationDelegate:delegate.get()];
+
+    finishedLoad = false;
+    didCrash = false;
+    receivedScriptMessage = false;
+    expectedCrashReason = _WKProcessTerminationReasonCrash;
+    shouldLoadAgainOnCrash = true;
+
+    [webView loadHTMLString:testHTML baseURL:nil];
+    TestWebKitAPI::Util::run(&finishedLoad);
+
+    EXPECT_TRUE(didCrash);
+    EXPECT_TRUE(!!webView.get()._webProcessIdentifier);
+    EXPECT_TRUE(receivedScriptMessage);
+}
+
+TEST(WKNavigation, FailureToStartWebProcessAfterCrashRecovery)
+{
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    auto handler = adoptNS([[CrashRecoveryScriptMessageHandler alloc] init]);
+    [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"testHandler"];
+
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+    auto delegate = adoptNS([[CrashOnStartNavigationDelegate alloc] init]);
+    [webView setNavigationDelegate:delegate.get()];
+
+    receivedScriptMessage = false;
+    finishedLoad = false;
+    didCrash = false;
+
+    [webView loadHTMLString:testHTML baseURL:nil];
+    TestWebKitAPI::Util::run(&finishedLoad);
+
+    EXPECT_FALSE(didCrash);
+    EXPECT_TRUE(!!webView.get()._webProcessIdentifier);
+    EXPECT_TRUE(receivedScriptMessage);
+
+    receivedScriptMessage = false;
+    shouldLoadAgainOnCrash = false;
+    expectedCrashReason = _WKProcessTerminationReasonRequestedByClient;
+    [webView _killWebContentProcessAndResetState];
+
+    TestWebKitAPI::Util::run(&didCrash);
+    EXPECT_TRUE(!webView.get()._webProcessIdentifier);
+    EXPECT_FALSE(receivedScriptMessage);
+
+    expectedCrashReason = _WKProcessTerminationReasonCrash;
+    didCrash = false;
+    finishedLoad = false;
+    receivedScriptMessage = false;
+    shouldLoadAgainOnCrash = true;
+
+    [configuration.get().processPool _makeNextWebProcessLaunchFailForTesting];
+    [webView loadHTMLString:testHTML baseURL:nil];
+
+    TestWebKitAPI::Util::run(&finishedLoad);
+
+    EXPECT_TRUE(didCrash);
+    EXPECT_TRUE(!!webView.get()._webProcessIdentifier);
+    EXPECT_TRUE(receivedScriptMessage);
+}
+
+#endif // WK_API_ENABLED
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to