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

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

Issue 2902083003: Fixed Navigation callbacks for reloading native context. (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « no previous file | ios/web/web_state/ui/crw_web_controller.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 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 #include <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 7
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #import "ios/web/public/navigation_item.h" 9 #import "ios/web/public/navigation_item.h"
10 #import "ios/web/public/navigation_manager.h" 10 #import "ios/web/public/navigation_manager.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 (*context)->GetPageTransition())); 143 (*context)->GetPageTransition()));
144 EXPECT_FALSE((*context)->IsSameDocument()); 144 EXPECT_FALSE((*context)->IsSameDocument());
145 EXPECT_FALSE((*context)->GetError()); 145 EXPECT_FALSE((*context)->GetError());
146 EXPECT_FALSE((*context)->GetResponseHeaders()); 146 EXPECT_FALSE((*context)->GetResponseHeaders());
147 NavigationManager* navigation_manager = web_state->GetNavigationManager(); 147 NavigationManager* navigation_manager = web_state->GetNavigationManager();
148 NavigationItem* item = navigation_manager->GetLastCommittedItem(); 148 NavigationItem* item = navigation_manager->GetLastCommittedItem();
149 EXPECT_GT(item->GetTimestamp().ToInternalValue(), 0); 149 EXPECT_GT(item->GetTimestamp().ToInternalValue(), 0);
150 EXPECT_EQ(url, item->GetURL()); 150 EXPECT_EQ(url, item->GetURL());
151 } 151 }
152 152
153 // Verifies correctness of |NavigationContext| (|arg0|) for reload navigation
154 // passed to |DidStartNavigation|. Stores |NavigationContext| in |context|
155 // pointer.
156 ACTION_P3(VerifyReloadStartedContext, web_state, url, context) {
157 *context = arg0;
158 ASSERT_TRUE(*context);
159 EXPECT_EQ(web_state, (*context)->GetWebState());
160 EXPECT_EQ(url, (*context)->GetUrl());
161 EXPECT_TRUE(
162 PageTransitionCoreTypeIs(ui::PageTransition::PAGE_TRANSITION_RELOAD,
163 (*context)->GetPageTransition()));
164 EXPECT_FALSE((*context)->IsSameDocument());
165 EXPECT_FALSE((*context)->GetError());
166 EXPECT_FALSE((*context)->GetResponseHeaders());
167 // TODO(crbug.com/676129): Reload does not create a pending item. Check
168 // pending item once the bug is fixed.
169 EXPECT_FALSE(web_state->GetNavigationManager()->GetPendingItem());
170 }
171
172 // Verifies correctness of |NavigationContext| (|arg0|) for reload navigation
173 // passed to |DidFinishNavigation|. Asserts that |NavigationContext| the same as
174 // |context|.
175 ACTION_P3(VerifyReloadFinishedContext, web_state, url, context) {
176 ASSERT_EQ(*context, arg0);
177 ASSERT_TRUE(*context);
178 EXPECT_EQ(web_state, (*context)->GetWebState());
179 EXPECT_EQ(url, (*context)->GetUrl());
180 EXPECT_TRUE(
181 PageTransitionCoreTypeIs(ui::PageTransition::PAGE_TRANSITION_RELOAD,
182 (*context)->GetPageTransition()));
183 EXPECT_FALSE((*context)->IsSameDocument());
184 EXPECT_FALSE((*context)->GetError());
185 EXPECT_FALSE((*context)->GetResponseHeaders());
186 NavigationManager* navigation_manager = web_state->GetNavigationManager();
187 NavigationItem* item = navigation_manager->GetLastCommittedItem();
188 EXPECT_GT(item->GetTimestamp().ToInternalValue(), 0);
189 EXPECT_EQ(url, item->GetURL());
190 }
191
153 // Mocks DidFinishNavigation navigation callback. 192 // Mocks DidFinishNavigation navigation callback.
154 class WebStateObserverMock : public WebStateObserver { 193 class WebStateObserverMock : public WebStateObserver {
155 public: 194 public:
156 WebStateObserverMock(WebState* web_state) : WebStateObserver(web_state) {} 195 WebStateObserverMock(WebState* web_state) : WebStateObserver(web_state) {}
157 MOCK_METHOD1(DidStartNavigation, void(NavigationContext* context)); 196 MOCK_METHOD1(DidStartNavigation, void(NavigationContext* context));
158 MOCK_METHOD1(DidFinishNavigation, void(NavigationContext* context)); 197 MOCK_METHOD1(DidFinishNavigation, void(NavigationContext* context));
159 }; 198 };
160 199
161 } // namespace 200 } // namespace
162 201
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 TEST_F(StartAndFinishNavigationTest, NativeContentNavigation) { 343 TEST_F(StartAndFinishNavigationTest, NativeContentNavigation) {
305 GURL url(url::SchemeHostPort(kTestNativeContentScheme, "ui", 0).Serialize()); 344 GURL url(url::SchemeHostPort(kTestNativeContentScheme, "ui", 0).Serialize());
306 NavigationContext* context = nullptr; 345 NavigationContext* context = nullptr;
307 EXPECT_CALL(*observer_, DidStartNavigation(_)) 346 EXPECT_CALL(*observer_, DidStartNavigation(_))
308 .WillOnce(VerifyNewNativePageStartedContext(web_state(), url, &context)); 347 .WillOnce(VerifyNewNativePageStartedContext(web_state(), url, &context));
309 EXPECT_CALL(*observer_, DidFinishNavigation(_)) 348 EXPECT_CALL(*observer_, DidFinishNavigation(_))
310 .WillOnce(VerifyNewNativePageFinishedContext(web_state(), url, &context)); 349 .WillOnce(VerifyNewNativePageFinishedContext(web_state(), url, &context));
311 LoadUrl(url); 350 LoadUrl(url);
312 } 351 }
313 352
353 // Tests native content reload navigation.
354 TEST_F(StartAndFinishNavigationTest, NativeContentReload) {
355 GURL url(url::SchemeHostPort(kTestNativeContentScheme, "ui", 0).Serialize());
356 NavigationContext* context = nullptr;
357 EXPECT_CALL(*observer_, DidStartNavigation(_));
358 EXPECT_CALL(*observer_, DidFinishNavigation(_));
359 LoadUrl(url);
360
361 // Reload native content.
362 EXPECT_CALL(*observer_, DidStartNavigation(_))
363 .WillOnce(VerifyReloadStartedContext(web_state(), url, &context));
364 EXPECT_CALL(*observer_, DidFinishNavigation(_))
365 .WillOnce(VerifyReloadFinishedContext(web_state(), url, &context));
366 navigation_manager()->Reload(ReloadType::NORMAL, false /*check_for_repost*/);
367 }
368
314 } // namespace web 369 } // namespace web
OLDNEW
« no previous file with comments | « no previous file | ios/web/web_state/ui/crw_web_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698