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

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

Issue 2910453002: Use ui::PAGE_TRANSITION_RELOAD transition for web page reload. (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
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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 EXPECT_FALSE((*context)->GetError()); 165 EXPECT_FALSE((*context)->GetError());
166 EXPECT_FALSE((*context)->GetResponseHeaders()); 166 EXPECT_FALSE((*context)->GetResponseHeaders());
167 // TODO(crbug.com/676129): Reload does not create a pending item. Check 167 // TODO(crbug.com/676129): Reload does not create a pending item. Check
168 // pending item once the bug is fixed. 168 // pending item once the bug is fixed.
169 EXPECT_FALSE(web_state->GetNavigationManager()->GetPendingItem()); 169 EXPECT_FALSE(web_state->GetNavigationManager()->GetPendingItem());
170 } 170 }
171 171
172 // Verifies correctness of |NavigationContext| (|arg0|) for reload navigation 172 // Verifies correctness of |NavigationContext| (|arg0|) for reload navigation
173 // passed to |DidFinishNavigation|. Asserts that |NavigationContext| the same as 173 // passed to |DidFinishNavigation|. Asserts that |NavigationContext| the same as
174 // |context|. 174 // |context|.
175 ACTION_P3(VerifyReloadFinishedContext, web_state, url, context) { 175 ACTION_P4(VerifyReloadFinishedContext, web_state, url, context, is_web_page) {
176 ASSERT_EQ(*context, arg0); 176 ASSERT_EQ(*context, arg0);
177 ASSERT_TRUE(*context); 177 ASSERT_TRUE(*context);
178 EXPECT_EQ(web_state, (*context)->GetWebState()); 178 EXPECT_EQ(web_state, (*context)->GetWebState());
179 EXPECT_EQ(url, (*context)->GetUrl()); 179 EXPECT_EQ(url, (*context)->GetUrl());
180 EXPECT_TRUE( 180 EXPECT_TRUE(
181 PageTransitionCoreTypeIs(ui::PageTransition::PAGE_TRANSITION_RELOAD, 181 PageTransitionCoreTypeIs(ui::PageTransition::PAGE_TRANSITION_RELOAD,
182 (*context)->GetPageTransition())); 182 (*context)->GetPageTransition()));
183 EXPECT_FALSE((*context)->IsSameDocument()); 183 EXPECT_FALSE((*context)->IsSameDocument());
184 EXPECT_FALSE((*context)->GetError()); 184 EXPECT_FALSE((*context)->GetError());
185 EXPECT_FALSE((*context)->GetResponseHeaders()); 185 if (is_web_page) {
186 ASSERT_TRUE((*context)->GetResponseHeaders());
187 std::string mime_type;
188 (*context)->GetResponseHeaders()->GetMimeType(&mime_type);
189 EXPECT_EQ(kExpectedMimeType, mime_type);
190 } else {
191 EXPECT_FALSE((*context)->GetResponseHeaders());
192 }
186 NavigationManager* navigation_manager = web_state->GetNavigationManager(); 193 NavigationManager* navigation_manager = web_state->GetNavigationManager();
187 NavigationItem* item = navigation_manager->GetLastCommittedItem(); 194 NavigationItem* item = navigation_manager->GetLastCommittedItem();
188 EXPECT_GT(item->GetTimestamp().ToInternalValue(), 0); 195 EXPECT_GT(item->GetTimestamp().ToInternalValue(), 0);
189 EXPECT_EQ(url, item->GetURL()); 196 EXPECT_EQ(url, item->GetURL());
190 } 197 }
191 198
192 // Mocks DidFinishNavigation navigation callback. 199 // Mocks DidFinishNavigation navigation callback.
193 class WebStateObserverMock : public WebStateObserver { 200 class WebStateObserverMock : public WebStateObserver {
194 public: 201 public:
195 WebStateObserverMock(WebState* web_state) : WebStateObserver(web_state) {} 202 WebStateObserverMock(WebState* web_state) : WebStateObserver(web_state) {}
(...skipping 27 matching lines...) Expand all
223 230
224 // Perform new page navigation. 231 // Perform new page navigation.
225 NavigationContext* context = nullptr; 232 NavigationContext* context = nullptr;
226 EXPECT_CALL(*observer_, DidStartNavigation(_)) 233 EXPECT_CALL(*observer_, DidStartNavigation(_))
227 .WillOnce(VerifyNewPageStartedContext(web_state(), url, &context)); 234 .WillOnce(VerifyNewPageStartedContext(web_state(), url, &context));
228 EXPECT_CALL(*observer_, DidFinishNavigation(_)) 235 EXPECT_CALL(*observer_, DidFinishNavigation(_))
229 .WillOnce(VerifyNewPageFinishedContext(web_state(), url, &context)); 236 .WillOnce(VerifyNewPageFinishedContext(web_state(), url, &context));
230 LoadUrl(url); 237 LoadUrl(url);
231 } 238 }
232 239
240 // Tests web page reload navigation.
241 TEST_F(StartAndFinishNavigationTest, WebPageReloadNavigation) {
242 const GURL url = HttpServer::MakeUrl("http://chromium.test");
243 std::map<GURL, std::string> responses;
244 responses[url] = "Chromium Test";
245 web::test::SetUpSimpleHttpServer(responses);
246
247 // Perform new page navigation.
248 NavigationContext* context = nullptr;
249 EXPECT_CALL(*observer_, DidStartNavigation(_));
250 EXPECT_CALL(*observer_, DidFinishNavigation(_));
251 LoadUrl(url);
252
253 // Reload web page.
254 EXPECT_CALL(*observer_, DidStartNavigation(_))
255 .WillOnce(VerifyReloadStartedContext(web_state(), url, &context));
256 EXPECT_CALL(*observer_, DidFinishNavigation(_))
257 .WillOnce(VerifyReloadFinishedContext(web_state(), url, &context,
258 true /* is_web_page */));
259 // TODO(crbug.com/700958): ios/web ignores |check_for_repost| flag and current
260 // delegate does not run callback for ShowRepostFormWarningDialog. Clearing
261 // the delegate will allow form resubmission. Remove this workaround (clearing
262 // the delegate, once |check_for_repost| is supported).
263 web_state()->SetDelegate(nullptr);
264 ExecuteBlockAndWaitForLoad(url, ^{
265 navigation_manager()->Reload(ReloadType::NORMAL,
266 false /*check_for_repost*/);
267 });
268 }
269
233 // Tests user-initiated hash change. 270 // Tests user-initiated hash change.
234 TEST_F(StartAndFinishNavigationTest, UserInitiatedHashChangeNavigation) { 271 TEST_F(StartAndFinishNavigationTest, UserInitiatedHashChangeNavigation) {
235 const GURL url = HttpServer::MakeUrl("http://chromium.test"); 272 const GURL url = HttpServer::MakeUrl("http://chromium.test");
236 std::map<GURL, std::string> responses; 273 std::map<GURL, std::string> responses;
237 responses[url] = "Chromium Test"; 274 responses[url] = "Chromium Test";
238 web::test::SetUpSimpleHttpServer(responses); 275 web::test::SetUpSimpleHttpServer(responses);
239 276
240 // Perform new page navigation. 277 // Perform new page navigation.
241 NavigationContext* context = nullptr; 278 NavigationContext* context = nullptr;
242 EXPECT_CALL(*observer_, DidStartNavigation(_)) 279 EXPECT_CALL(*observer_, DidStartNavigation(_))
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 GURL url(url::SchemeHostPort(kTestNativeContentScheme, "ui", 0).Serialize()); 392 GURL url(url::SchemeHostPort(kTestNativeContentScheme, "ui", 0).Serialize());
356 NavigationContext* context = nullptr; 393 NavigationContext* context = nullptr;
357 EXPECT_CALL(*observer_, DidStartNavigation(_)); 394 EXPECT_CALL(*observer_, DidStartNavigation(_));
358 EXPECT_CALL(*observer_, DidFinishNavigation(_)); 395 EXPECT_CALL(*observer_, DidFinishNavigation(_));
359 LoadUrl(url); 396 LoadUrl(url);
360 397
361 // Reload native content. 398 // Reload native content.
362 EXPECT_CALL(*observer_, DidStartNavigation(_)) 399 EXPECT_CALL(*observer_, DidStartNavigation(_))
363 .WillOnce(VerifyReloadStartedContext(web_state(), url, &context)); 400 .WillOnce(VerifyReloadStartedContext(web_state(), url, &context));
364 EXPECT_CALL(*observer_, DidFinishNavigation(_)) 401 EXPECT_CALL(*observer_, DidFinishNavigation(_))
365 .WillOnce(VerifyReloadFinishedContext(web_state(), url, &context)); 402 .WillOnce(VerifyReloadFinishedContext(web_state(), url, &context,
403 false /* is_web_page */));
366 navigation_manager()->Reload(ReloadType::NORMAL, false /*check_for_repost*/); 404 navigation_manager()->Reload(ReloadType::NORMAL, false /*check_for_repost*/);
367 } 405 }
368 406
369 } // namespace web 407 } // namespace web
OLDNEW
« no previous file with comments | « no previous file | ios/web/web_state/ui/crw_web_controller.mm » ('j') | ios/web/web_state/ui/crw_web_controller.mm » ('J')

Powered by Google App Engine
This is Rietveld 408576698