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

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

Issue 2674503002: Unit tests for WebStateObserverBridge class. (Closed)
Patch Set: 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "ios/web/public/web_state/web_state_observer_bridge.h"
6
7 #import "base/mac/scoped_nsobject.h"
8 #include "base/memory/ptr_util.h"
9 #include "ios/web/public/favicon_url.h"
10 #import "ios/web/public/test/fakes/crw_test_web_state_observer.h"
11 #import "ios/web/public/test/fakes/test_web_state.h"
12 #import "ios/web/public/web_state/web_state_observer_bridge.h"
13 #include "testing/platform_test.h"
14
15 namespace web {
16
17 // Test fixture to test WebStateObserverBridge class.
18 class WebStateObserverBridgeTest : public PlatformTest {
19 protected:
20 WebStateObserverBridgeTest()
21 : observer_([[CRWTestWebStateObserver alloc] init]),
22 bridge_(base::MakeUnique<WebStateObserverBridge>(&test_web_state_,
23 observer_.get())) {}
24
25 web::TestWebState test_web_state_;
26 base::scoped_nsobject<CRWTestWebStateObserver> observer_;
27 std::unique_ptr<WebStateObserverBridge> bridge_;
28 };
29
30 // Tests |webState:didStartProvisionalNavigationForURL:| forwarding.
31 TEST_F(WebStateObserverBridgeTest, ProvisionalNavigationStarted) {
32 ASSERT_FALSE([observer_ startProvisionalNavigationInfo]);
33
34 GURL url("https://chromium.test/");
35 bridge_->ProvisionalNavigationStarted(url);
36
37 ASSERT_TRUE([observer_ startProvisionalNavigationInfo]);
38 EXPECT_EQ(&test_web_state_,
39 [observer_ startProvisionalNavigationInfo]->web_state);
40 EXPECT_EQ(url, [observer_ startProvisionalNavigationInfo]->url);
41 }
42
43 // Tests |webState:didCommitNavigationWithDetails:| forwarding.
44 TEST_F(WebStateObserverBridgeTest, NavigationItemCommitted) {
45 ASSERT_FALSE([observer_ commitNavigationInfo]);
46
47 LoadCommittedDetails load_details;
48 load_details.item = reinterpret_cast<web::NavigationItem*>(1);
49 load_details.previous_item_index = 15;
50 load_details.previous_url = GURL("https://chromium.test/");
51 load_details.is_in_page = true;
52
53 bridge_->NavigationItemCommitted(load_details);
54
55 ASSERT_TRUE([observer_ commitNavigationInfo]);
56 EXPECT_EQ(&test_web_state_, [observer_ commitNavigationInfo]->web_state);
57 EXPECT_EQ(load_details.item,
58 [observer_ commitNavigationInfo]->load_details.item);
59 EXPECT_EQ(load_details.previous_item_index,
60 [observer_ commitNavigationInfo]->load_details.previous_item_index);
61 EXPECT_EQ(load_details.previous_url,
62 [observer_ commitNavigationInfo]->load_details.previous_url);
63 EXPECT_EQ(load_details.is_in_page,
64 [observer_ commitNavigationInfo]->load_details.is_in_page);
65 }
66
67 // Tests |webState:didLoadPageWithSuccess:| forwarding.
68 TEST_F(WebStateObserverBridgeTest, PageLoaded) {
69 ASSERT_FALSE([observer_ loadPageInfo]);
70
71 // Forwarding PageLoadCompletionStatus::SUCCESS.
72 bridge_->PageLoaded(PageLoadCompletionStatus::SUCCESS);
73 ASSERT_TRUE([observer_ loadPageInfo]);
74 EXPECT_EQ(&test_web_state_, [observer_ loadPageInfo]->web_state);
75 EXPECT_TRUE([observer_ loadPageInfo]->success);
76
77 // Forwarding PageLoadCompletionStatus::FAILURE.
78 bridge_->PageLoaded(PageLoadCompletionStatus::FAILURE);
79 ASSERT_TRUE([observer_ loadPageInfo]);
80 EXPECT_EQ(&test_web_state_, [observer_ loadPageInfo]->web_state);
81 EXPECT_FALSE([observer_ loadPageInfo]->success);
82 }
83
84 // Tests |webState:webStateDidDismissInterstitial:| forwarding.
85 TEST_F(WebStateObserverBridgeTest, InterstitialDismissed) {
86 ASSERT_FALSE([observer_ dismissInterstitialInfo]);
87
88 // TODO(crbug.com/687735): Fix this method name.
89 bridge_->InsterstitialDismissed();
90 ASSERT_TRUE([observer_ dismissInterstitialInfo]);
91 EXPECT_EQ(&test_web_state_, [observer_ dismissInterstitialInfo]->web_state);
92 }
93
94 // Tests |webState:webStateDidChangeURLHash:| forwarding.
95 TEST_F(WebStateObserverBridgeTest, UrlHashChanged) {
96 ASSERT_FALSE([observer_ changeUrlHashInfo]);
97
98 bridge_->UrlHashChanged();
99 ASSERT_TRUE([observer_ changeUrlHashInfo]);
100 EXPECT_EQ(&test_web_state_, [observer_ changeUrlHashInfo]->web_state);
101 }
102
103 // Tests |webState:webStateDidChangeHistoryState:| forwarding.
104 TEST_F(WebStateObserverBridgeTest, HistoryStateChanged) {
105 ASSERT_FALSE([observer_ changeHistoryStateInfo]);
106
107 bridge_->HistoryStateChanged();
108 ASSERT_TRUE([observer_ changeHistoryStateInfo]);
109 EXPECT_EQ(&test_web_state_, [observer_ changeHistoryStateInfo]->web_state);
110 }
111
112 // Tests |webState:didChangeLoadingProgress:| forwarding.
113 TEST_F(WebStateObserverBridgeTest, LoadProgressChanged) {
114 ASSERT_FALSE([observer_ changeLoadingProgressInfo]);
115
116 const double kTestLoadProgress = 0.75;
117 bridge_->LoadProgressChanged(kTestLoadProgress);
118 ASSERT_TRUE([observer_ changeLoadingProgressInfo]);
119 EXPECT_EQ(&test_web_state_, [observer_ changeLoadingProgressInfo]->web_state);
120 EXPECT_EQ(kTestLoadProgress, [observer_ changeLoadingProgressInfo]->progress);
121 }
122
123 // Tests |webState:didSubmitDocumentWithFormNamed:userInitiated:| forwarding.
124 TEST_F(WebStateObserverBridgeTest, DocumentSubmitted) {
125 ASSERT_FALSE([observer_ submitDocumentInfo]);
126
127 std::string kTestFormName("form-name");
128 BOOL user_initiated = YES;
129 bridge_->DocumentSubmitted(kTestFormName, user_initiated);
130 ASSERT_TRUE([observer_ submitDocumentInfo]);
131 EXPECT_EQ(&test_web_state_, [observer_ submitDocumentInfo]->web_state);
132 EXPECT_EQ(kTestFormName, [observer_ submitDocumentInfo]->form_name);
133 EXPECT_EQ(user_initiated, [observer_ submitDocumentInfo]->user_initiated);
134 }
135
136 // Tests |webState:didRegisterFormActivityWithFormNamed:...| forwarding.
137 TEST_F(WebStateObserverBridgeTest, FormActivityRegistered) {
138 ASSERT_FALSE([observer_ formActivityInfo]);
139
140 std::string kTestFormName("form-name");
141 std::string kTestFieldName("field-name");
142 std::string kTestTypeType("type");
143 std::string kTestValue("value");
144 bridge_->FormActivityRegistered(kTestFormName, kTestFieldName, kTestTypeType,
145 kTestValue, true);
146 ASSERT_TRUE([observer_ formActivityInfo]);
147 EXPECT_EQ(&test_web_state_, [observer_ formActivityInfo]->web_state);
148 EXPECT_EQ(kTestFormName, [observer_ formActivityInfo]->form_name);
149 EXPECT_EQ(kTestFieldName, [observer_ formActivityInfo]->field_name);
150 EXPECT_EQ(kTestTypeType, [observer_ formActivityInfo]->type);
151 EXPECT_EQ(kTestValue, [observer_ formActivityInfo]->value);
152 EXPECT_TRUE([observer_ formActivityInfo]->input_missing);
153 }
154
155 // Tests |webState:didUpdateFaviconURLCandidates:| forwarding.
156 TEST_F(WebStateObserverBridgeTest, FaviconUrlUpdated) {
157 ASSERT_FALSE([observer_ updateFaviconUrlCandidatesInfo]);
158
159 web::FaviconURL url(GURL("https://chromium.test/"),
160 web::FaviconURL::TOUCH_ICON, {gfx::Size(5, 6)});
161
162 bridge_->FaviconUrlUpdated({url});
163 ASSERT_TRUE([observer_ updateFaviconUrlCandidatesInfo]);
164 EXPECT_EQ(&test_web_state_,
165 [observer_ updateFaviconUrlCandidatesInfo]->web_state);
166 ASSERT_EQ(1U, [observer_ updateFaviconUrlCandidatesInfo]->candidates.size());
167 const web::FaviconURL& actual_url =
168 [observer_ updateFaviconUrlCandidatesInfo]->candidates[0];
169 EXPECT_EQ(url.icon_url, actual_url.icon_url);
170 EXPECT_EQ(url.icon_type, actual_url.icon_type);
171 ASSERT_EQ(url.icon_sizes.size(), actual_url.icon_sizes.size());
172 EXPECT_EQ(url.icon_sizes[0].width(), actual_url.icon_sizes[0].width());
173 EXPECT_EQ(url.icon_sizes[0].height(), actual_url.icon_sizes[0].height());
174 }
175
176 // Tests |webState:renderProcessGoneForWebState:| forwarding.
177 TEST_F(WebStateObserverBridgeTest, RenderProcessGone) {
178 ASSERT_FALSE([observer_ renderProcessGoneInfo]);
179
180 bridge_->RenderProcessGone();
181 ASSERT_TRUE([observer_ renderProcessGoneInfo]);
182 EXPECT_EQ(&test_web_state_, [observer_ renderProcessGoneInfo]->web_state);
183 }
184
185 // Tests |webState:webStateDestroyed:| forwarding.
186 TEST_F(WebStateObserverBridgeTest, WebStateDestroyed) {
187 ASSERT_FALSE([observer_ webStateDestroyedInfo]);
188
189 bridge_->WebStateDestroyed();
190 ASSERT_TRUE([observer_ webStateDestroyedInfo]);
191 EXPECT_EQ(&test_web_state_, [observer_ webStateDestroyedInfo]->web_state);
192 }
193
194 // Tests |webState:webStateDidStopLoading:| forwarding.
195 TEST_F(WebStateObserverBridgeTest, DidStopLoading) {
196 ASSERT_FALSE([observer_ stopLoadingInfo]);
197
198 bridge_->DidStopLoading();
199 ASSERT_TRUE([observer_ stopLoadingInfo]);
200 EXPECT_EQ(&test_web_state_, [observer_ stopLoadingInfo]->web_state);
201 }
202
203 // Tests |webState:webStateDidStartLoading:| forwarding.
204 TEST_F(WebStateObserverBridgeTest, DidStartLoading) {
205 ASSERT_FALSE([observer_ startLoadingInfo]);
206
207 bridge_->DidStartLoading();
208 ASSERT_TRUE([observer_ startLoadingInfo]);
209 EXPECT_EQ(&test_web_state_, [observer_ startLoadingInfo]->web_state);
210 }
211
212 } // namespace web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698