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

Side by Side Diff: content/browser/frame_host/navigation_controller_impl_unittest.cc

Issue 636673002: Remove navigation from TestRenderViewHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a TODO Created 6 years, 2 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) { 819 TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) {
820 NavigationControllerImpl& controller = controller_impl(); 820 NavigationControllerImpl& controller = controller_impl();
821 TestNotificationTracker notifications; 821 TestNotificationTracker notifications;
822 RegisterForAllNavNotifications(&notifications, &controller); 822 RegisterForAllNavNotifications(&notifications, &controller);
823 823
824 // First make some history, starting with a privileged URL. 824 // First make some history, starting with a privileged URL.
825 const GURL kExistingURL1("http://privileged"); 825 const GURL kExistingURL1("http://privileged");
826 controller.LoadURL( 826 controller.LoadURL(
827 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 827 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
828 // Pretend it has bindings so we can tell if we incorrectly copy it. 828 // Pretend it has bindings so we can tell if we incorrectly copy it.
829 test_rvh()->AllowBindings(2); 829 main_test_rfh()->GetRenderViewHost()->AllowBindings(2);
830 main_test_rfh()->SendNavigate(0, kExistingURL1); 830 main_test_rfh()->SendNavigate(0, kExistingURL1);
831 EXPECT_EQ(1U, navigation_entry_committed_counter_); 831 EXPECT_EQ(1U, navigation_entry_committed_counter_);
832 navigation_entry_committed_counter_ = 0; 832 navigation_entry_committed_counter_ = 0;
833 833
834 // Navigate cross-process to a second URL. 834 // Navigate cross-process to a second URL.
835 const GURL kExistingURL2("http://foo/eh"); 835 const GURL kExistingURL2("http://foo/eh");
836 controller.LoadURL( 836 controller.LoadURL(
837 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 837 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
838 main_test_rfh()->SendBeforeUnloadACK(true); 838 main_test_rfh()->SendBeforeUnloadACK(true);
839 TestRenderFrameHost* foo_rfh = contents()->GetPendingMainFrame(); 839 TestRenderFrameHost* foo_rfh = contents()->GetPendingMainFrame();
(...skipping 1431 matching lines...) Expand 10 before | Expand all | Expand 10 after
2271 2271
2272 TEST_F(NavigationControllerTest, PushStateWithoutPreviousEntry) 2272 TEST_F(NavigationControllerTest, PushStateWithoutPreviousEntry)
2273 { 2273 {
2274 ASSERT_FALSE(controller_impl().GetLastCommittedEntry()); 2274 ASSERT_FALSE(controller_impl().GetLastCommittedEntry());
2275 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2275 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2276 GURL url("http://foo"); 2276 GURL url("http://foo");
2277 params.page_id = 1; 2277 params.page_id = 1;
2278 params.url = url; 2278 params.url = url;
2279 params.page_state = PageState::CreateFromURL(url); 2279 params.page_state = PageState::CreateFromURL(url);
2280 params.was_within_same_page = true; 2280 params.was_within_same_page = true;
2281 test_rvh()->SendNavigateWithParams(&params); 2281 contents()->GetMainFrame()->SendNavigateWithParams(&params);
2282 // We pass if we don't crash. 2282 // We pass if we don't crash.
2283 } 2283 }
2284 2284
2285 // NotificationObserver implementation used in verifying we've received the 2285 // NotificationObserver implementation used in verifying we've received the
2286 // NOTIFICATION_NAV_LIST_PRUNED method. 2286 // NOTIFICATION_NAV_LIST_PRUNED method.
2287 class PrunedListener : public NotificationObserver { 2287 class PrunedListener : public NotificationObserver {
2288 public: 2288 public:
2289 explicit PrunedListener(NavigationControllerImpl* controller) 2289 explicit PrunedListener(NavigationControllerImpl* controller)
2290 : notification_count_(0) { 2290 : notification_count_(0) {
2291 registrar_.Add(this, NOTIFICATION_NAV_LIST_PRUNED, 2291 registrar_.Add(this, NOTIFICATION_NAV_LIST_PRUNED,
(...skipping 1947 matching lines...) Expand 10 before | Expand all | Expand 10 after
4239 for (int i = 0; i < controller.GetEntryCount(); ++i) { 4239 for (int i = 0; i < controller.GetEntryCount(); ++i) {
4240 entry = NavigationEntryImpl::FromNavigationEntry( 4240 entry = NavigationEntryImpl::FromNavigationEntry(
4241 controller.GetEntryAtIndex(i)); 4241 controller.GetEntryAtIndex(i));
4242 EXPECT_FALSE(entry->screenshot().get()) << "Screenshot " << i 4242 EXPECT_FALSE(entry->screenshot().get()) << "Screenshot " << i
4243 << " not cleared"; 4243 << " not cleared";
4244 } 4244 }
4245 } 4245 }
4246 4246
4247 TEST_F(NavigationControllerTest, PushStateUpdatesTitleAndFavicon) { 4247 TEST_F(NavigationControllerTest, PushStateUpdatesTitleAndFavicon) {
4248 // Navigate. 4248 // Navigate.
4249 test_rvh()->SendNavigate(1, GURL("http://foo")); 4249 contents()->GetMainFrame()->SendNavigate(1, GURL("http://foo"));
4250 4250
4251 // Set title and favicon. 4251 // Set title and favicon.
4252 base::string16 title(base::ASCIIToUTF16("Title")); 4252 base::string16 title(base::ASCIIToUTF16("Title"));
4253 FaviconStatus favicon; 4253 FaviconStatus favicon;
4254 favicon.valid = true; 4254 favicon.valid = true;
4255 favicon.url = GURL("http://foo/favicon.ico"); 4255 favicon.url = GURL("http://foo/favicon.ico");
4256 controller().GetLastCommittedEntry()->SetTitle(title); 4256 controller().GetLastCommittedEntry()->SetTitle(title);
4257 controller().GetLastCommittedEntry()->GetFavicon() = favicon; 4257 controller().GetLastCommittedEntry()->GetFavicon() = favicon;
4258 4258
4259 // history.pushState() is called. 4259 // history.pushState() is called.
4260 FrameHostMsg_DidCommitProvisionalLoad_Params params; 4260 FrameHostMsg_DidCommitProvisionalLoad_Params params;
4261 GURL url("http://foo#foo"); 4261 GURL url("http://foo#foo");
4262 params.page_id = 2; 4262 params.page_id = 2;
4263 params.url = url; 4263 params.url = url;
4264 params.page_state = PageState::CreateFromURL(url); 4264 params.page_state = PageState::CreateFromURL(url);
4265 params.was_within_same_page = true; 4265 params.was_within_same_page = true;
4266 test_rvh()->SendNavigateWithParams(&params); 4266 contents()->GetMainFrame()->SendNavigateWithParams(&params);
4267 4267
4268 // The title should immediately be visible on the new NavigationEntry. 4268 // The title should immediately be visible on the new NavigationEntry.
4269 base::string16 new_title = 4269 base::string16 new_title =
4270 controller().GetLastCommittedEntry()->GetTitleForDisplay(std::string()); 4270 controller().GetLastCommittedEntry()->GetTitleForDisplay(std::string());
4271 EXPECT_EQ(title, new_title); 4271 EXPECT_EQ(title, new_title);
4272 FaviconStatus new_favicon = 4272 FaviconStatus new_favicon =
4273 controller().GetLastCommittedEntry()->GetFavicon(); 4273 controller().GetLastCommittedEntry()->GetFavicon();
4274 EXPECT_EQ(favicon.valid, new_favicon.valid); 4274 EXPECT_EQ(favicon.valid, new_favicon.valid);
4275 EXPECT_EQ(favicon.url, new_favicon.url); 4275 EXPECT_EQ(favicon.url, new_favicon.url);
4276 } 4276 }
(...skipping 24 matching lines...) Expand all
4301 controller.LoadURLWithParams(params); 4301 controller.LoadURLWithParams(params);
4302 4302
4303 // Verify that the pending entry correctly indicates that the session history 4303 // Verify that the pending entry correctly indicates that the session history
4304 // should be cleared. 4304 // should be cleared.
4305 NavigationEntryImpl* entry = 4305 NavigationEntryImpl* entry =
4306 NavigationEntryImpl::FromNavigationEntry( 4306 NavigationEntryImpl::FromNavigationEntry(
4307 controller.GetPendingEntry()); 4307 controller.GetPendingEntry());
4308 ASSERT_TRUE(entry); 4308 ASSERT_TRUE(entry);
4309 EXPECT_TRUE(entry->should_clear_history_list()); 4309 EXPECT_TRUE(entry->should_clear_history_list());
4310 4310
4311 // Assume that the RV correctly cleared its history and commit the navigation. 4311 // Assume that the RF correctly cleared its history and commit the navigation.
4312 contents()->GetPendingMainFrame()->GetRenderViewHost()-> 4312 contents()->GetPendingMainFrame()->
4313 set_simulate_history_list_was_cleared(true); 4313 set_simulate_history_list_was_cleared(true);
4314 contents()->CommitPendingNavigation(); 4314 contents()->CommitPendingNavigation();
4315 4315
4316 // Verify that the NavigationController's session history was correctly 4316 // Verify that the NavigationController's session history was correctly
4317 // cleared. 4317 // cleared.
4318 EXPECT_EQ(1, controller.GetEntryCount()); 4318 EXPECT_EQ(1, controller.GetEntryCount());
4319 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 4319 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
4320 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 4320 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
4321 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 4321 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
4322 EXPECT_FALSE(controller.CanGoBack()); 4322 EXPECT_FALSE(controller.CanGoBack());
(...skipping 10 matching lines...) Expand all
4333 GURL url("http://foo"); 4333 GURL url("http://foo");
4334 FrameHostMsg_DidCommitProvisionalLoad_Params params; 4334 FrameHostMsg_DidCommitProvisionalLoad_Params params;
4335 params.page_id = 1; 4335 params.page_id = 1;
4336 params.url = url; 4336 params.url = url;
4337 params.transition = ui::PAGE_TRANSITION_FORM_SUBMIT; 4337 params.transition = ui::PAGE_TRANSITION_FORM_SUBMIT;
4338 params.gesture = NavigationGestureUser; 4338 params.gesture = NavigationGestureUser;
4339 params.page_state = PageState::CreateFromURL(url); 4339 params.page_state = PageState::CreateFromURL(url);
4340 params.was_within_same_page = false; 4340 params.was_within_same_page = false;
4341 params.is_post = true; 4341 params.is_post = true;
4342 params.post_id = 2; 4342 params.post_id = 2;
4343 test_rvh()->SendNavigateWithParams(&params); 4343 contents()->GetMainFrame()->SendNavigateWithParams(&params);
4344 4344
4345 // history.replaceState() is called. 4345 // history.replaceState() is called.
4346 GURL replace_url("http://foo#foo"); 4346 GURL replace_url("http://foo#foo");
4347 params.page_id = 1; 4347 params.page_id = 1;
4348 params.url = replace_url; 4348 params.url = replace_url;
4349 params.transition = ui::PAGE_TRANSITION_LINK; 4349 params.transition = ui::PAGE_TRANSITION_LINK;
4350 params.gesture = NavigationGestureUser; 4350 params.gesture = NavigationGestureUser;
4351 params.page_state = PageState::CreateFromURL(replace_url); 4351 params.page_state = PageState::CreateFromURL(replace_url);
4352 params.was_within_same_page = true; 4352 params.was_within_same_page = true;
4353 params.is_post = false; 4353 params.is_post = false;
4354 params.post_id = -1; 4354 params.post_id = -1;
4355 test_rvh()->SendNavigateWithParams(&params); 4355 contents()->GetMainFrame()->SendNavigateWithParams(&params);
4356 4356
4357 // Now reload. replaceState overrides the POST, so we should not show a 4357 // Now reload. replaceState overrides the POST, so we should not show a
4358 // repost warning dialog. 4358 // repost warning dialog.
4359 controller_impl().Reload(true); 4359 controller_impl().Reload(true);
4360 EXPECT_EQ(0, delegate->repost_form_warning_count()); 4360 EXPECT_EQ(0, delegate->repost_form_warning_count());
4361 } 4361 }
4362 4362
4363 } // namespace content 4363 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698