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

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

Issue 2642233004: Removed Form Resubmission callback from CRWWebDelegate. (Closed)
Patch Set: Added ShowRepostFormWarningWithNoDelegateMethod test Created 3 years, 10 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 #import "base/mac/scoped_nsobject.h" 12 #import "base/mac/scoped_nsobject.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #import "ios/web/public/test/fakes/test_web_state.h" 14 #import "ios/web/public/test/fakes/test_web_state.h"
14 #import "ios/web/public/web_state/context_menu_params.h" 15 #import "ios/web/public/web_state/context_menu_params.h"
15 #import "ios/web/web_state/web_state_delegate_stub.h" 16 #import "ios/web/web_state/web_state_delegate_stub.h"
16 #include "testing/platform_test.h" 17 #include "testing/platform_test.h"
17 #import "third_party/ocmock/gtest_support.h" 18 #import "third_party/ocmock/gtest_support.h"
18 #include "ui/base/page_transition_types.h" 19 #include "ui/base/page_transition_types.h"
19 20
21 // Class which conforms to CRWWebStateDelegate protocol, but does not implement
22 // any optional methods.
23 @interface TestEmptyWebStateDelegate : NSObject<CRWWebStateDelegate>
24 @end
25 @implementation TestEmptyWebStateDelegate
26 @end
27
20 namespace web { 28 namespace web {
21 29
22 // Test fixture to test WebStateDelegateBridge class. 30 // Test fixture to test WebStateDelegateBridge class.
23 class WebStateDelegateBridgeTest : public PlatformTest { 31 class WebStateDelegateBridgeTest : public PlatformTest {
24 protected: 32 protected:
25 void SetUp() override { 33 void SetUp() override {
26 PlatformTest::SetUp(); 34 PlatformTest::SetUp();
27 35
28 id originalMockDelegate = 36 id originalMockDelegate =
29 [OCMockObject niceMockForProtocol:@protocol(CRWWebStateDelegate)]; 37 [OCMockObject niceMockForProtocol:@protocol(CRWWebStateDelegate)];
30 delegate_.reset([[CRWWebStateDelegateStub alloc] 38 delegate_.reset([[CRWWebStateDelegateStub alloc]
31 initWithRepresentedObject:originalMockDelegate]); 39 initWithRepresentedObject:originalMockDelegate]);
40 empty_delegate_.reset([[TestEmptyWebStateDelegate alloc] init]);
32 41
33 bridge_.reset(new WebStateDelegateBridge(delegate_.get())); 42 bridge_.reset(new WebStateDelegateBridge(delegate_.get()));
43 empty_delegate_bridge_.reset(
44 new WebStateDelegateBridge(empty_delegate_.get()));
34 } 45 }
35 46
36 void TearDown() override { 47 void TearDown() override {
37 EXPECT_OCMOCK_VERIFY(delegate_); 48 EXPECT_OCMOCK_VERIFY(delegate_);
38 PlatformTest::TearDown(); 49 PlatformTest::TearDown();
39 } 50 }
40 51
41 base::scoped_nsprotocol<id> delegate_; 52 base::scoped_nsprotocol<id> delegate_;
53 base::scoped_nsprotocol<id> empty_delegate_;
42 std::unique_ptr<WebStateDelegateBridge> bridge_; 54 std::unique_ptr<WebStateDelegateBridge> bridge_;
55 std::unique_ptr<WebStateDelegateBridge> empty_delegate_bridge_;
43 web::TestWebState test_web_state_; 56 web::TestWebState test_web_state_;
44 }; 57 };
45 58
46 // Tests |webState:openURLWithParams:| forwarding. 59 // Tests |webState:openURLWithParams:| forwarding.
47 TEST_F(WebStateDelegateBridgeTest, OpenURLFromWebState) { 60 TEST_F(WebStateDelegateBridgeTest, OpenURLFromWebState) {
48 ASSERT_FALSE([delegate_ webState]); 61 ASSERT_FALSE([delegate_ webState]);
49 ASSERT_FALSE([delegate_ openURLParams]); 62 ASSERT_FALSE([delegate_ openURLParams]);
50 63
51 web::WebState::OpenURLParams params( 64 web::WebState::OpenURLParams params(
52 GURL("https://chromium.test/"), 65 GURL("https://chromium.test/"),
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 EXPECT_EQ(context_menu_params.menu_title, result_params->menu_title); 103 EXPECT_EQ(context_menu_params.menu_title, result_params->menu_title);
91 EXPECT_EQ(context_menu_params.link_url, result_params->link_url); 104 EXPECT_EQ(context_menu_params.link_url, result_params->link_url);
92 EXPECT_EQ(context_menu_params.src_url, result_params->src_url); 105 EXPECT_EQ(context_menu_params.src_url, result_params->src_url);
93 EXPECT_EQ(context_menu_params.referrer_policy, 106 EXPECT_EQ(context_menu_params.referrer_policy,
94 result_params->referrer_policy); 107 result_params->referrer_policy);
95 EXPECT_EQ(context_menu_params.view, result_params->view); 108 EXPECT_EQ(context_menu_params.view, result_params->view);
96 EXPECT_EQ(context_menu_params.location.x, result_params->location.x); 109 EXPECT_EQ(context_menu_params.location.x, result_params->location.x);
97 EXPECT_EQ(context_menu_params.location.y, result_params->location.y); 110 EXPECT_EQ(context_menu_params.location.y, result_params->location.y);
98 } 111 }
99 112
113 // Tests |ShowRepostFormWarningDialog| forwarding.
114 TEST_F(WebStateDelegateBridgeTest, ShowRepostFormWarningDialog) {
115 EXPECT_FALSE([delegate_ repostFormWarningRequested]);
116 EXPECT_FALSE([delegate_ webState]);
117 base::Callback<void(bool)> callback;
118 bridge_->ShowRepostFormWarningDialog(&test_web_state_, callback);
119 EXPECT_TRUE([delegate_ repostFormWarningRequested]);
120 EXPECT_EQ(&test_web_state_, [delegate_ webState]);
121 }
122
123 // Tests |ShowRepostFormWarningDialog| forwarding to delegate which does not
124 // implement |webState:runRepostFormDialogWithCompletionHandler:| method.
125 TEST_F(WebStateDelegateBridgeTest, ShowRepostFormWarningWithNoDelegateMethod) {
126 __block bool callback_called = false;
127 empty_delegate_bridge_->ShowRepostFormWarningDialog(
128 nullptr, base::BindBlock(^(bool should_repost) {
129 EXPECT_TRUE(should_repost);
130 callback_called = true;
131 }));
132 EXPECT_TRUE(callback_called);
133 }
134
100 // Tests |GetJavaScriptDialogPresenter| forwarding. 135 // Tests |GetJavaScriptDialogPresenter| forwarding.
101 TEST_F(WebStateDelegateBridgeTest, GetJavaScriptDialogPresenter) { 136 TEST_F(WebStateDelegateBridgeTest, GetJavaScriptDialogPresenter) {
102 EXPECT_FALSE([delegate_ javaScriptDialogPresenterRequested]); 137 EXPECT_FALSE([delegate_ javaScriptDialogPresenterRequested]);
103 bridge_->GetJavaScriptDialogPresenter(nullptr); 138 bridge_->GetJavaScriptDialogPresenter(nullptr);
104 EXPECT_TRUE([delegate_ javaScriptDialogPresenterRequested]); 139 EXPECT_TRUE([delegate_ javaScriptDialogPresenterRequested]);
105 } 140 }
106 141
107 // Tests |OnAuthRequired| forwarding. 142 // Tests |OnAuthRequired| forwarding.
108 TEST_F(WebStateDelegateBridgeTest, OnAuthRequired) { 143 TEST_F(WebStateDelegateBridgeTest, OnAuthRequired) {
109 EXPECT_FALSE([delegate_ authenticationRequested]); 144 EXPECT_FALSE([delegate_ authenticationRequested]);
110 EXPECT_FALSE([delegate_ webState]); 145 EXPECT_FALSE([delegate_ webState]);
111 base::scoped_nsobject<NSURLProtectionSpace> protection_space( 146 base::scoped_nsobject<NSURLProtectionSpace> protection_space(
112 [[NSURLProtectionSpace alloc] init]); 147 [[NSURLProtectionSpace alloc] init]);
113 base::scoped_nsobject<NSURLCredential> credential( 148 base::scoped_nsobject<NSURLCredential> credential(
114 [[NSURLCredential alloc] init]); 149 [[NSURLCredential alloc] init]);
115 WebStateDelegate::AuthCallback callback; 150 WebStateDelegate::AuthCallback callback;
116 bridge_->OnAuthRequired(&test_web_state_, protection_space.get(), 151 bridge_->OnAuthRequired(&test_web_state_, protection_space.get(),
117 credential.get(), callback); 152 credential.get(), callback);
118 EXPECT_TRUE([delegate_ authenticationRequested]); 153 EXPECT_TRUE([delegate_ authenticationRequested]);
119 EXPECT_EQ(&test_web_state_, [delegate_ webState]); 154 EXPECT_EQ(&test_web_state_, [delegate_ webState]);
120 } 155 }
121 156
122 } // namespace web 157 } // namespace web
OLDNEW
« no previous file with comments | « ios/web/web_state/web_state_delegate_bridge.mm ('k') | ios/web/web_state/web_state_delegate_stub.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698