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

Side by Side Diff: ios/web/web_state/web_state_delegate_bridge_unittest.mm

Issue 2935933003: [ObjC ARC] Converts ios/web:ios_web_web_state_unittests to ARC. (Closed)
Patch Set: Review fixes. 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/public/web_state/web_state_delegate_bridge.h" 5 #import "ios/web/public/web_state/web_state_delegate_bridge.h"
6 6
7 #import <Foundation/Foundation.h> 7 #import <Foundation/Foundation.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/mac/bind_objc_block.h" 11 #include "base/mac/bind_objc_block.h"
12 #import "base/mac/scoped_nsobject.h"
13 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
14 #import "ios/web/public/test/crw_mock_web_state_delegate.h" 13 #import "ios/web/public/test/crw_mock_web_state_delegate.h"
15 #import "ios/web/public/test/fakes/test_web_state.h" 14 #import "ios/web/public/test/fakes/test_web_state.h"
16 #import "ios/web/public/web_state/context_menu_params.h" 15 #import "ios/web/public/web_state/context_menu_params.h"
17 #include "testing/platform_test.h" 16 #include "testing/platform_test.h"
18 #import "third_party/ocmock/gtest_support.h" 17 #import "third_party/ocmock/gtest_support.h"
19 #include "ui/base/page_transition_types.h" 18 #include "ui/base/page_transition_types.h"
20 19
20 #if !defined(__has_feature) || !__has_feature(objc_arc)
21 #error "This file requires ARC support."
22 #endif
23
21 // Class which conforms to CRWWebStateDelegate protocol, but does not implement 24 // Class which conforms to CRWWebStateDelegate protocol, but does not implement
22 // any optional methods. 25 // any optional methods.
23 @interface TestEmptyWebStateDelegate : NSObject<CRWWebStateDelegate> 26 @interface TestEmptyWebStateDelegate : NSObject<CRWWebStateDelegate>
24 @end 27 @end
25 @implementation TestEmptyWebStateDelegate 28 @implementation TestEmptyWebStateDelegate
26 @end 29 @end
27 30
28 namespace web { 31 namespace web {
29 32
30 // Test fixture to test WebStateDelegateBridge class. 33 // Test fixture to test WebStateDelegateBridge class.
31 class WebStateDelegateBridgeTest : public PlatformTest { 34 class WebStateDelegateBridgeTest : public PlatformTest {
32 protected: 35 protected:
33 void SetUp() override { 36 void SetUp() override {
34 PlatformTest::SetUp(); 37 PlatformTest::SetUp();
35 38
36 id originalMockDelegate = 39 id originalMockDelegate =
37 [OCMockObject niceMockForProtocol:@protocol(CRWWebStateDelegate)]; 40 [OCMockObject niceMockForProtocol:@protocol(CRWWebStateDelegate)];
38 delegate_.reset([[CRWMockWebStateDelegate alloc] 41 delegate_ = [[CRWMockWebStateDelegate alloc]
39 initWithRepresentedObject:originalMockDelegate]); 42 initWithRepresentedObject:originalMockDelegate];
40 empty_delegate_.reset([[TestEmptyWebStateDelegate alloc] init]); 43 empty_delegate_ = [[TestEmptyWebStateDelegate alloc] init];
41 44
42 bridge_.reset(new WebStateDelegateBridge(delegate_.get())); 45 bridge_.reset(new WebStateDelegateBridge(delegate_));
43 empty_delegate_bridge_.reset( 46 empty_delegate_bridge_.reset(new WebStateDelegateBridge(empty_delegate_));
44 new WebStateDelegateBridge(empty_delegate_.get()));
45 } 47 }
46 48
47 void TearDown() override { 49 void TearDown() override {
48 EXPECT_OCMOCK_VERIFY(delegate_); 50 EXPECT_OCMOCK_VERIFY(delegate_);
49 PlatformTest::TearDown(); 51 PlatformTest::TearDown();
50 } 52 }
51 53
52 base::scoped_nsprotocol<id> delegate_; 54 id delegate_;
53 base::scoped_nsprotocol<id> empty_delegate_; 55 id empty_delegate_;
54 std::unique_ptr<WebStateDelegateBridge> bridge_; 56 std::unique_ptr<WebStateDelegateBridge> bridge_;
55 std::unique_ptr<WebStateDelegateBridge> empty_delegate_bridge_; 57 std::unique_ptr<WebStateDelegateBridge> empty_delegate_bridge_;
56 web::TestWebState test_web_state_; 58 web::TestWebState test_web_state_;
57 }; 59 };
58 60
59 // Tests |webState:createNewWebStateForURL:openerURL:initiatedByUser:| 61 // Tests |webState:createNewWebStateForURL:openerURL:initiatedByUser:|
60 // forwarding. 62 // forwarding.
61 TEST_F(WebStateDelegateBridgeTest, CreateNewWebState) { 63 TEST_F(WebStateDelegateBridgeTest, CreateNewWebState) {
62 ASSERT_FALSE([delegate_ webState]); 64 ASSERT_FALSE([delegate_ webState]);
63 ASSERT_FALSE([delegate_ webStateCreationRequested]); 65 ASSERT_FALSE([delegate_ webStateCreationRequested]);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 bridge_->ShowRepostFormWarningDialog(&test_web_state_, callback); 137 bridge_->ShowRepostFormWarningDialog(&test_web_state_, callback);
136 EXPECT_TRUE([delegate_ repostFormWarningRequested]); 138 EXPECT_TRUE([delegate_ repostFormWarningRequested]);
137 EXPECT_EQ(&test_web_state_, [delegate_ webState]); 139 EXPECT_EQ(&test_web_state_, [delegate_ webState]);
138 } 140 }
139 141
140 // Tests |ShowRepostFormWarningDialog| forwarding to delegate which does not 142 // Tests |ShowRepostFormWarningDialog| forwarding to delegate which does not
141 // implement |webState:runRepostFormDialogWithCompletionHandler:| method. 143 // implement |webState:runRepostFormDialogWithCompletionHandler:| method.
142 TEST_F(WebStateDelegateBridgeTest, ShowRepostFormWarningWithNoDelegateMethod) { 144 TEST_F(WebStateDelegateBridgeTest, ShowRepostFormWarningWithNoDelegateMethod) {
143 __block bool callback_called = false; 145 __block bool callback_called = false;
144 empty_delegate_bridge_->ShowRepostFormWarningDialog( 146 empty_delegate_bridge_->ShowRepostFormWarningDialog(
145 nullptr, base::BindBlock(^(bool should_repost) { 147 nullptr, base::BindBlockArc(^(bool should_repost) {
146 EXPECT_TRUE(should_repost); 148 EXPECT_TRUE(should_repost);
147 callback_called = true; 149 callback_called = true;
148 })); 150 }));
149 EXPECT_TRUE(callback_called); 151 EXPECT_TRUE(callback_called);
150 } 152 }
151 153
152 // Tests |GetJavaScriptDialogPresenter| forwarding. 154 // Tests |GetJavaScriptDialogPresenter| forwarding.
153 TEST_F(WebStateDelegateBridgeTest, GetJavaScriptDialogPresenter) { 155 TEST_F(WebStateDelegateBridgeTest, GetJavaScriptDialogPresenter) {
154 EXPECT_FALSE([delegate_ javaScriptDialogPresenterRequested]); 156 EXPECT_FALSE([delegate_ javaScriptDialogPresenterRequested]);
155 bridge_->GetJavaScriptDialogPresenter(nullptr); 157 bridge_->GetJavaScriptDialogPresenter(nullptr);
156 EXPECT_TRUE([delegate_ javaScriptDialogPresenterRequested]); 158 EXPECT_TRUE([delegate_ javaScriptDialogPresenterRequested]);
157 } 159 }
158 160
159 // Tests |OnAuthRequired| forwarding. 161 // Tests |OnAuthRequired| forwarding.
160 TEST_F(WebStateDelegateBridgeTest, OnAuthRequired) { 162 TEST_F(WebStateDelegateBridgeTest, OnAuthRequired) {
161 EXPECT_FALSE([delegate_ authenticationRequested]); 163 EXPECT_FALSE([delegate_ authenticationRequested]);
162 EXPECT_FALSE([delegate_ webState]); 164 EXPECT_FALSE([delegate_ webState]);
163 base::scoped_nsobject<NSURLProtectionSpace> protection_space( 165 NSURLProtectionSpace* protection_space = [[NSURLProtectionSpace alloc] init];
164 [[NSURLProtectionSpace alloc] init]); 166 NSURLCredential* credential = [[NSURLCredential alloc] init];
165 base::scoped_nsobject<NSURLCredential> credential(
166 [[NSURLCredential alloc] init]);
167 WebStateDelegate::AuthCallback callback; 167 WebStateDelegate::AuthCallback callback;
168 bridge_->OnAuthRequired(&test_web_state_, protection_space.get(), 168 bridge_->OnAuthRequired(&test_web_state_, protection_space, credential,
169 credential.get(), callback); 169 callback);
170 EXPECT_TRUE([delegate_ authenticationRequested]); 170 EXPECT_TRUE([delegate_ authenticationRequested]);
171 EXPECT_EQ(&test_web_state_, [delegate_ webState]); 171 EXPECT_EQ(&test_web_state_, [delegate_ webState]);
172 } 172 }
173 173
174 } // namespace web 174 } // namespace web
OLDNEW
« no previous file with comments | « ios/web/web_state/page_display_state_unittest.mm ('k') | ios/web/web_state/web_state_impl_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698