| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/web/web_state/ui/crw_web_controller.h" | 5 #import "ios/web/web_state/ui/crw_web_controller.h" |
| 6 | 6 |
| 7 #import <WebKit/WebKit.h> | 7 #import <WebKit/WebKit.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 webView_.reset([web::BuildTerminatedWKWebView() retain]); | 1015 webView_.reset([web::BuildTerminatedWKWebView() retain]); |
| 1016 base::scoped_nsobject<TestWebViewContentView> webViewContentView( | 1016 base::scoped_nsobject<TestWebViewContentView> webViewContentView( |
| 1017 [[TestWebViewContentView alloc] | 1017 [[TestWebViewContentView alloc] |
| 1018 initWithMockWebView:webView_ | 1018 initWithMockWebView:webView_ |
| 1019 scrollView:[webView_ scrollView]]); | 1019 scrollView:[webView_ scrollView]]); |
| 1020 [web_controller() injectWebViewContentView:webViewContentView]; | 1020 [web_controller() injectWebViewContentView:webViewContentView]; |
| 1021 } | 1021 } |
| 1022 base::scoped_nsobject<WKWebView> webView_; | 1022 base::scoped_nsobject<WKWebView> webView_; |
| 1023 }; | 1023 }; |
| 1024 | 1024 |
| 1025 // Tests that -[CRWWebDelegate webControllerWebProcessDidCrash:] is called | 1025 // Tests that WebStateDelegate::RenderProcessGone is called when WKWebView web |
| 1026 // when WKWebView web process has crashed. | 1026 // process has crashed. |
| 1027 TEST_F(CRWWebControllerWebProcessTest, Crash) { | 1027 TEST_F(CRWWebControllerWebProcessTest, Crash) { |
| 1028 id delegate = [OCMockObject niceMockForProtocol:@protocol(CRWWebDelegate)]; | 1028 // Observes and waits for RenderProcessGone call. |
| 1029 [[delegate expect] webControllerWebProcessDidCrash:web_controller()]; | 1029 class RenderProcessGoneObserver : public web::WebStateObserver { |
| 1030 public: |
| 1031 explicit RenderProcessGoneObserver(web::WebState* web_state) |
| 1032 : web::WebStateObserver(web_state) {} |
| 1033 void WaitForRenderProcessGone() const { |
| 1034 base::test::ios::WaitUntilCondition(^{ |
| 1035 return render_process_gone_; |
| 1036 }); |
| 1037 } |
| 1038 // WebStateObserver overrides: |
| 1039 void RenderProcessGone() override { render_process_gone_ = true; } |
| 1030 | 1040 |
| 1031 [web_controller() setDelegate:delegate]; | 1041 private: |
| 1042 bool render_process_gone_ = false; |
| 1043 }; |
| 1044 |
| 1045 RenderProcessGoneObserver observer(web_state()); |
| 1032 web::SimulateWKWebViewCrash(webView_); | 1046 web::SimulateWKWebViewCrash(webView_); |
| 1047 observer.WaitForRenderProcessGone(); |
| 1033 | 1048 |
| 1034 EXPECT_OCMOCK_VERIFY(delegate); | |
| 1035 EXPECT_FALSE([web_controller() isViewAlive]); | 1049 EXPECT_FALSE([web_controller() isViewAlive]); |
| 1036 [web_controller() setDelegate:nil]; | |
| 1037 }; | 1050 }; |
| 1038 | 1051 |
| 1039 } // namespace | 1052 } // namespace |
| OLD | NEW |