|
| 1 | +/* |
| 2 | + * Copyright (C) 2017 Apple Inc. All rights reserved. |
| 3 | + * |
| 4 | + * Redistribution and use in source and binary forms, with or without |
| 5 | + * modification, are permitted provided that the following conditions |
| 6 | + * are met: |
| 7 | + * 1. Redistributions of source code must retain the above copyright |
| 8 | + * notice, this list of conditions and the following disclaimer. |
| 9 | + * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | + * notice, this list of conditions and the following disclaimer in the |
| 11 | + * documentation and/or other materials provided with the distribution. |
| 12 | + * |
| 13 | + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | + * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | + */ |
| 25 | + |
| 26 | +#import "config.h" |
| 27 | + |
| 28 | +#import "PlatformUtilities.h" |
| 29 | +#import "Test.h" |
| 30 | +#import "TestNavigationDelegate.h" |
| 31 | +#import <WebKit/WKContextPrivate.h> |
| 32 | +#import <WebKit/WKProcessGroupPrivate.h> |
| 33 | +#import <WebKit/WKProcessPoolPrivate.h> |
| 34 | +#import <WebKit/WKWebViewPrivate.h> |
| 35 | +#import <WebKit/WebKit.h> |
| 36 | +#import <wtf/RetainPtr.h> |
| 37 | + |
| 38 | +#if WK_API_ENABLED |
| 39 | + |
| 40 | +namespace TestWebKitAPI { |
| 41 | + |
| 42 | +static bool loadedOrCrashed = false; |
| 43 | +static bool loaded = false; |
| 44 | +static bool webProcessCrashed = false; |
| 45 | +static bool networkProcessCrashed = false; |
| 46 | + |
| 47 | +TEST(WebKit2, NetworkProcessCrashWithPendingConnection) |
| 48 | +{ |
| 49 | + RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]); |
| 50 | + RetainPtr<WKProcessPool> processPool = adoptNS([[WKProcessPool alloc] init]); |
| 51 | + [configuration setProcessPool:processPool.get()]; |
| 52 | + |
| 53 | + // FIXME: Adopt the new API once it's added in webkit.org/b/174061. |
| 54 | + WKContextClientV0 client; |
| 55 | + memset(&client, 0, sizeof(client)); |
| 56 | + client.networkProcessDidCrash = [](WKContextRef context, const void* clientInfo) { |
| 57 | + networkProcessCrashed = true; |
| 58 | + }; |
| 59 | + WKContextSetClient(static_cast<WKContextRef>(processPool.get()), &client.base); |
| 60 | + |
| 61 | + RetainPtr<WKWebView> webView1 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); |
| 62 | + RetainPtr<WKWebView> webView2 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); |
| 63 | + |
| 64 | + [webView1.get() loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]]; |
| 65 | + [webView1.get() _test_waitForDidFinishNavigation]; |
| 66 | + |
| 67 | + [webView2.get() loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]]; |
| 68 | + [webView2.get() _test_waitForDidFinishNavigation]; |
| 69 | + |
| 70 | + pid_t webView1PID = [webView1.get() _webProcessIdentifier]; |
| 71 | + pid_t webView2PID = [webView2.get() _webProcessIdentifier]; |
| 72 | + EXPECT_NE(webView1PID, webView2PID); |
| 73 | + |
| 74 | + pid_t initialNetworkProcessIdentififer = [processPool.get() _networkProcessIdentifier]; |
| 75 | + EXPECT_NE(initialNetworkProcessIdentififer, 0); |
| 76 | + kill(initialNetworkProcessIdentififer, SIGKILL); |
| 77 | + Util::run(&networkProcessCrashed); |
| 78 | + networkProcessCrashed = false; |
| 79 | + |
| 80 | + [webView1.get() loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]]; |
| 81 | + [webView1.get() _test_waitForDidFinishNavigation]; |
| 82 | + |
| 83 | + pid_t relaunchedNetworkProcessIdentifier = [processPool.get() _networkProcessIdentifier]; |
| 84 | + EXPECT_NE(initialNetworkProcessIdentififer, relaunchedNetworkProcessIdentifier); |
| 85 | + EXPECT_FALSE(networkProcessCrashed); |
| 86 | + |
| 87 | + kill(relaunchedNetworkProcessIdentifier, SIGSTOP); |
| 88 | + |
| 89 | + [webView2.get() loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]]; |
| 90 | + Util::sleep(0.5); // Wait for the WebContent process to send CreateNetworkConnectionToWebProcess |
| 91 | + kill(relaunchedNetworkProcessIdentifier, SIGKILL); |
| 92 | + Util::run(&networkProcessCrashed); |
| 93 | + |
| 94 | + auto navigationDelegate = adoptNS([[TestNavigationDelegate alloc] init]); |
| 95 | + loadedOrCrashed = false; |
| 96 | + [navigationDelegate setDidFinishNavigation:^(WKWebView *, WKNavigation *) { |
| 97 | + loadedOrCrashed = true; |
| 98 | + loaded = true; |
| 99 | + }]; |
| 100 | + [navigationDelegate setWebContentProcessDidTerminate:^(WKWebView *) { |
| 101 | + loadedOrCrashed = true; |
| 102 | + webProcessCrashed = true; |
| 103 | + }]; |
| 104 | + [webView2 setNavigationDelegate:navigationDelegate.get()]; |
| 105 | + TestWebKitAPI::Util::run(&loadedOrCrashed); |
| 106 | + EXPECT_TRUE(loaded); |
| 107 | + EXPECT_FALSE(webProcessCrashed); |
| 108 | +} |
| 109 | + |
| 110 | +} // namespace TestWebKitAPI |
| 111 | + |
| 112 | +#endif |
0 commit comments