Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: ios/web/web_state/ui/crw_web_controller_unittest.mm

Issue 2933363002: [ObjC ARC] Converts ios/web:ios_web_web_state_ui_unittests to ARC. (Closed)
Patch Set: removed spurious test. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 #include "base/ios/ios_util.h" 11 #include "base/ios/ios_util.h"
12 #import "base/ios/weak_nsobject.h"
13 #import "base/mac/scoped_nsobject.h"
14 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
15 #import "base/test/ios/wait_util.h" 13 #import "base/test/ios/wait_util.h"
16 #import "ios/testing/ocmock_complex_type_helper.h" 14 #import "ios/testing/ocmock_complex_type_helper.h"
17 #import "ios/web/navigation/crw_session_controller.h" 15 #import "ios/web/navigation/crw_session_controller.h"
18 #import "ios/web/navigation/navigation_item_impl.h" 16 #import "ios/web/navigation/navigation_item_impl.h"
19 #import "ios/web/navigation/navigation_manager_impl.h" 17 #import "ios/web/navigation/navigation_manager_impl.h"
20 #include "ios/web/public/referrer.h" 18 #include "ios/web/public/referrer.h"
21 #import "ios/web/public/test/fakes/test_native_content.h" 19 #import "ios/web/public/test/fakes/test_native_content.h"
22 #import "ios/web/public/test/fakes/test_native_content_provider.h" 20 #import "ios/web/public/test/fakes/test_native_content_provider.h"
23 #import "ios/web/public/test/fakes/test_web_client.h" 21 #import "ios/web/public/test/fakes/test_web_client.h"
(...skipping 18 matching lines...) Expand all
42 #include "net/ssl/ssl_info.h" 40 #include "net/ssl/ssl_info.h"
43 #include "net/test/cert_test_util.h" 41 #include "net/test/cert_test_util.h"
44 #include "net/test/test_data_directory.h" 42 #include "net/test/test_data_directory.h"
45 #include "testing/gtest/include/gtest/gtest.h" 43 #include "testing/gtest/include/gtest/gtest.h"
46 #import "testing/gtest_mac.h" 44 #import "testing/gtest_mac.h"
47 #include "third_party/ocmock/OCMock/OCMock.h" 45 #include "third_party/ocmock/OCMock/OCMock.h"
48 #include "third_party/ocmock/gtest_support.h" 46 #include "third_party/ocmock/gtest_support.h"
49 #include "third_party/ocmock/ocmock_extensions.h" 47 #include "third_party/ocmock/ocmock_extensions.h"
50 #import "ui/base/test/ios/ui_view_test_utils.h" 48 #import "ui/base/test/ios/ui_view_test_utils.h"
51 49
50 #if !defined(__has_feature) || !__has_feature(objc_arc)
51 #error "This file requires ARC support."
52 #endif
53
52 using web::NavigationManagerImpl; 54 using web::NavigationManagerImpl;
53 55
54 @interface CRWWebController (PrivateAPI) 56 @interface CRWWebController (PrivateAPI)
55 @property(nonatomic, readwrite) web::PageDisplayState pageDisplayState; 57 @property(nonatomic, readwrite) web::PageDisplayState pageDisplayState;
56 @end 58 @end
57 59
58 @interface CountingObserver : NSObject<CRWWebControllerObserver> 60 @interface CountingObserver : NSObject<CRWWebControllerObserver>
59 61
60 @property(nonatomic, readonly) int pageLoadedCount; 62 @property(nonatomic, readonly) int pageLoadedCount;
61 @end 63 @end
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 base::test::ios::WaitUntilCondition(^bool() { 114 base::test::ios::WaitUntilCondition(^bool() {
113 return webController.pageDisplayState.zoom_state() == zoom_state; 115 return webController.pageDisplayState.zoom_state() == zoom_state;
114 }); 116 });
115 } 117 }
116 118
117 // Test fixture for testing CRWWebController. Stubs out web view. 119 // Test fixture for testing CRWWebController. Stubs out web view.
118 class CRWWebControllerTest : public web::WebTestWithWebController { 120 class CRWWebControllerTest : public web::WebTestWithWebController {
119 protected: 121 protected:
120 void SetUp() override { 122 void SetUp() override {
121 web::WebTestWithWebController::SetUp(); 123 web::WebTestWithWebController::SetUp();
122 mock_web_view_.reset([CreateMockWebView() retain]); 124 mock_web_view_ = CreateMockWebView();
123 scroll_view_.reset([[UIScrollView alloc] init]); 125 scroll_view_ = [[UIScrollView alloc] init];
124 [[[mock_web_view_ stub] andReturn:scroll_view_.get()] scrollView]; 126 [[[mock_web_view_ stub] andReturn:scroll_view_] scrollView];
125 127
126 base::scoped_nsobject<TestWebViewContentView> webViewContentView( 128 TestWebViewContentView* webViewContentView =
Eugene But (OOO till 7-30) 2017/06/14 13:42:20 Optional nit: s/webViewContentView/web_view_conten
marq (ping after 24h) 2017/06/14 14:19:02 Done.
127 [[TestWebViewContentView alloc] initWithMockWebView:mock_web_view_ 129 [[TestWebViewContentView alloc] initWithMockWebView:mock_web_view_
128 scrollView:scroll_view_]); 130 scrollView:scroll_view_];
129 [web_controller() injectWebViewContentView:webViewContentView]; 131 [web_controller() injectWebViewContentView:webViewContentView];
130 } 132 }
131 133
132 void TearDown() override { 134 void TearDown() override {
133 EXPECT_OCMOCK_VERIFY(mock_web_view_); 135 EXPECT_OCMOCK_VERIFY(mock_web_view_);
134 [web_controller() resetInjectedWebViewContentView]; 136 [web_controller() resetInjectedWebViewContentView];
135 web::WebTestWithWebController::TearDown(); 137 web::WebTestWithWebController::TearDown();
136 } 138 }
137 139
138 // The value for web view OCMock objects to expect for |-setFrame:|. 140 // The value for web view OCMock objects to expect for |-setFrame:|.
(...skipping 10 matching lines...) Expand all
149 151
150 if (base::ios::IsRunningOnIOS10OrLater()) { 152 if (base::ios::IsRunningOnIOS10OrLater()) {
151 [[result stub] serverTrust]; 153 [[result stub] serverTrust];
152 } else { 154 } else {
153 [[result stub] certificateChain]; 155 [[result stub] certificateChain];
154 } 156 }
155 157
156 [[result stub] backForwardList]; 158 [[result stub] backForwardList];
157 [[[result stub] andReturn:[NSURL URLWithString:@(kTestURLString)]] URL]; 159 [[[result stub] andReturn:[NSURL URLWithString:@(kTestURLString)]] URL];
158 [[result stub] setNavigationDelegate:[OCMArg checkWithBlock:^(id delegate) { 160 [[result stub] setNavigationDelegate:[OCMArg checkWithBlock:^(id delegate) {
159 navigation_delegate_.reset(delegate); 161 navigation_delegate_ = delegate;
160 return YES; 162 return YES;
161 }]]; 163 }]];
162 [[result stub] setUIDelegate:OCMOCK_ANY]; 164 [[result stub] setUIDelegate:OCMOCK_ANY];
163 [[result stub] setFrame:GetExpectedWebViewFrame()]; 165 [[result stub] setFrame:GetExpectedWebViewFrame()];
164 [[result stub] addObserver:web_controller() 166 [[result stub] addObserver:web_controller()
165 forKeyPath:OCMOCK_ANY 167 forKeyPath:OCMOCK_ANY
166 options:0 168 options:0
167 context:nullptr]; 169 context:nullptr];
168 [[result stub] removeObserver:web_controller() forKeyPath:OCMOCK_ANY]; 170 [[result stub] removeObserver:web_controller() forKeyPath:OCMOCK_ANY];
169 171
170 return result; 172 return result;
171 } 173 }
172 174
173 base::WeakNSProtocol<id<WKNavigationDelegate>> navigation_delegate_; 175 __weak id<WKNavigationDelegate> navigation_delegate_;
174 base::scoped_nsobject<UIScrollView> scroll_view_; 176 UIScrollView* scroll_view_;
175 base::scoped_nsobject<id> mock_web_view_; 177 id mock_web_view_;
176 }; 178 };
177 179
178 // Tests that AllowCertificateError is called with correct arguments if 180 // Tests that AllowCertificateError is called with correct arguments if
179 // WKWebView fails to load a page with bad SSL cert. 181 // WKWebView fails to load a page with bad SSL cert.
180 TEST_F(CRWWebControllerTest, SslCertError) { 182 TEST_F(CRWWebControllerTest, SslCertError) {
181 web::TestWebStateObserver observer(web_state()); 183 web::TestWebStateObserver observer(web_state());
182 ASSERT_FALSE(observer.did_change_visible_security_state_info()); 184 ASSERT_FALSE(observer.did_change_visible_security_state_info());
183 185
184 // Last arguments passed to AllowCertificateError must be in default state. 186 // Last arguments passed to AllowCertificateError must be in default state.
185 ASSERT_FALSE(GetWebClient()->last_cert_error_code()); 187 ASSERT_FALSE(GetWebClient()->last_cert_error_code());
186 ASSERT_FALSE(GetWebClient()->last_cert_error_ssl_info().is_valid()); 188 ASSERT_FALSE(GetWebClient()->last_cert_error_ssl_info().is_valid());
187 ASSERT_FALSE(GetWebClient()->last_cert_error_ssl_info().cert_status); 189 ASSERT_FALSE(GetWebClient()->last_cert_error_ssl_info().cert_status);
188 ASSERT_FALSE(GetWebClient()->last_cert_error_request_url().is_valid()); 190 ASSERT_FALSE(GetWebClient()->last_cert_error_request_url().is_valid());
189 ASSERT_TRUE(GetWebClient()->last_cert_error_overridable()); 191 ASSERT_TRUE(GetWebClient()->last_cert_error_overridable());
190 192
191 scoped_refptr<net::X509Certificate> cert = 193 scoped_refptr<net::X509Certificate> cert =
192 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); 194 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem");
193 ASSERT_TRUE(cert); 195 ASSERT_TRUE(cert);
194 base::ScopedCFTypeRef<CFMutableArrayRef> chain( 196 base::ScopedCFTypeRef<CFMutableArrayRef> chain(
195 net::x509_util::CreateSecCertificateArrayForX509Certificate(cert.get())); 197 net::x509_util::CreateSecCertificateArrayForX509Certificate(cert.get()));
196 ASSERT_TRUE(chain); 198 ASSERT_TRUE(chain);
197 199
198 GURL url("https://chromium.test"); 200 GURL url("https://chromium.test");
199 NSError* error = 201 NSError* error =
200 [NSError errorWithDomain:NSURLErrorDomain 202 [NSError errorWithDomain:NSURLErrorDomain
201 code:NSURLErrorServerCertificateHasUnknownRoot 203 code:NSURLErrorServerCertificateHasUnknownRoot
202 userInfo:@{ 204 userInfo:@{
203 web::kNSErrorPeerCertificateChainKey : 205 web::kNSErrorPeerCertificateChainKey :
204 static_cast<NSArray*>(chain.get()), 206 (__bridge NSArray*)chain.get(),
Eugene But (OOO till 7-30) 2017/06/14 13:42:20 Is there anything in foundation_util.h which you c
marq (ping after 24h) 2017/06/14 14:19:02 Done.
205 web::kNSErrorFailingURLKey : net::NSURLWithGURL(url), 207 web::kNSErrorFailingURLKey : net::NSURLWithGURL(url),
206 }]; 208 }];
207 base::scoped_nsobject<NSObject> navigation([[NSObject alloc] init]); 209 NSObject* navigation = [[NSObject alloc] init];
208 [navigation_delegate_ webView:mock_web_view_ 210 [navigation_delegate_ webView:mock_web_view_
209 didStartProvisionalNavigation:static_cast<WKNavigation*>(navigation)]; 211 didStartProvisionalNavigation:static_cast<WKNavigation*>(navigation)];
210 [navigation_delegate_ webView:mock_web_view_ 212 [navigation_delegate_ webView:mock_web_view_
211 didFailProvisionalNavigation:static_cast<WKNavigation*>(navigation) 213 didFailProvisionalNavigation:static_cast<WKNavigation*>(navigation)
212 withError:error]; 214 withError:error];
213 215
214 // Verify correctness of AllowCertificateError method call. 216 // Verify correctness of AllowCertificateError method call.
215 EXPECT_EQ(net::ERR_CERT_INVALID, GetWebClient()->last_cert_error_code()); 217 EXPECT_EQ(net::ERR_CERT_INVALID, GetWebClient()->last_cert_error_code());
216 EXPECT_TRUE(GetWebClient()->last_cert_error_ssl_info().is_valid()); 218 EXPECT_TRUE(GetWebClient()->last_cert_error_ssl_info().is_valid());
217 EXPECT_EQ(net::CERT_STATUS_INVALID, 219 EXPECT_EQ(net::CERT_STATUS_INVALID,
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 644
643 EXPECT_EQ(GURL(kTestURLString), url); 645 EXPECT_EQ(GURL(kTestURLString), url);
644 EXPECT_EQ(web::kAbsolute, trust_level); 646 EXPECT_EQ(web::kAbsolute, trust_level);
645 } 647 }
646 648
647 // Test fixture for testing CRWWebController presenting native content. 649 // Test fixture for testing CRWWebController presenting native content.
648 class CRWWebControllerNativeContentTest : public web::WebTestWithWebController { 650 class CRWWebControllerNativeContentTest : public web::WebTestWithWebController {
649 protected: 651 protected:
650 void SetUp() override { 652 void SetUp() override {
651 web::WebTestWithWebController::SetUp(); 653 web::WebTestWithWebController::SetUp();
652 mock_native_provider_.reset([[TestNativeContentProvider alloc] init]); 654 mock_native_provider_ = [[TestNativeContentProvider alloc] init];
653 [web_controller() setNativeProvider:mock_native_provider_]; 655 [web_controller() setNativeProvider:mock_native_provider_];
654 } 656 }
655 657
656 void Load(const GURL& URL) { 658 void Load(const GURL& URL) {
657 NavigationManagerImpl& navigation_manager = 659 NavigationManagerImpl& navigation_manager =
658 [web_controller() webStateImpl]->GetNavigationManagerImpl(); 660 [web_controller() webStateImpl]->GetNavigationManagerImpl();
659 navigation_manager.AddPendingItem( 661 navigation_manager.AddPendingItem(
660 URL, web::Referrer(), ui::PAGE_TRANSITION_TYPED, 662 URL, web::Referrer(), ui::PAGE_TRANSITION_TYPED,
661 web::NavigationInitiationType::USER_INITIATED, 663 web::NavigationInitiationType::USER_INITIATED,
662 web::NavigationManager::UserAgentOverrideOption::INHERIT); 664 web::NavigationManager::UserAgentOverrideOption::INHERIT);
663 [web_controller() loadCurrentURL]; 665 [web_controller() loadCurrentURL];
664 } 666 }
665 667
666 base::scoped_nsobject<TestNativeContentProvider> mock_native_provider_; 668 TestNativeContentProvider* mock_native_provider_;
667 }; 669 };
668 670
669 // Tests WebState and NavigationManager correctly return native content URL. 671 // Tests WebState and NavigationManager correctly return native content URL.
670 TEST_F(CRWWebControllerNativeContentTest, NativeContentURL) { 672 TEST_F(CRWWebControllerNativeContentTest, NativeContentURL) {
671 GURL url_to_load(kTestAppSpecificURL); 673 GURL url_to_load(kTestAppSpecificURL);
672 base::scoped_nsobject<TestNativeContent> content( 674 TestNativeContent* content =
673 [[TestNativeContent alloc] initWithURL:url_to_load virtualURL:GURL()]); 675 [[TestNativeContent alloc] initWithURL:url_to_load virtualURL:GURL()];
674 [mock_native_provider_ setController:content forURL:url_to_load]; 676 [mock_native_provider_ setController:content forURL:url_to_load];
675 Load(url_to_load); 677 Load(url_to_load);
676 web::URLVerificationTrustLevel trust_level = web::kNone; 678 web::URLVerificationTrustLevel trust_level = web::kNone;
677 GURL gurl = [web_controller() currentURLWithTrustLevel:&trust_level]; 679 GURL gurl = [web_controller() currentURLWithTrustLevel:&trust_level];
678 EXPECT_EQ(gurl, url_to_load); 680 EXPECT_EQ(gurl, url_to_load);
679 EXPECT_EQ(web::kAbsolute, trust_level); 681 EXPECT_EQ(web::kAbsolute, trust_level);
680 EXPECT_EQ([web_controller() webState]->GetVisibleURL(), url_to_load); 682 EXPECT_EQ([web_controller() webState]->GetVisibleURL(), url_to_load);
681 NavigationManagerImpl& navigationManager = 683 NavigationManagerImpl& navigationManager =
682 [web_controller() webStateImpl]->GetNavigationManagerImpl(); 684 [web_controller() webStateImpl]->GetNavigationManagerImpl();
683 EXPECT_EQ(navigationManager.GetVisibleItem()->GetURL(), url_to_load); 685 EXPECT_EQ(navigationManager.GetVisibleItem()->GetURL(), url_to_load);
684 EXPECT_EQ(navigationManager.GetVisibleItem()->GetVirtualURL(), url_to_load); 686 EXPECT_EQ(navigationManager.GetVisibleItem()->GetVirtualURL(), url_to_load);
685 EXPECT_EQ(navigationManager.GetLastCommittedItem()->GetURL(), url_to_load); 687 EXPECT_EQ(navigationManager.GetLastCommittedItem()->GetURL(), url_to_load);
686 EXPECT_EQ(navigationManager.GetLastCommittedItem()->GetVirtualURL(), 688 EXPECT_EQ(navigationManager.GetLastCommittedItem()->GetVirtualURL(),
687 url_to_load); 689 url_to_load);
688 } 690 }
689 691
690 // Tests WebState and NavigationManager correctly return native content URL and 692 // Tests WebState and NavigationManager correctly return native content URL and
691 // VirtualURL 693 // VirtualURL
692 TEST_F(CRWWebControllerNativeContentTest, NativeContentVirtualURL) { 694 TEST_F(CRWWebControllerNativeContentTest, NativeContentVirtualURL) {
693 GURL url_to_load(kTestAppSpecificURL); 695 GURL url_to_load(kTestAppSpecificURL);
694 GURL virtual_url(kTestURLString); 696 GURL virtual_url(kTestURLString);
695 base::scoped_nsobject<TestNativeContent> content([[TestNativeContent alloc] 697 TestNativeContent* content =
696 initWithURL:virtual_url 698 [[TestNativeContent alloc] initWithURL:virtual_url
697 virtualURL:virtual_url]); 699 virtualURL:virtual_url];
698 [mock_native_provider_ setController:content forURL:url_to_load]; 700 [mock_native_provider_ setController:content forURL:url_to_load];
699 Load(url_to_load); 701 Load(url_to_load);
700 web::URLVerificationTrustLevel trust_level = web::kNone; 702 web::URLVerificationTrustLevel trust_level = web::kNone;
701 GURL gurl = [web_controller() currentURLWithTrustLevel:&trust_level]; 703 GURL gurl = [web_controller() currentURLWithTrustLevel:&trust_level];
702 EXPECT_EQ(gurl, virtual_url); 704 EXPECT_EQ(gurl, virtual_url);
703 EXPECT_EQ(web::kAbsolute, trust_level); 705 EXPECT_EQ(web::kAbsolute, trust_level);
704 EXPECT_EQ([web_controller() webState]->GetVisibleURL(), virtual_url); 706 EXPECT_EQ([web_controller() webState]->GetVisibleURL(), virtual_url);
705 NavigationManagerImpl& navigationManager = 707 NavigationManagerImpl& navigationManager =
706 [web_controller() webStateImpl]->GetNavigationManagerImpl(); 708 [web_controller() webStateImpl]->GetNavigationManagerImpl();
707 EXPECT_EQ(navigationManager.GetVisibleItem()->GetURL(), url_to_load); 709 EXPECT_EQ(navigationManager.GetVisibleItem()->GetURL(), url_to_load);
708 EXPECT_EQ(navigationManager.GetVisibleItem()->GetVirtualURL(), virtual_url); 710 EXPECT_EQ(navigationManager.GetVisibleItem()->GetVirtualURL(), virtual_url);
709 EXPECT_EQ(navigationManager.GetLastCommittedItem()->GetURL(), url_to_load); 711 EXPECT_EQ(navigationManager.GetLastCommittedItem()->GetURL(), url_to_load);
710 EXPECT_EQ(navigationManager.GetLastCommittedItem()->GetVirtualURL(), 712 EXPECT_EQ(navigationManager.GetLastCommittedItem()->GetVirtualURL(),
711 virtual_url); 713 virtual_url);
712 } 714 }
713 715
714 // A separate test class, as none of the |CRWUIWebViewWebControllerTest| setup 716 // A separate test class, as none of the |CRWUIWebViewWebControllerTest| setup
715 // is needed; 717 // is needed;
716 typedef web::WebTestWithWebController CRWWebControllerObserversTest; 718 typedef web::WebTestWithWebController CRWWebControllerObserversTest;
717 719
718 // Tests that CRWWebControllerObservers are called. 720 // Tests that CRWWebControllerObservers are called.
719 TEST_F(CRWWebControllerObserversTest, Observers) { 721 TEST_F(CRWWebControllerObserversTest, Observers) {
720 base::scoped_nsobject<CountingObserver> observer( 722 CountingObserver* observer = [[CountingObserver alloc] init];
721 [[CountingObserver alloc] init]);
722 EXPECT_EQ(0u, [web_controller() observerCount]); 723 EXPECT_EQ(0u, [web_controller() observerCount]);
723 [web_controller() addObserver:observer]; 724 [web_controller() addObserver:observer];
724 EXPECT_EQ(1u, [web_controller() observerCount]); 725 EXPECT_EQ(1u, [web_controller() observerCount]);
725 726
726 EXPECT_EQ(0, [observer pageLoadedCount]); 727 EXPECT_EQ(0, [observer pageLoadedCount]);
727 [web_controller() webStateImpl]->OnPageLoaded(GURL("http://test"), false); 728 [web_controller() webStateImpl]->OnPageLoaded(GURL("http://test"), false);
728 EXPECT_EQ(0, [observer pageLoadedCount]); 729 EXPECT_EQ(0, [observer pageLoadedCount]);
729 [web_controller() webStateImpl]->OnPageLoaded(GURL("http://test"), true); 730 [web_controller() webStateImpl]->OnPageLoaded(GURL("http://test"), true);
730 EXPECT_EQ(1, [observer pageLoadedCount]); 731 EXPECT_EQ(1, [observer pageLoadedCount]);
731 732
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 protected: 870 protected:
870 // Calls |executeUserJavaScript:completionHandler:|, waits for script 871 // Calls |executeUserJavaScript:completionHandler:|, waits for script
871 // execution completion, and synchronously returns the result. 872 // execution completion, and synchronously returns the result.
872 id ExecuteUserJavaScript(NSString* java_script, NSError** error) { 873 id ExecuteUserJavaScript(NSString* java_script, NSError** error) {
873 __block id script_result = nil; 874 __block id script_result = nil;
874 __block NSError* script_error = nil; 875 __block NSError* script_error = nil;
875 __block bool script_executed = false; 876 __block bool script_executed = false;
876 [web_controller() 877 [web_controller()
877 executeUserJavaScript:java_script 878 executeUserJavaScript:java_script
878 completionHandler:^(id local_result, NSError* local_error) { 879 completionHandler:^(id local_result, NSError* local_error) {
879 script_result = [local_result retain]; 880 script_result = local_result;
880 script_error = [local_error retain]; 881 script_error = local_error;
881 script_executed = true; 882 script_executed = true;
882 }]; 883 }];
883 884
884 WaitForCondition(^{ 885 WaitForCondition(^{
885 return script_executed; 886 return script_executed;
886 }); 887 });
887 888
888 if (error) { 889 if (error) {
889 *error = script_error; 890 *error = script_error;
890 } 891 }
891 [script_error autorelease]; 892 return script_result;
892 return [script_result autorelease];
893 } 893 }
894 }; 894 };
895 895
896 // Tests evaluating user script on an http page. 896 // Tests evaluating user script on an http page.
897 TEST_F(ScriptExecutionTest, UserScriptOnHttpPage) { 897 TEST_F(ScriptExecutionTest, UserScriptOnHttpPage) {
898 LoadHtml(@"<html></html>", GURL(kTestURLString)); 898 LoadHtml(@"<html></html>", GURL(kTestURLString));
899 NSError* error = nil; 899 NSError* error = nil;
900 EXPECT_NSEQ(@0, ExecuteUserJavaScript(@"window.w = 0;", &error)); 900 EXPECT_NSEQ(@0, ExecuteUserJavaScript(@"window.w = 0;", &error));
901 EXPECT_FALSE(error); 901 EXPECT_FALSE(error);
902 902
(...skipping 22 matching lines...) Expand all
925 EXPECT_EQ(web::JS_EVALUATION_ERROR_CODE_NO_WEB_VIEW, error.code); 925 EXPECT_EQ(web::JS_EVALUATION_ERROR_CODE_NO_WEB_VIEW, error.code);
926 926
927 EXPECT_FALSE(ExecuteJavaScript(@"window.w")); 927 EXPECT_FALSE(ExecuteJavaScript(@"window.w"));
928 }; 928 };
929 929
930 // Fixture class to test WKWebView crashes. 930 // Fixture class to test WKWebView crashes.
931 class CRWWebControllerWebProcessTest : public web::WebTestWithWebController { 931 class CRWWebControllerWebProcessTest : public web::WebTestWithWebController {
932 protected: 932 protected:
933 void SetUp() override { 933 void SetUp() override {
934 web::WebTestWithWebController::SetUp(); 934 web::WebTestWithWebController::SetUp();
935 webView_.reset([web::BuildTerminatedWKWebView() retain]); 935 webView_ = web::BuildTerminatedWKWebView();
936 base::scoped_nsobject<TestWebViewContentView> webViewContentView( 936 TestWebViewContentView* webViewContentView = [[TestWebViewContentView alloc]
937 [[TestWebViewContentView alloc] 937 initWithMockWebView:webView_
938 initWithMockWebView:webView_ 938 scrollView:[webView_ scrollView]];
939 scrollView:[webView_ scrollView]]);
940 [web_controller() injectWebViewContentView:webViewContentView]; 939 [web_controller() injectWebViewContentView:webViewContentView];
941 940
942 // This test intentionally crashes the render process. 941 // This test intentionally crashes the render process.
943 SetIgnoreRenderProcessCrashesDuringTesting(true); 942 SetIgnoreRenderProcessCrashesDuringTesting(true);
944 } 943 }
945 base::scoped_nsobject<WKWebView> webView_; 944 WKWebView* webView_;
946 }; 945 };
947 946
948 // Tests that WebStateDelegate::RenderProcessGone is called when WKWebView web 947 // Tests that WebStateDelegate::RenderProcessGone is called when WKWebView web
949 // process has crashed. 948 // process has crashed.
950 TEST_F(CRWWebControllerWebProcessTest, Crash) { 949 TEST_F(CRWWebControllerWebProcessTest, Crash) {
951 web::TestWebStateObserver observer(web_state()); 950 web::TestWebStateObserver observer(web_state());
952 web::TestWebStateObserver* observer_ptr = &observer; 951 web::TestWebStateObserver* observer_ptr = &observer;
953 web::SimulateWKWebViewCrash(webView_); 952 web::SimulateWKWebViewCrash(webView_);
954 base::test::ios::WaitUntilCondition(^bool() { 953 base::test::ios::WaitUntilCondition(^bool() {
955 return observer_ptr->render_process_gone_info(); 954 return observer_ptr->render_process_gone_info();
956 }); 955 });
957 EXPECT_EQ(web_state(), observer.render_process_gone_info()->web_state); 956 EXPECT_EQ(web_state(), observer.render_process_gone_info()->web_state);
958 EXPECT_FALSE([web_controller() isViewAlive]); 957 EXPECT_FALSE([web_controller() isViewAlive]);
959 }; 958 };
960 959
961 } // namespace 960 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698