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

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

Issue 1874903003: Reversed WebState <-> CRWWebController ownership. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merged with origin/master Created 4 years, 8 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
(...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 void SetUp() override { 843 void SetUp() override {
844 web::WebTestWithWebController::SetUp(); 844 web::WebTestWithWebController::SetUp();
845 845
846 // Configure web delegate. 846 // Configure web delegate.
847 delegate_.reset([[MockInteractionLoader alloc] 847 delegate_.reset([[MockInteractionLoader alloc]
848 initWithRepresentedObject: 848 initWithRepresentedObject:
849 [OCMockObject niceMockForProtocol:@protocol(CRWWebDelegate)]]); 849 [OCMockObject niceMockForProtocol:@protocol(CRWWebDelegate)]]);
850 ASSERT_TRUE([delegate_ blockPopups]); 850 ASSERT_TRUE([delegate_ blockPopups]);
851 [webController_ setDelegate:delegate_]; 851 [webController_ setDelegate:delegate_];
852 852
853 // Configure child web controller. 853 // Configure child web state.
854 child_.reset(CreateWebController()); 854 child_web_state_.reset(new web::WebStateImpl(GetBrowserState()));
855 [child_ setWebUsageEnabled:YES]; 855 [child_web_state_->GetWebController() setWebUsageEnabled:YES];
856 [delegate_ setChildWebController:child_]; 856 [delegate_ setChildWebController:child_web_state_->GetWebController()];
857 857
858 // Configure child web controller's session controller mock. 858 // Configure child web controller's session controller mock.
859 id sessionController = 859 id sessionController =
860 [OCMockObject niceMockForClass:[CRWSessionController class]]; 860 [OCMockObject niceMockForClass:[CRWSessionController class]];
861 BOOL yes = YES; 861 BOOL yes = YES;
862 [[[sessionController stub] andReturnValue:OCMOCK_VALUE(yes)] isOpenedByDOM]; 862 [[[sessionController stub] andReturnValue:OCMOCK_VALUE(yes)] isOpenedByDOM];
863 [child_ webStateImpl]->GetNavigationManagerImpl().SetSessionController( 863 child_web_state_->GetNavigationManagerImpl().SetSessionController(
864 sessionController); 864 sessionController);
865 865
866 LoadHtml(@"<html><body></body></html>"); 866 LoadHtml(@"<html><body></body></html>");
867 } 867 }
868 void TearDown() override { 868 void TearDown() override {
869 EXPECT_OCMOCK_VERIFY(delegate_); 869 EXPECT_OCMOCK_VERIFY(delegate_);
870 [webController_ setDelegate:nil]; 870 [webController_ setDelegate:nil];
871 [child_ close];
872 871
873 web::WebTestWithWebController::TearDown(); 872 web::WebTestWithWebController::TearDown();
874 } 873 }
875 // Executes JavaScript that opens a new window and returns evaluation result 874 // Executes JavaScript that opens a new window and returns evaluation result
876 // as a string. 875 // as a string.
877 NSString* OpenWindowByDOM() { 876 NSString* OpenWindowByDOM() {
878 NSString* const kOpenWindowScript = 877 NSString* const kOpenWindowScript =
879 @"var w = window.open('javascript:void(0);', target='_blank');" 878 @"var w = window.open('javascript:void(0);', target='_blank');"
880 "w.toString();"; 879 "w.toString();";
881 NSString* windowJSObject = EvaluateJavaScriptAsString(kOpenWindowScript); 880 NSString* windowJSObject = EvaluateJavaScriptAsString(kOpenWindowScript);
882 WaitForBackgroundTasks(); 881 WaitForBackgroundTasks();
883 return windowJSObject; 882 return windowJSObject;
884 } 883 }
885 // A CRWWebDelegate mock used for testing. 884 // A CRWWebDelegate mock used for testing.
886 base::scoped_nsobject<id> delegate_; 885 base::scoped_nsobject<id> delegate_;
887 // A child CRWWebController used for testing. 886 // A child WebState used for testing.
888 base::scoped_nsobject<CRWWebController> child_; 887 std::unique_ptr<web::WebStateImpl> child_web_state_;
889 }; 888 };
890 889
891 // Tests that absence of web delegate is handled gracefully. 890 // Tests that absence of web delegate is handled gracefully.
892 TEST_F(CRWWebControllerWindowOpenTest, NoDelegate) { 891 TEST_F(CRWWebControllerWindowOpenTest, NoDelegate) {
893 [webController_ setDelegate:nil]; 892 [webController_ setDelegate:nil];
894 893
895 EXPECT_NSEQ(@"", OpenWindowByDOM()); 894 EXPECT_NSEQ(@"", OpenWindowByDOM());
896 895
897 EXPECT_FALSE([delegate_ blockedPopupInfo]); 896 EXPECT_FALSE([delegate_ blockedPopupInfo]);
898 } 897 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 988
990 [webController_ setDelegate:delegate]; 989 [webController_ setDelegate:delegate];
991 web::SimulateWKWebViewCrash(webView_); 990 web::SimulateWKWebViewCrash(webView_);
992 991
993 EXPECT_OCMOCK_VERIFY(delegate); 992 EXPECT_OCMOCK_VERIFY(delegate);
994 EXPECT_FALSE([webController_ isViewAlive]); 993 EXPECT_FALSE([webController_ isViewAlive]);
995 [webController_ setDelegate:nil]; 994 [webController_ setDelegate:nil];
996 }; 995 };
997 996
998 } // namespace 997 } // namespace
OLDNEW
« no previous file with comments | « ios/web/web_state/ui/crw_web_controller+protected.h ('k') | ios/web/web_state/ui/crw_wk_web_view_web_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698