diff options
25 files changed, 788 insertions, 951 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index d80401d..24179f39 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -2159,17 +2159,16 @@ void AutomationProvider::ShowInterstitialPage(int tab_handle, if (tab_tracker_->ContainsHandle(tab_handle)) { NavigationController* controller = tab_tracker_->GetResource(tab_handle); TabContents* tab_contents = controller->active_contents(); - if (tab_contents->type() == TAB_CONTENTS_WEB) { - AddNavigationStatusListener<bool>(controller, reply_message, true, - false, false); - WebContents* web_contents = tab_contents->AsWebContents(); - AutomationInterstitialPage* interstitial = - new AutomationInterstitialPage(web_contents, - GURL("about:interstitial"), - html_text); - interstitial->Show(); - return; - } + + AddNavigationStatusListener<bool>(controller, reply_message, true, + false, false); + WebContents* web_contents = tab_contents->AsWebContents(); + AutomationInterstitialPage* interstitial = + new AutomationInterstitialPage(web_contents, + GURL("about:interstitial"), + html_text); + interstitial->Show(); + return; } AutomationMsg_ShowInterstitialPage::WriteReplyParams(reply_message, false); @@ -2345,7 +2344,7 @@ void AutomationProvider::ActionOnSSLBlockingPage(int handle, bool proceed, NavigationController* tab = tab_tracker_->GetResource(handle); NavigationEntry* entry = tab->GetActiveEntry(); if (entry->page_type() == NavigationEntry::INTERSTITIAL_PAGE) { - TabContents* tab_contents = tab->GetTabContents(TAB_CONTENTS_WEB); + TabContents* tab_contents = tab->tab_contents(); InterstitialPage* ssl_blocking_page = InterstitialPage::GetInterstitialPage(tab_contents->AsWebContents()); if (ssl_blocking_page) { @@ -2430,17 +2429,12 @@ void AutomationProvider::SavePage(int tab_handle, return; } - TabContents* tab_contents = nav->active_contents(); - if (tab_contents->type() != TAB_CONTENTS_WEB) { - *success = false; - return; - } - SavePackage::SavePackageType save_type = static_cast<SavePackage::SavePackageType>(type); DCHECK(save_type >= SavePackage::SAVE_AS_ONLY_HTML && save_type <= SavePackage::SAVE_AS_COMPLETE_HTML); - tab_contents->AsWebContents()->SavePage(file_name, dir_path, save_type); + nav->tab_contents()->AsWebContents()->SavePage( + file_name, dir_path, save_type); *success = true; } @@ -2505,7 +2499,7 @@ void AutomationProvider::OnMessageFromExternalHost(int handle, NOTREACHED(); return; } - TabContents* tab_contents = tab->GetTabContents(TAB_CONTENTS_WEB); + TabContents* tab_contents = tab->tab_contents(); if (!tab_contents) { NOTREACHED(); return; @@ -2532,7 +2526,7 @@ WebContents* AutomationProvider::GetWebContentsForHandle( if (tab_tracker_->ContainsHandle(handle)) { NavigationController* nav_controller = tab_tracker_->GetResource(handle); TabContents* tab_contents = nav_controller->active_contents(); - if (tab_contents && tab_contents->type() == TAB_CONTENTS_WEB) { + if (tab_contents) { web_contents = tab_contents->AsWebContents(); if (tab) *tab = nav_controller; @@ -2544,12 +2538,8 @@ WebContents* AutomationProvider::GetWebContentsForHandle( ExternalTabContainer* AutomationProvider::GetExternalTabForHandle(int handle) { if (tab_tracker_->ContainsHandle(handle)) { NavigationController* tab = tab_tracker_->GetResource(handle); - TabContents* tab_contents = tab->GetTabContents(TAB_CONTENTS_WEB); - DCHECK(tab_contents); - if (tab_contents) { - return ExternalTabContainer::GetContainerForTab( - tab_contents->GetNativeView()); - } + return ExternalTabContainer::GetContainerForTab( + tab->tab_contents()->GetNativeView()); } return NULL; @@ -2734,7 +2724,6 @@ void AutomationProvider::GetPageCurrentEncoding( if (browser->command_updater()->IsCommandEnabled(IDC_ENCODING_MENU)) { TabContents* tab_contents = nav->active_contents(); - DCHECK(tab_contents->type() == TAB_CONTENTS_WEB); *current_encoding = tab_contents->AsWebContents()->encoding(); } } @@ -2753,7 +2742,6 @@ void AutomationProvider::OverrideEncoding(int tab_handle, if (browser->command_updater()->IsCommandEnabled(IDC_ENCODING_MENU)) { TabContents* tab_contents = nav->active_contents(); - DCHECK(tab_contents->type() == TAB_CONTENTS_WEB); int selected_encoding_id = CharacterEncoding::GetCommandIdByCanonicalEncodingName(encoding_name); if (selected_encoding_id) { diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 26ade9e..16544fd 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -28,7 +28,6 @@ #include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/browser/tab_contents/site_instance.h" -#include "chrome/browser/tab_contents/tab_contents_type.h" #include "chrome/browser/tab_contents/web_contents.h" #include "chrome/browser/tab_contents/web_contents_view.h" #include "chrome/common/chrome_constants.h" @@ -1339,7 +1338,8 @@ TabContents* Browser::CreateTabContentsForURL( TabContentsType type = TabContents::TypeForURL(&real_url); DCHECK(type != TAB_CONTENTS_UNKNOWN_TYPE); - TabContents* contents = TabContents::CreateWithType(type, profile, instance); + TabContents* contents = TabContents::CreateWithType(type, profile, instance, + NULL); contents->SetupController(profile); if (!defer_load) { @@ -2365,7 +2365,8 @@ NavigationController* Browser::BuildRestoredNavigationController( selected_navigation < static_cast<int>(navigations.size())); // Create a NavigationController. This constructor creates the appropriate // set of TabContents. - return new NavigationController(profile_, navigations, selected_navigation); + return new NavigationController(profile_, navigations, selected_navigation, + NULL); } else { // No navigations. Create a tab with about:blank. TabContents* contents = diff --git a/chrome/browser/debugger/devtools_view.cc b/chrome/browser/debugger/devtools_view.cc index 5913190..df4258e 100644 --- a/chrome/browser/debugger/devtools_view.cc +++ b/chrome/browser/debugger/devtools_view.cc @@ -50,7 +50,7 @@ void DevToolsView::Init() { Profile* profile = BrowserList::GetLastActive()->profile(); TabContents* tc = TabContents::CreateWithType(TAB_CONTENTS_WEB, profile, - NULL); + NULL, NULL); web_contents_ = tc->AsWebContents(); web_contents_->SetupController(profile); web_contents_->set_delegate(this); diff --git a/chrome/browser/dom_ui/dom_ui_host.cc b/chrome/browser/dom_ui/dom_ui_host.cc index f68105e..ae7bcc40 100644 --- a/chrome/browser/dom_ui/dom_ui_host.cc +++ b/chrome/browser/dom_ui/dom_ui_host.cc @@ -10,7 +10,6 @@ #include "chrome/browser/browser.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/navigation_entry.h" -#include "chrome/browser/tab_contents/tab_contents_type.h" DOMUIHost::DOMUIHost(Profile* profile, SiteInstance* instance, diff --git a/chrome/browser/download/download_request_manager_unittest.cc b/chrome/browser/download/download_request_manager_unittest.cc index 683ee09..943b439 100644 --- a/chrome/browser/download/download_request_manager_unittest.cc +++ b/chrome/browser/download/download_request_manager_unittest.cc @@ -3,29 +3,30 @@ // found in the LICENSE file. #include "chrome/browser/download/download_request_manager.h" +#include "chrome/browser/renderer_host/test_render_view_host.h" #include "chrome/browser/tab_contents/navigation_controller.h" -#include "chrome/test/test_tab_contents.h" #include "chrome/test/testing_profile.h" #include "testing/gtest/include/gtest/gtest.h" -class DownloadRequestManagerTest : public testing::Test, - public DownloadRequestManager::Callback { +class DownloadRequestManagerTest + : public RenderViewHostTestHarness, + public DownloadRequestManager::Callback { public: virtual void SetUp() { + RenderViewHostTestHarness::SetUp(); + allow_download_ = true; ask_allow_count_ = cancel_count_ = continue_count_ = 0; - factory_.reset(TestTabContentsFactory::CreateAndRegisterFactory()); - TestTabContents* contents = factory_->CreateInstanceImpl(); - contents->set_commit_on_navigate(true); - controller_ = new NavigationController(contents, &profile_); + download_request_manager_ = new DownloadRequestManager(NULL, NULL); test_delegate_.reset(new DownloadRequestManagerTestDelegate(this)); DownloadRequestManager::SetTestingDelegate(test_delegate_.get()); } virtual void TearDown() { - controller_->Destroy(); DownloadRequestManager::SetTestingDelegate(NULL); + + RenderViewHostTestHarness::TearDown(); } virtual void ContinueDownload() { @@ -37,7 +38,7 @@ class DownloadRequestManagerTest : public testing::Test, void CanDownload() { download_request_manager_->CanDownloadImpl( - controller_->active_contents(), this); + controller()->tab_contents(), this); } bool ShouldAllowDownload() { @@ -60,10 +61,7 @@ class DownloadRequestManagerTest : public testing::Test, DownloadRequestManagerTest* test_; }; - TestingProfile profile_; - scoped_ptr<TestTabContentsFactory> factory_; scoped_ptr<DownloadRequestManagerTestDelegate> test_delegate_; - NavigationController* controller_; scoped_refptr<DownloadRequestManager> download_request_manager_; // Number of times ContinueDownload was invoked. @@ -83,13 +81,13 @@ TEST_F(DownloadRequestManagerTest, Allow) { // All tabs should initially start at ALLOW_ONE_DOWNLOAD. ASSERT_EQ(DownloadRequestManager::ALLOW_ONE_DOWNLOAD, download_request_manager_->GetDownloadStatus( - controller_->active_contents())); + controller()->tab_contents())); // Ask if the tab can do a download. This moves to PROMPT_BEFORE_DOWNLOAD. CanDownload(); ASSERT_EQ(DownloadRequestManager::PROMPT_BEFORE_DOWNLOAD, download_request_manager_->GetDownloadStatus( - controller_->active_contents())); + controller()->tab_contents())); // We should have been told we can download. ASSERT_EQ(1, continue_count_); ASSERT_EQ(0, cancel_count_); @@ -104,7 +102,7 @@ TEST_F(DownloadRequestManagerTest, Allow) { ask_allow_count_ = 0; ASSERT_EQ(DownloadRequestManager::ALLOW_ALL_DOWNLOADS, download_request_manager_->GetDownloadStatus( - controller_->active_contents())); + controller()->tab_contents())); // We should have been told we can download. ASSERT_EQ(1, continue_count_); ASSERT_EQ(0, cancel_count_); @@ -116,7 +114,7 @@ TEST_F(DownloadRequestManagerTest, Allow) { ASSERT_EQ(0, ask_allow_count_); ASSERT_EQ(DownloadRequestManager::ALLOW_ALL_DOWNLOADS, download_request_manager_->GetDownloadStatus( - controller_->active_contents())); + controller()->tab_contents())); // We should have been told we can download. ASSERT_EQ(1, continue_count_); ASSERT_EQ(0, cancel_count_); @@ -124,7 +122,7 @@ TEST_F(DownloadRequestManagerTest, Allow) { } TEST_F(DownloadRequestManagerTest, ResetOnNavigation) { - controller_->LoadURL(GURL(factory_->scheme() + "://foo.com/bar"), GURL(), 0); + NavigateAndCommit(GURL("http://foo.com/bar")); // Do two downloads, allowing the second so that we end up with allow all. CanDownload(); @@ -133,12 +131,11 @@ TEST_F(DownloadRequestManagerTest, ResetOnNavigation) { ask_allow_count_ = continue_count_ = cancel_count_ = 0; ASSERT_EQ(DownloadRequestManager::ALLOW_ALL_DOWNLOADS, download_request_manager_->GetDownloadStatus( - controller_->active_contents())); + controller()->tab_contents())); // Navigate to a new URL with the same host, which shouldn't reset the allow // all state. - controller_->LoadURL(GURL(factory_->scheme() + "://foo.com/bar2"), - GURL(), 0); + NavigateAndCommit(GURL("http://foo.com/bar2")); CanDownload(); ASSERT_EQ(1, continue_count_); ASSERT_EQ(0, cancel_count_); @@ -146,37 +143,37 @@ TEST_F(DownloadRequestManagerTest, ResetOnNavigation) { ask_allow_count_ = continue_count_ = cancel_count_ = 0; ASSERT_EQ(DownloadRequestManager::ALLOW_ALL_DOWNLOADS, download_request_manager_->GetDownloadStatus( - controller_->active_contents())); + controller()->tab_contents())); // Do a user gesture, because we're at allow all, this shouldn't change the // state. - download_request_manager_->OnUserGesture(controller_->active_contents()); + download_request_manager_->OnUserGesture(controller()->tab_contents()); ASSERT_EQ(DownloadRequestManager::ALLOW_ALL_DOWNLOADS, download_request_manager_->GetDownloadStatus( - controller_->active_contents())); + controller()->tab_contents())); // Navigate to a completely different host, which should reset the state. - controller_->LoadURL(GURL(factory_->scheme() + "://fooey.com"), GURL(), 0); + NavigateAndCommit(GURL("http://fooey.com")); ASSERT_EQ(DownloadRequestManager::ALLOW_ONE_DOWNLOAD, download_request_manager_->GetDownloadStatus( - controller_->active_contents())); + controller()->tab_contents())); } TEST_F(DownloadRequestManagerTest, ResetOnUserGesture) { - controller_->LoadURL(GURL(factory_->scheme() + "://foo.com/bar"), GURL(), 0); + NavigateAndCommit(GURL("http://foo.com/bar")); // Do one download, which should change to prompt before download. CanDownload(); ask_allow_count_ = continue_count_ = cancel_count_ = 0; ASSERT_EQ(DownloadRequestManager::PROMPT_BEFORE_DOWNLOAD, download_request_manager_->GetDownloadStatus( - controller_->active_contents())); + controller()->tab_contents())); // Do a user gesture, which should reset back to allow one. - download_request_manager_->OnUserGesture(controller_->active_contents()); + download_request_manager_->OnUserGesture(controller()->tab_contents()); ASSERT_EQ(DownloadRequestManager::ALLOW_ONE_DOWNLOAD, download_request_manager_->GetDownloadStatus( - controller_->active_contents())); + controller()->tab_contents())); // Ask twice, which triggers calling the delegate. Don't allow the download // so that we end up with not allowed. @@ -185,13 +182,13 @@ TEST_F(DownloadRequestManagerTest, ResetOnUserGesture) { CanDownload(); ASSERT_EQ(DownloadRequestManager::DOWNLOADS_NOT_ALLOWED, download_request_manager_->GetDownloadStatus( - controller_->active_contents())); + controller()->tab_contents())); // A user gesture now should NOT change the state. - download_request_manager_->OnUserGesture(controller_->active_contents()); + download_request_manager_->OnUserGesture(controller()->tab_contents()); ASSERT_EQ(DownloadRequestManager::DOWNLOADS_NOT_ALLOWED, download_request_manager_->GetDownloadStatus( - controller_->active_contents())); + controller()->tab_contents())); // And make sure we really can't download. ask_allow_count_ = continue_count_ = cancel_count_ = 0; CanDownload(); @@ -201,5 +198,5 @@ TEST_F(DownloadRequestManagerTest, ResetOnUserGesture) { // And the state shouldn't have changed. ASSERT_EQ(DownloadRequestManager::DOWNLOADS_NOT_ALLOWED, download_request_manager_->GetDownloadStatus( - controller_->active_contents())); + controller()->tab_contents())); } diff --git a/chrome/browser/external_tab_container.cc b/chrome/browser/external_tab_container.cc index 9ac5706..da38c7e 100644 --- a/chrome/browser/external_tab_container.cc +++ b/chrome/browser/external_tab_container.cc @@ -64,7 +64,8 @@ bool ExternalTabContainer::Init(Profile* profile, HWND parent, DCHECK(focus_manager); focus_manager->AddKeystrokeListener(this); - tab_contents_ = TabContents::CreateWithType(TAB_CONTENTS_WEB, profile, NULL); + tab_contents_ = TabContents::CreateWithType(TAB_CONTENTS_WEB, profile, + NULL, NULL); if (!tab_contents_) { NOTREACHED(); DestroyWindow(); diff --git a/chrome/browser/navigation_controller_unittest.cc b/chrome/browser/navigation_controller_unittest.cc index 57a602d..6a11b3f 100644 --- a/chrome/browser/navigation_controller_unittest.cc +++ b/chrome/browser/navigation_controller_unittest.cc @@ -7,6 +7,7 @@ #include "base/string_util.h" #include "chrome/browser/profile_manager.h" #include "chrome/browser/history/history.h" +#include "chrome/browser/renderer_host/test_render_view_host.h" #include "chrome/browser/sessions/session_service.h" #include "chrome/browser/sessions/session_service_test_helper.h" #include "chrome/browser/sessions/session_types.h" @@ -23,6 +24,7 @@ #include "chrome/test/testing_profile.h" #include "net/base/net_util.h" #include "testing/gtest/include/gtest/gtest.h" +#include "webkit/glue/webkit_glue.h" // TODO(port): get rid of this section, finish porting. #if defined(OS_WIN) @@ -37,91 +39,9 @@ namespace { // NavigationControllerTest ---------------------------------------------------- -class NavigationControllerTest : public testing::Test, - public TabContentsDelegate { +class NavigationControllerTest : public RenderViewHostTestHarness { public: - NavigationControllerTest() - : contents(NULL), - profile(NULL), - factory1_(TestTabContentsFactory::CreateAndRegisterFactory()), - factory2_(TestTabContentsFactory::CreateAndRegisterFactory()) { - } - - ~NavigationControllerTest() { - delete profile; - } - - // testing::Test methods: - - virtual void SetUp() { - if (!profile) - profile = new TestingProfile(); - - contents = new TestTabContents(type1()); - contents->set_delegate(this); - contents->SetupController(profile); - } - - virtual void TearDown() { - TestTabContents::set_site_instance(NULL); - - // Make sure contents is valid. NavigationControllerHistoryTest ends up - // resetting this before TearDown is invoked. - if (contents) - ClearContents(); - } - - - void ClearContents() { - contents->set_delegate(NULL); - contents->CloseContents(); - contents = NULL; - } - - // TabContentsDelegate methods (only care about ReplaceContents): - virtual void OpenURLFromTab(TabContents*, - const GURL&, - const GURL&, - WindowOpenDisposition, - PageTransition::Type) {} - virtual void NavigationStateChanged(const TabContents*, - unsigned flags) {} - virtual void ReplaceContents(TabContents* source, - TabContents* new_contents) { - contents->set_delegate(NULL); - contents = static_cast<TestTabContents*>(new_contents); - contents->set_delegate(this); - } - virtual void AddNewContents(TabContents*, - TabContents*, - WindowOpenDisposition, - const gfx::Rect&, - bool user_gesture) {} - virtual void ActivateContents(TabContents*) {} - virtual void LoadingStateChanged(TabContents*) {} - virtual void NavigateToPage(TabContents*, const GURL&, - PageTransition::Type) {} - virtual void CloseContents(TabContents*) {} - virtual void MoveContents(TabContents*, const gfx::Rect&) {} - virtual bool IsPopup(TabContents*) { return false; } - virtual void ToolbarSizeChanged(TabContents* source, bool is_animating) {} - virtual void URLStarredChanged(TabContents* source, bool starred) {} - virtual void UpdateTargetURL(TabContents* source, const GURL& url) {}; - - TabContentsType type1() const { return factory1_->type(); } - TabContentsType type2() const { return factory2_->type(); } - - const std::string& scheme1() const { return factory1_->scheme(); } - const std::string& scheme2() const { return factory2_->scheme(); } - - TestTabContents* contents; - - Profile* profile; - - private: - MessageLoopForUI message_loop_; - scoped_ptr<TestTabContentsFactory> factory1_; - scoped_ptr<TestTabContentsFactory> factory2_; + NavigationControllerTest() {} }; // NavigationControllerHistoryTest --------------------------------------------- @@ -129,61 +49,51 @@ class NavigationControllerTest : public testing::Test, class NavigationControllerHistoryTest : public NavigationControllerTest { public: NavigationControllerHistoryTest() - : url0(scheme1() + ":foo1"), - url1(scheme1() + ":foo1"), - url2(scheme1() + ":foo1"), + : url0("http://foo1"), + url1("http://foo1"), + url2("http://foo1"), profile_manager_(NULL) { } virtual ~NavigationControllerHistoryTest() { // Prevent our base class from deleting the profile since profile's // lifetime is managed by profile_manager_. - profile = NULL; STLDeleteElements(&windows_); } + // testing::Test overrides. virtual void SetUp() { - // Calculate the path for a scratch profile, and make sure it's empty. - ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_)); - file_util::AppendToPath(&test_dir_, L"NavigationControllerTest"); - profile_path_ = test_dir_; - file_util::AppendToPath(&profile_path_, L"New Profile"); - file_util::Delete(test_dir_, true); - file_util::CreateDirectory(test_dir_); - - // Create a profile. - profile_manager_ = new ProfileManager(); - profile = ProfileManager::CreateProfile( - FilePath::FromWStringHack(profile_path_), - L"New Profile", L"new-profile", L""); - ASSERT_TRUE(profile); - profile_manager_->AddProfile(profile); - - // Do the super thing. Notice that the above code sets profile, profile is - // used in NavigationControllerTest::SetUp(), hence it now. NavigationControllerTest::SetUp(); // Force the session service to be created. - SessionService* service = profile->GetSessionService(); + SessionService* service = new SessionService(profile()); + profile()->set_session_service(service); service->SetWindowType(window_id, Browser::TYPE_NORMAL); service->SetWindowBounds(window_id, gfx::Rect(0, 1, 2, 3), false); service->SetTabIndexInWindow(window_id, - contents->controller()->session_id(), 0); - contents->controller()->SetWindowID(window_id); + controller()->session_id(), 0); + controller()->SetWindowID(window_id); + + session_helper_.set_service(service); } virtual void TearDown() { - NavigationControllerTest::TearDown(); - - helper_.set_service(NULL); + // Release profile's reference to the session service. Otherwise the file + // will still be open and we won't be able to delete the directory below. + profile()->set_session_service(NULL); + session_helper_.set_service(NULL); // Make sure we wait for history to shut down before continuing. The task // we add will cause our message loop to quit once it is destroyed. HistoryService* history = - profile->GetHistoryService(Profile::IMPLICIT_ACCESS); - history->SetOnBackendDestroyTask(new MessageLoop::QuitTask); - delete profile_manager_; - MessageLoop::current()->Run(); + profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); + if (history) { + history->SetOnBackendDestroyTask(new MessageLoop::QuitTask); + MessageLoop::current()->Run(); + } + + // Do normal cleanup before deleting the profile directory below. + NavigationControllerTest::TearDown(); ASSERT_TRUE(file_util::Delete(test_dir_, true)); ASSERT_FALSE(file_util::PathExists(test_dir_)); @@ -192,27 +102,22 @@ class NavigationControllerHistoryTest : public NavigationControllerTest { // Deletes the current profile manager and creates a new one. Indirectly this // shuts down the history database and reopens it. void ReopenDatabase() { - ClearContents(); - helper_.set_service(NULL); - delete profile_manager_; - profile_manager_ = new ProfileManager(); - profile_manager_->AddProfileByPath( - FilePath::FromWStringHack(profile_path_)); - profile = profile_manager_->GetProfileByPath( - FilePath::FromWStringHack(profile_path_)); - helper_.set_service(profile->GetSessionService()); + session_helper_.set_service(NULL); + profile()->set_session_service(NULL); + + SessionService* service = new SessionService(profile()); + profile()->set_session_service(service); + session_helper_.set_service(service); } void GetLastSession() { - Profile* profile = contents->profile(); - profile->GetSessionService()->TabClosed( - contents->controller()->window_id(), - contents->controller()->session_id()); + profile()->GetSessionService()->TabClosed(controller()->window_id(), + controller()->session_id()); ReopenDatabase(); Time close_time; - helper_.ReadWindows(&windows_); + session_helper_.ReadWindows(&windows_); } CancelableRequestConsumer consumer; @@ -226,7 +131,7 @@ class NavigationControllerHistoryTest : public NavigationControllerTest { SessionID window_id; - SessionServiceTestHelper helper_; + SessionServiceTestHelper session_helper_; private: ProfileManager* profile_manager_; @@ -249,83 +154,83 @@ void RegisterForAllNavNotifications(TestNotificationTracker* tracker, // ----------------------------------------------------------------------------- TEST_F(NavigationControllerTest, Defaults) { - EXPECT_TRUE(contents->is_active()); - EXPECT_TRUE(contents->controller()); - EXPECT_FALSE(contents->controller()->GetPendingEntry()); - EXPECT_FALSE(contents->controller()->GetLastCommittedEntry()); - EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); - EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), -1); - EXPECT_EQ(contents->controller()->GetEntryCount(), 0); - EXPECT_FALSE(contents->controller()->CanGoBack()); - EXPECT_FALSE(contents->controller()->CanGoForward()); + EXPECT_TRUE(contents()->is_active()); + EXPECT_TRUE(controller()); + EXPECT_FALSE(controller()->GetPendingEntry()); + EXPECT_FALSE(controller()->GetLastCommittedEntry()); + EXPECT_EQ(controller()->GetPendingEntryIndex(), -1); + EXPECT_EQ(controller()->GetLastCommittedEntryIndex(), -1); + EXPECT_EQ(controller()->GetEntryCount(), 0); + EXPECT_FALSE(controller()->CanGoBack()); + EXPECT_FALSE(controller()->CanGoForward()); } TEST_F(NavigationControllerTest, LoadURL) { TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); + RegisterForAllNavNotifications(¬ifications, controller()); - const GURL url1(scheme1() + ":foo1"); - const GURL url2(scheme1() + ":foo2"); + const GURL url1("http://foo1"); + const GURL url2("http://foo2"); - contents->controller()->LoadURL(url1, GURL(), PageTransition::TYPED); + controller()->LoadURL(url1, GURL(), PageTransition::TYPED); // Creating a pending notification should not have issued any of the // notifications we're listening for. EXPECT_EQ(0U, notifications.size()); // The load should now be pending. - EXPECT_EQ(contents->controller()->GetEntryCount(), 0); - EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), -1); - EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); - EXPECT_FALSE(contents->controller()->GetLastCommittedEntry()); - EXPECT_TRUE(contents->controller()->GetPendingEntry()); - EXPECT_FALSE(contents->controller()->CanGoBack()); - EXPECT_FALSE(contents->controller()->CanGoForward()); - EXPECT_EQ(contents->GetMaxPageID(), -1); + EXPECT_EQ(controller()->GetEntryCount(), 0); + EXPECT_EQ(controller()->GetLastCommittedEntryIndex(), -1); + EXPECT_EQ(controller()->GetPendingEntryIndex(), -1); + EXPECT_FALSE(controller()->GetLastCommittedEntry()); + EXPECT_TRUE(controller()->GetPendingEntry()); + EXPECT_FALSE(controller()->CanGoBack()); + EXPECT_FALSE(controller()->CanGoForward()); + EXPECT_EQ(contents()->GetMaxPageID(), -1); // We should have gotten no notifications from the preceeding checks. EXPECT_EQ(0U, notifications.size()); - contents->CompleteNavigationAsRenderer(0, url1); + rvh()->SendNavigate(0, url1); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); // The load should now be committed. - EXPECT_EQ(contents->controller()->GetEntryCount(), 1); - EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); - EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); - EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); - EXPECT_FALSE(contents->controller()->GetPendingEntry()); - EXPECT_FALSE(contents->controller()->CanGoBack()); - EXPECT_FALSE(contents->controller()->CanGoForward()); - EXPECT_EQ(contents->GetMaxPageID(), 0); + EXPECT_EQ(controller()->GetEntryCount(), 1); + EXPECT_EQ(controller()->GetLastCommittedEntryIndex(), 0); + EXPECT_EQ(controller()->GetPendingEntryIndex(), -1); + EXPECT_TRUE(controller()->GetLastCommittedEntry()); + EXPECT_FALSE(controller()->GetPendingEntry()); + EXPECT_FALSE(controller()->CanGoBack()); + EXPECT_FALSE(controller()->CanGoForward()); + EXPECT_EQ(contents()->GetMaxPageID(), 0); // Load another... - contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED); + controller()->LoadURL(url2, GURL(), PageTransition::TYPED); // The load should now be pending. - EXPECT_EQ(contents->controller()->GetEntryCount(), 1); - EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); - EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); - EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); - EXPECT_TRUE(contents->controller()->GetPendingEntry()); + EXPECT_EQ(controller()->GetEntryCount(), 1); + EXPECT_EQ(controller()->GetLastCommittedEntryIndex(), 0); + EXPECT_EQ(controller()->GetPendingEntryIndex(), -1); + EXPECT_TRUE(controller()->GetLastCommittedEntry()); + EXPECT_TRUE(controller()->GetPendingEntry()); // TODO(darin): maybe this should really be true? - EXPECT_FALSE(contents->controller()->CanGoBack()); - EXPECT_FALSE(contents->controller()->CanGoForward()); - EXPECT_EQ(contents->GetMaxPageID(), 0); + EXPECT_FALSE(controller()->CanGoBack()); + EXPECT_FALSE(controller()->CanGoForward()); + EXPECT_EQ(contents()->GetMaxPageID(), 0); - contents->CompleteNavigationAsRenderer(1, url2); + rvh()->SendNavigate(1, url2); EXPECT_TRUE(notifications.Check1AndReset( - NotificationType::NAV_ENTRY_COMMITTED)); + NotificationType::NAV_ENTRY_COMMITTED)); // The load should now be committed. - EXPECT_EQ(contents->controller()->GetEntryCount(), 2); - EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1); - EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); - EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); - EXPECT_FALSE(contents->controller()->GetPendingEntry()); - EXPECT_TRUE(contents->controller()->CanGoBack()); - EXPECT_FALSE(contents->controller()->CanGoForward()); - EXPECT_EQ(contents->GetMaxPageID(), 1); + EXPECT_EQ(controller()->GetEntryCount(), 2); + EXPECT_EQ(controller()->GetLastCommittedEntryIndex(), 1); + EXPECT_EQ(controller()->GetPendingEntryIndex(), -1); + EXPECT_TRUE(controller()->GetLastCommittedEntry()); + EXPECT_FALSE(controller()->GetPendingEntry()); + EXPECT_TRUE(controller()->CanGoBack()); + EXPECT_FALSE(controller()->CanGoForward()); + EXPECT_EQ(contents()->GetMaxPageID(), 1); } // Tests what happens when the same page is loaded again. Should not create a @@ -334,85 +239,85 @@ TEST_F(NavigationControllerTest, LoadURL) { // the load commits (because WebCore didn't actually make a new entry). TEST_F(NavigationControllerTest, LoadURL_SamePage) { TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); + RegisterForAllNavNotifications(¬ifications, controller()); - const GURL url1(scheme1() + ":foo1"); + const GURL url1("http://foo1"); - contents->controller()->LoadURL(url1, GURL(), PageTransition::TYPED); + controller()->LoadURL(url1, GURL(), PageTransition::TYPED); EXPECT_EQ(0U, notifications.size()); - contents->CompleteNavigationAsRenderer(0, url1); + rvh()->SendNavigate(0, url1); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - contents->controller()->LoadURL(url1, GURL(), PageTransition::TYPED); + controller()->LoadURL(url1, GURL(), PageTransition::TYPED); EXPECT_EQ(0U, notifications.size()); - contents->CompleteNavigationAsRenderer(0, url1); + rvh()->SendNavigate(0, url1); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); // We should not have produced a new session history entry. - EXPECT_EQ(contents->controller()->GetEntryCount(), 1); - EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); - EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); - EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); - EXPECT_FALSE(contents->controller()->GetPendingEntry()); - EXPECT_FALSE(contents->controller()->CanGoBack()); - EXPECT_FALSE(contents->controller()->CanGoForward()); + EXPECT_EQ(controller()->GetEntryCount(), 1); + EXPECT_EQ(controller()->GetLastCommittedEntryIndex(), 0); + EXPECT_EQ(controller()->GetPendingEntryIndex(), -1); + EXPECT_TRUE(controller()->GetLastCommittedEntry()); + EXPECT_FALSE(controller()->GetPendingEntry()); + EXPECT_FALSE(controller()->CanGoBack()); + EXPECT_FALSE(controller()->CanGoForward()); } // Tests loading a URL but discarding it before the load commits. TEST_F(NavigationControllerTest, LoadURL_Discarded) { TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); + RegisterForAllNavNotifications(¬ifications, controller()); - const GURL url1(scheme1() + ":foo1"); - const GURL url2(scheme1() + ":foo2"); + const GURL url1("http://foo1"); + const GURL url2("http://foo2"); - contents->controller()->LoadURL(url1, GURL(), PageTransition::TYPED); + controller()->LoadURL(url1, GURL(), PageTransition::TYPED); EXPECT_EQ(0U, notifications.size()); - contents->CompleteNavigationAsRenderer(0, url1); + rvh()->SendNavigate(0, url1); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED); - contents->controller()->DiscardNonCommittedEntries(); + controller()->LoadURL(url2, GURL(), PageTransition::TYPED); + controller()->DiscardNonCommittedEntries(); EXPECT_EQ(0U, notifications.size()); // Should not have produced a new session history entry. - EXPECT_EQ(contents->controller()->GetEntryCount(), 1); - EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); - EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); - EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); - EXPECT_FALSE(contents->controller()->GetPendingEntry()); - EXPECT_FALSE(contents->controller()->CanGoBack()); - EXPECT_FALSE(contents->controller()->CanGoForward()); + EXPECT_EQ(controller()->GetEntryCount(), 1); + EXPECT_EQ(controller()->GetLastCommittedEntryIndex(), 0); + EXPECT_EQ(controller()->GetPendingEntryIndex(), -1); + EXPECT_TRUE(controller()->GetLastCommittedEntry()); + EXPECT_FALSE(controller()->GetPendingEntry()); + EXPECT_FALSE(controller()->CanGoBack()); + EXPECT_FALSE(controller()->CanGoForward()); } // Tests navigations that come in unrequested. This happens when the user // navigates from the web page, and here we test that there is no pending entry. TEST_F(NavigationControllerTest, LoadURL_NoPending) { TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); + RegisterForAllNavNotifications(¬ifications, controller()); // First make an existing committed entry. - const GURL kExistingURL1(scheme1() + ":eh"); - contents->controller()->LoadURL(kExistingURL1, GURL(), + const GURL kExistingURL1("http://eh"); + controller()->LoadURL(kExistingURL1, GURL(), PageTransition::TYPED); - contents->CompleteNavigationAsRenderer(0, kExistingURL1); + rvh()->SendNavigate(0, kExistingURL1); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); // Do a new navigation without making a pending one. - const GURL kNewURL(scheme1() + ":see"); - contents->CompleteNavigationAsRenderer(99, kNewURL); + const GURL kNewURL("http://see"); + rvh()->SendNavigate(99, kNewURL); // There should no longer be any pending entry, and the third navigation we // just made should be committed. EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - EXPECT_EQ(-1, contents->controller()->GetPendingEntryIndex()); - EXPECT_EQ(1, contents->controller()->GetLastCommittedEntryIndex()); - EXPECT_EQ(kNewURL, contents->controller()->GetActiveEntry()->url()); + EXPECT_EQ(-1, controller()->GetPendingEntryIndex()); + EXPECT_EQ(1, controller()->GetLastCommittedEntryIndex()); + EXPECT_EQ(kNewURL, controller()->GetActiveEntry()->url()); } // Tests navigating to a new URL when there is a new pending navigation that is @@ -421,33 +326,33 @@ TEST_F(NavigationControllerTest, LoadURL_NoPending) { // commits. TEST_F(NavigationControllerTest, LoadURL_NewPending) { TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); + RegisterForAllNavNotifications(¬ifications, controller()); // First make an existing committed entry. - const GURL kExistingURL1(scheme1() + ":eh"); - contents->controller()->LoadURL(kExistingURL1, GURL(), + const GURL kExistingURL1("http://eh"); + controller()->LoadURL(kExistingURL1, GURL(), PageTransition::TYPED); - contents->CompleteNavigationAsRenderer(0, kExistingURL1); + rvh()->SendNavigate(0, kExistingURL1); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); // Make a pending entry to somewhere new. - const GURL kExistingURL2(scheme1() + ":bee"); - contents->controller()->LoadURL(kExistingURL2, GURL(), + const GURL kExistingURL2("http://bee"); + controller()->LoadURL(kExistingURL2, GURL(), PageTransition::TYPED); EXPECT_EQ(0U, notifications.size()); // Before that commits, do a new navigation. - const GURL kNewURL(scheme1() + ":see"); - contents->CompleteNavigationAsRenderer(3, kNewURL); + const GURL kNewURL("http://see"); + rvh()->SendNavigate(3, kNewURL); // There should no longer be any pending entry, and the third navigation we // just made should be committed. EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - EXPECT_EQ(-1, contents->controller()->GetPendingEntryIndex()); - EXPECT_EQ(1, contents->controller()->GetLastCommittedEntryIndex()); - EXPECT_EQ(kNewURL, contents->controller()->GetActiveEntry()->url()); + EXPECT_EQ(-1, controller()->GetPendingEntryIndex()); + EXPECT_EQ(1, controller()->GetLastCommittedEntryIndex()); + EXPECT_EQ(kNewURL, controller()->GetActiveEntry()->url()); } // Tests navigating to a new URL when there is a pending back/forward @@ -455,378 +360,383 @@ TEST_F(NavigationControllerTest, LoadURL_NewPending) { // they navigate somewhere new. TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); + RegisterForAllNavNotifications(¬ifications, controller()); // First make some history. - const GURL kExistingURL1(scheme1() + ":eh"); - contents->controller()->LoadURL(kExistingURL1, GURL(), + const GURL kExistingURL1("http://eh"); + controller()->LoadURL(kExistingURL1, GURL(), PageTransition::TYPED); - contents->CompleteNavigationAsRenderer(0, kExistingURL1); + rvh()->SendNavigate(0, kExistingURL1); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - const GURL kExistingURL2(scheme1() + ":bee"); - contents->controller()->LoadURL(kExistingURL2, GURL(), + const GURL kExistingURL2("http://bee"); + controller()->LoadURL(kExistingURL2, GURL(), PageTransition::TYPED); - contents->CompleteNavigationAsRenderer(1, kExistingURL2); + rvh()->SendNavigate(1, kExistingURL2); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); // Now make a pending back/forward navigation. The zeroth entry should be // pending. - contents->controller()->GoBack(); + controller()->GoBack(); EXPECT_EQ(0U, notifications.size()); - EXPECT_EQ(0, contents->controller()->GetPendingEntryIndex()); - EXPECT_EQ(1, contents->controller()->GetLastCommittedEntryIndex()); + EXPECT_EQ(0, controller()->GetPendingEntryIndex()); + EXPECT_EQ(1, controller()->GetLastCommittedEntryIndex()); // Before that commits, do a new navigation. - const GURL kNewURL(scheme1() + ":see"); + const GURL kNewURL("http://see"); NavigationController::LoadCommittedDetails details; - contents->CompleteNavigationAsRenderer(3, kNewURL); + rvh()->SendNavigate(3, kNewURL); // There should no longer be any pending entry, and the third navigation we // just made should be committed. EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - EXPECT_EQ(-1, contents->controller()->GetPendingEntryIndex()); - EXPECT_EQ(2, contents->controller()->GetLastCommittedEntryIndex()); - EXPECT_EQ(kNewURL, contents->controller()->GetActiveEntry()->url()); + EXPECT_EQ(-1, controller()->GetPendingEntryIndex()); + EXPECT_EQ(2, controller()->GetLastCommittedEntryIndex()); + EXPECT_EQ(kNewURL, controller()->GetActiveEntry()->url()); } TEST_F(NavigationControllerTest, Reload) { TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); + RegisterForAllNavNotifications(¬ifications, controller()); - const GURL url1(scheme1() + ":foo1"); + const GURL url1("http://foo1"); - contents->controller()->LoadURL(url1, GURL(), PageTransition::TYPED); + controller()->LoadURL(url1, GURL(), PageTransition::TYPED); EXPECT_EQ(0U, notifications.size()); - contents->CompleteNavigationAsRenderer(0, url1); + rvh()->SendNavigate(0, url1); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - contents->controller()->Reload(true); + controller()->Reload(true); EXPECT_EQ(0U, notifications.size()); // The reload is pending. - EXPECT_EQ(contents->controller()->GetEntryCount(), 1); - EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); - EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), 0); - EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); - EXPECT_TRUE(contents->controller()->GetPendingEntry()); - EXPECT_FALSE(contents->controller()->CanGoBack()); - EXPECT_FALSE(contents->controller()->CanGoForward()); - - contents->CompleteNavigationAsRenderer(0, url1); + EXPECT_EQ(controller()->GetEntryCount(), 1); + EXPECT_EQ(controller()->GetLastCommittedEntryIndex(), 0); + EXPECT_EQ(controller()->GetPendingEntryIndex(), 0); + EXPECT_TRUE(controller()->GetLastCommittedEntry()); + EXPECT_TRUE(controller()->GetPendingEntry()); + EXPECT_FALSE(controller()->CanGoBack()); + EXPECT_FALSE(controller()->CanGoForward()); + + rvh()->SendNavigate(0, url1); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); // Now the reload is committed. - EXPECT_EQ(contents->controller()->GetEntryCount(), 1); - EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); - EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); - EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); - EXPECT_FALSE(contents->controller()->GetPendingEntry()); - EXPECT_FALSE(contents->controller()->CanGoBack()); - EXPECT_FALSE(contents->controller()->CanGoForward()); + EXPECT_EQ(controller()->GetEntryCount(), 1); + EXPECT_EQ(controller()->GetLastCommittedEntryIndex(), 0); + EXPECT_EQ(controller()->GetPendingEntryIndex(), -1); + EXPECT_TRUE(controller()->GetLastCommittedEntry()); + EXPECT_FALSE(controller()->GetPendingEntry()); + EXPECT_FALSE(controller()->CanGoBack()); + EXPECT_FALSE(controller()->CanGoForward()); } // Tests what happens when a reload navigation produces a new page. TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); + RegisterForAllNavNotifications(¬ifications, controller()); - const GURL url1(scheme1() + ":foo1"); - const GURL url2(scheme1() + ":foo2"); + const GURL url1("http://foo1"); + const GURL url2("http://foo2"); - contents->controller()->LoadURL(url1, GURL(), PageTransition::TYPED); - contents->CompleteNavigationAsRenderer(0, url1); + controller()->LoadURL(url1, GURL(), PageTransition::TYPED); + rvh()->SendNavigate(0, url1); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - contents->controller()->Reload(true); + controller()->Reload(true); EXPECT_EQ(0U, notifications.size()); - contents->CompleteNavigationAsRenderer(1, url2); + rvh()->SendNavigate(1, url2); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); // Now the reload is committed. - EXPECT_EQ(contents->controller()->GetEntryCount(), 2); - EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1); - EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); - EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); - EXPECT_FALSE(contents->controller()->GetPendingEntry()); - EXPECT_TRUE(contents->controller()->CanGoBack()); - EXPECT_FALSE(contents->controller()->CanGoForward()); + EXPECT_EQ(controller()->GetEntryCount(), 2); + EXPECT_EQ(controller()->GetLastCommittedEntryIndex(), 1); + EXPECT_EQ(controller()->GetPendingEntryIndex(), -1); + EXPECT_TRUE(controller()->GetLastCommittedEntry()); + EXPECT_FALSE(controller()->GetPendingEntry()); + EXPECT_TRUE(controller()->CanGoBack()); + EXPECT_FALSE(controller()->CanGoForward()); } // Tests what happens when we navigate back successfully TEST_F(NavigationControllerTest, Back) { TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); + RegisterForAllNavNotifications(¬ifications, controller()); - const GURL url1(scheme1() + ":foo1"); - contents->CompleteNavigationAsRenderer(0, url1); + const GURL url1("http://foo1"); + rvh()->SendNavigate(0, url1); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - const GURL url2(scheme1() + ":foo2"); - contents->CompleteNavigationAsRenderer(1, url2); + const GURL url2("http://foo2"); + rvh()->SendNavigate(1, url2); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - contents->controller()->GoBack(); + controller()->GoBack(); EXPECT_EQ(0U, notifications.size()); // We should now have a pending navigation to go back. - EXPECT_EQ(contents->controller()->GetEntryCount(), 2); - EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1); - EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), 0); - EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); - EXPECT_TRUE(contents->controller()->GetPendingEntry()); - EXPECT_FALSE(contents->controller()->CanGoBack()); - EXPECT_TRUE(contents->controller()->CanGoForward()); - - contents->CompleteNavigationAsRenderer(0, url2); + EXPECT_EQ(controller()->GetEntryCount(), 2); + EXPECT_EQ(controller()->GetLastCommittedEntryIndex(), 1); + EXPECT_EQ(controller()->GetPendingEntryIndex(), 0); + EXPECT_TRUE(controller()->GetLastCommittedEntry()); + EXPECT_TRUE(controller()->GetPendingEntry()); + EXPECT_FALSE(controller()->CanGoBack()); + EXPECT_TRUE(controller()->CanGoForward()); + + rvh()->SendNavigate(0, url2); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); // The back navigation completed successfully. - EXPECT_EQ(contents->controller()->GetEntryCount(), 2); - EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); - EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); - EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); - EXPECT_FALSE(contents->controller()->GetPendingEntry()); - EXPECT_FALSE(contents->controller()->CanGoBack()); - EXPECT_TRUE(contents->controller()->CanGoForward()); + EXPECT_EQ(controller()->GetEntryCount(), 2); + EXPECT_EQ(controller()->GetLastCommittedEntryIndex(), 0); + EXPECT_EQ(controller()->GetPendingEntryIndex(), -1); + EXPECT_TRUE(controller()->GetLastCommittedEntry()); + EXPECT_FALSE(controller()->GetPendingEntry()); + EXPECT_FALSE(controller()->CanGoBack()); + EXPECT_TRUE(controller()->CanGoForward()); } // Tests what happens when a back navigation produces a new page. TEST_F(NavigationControllerTest, Back_GeneratesNewPage) { TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); + RegisterForAllNavNotifications(¬ifications, controller()); - const GURL url1(scheme1() + ":foo1"); - const GURL url2(scheme1() + ":foo2"); - const GURL url3(scheme1() + ":foo3"); + const GURL url1("http://foo1"); + const GURL url2("http://foo2"); + const GURL url3("http://foo3"); - contents->controller()->LoadURL(url1, GURL(), PageTransition::TYPED); - contents->CompleteNavigationAsRenderer(0, url1); + controller()->LoadURL(url1, GURL(), PageTransition::TYPED); + rvh()->SendNavigate(0, url1); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED); - contents->CompleteNavigationAsRenderer(1, url2); + controller()->LoadURL(url2, GURL(), PageTransition::TYPED); + rvh()->SendNavigate(1, url2); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - contents->controller()->GoBack(); + controller()->GoBack(); EXPECT_EQ(0U, notifications.size()); // We should now have a pending navigation to go back. - EXPECT_EQ(contents->controller()->GetEntryCount(), 2); - EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1); - EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), 0); - EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); - EXPECT_TRUE(contents->controller()->GetPendingEntry()); - EXPECT_FALSE(contents->controller()->CanGoBack()); - EXPECT_TRUE(contents->controller()->CanGoForward()); - - contents->CompleteNavigationAsRenderer(2, url3); + EXPECT_EQ(controller()->GetEntryCount(), 2); + EXPECT_EQ(controller()->GetLastCommittedEntryIndex(), 1); + EXPECT_EQ(controller()->GetPendingEntryIndex(), 0); + EXPECT_TRUE(controller()->GetLastCommittedEntry()); + EXPECT_TRUE(controller()->GetPendingEntry()); + EXPECT_FALSE(controller()->CanGoBack()); + EXPECT_TRUE(controller()->CanGoForward()); + + rvh()->SendNavigate(2, url3); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); // The back navigation resulted in a completely new navigation. // TODO(darin): perhaps this behavior will be confusing to users? - EXPECT_EQ(contents->controller()->GetEntryCount(), 3); - EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 2); - EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); - EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); - EXPECT_FALSE(contents->controller()->GetPendingEntry()); - EXPECT_TRUE(contents->controller()->CanGoBack()); - EXPECT_FALSE(contents->controller()->CanGoForward()); + EXPECT_EQ(controller()->GetEntryCount(), 3); + EXPECT_EQ(controller()->GetLastCommittedEntryIndex(), 2); + EXPECT_EQ(controller()->GetPendingEntryIndex(), -1); + EXPECT_TRUE(controller()->GetLastCommittedEntry()); + EXPECT_FALSE(controller()->GetPendingEntry()); + EXPECT_TRUE(controller()->CanGoBack()); + EXPECT_FALSE(controller()->CanGoForward()); } // Receives a back message when there is a new pending navigation entry. TEST_F(NavigationControllerTest, Back_NewPending) { TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); + RegisterForAllNavNotifications(¬ifications, controller()); - const GURL kUrl1(scheme1() + ":foo1"); - const GURL kUrl2(scheme1() + ":foo2"); - const GURL kUrl3(scheme1() + ":foo3"); + const GURL kUrl1("http://foo1"); + const GURL kUrl2("http://foo2"); + const GURL kUrl3("http://foo3"); // First navigate two places so we have some back history. - contents->CompleteNavigationAsRenderer(0, kUrl1); + rvh()->SendNavigate(0, kUrl1); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - //contents->controller()->LoadURL(kUrl2, PageTransition::TYPED); - contents->CompleteNavigationAsRenderer(1, kUrl2); + //controller()->LoadURL(kUrl2, PageTransition::TYPED); + rvh()->SendNavigate(1, kUrl2); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); // Now start a new pending navigation and go back before it commits. - contents->controller()->LoadURL(kUrl3, GURL(), PageTransition::TYPED); - EXPECT_EQ(-1, contents->controller()->GetPendingEntryIndex()); - EXPECT_EQ(kUrl3, contents->controller()->GetPendingEntry()->url()); - contents->controller()->GoBack(); + controller()->LoadURL(kUrl3, GURL(), PageTransition::TYPED); + EXPECT_EQ(-1, controller()->GetPendingEntryIndex()); + EXPECT_EQ(kUrl3, controller()->GetPendingEntry()->url()); + controller()->GoBack(); // The pending navigation should now be the "back" item and the new one // should be gone. - EXPECT_EQ(0, contents->controller()->GetPendingEntryIndex()); - EXPECT_EQ(kUrl1, contents->controller()->GetPendingEntry()->url()); + EXPECT_EQ(0, controller()->GetPendingEntryIndex()); + EXPECT_EQ(kUrl1, controller()->GetPendingEntry()->url()); } // Receives a back message when there is a different renavigation already // pending. TEST_F(NavigationControllerTest, Back_OtherBackPending) { - const GURL kUrl1(scheme1() + ":foo1"); - const GURL kUrl2(scheme1() + ":foo2"); - const GURL kUrl3(scheme1() + ":foo3"); + const GURL kUrl1("http://foo/1"); + const GURL kUrl2("http://foo/2"); + const GURL kUrl3("http://foo/3"); // First navigate three places so we have some back history. - contents->CompleteNavigationAsRenderer(0, kUrl1); - contents->CompleteNavigationAsRenderer(1, kUrl2); - contents->CompleteNavigationAsRenderer(2, kUrl3); + rvh()->SendNavigate(0, kUrl1); + rvh()->SendNavigate(1, kUrl2); + rvh()->SendNavigate(2, kUrl3); // With nothing pending, say we get a navigation to the second entry. - contents->CompleteNavigationAsRenderer(1, kUrl2); + rvh()->SendNavigate(1, kUrl2); + + // We know all the entries have the same site instance, so we can just grab + // a random one for looking up other entries. + SiteInstance* site_instance = + controller()->GetLastCommittedEntry()->site_instance(); // That second URL should be the last committed and it should have gotten the // new title. - EXPECT_EQ(kUrl2, contents->controller()->GetEntryWithPageID( - type1(), NULL, 1)->url()); - EXPECT_EQ(1, contents->controller()->GetLastCommittedEntryIndex()); - EXPECT_EQ(-1, contents->controller()->GetPendingEntryIndex()); + EXPECT_EQ(kUrl2, controller()->GetEntryWithPageID( + TAB_CONTENTS_WEB, site_instance, 1)->url()); + EXPECT_EQ(1, controller()->GetLastCommittedEntryIndex()); + EXPECT_EQ(-1, controller()->GetPendingEntryIndex()); // Now go forward to the last item again and say it was committed. - contents->controller()->GoForward(); - contents->CompleteNavigationAsRenderer(2, kUrl3); + controller()->GoForward(); + rvh()->SendNavigate(2, kUrl3); // Now start going back one to the second page. It will be pending. - contents->controller()->GoBack(); - EXPECT_EQ(1, contents->controller()->GetPendingEntryIndex()); - EXPECT_EQ(2, contents->controller()->GetLastCommittedEntryIndex()); + controller()->GoBack(); + EXPECT_EQ(1, controller()->GetPendingEntryIndex()); + EXPECT_EQ(2, controller()->GetLastCommittedEntryIndex()); // Not synthesize a totally new back event to the first page. This will not // match the pending one. - contents->CompleteNavigationAsRenderer(0, kUrl1); + rvh()->SendNavigate(0, kUrl1); // The navigation should not have affected the pending entry. - EXPECT_EQ(1, contents->controller()->GetPendingEntryIndex()); + EXPECT_EQ(1, controller()->GetPendingEntryIndex()); // But the navigated entry should be the last committed. - EXPECT_EQ(0, contents->controller()->GetLastCommittedEntryIndex()); - EXPECT_EQ(kUrl1, contents->controller()->GetLastCommittedEntry()->url()); + EXPECT_EQ(0, controller()->GetLastCommittedEntryIndex()); + EXPECT_EQ(kUrl1, controller()->GetLastCommittedEntry()->url()); } // Tests what happens when we navigate forward successfully. TEST_F(NavigationControllerTest, Forward) { TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); + RegisterForAllNavNotifications(¬ifications, controller()); - const GURL url1(scheme1() + ":foo1"); - const GURL url2(scheme1() + ":foo2"); + const GURL url1("http://foo1"); + const GURL url2("http://foo2"); - contents->CompleteNavigationAsRenderer(0, url1); + rvh()->SendNavigate(0, url1); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - contents->CompleteNavigationAsRenderer(1, url2); + rvh()->SendNavigate(1, url2); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - contents->controller()->GoBack(); - contents->CompleteNavigationAsRenderer(0, url1); + controller()->GoBack(); + rvh()->SendNavigate(0, url1); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - contents->controller()->GoForward(); + controller()->GoForward(); // We should now have a pending navigation to go forward. - EXPECT_EQ(contents->controller()->GetEntryCount(), 2); - EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); - EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), 1); - EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); - EXPECT_TRUE(contents->controller()->GetPendingEntry()); - EXPECT_TRUE(contents->controller()->CanGoBack()); - EXPECT_FALSE(contents->controller()->CanGoForward()); - - contents->CompleteNavigationAsRenderer(1, url2); + EXPECT_EQ(controller()->GetEntryCount(), 2); + EXPECT_EQ(controller()->GetLastCommittedEntryIndex(), 0); + EXPECT_EQ(controller()->GetPendingEntryIndex(), 1); + EXPECT_TRUE(controller()->GetLastCommittedEntry()); + EXPECT_TRUE(controller()->GetPendingEntry()); + EXPECT_TRUE(controller()->CanGoBack()); + EXPECT_FALSE(controller()->CanGoForward()); + + rvh()->SendNavigate(1, url2); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); // The forward navigation completed successfully. - EXPECT_EQ(contents->controller()->GetEntryCount(), 2); - EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1); - EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); - EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); - EXPECT_FALSE(contents->controller()->GetPendingEntry()); - EXPECT_TRUE(contents->controller()->CanGoBack()); - EXPECT_FALSE(contents->controller()->CanGoForward()); + EXPECT_EQ(controller()->GetEntryCount(), 2); + EXPECT_EQ(controller()->GetLastCommittedEntryIndex(), 1); + EXPECT_EQ(controller()->GetPendingEntryIndex(), -1); + EXPECT_TRUE(controller()->GetLastCommittedEntry()); + EXPECT_FALSE(controller()->GetPendingEntry()); + EXPECT_TRUE(controller()->CanGoBack()); + EXPECT_FALSE(controller()->CanGoForward()); } // Tests what happens when a forward navigation produces a new page. TEST_F(NavigationControllerTest, Forward_GeneratesNewPage) { TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); + RegisterForAllNavNotifications(¬ifications, controller()); - const GURL url1(scheme1() + ":foo1"); - const GURL url2(scheme1() + ":foo2"); - const GURL url3(scheme1() + ":foo3"); + const GURL url1("http://foo1"); + const GURL url2("http://foo2"); + const GURL url3("http://foo3"); - contents->CompleteNavigationAsRenderer(0, url1); + rvh()->SendNavigate(0, url1); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - contents->CompleteNavigationAsRenderer(1, url2); + rvh()->SendNavigate(1, url2); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - contents->controller()->GoBack(); - contents->CompleteNavigationAsRenderer(0, url1); + controller()->GoBack(); + rvh()->SendNavigate(0, url1); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - contents->controller()->GoForward(); + controller()->GoForward(); EXPECT_EQ(0U, notifications.size()); // Should now have a pending navigation to go forward. - EXPECT_EQ(contents->controller()->GetEntryCount(), 2); - EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); - EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), 1); - EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); - EXPECT_TRUE(contents->controller()->GetPendingEntry()); - EXPECT_TRUE(contents->controller()->CanGoBack()); - EXPECT_FALSE(contents->controller()->CanGoForward()); - - contents->CompleteNavigationAsRenderer(2, url3); + EXPECT_EQ(controller()->GetEntryCount(), 2); + EXPECT_EQ(controller()->GetLastCommittedEntryIndex(), 0); + EXPECT_EQ(controller()->GetPendingEntryIndex(), 1); + EXPECT_TRUE(controller()->GetLastCommittedEntry()); + EXPECT_TRUE(controller()->GetPendingEntry()); + EXPECT_TRUE(controller()->CanGoBack()); + EXPECT_FALSE(controller()->CanGoForward()); + + rvh()->SendNavigate(2, url3); EXPECT_TRUE(notifications.Check2AndReset( NotificationType::NAV_LIST_PRUNED, NotificationType::NAV_ENTRY_COMMITTED)); - EXPECT_EQ(contents->controller()->GetEntryCount(), 2); - EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1); - EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); - EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); - EXPECT_FALSE(contents->controller()->GetPendingEntry()); - EXPECT_TRUE(contents->controller()->CanGoBack()); - EXPECT_FALSE(contents->controller()->CanGoForward()); + EXPECT_EQ(controller()->GetEntryCount(), 2); + EXPECT_EQ(controller()->GetLastCommittedEntryIndex(), 1); + EXPECT_EQ(controller()->GetPendingEntryIndex(), -1); + EXPECT_TRUE(controller()->GetLastCommittedEntry()); + EXPECT_FALSE(controller()->GetPendingEntry()); + EXPECT_TRUE(controller()->CanGoBack()); + EXPECT_FALSE(controller()->CanGoForward()); } // Tests navigation via link click within a subframe. A new navigation entry // should be created. TEST_F(NavigationControllerTest, NewSubframe) { TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); + RegisterForAllNavNotifications(¬ifications, controller()); - const GURL url1(scheme1() + ":foo1"); - contents->CompleteNavigationAsRenderer(0, url1); + const GURL url1("http://foo1"); + rvh()->SendNavigate(0, url1); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - const GURL url2(scheme1() + ":foo2"); + const GURL url2("http://foo2"); ViewHostMsg_FrameNavigate_Params params; params.page_id = 1; params.url = url2; @@ -836,7 +746,7 @@ TEST_F(NavigationControllerTest, NewSubframe) { params.is_post = false; NavigationController::LoadCommittedDetails details; - EXPECT_TRUE(contents->controller()->RendererDidNavigate(params, &details)); + EXPECT_TRUE(controller()->RendererDidNavigate(params, &details)); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); EXPECT_EQ(url1, details.previous_url); @@ -845,7 +755,7 @@ TEST_F(NavigationControllerTest, NewSubframe) { EXPECT_FALSE(details.is_main_frame); // The new entry should be appended. - EXPECT_EQ(2, contents->controller()->GetEntryCount()); + EXPECT_EQ(2, controller()->GetEntryCount()); // New entry should refer to the new page, but the old URL (entries only // reflect the toplevel URL). @@ -858,10 +768,10 @@ TEST_F(NavigationControllerTest, NewSubframe) { // just get thrown on the ground, but we shouldn't crash. TEST_F(NavigationControllerTest, SubframeOnEmptyPage) { TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); + RegisterForAllNavNotifications(¬ifications, controller()); // Navigation controller currently has no entries. - const GURL url(scheme1() + ":foo2"); + const GURL url("http://foo2"); ViewHostMsg_FrameNavigate_Params params; params.page_id = 1; params.url = url; @@ -871,7 +781,7 @@ TEST_F(NavigationControllerTest, SubframeOnEmptyPage) { params.is_post = false; NavigationController::LoadCommittedDetails details; - EXPECT_FALSE(contents->controller()->RendererDidNavigate(params, &details)); + EXPECT_FALSE(controller()->RendererDidNavigate(params, &details)); EXPECT_EQ(0U, notifications.size()); } @@ -879,14 +789,14 @@ TEST_F(NavigationControllerTest, SubframeOnEmptyPage) { // not create new navigation entries. TEST_F(NavigationControllerTest, AutoSubframe) { TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); + RegisterForAllNavNotifications(¬ifications, controller()); - const GURL url1(scheme1() + ":foo1"); - contents->CompleteNavigationAsRenderer(0, url1); + const GURL url1("http://foo1"); + rvh()->SendNavigate(0, url1); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - const GURL url2(scheme1() + ":foo2"); + const GURL url2("http://foo2"); ViewHostMsg_FrameNavigate_Params params; params.page_id = 0; params.url = url2; @@ -897,26 +807,26 @@ TEST_F(NavigationControllerTest, AutoSubframe) { // Navigating should do nothing. NavigationController::LoadCommittedDetails details; - EXPECT_FALSE(contents->controller()->RendererDidNavigate(params, &details)); + EXPECT_FALSE(controller()->RendererDidNavigate(params, &details)); EXPECT_EQ(0U, notifications.size()); // There should still be only one entry. - EXPECT_EQ(1, contents->controller()->GetEntryCount()); + EXPECT_EQ(1, controller()->GetEntryCount()); } // Tests navigation and then going back to a subframe navigation. TEST_F(NavigationControllerTest, BackSubframe) { TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); + RegisterForAllNavNotifications(¬ifications, controller()); // Main page. - const GURL url1(scheme1() + ":foo1"); - contents->CompleteNavigationAsRenderer(0, url1); + const GURL url1("http://foo1"); + rvh()->SendNavigate(0, url1); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); // First manual subframe navigation. - const GURL url2(scheme1() + ":foo2"); + const GURL url2("http://foo2"); ViewHostMsg_FrameNavigate_Params params; params.page_id = 1; params.url = url2; @@ -927,80 +837,80 @@ TEST_F(NavigationControllerTest, BackSubframe) { // This should generate a new entry. NavigationController::LoadCommittedDetails details; - EXPECT_TRUE(contents->controller()->RendererDidNavigate(params, &details)); + EXPECT_TRUE(controller()->RendererDidNavigate(params, &details)); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - EXPECT_EQ(2, contents->controller()->GetEntryCount()); + EXPECT_EQ(2, controller()->GetEntryCount()); // Second manual subframe navigation should also make a new entry. - const GURL url3(scheme1() + ":foo3"); + const GURL url3("http://foo3"); params.page_id = 2; params.url = url3; - EXPECT_TRUE(contents->controller()->RendererDidNavigate(params, &details)); + EXPECT_TRUE(controller()->RendererDidNavigate(params, &details)); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - EXPECT_EQ(3, contents->controller()->GetEntryCount()); - EXPECT_EQ(2, contents->controller()->GetCurrentEntryIndex()); + EXPECT_EQ(3, controller()->GetEntryCount()); + EXPECT_EQ(2, controller()->GetCurrentEntryIndex()); // Go back one. - contents->controller()->GoBack(); + controller()->GoBack(); params.url = url2; params.page_id = 1; - EXPECT_TRUE(contents->controller()->RendererDidNavigate(params, &details)); + EXPECT_TRUE(controller()->RendererDidNavigate(params, &details)); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - EXPECT_EQ(3, contents->controller()->GetEntryCount()); - EXPECT_EQ(1, contents->controller()->GetCurrentEntryIndex()); + EXPECT_EQ(3, controller()->GetEntryCount()); + EXPECT_EQ(1, controller()->GetCurrentEntryIndex()); // Go back one more. - contents->controller()->GoBack(); + controller()->GoBack(); params.url = url1; params.page_id = 0; - EXPECT_TRUE(contents->controller()->RendererDidNavigate(params, &details)); + EXPECT_TRUE(controller()->RendererDidNavigate(params, &details)); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - EXPECT_EQ(3, contents->controller()->GetEntryCount()); - EXPECT_EQ(0, contents->controller()->GetCurrentEntryIndex()); + EXPECT_EQ(3, controller()->GetEntryCount()); + EXPECT_EQ(0, controller()->GetCurrentEntryIndex()); } TEST_F(NavigationControllerTest, LinkClick) { TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); + RegisterForAllNavNotifications(¬ifications, controller()); - const GURL url1(scheme1() + ":foo1"); - const GURL url2(scheme1() + ":foo2"); + const GURL url1("http://foo1"); + const GURL url2("http://foo2"); - contents->CompleteNavigationAsRenderer(0, url1); + rvh()->SendNavigate(0, url1); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - contents->CompleteNavigationAsRenderer(1, url2); + rvh()->SendNavigate(1, url2); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); // Should not have produced a new session history entry. - EXPECT_EQ(contents->controller()->GetEntryCount(), 2); - EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1); - EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); - EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); - EXPECT_FALSE(contents->controller()->GetPendingEntry()); - EXPECT_TRUE(contents->controller()->CanGoBack()); - EXPECT_FALSE(contents->controller()->CanGoForward()); + EXPECT_EQ(controller()->GetEntryCount(), 2); + EXPECT_EQ(controller()->GetLastCommittedEntryIndex(), 1); + EXPECT_EQ(controller()->GetPendingEntryIndex(), -1); + EXPECT_TRUE(controller()->GetLastCommittedEntry()); + EXPECT_FALSE(controller()->GetPendingEntry()); + EXPECT_TRUE(controller()->CanGoBack()); + EXPECT_FALSE(controller()->CanGoForward()); } TEST_F(NavigationControllerTest, InPage) { TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); + RegisterForAllNavNotifications(¬ifications, controller()); // Main page. Note that we need "://" so this URL is treated as "standard" // which are the only ones that can have a ref. - const GURL url1(scheme1() + "://foo"); - contents->CompleteNavigationAsRenderer(0, url1); + const GURL url1("http:////foo"); + rvh()->SendNavigate(0, url1); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); // First navigation. - const GURL url2(scheme1() + "://foo#a"); + const GURL url2("http:////foo#a"); ViewHostMsg_FrameNavigate_Params params; params.page_id = 1; params.url = url2; @@ -1011,174 +921,50 @@ TEST_F(NavigationControllerTest, InPage) { // This should generate a new entry. NavigationController::LoadCommittedDetails details; - EXPECT_TRUE(contents->controller()->RendererDidNavigate(params, &details)); + EXPECT_TRUE(controller()->RendererDidNavigate(params, &details)); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - EXPECT_EQ(2, contents->controller()->GetEntryCount()); + EXPECT_EQ(2, controller()->GetEntryCount()); // Go back one. ViewHostMsg_FrameNavigate_Params back_params(params); - contents->controller()->GoBack(); + controller()->GoBack(); back_params.url = url1; back_params.page_id = 0; - EXPECT_TRUE(contents->controller()->RendererDidNavigate(back_params, + EXPECT_TRUE(controller()->RendererDidNavigate(back_params, &details)); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - EXPECT_EQ(2, contents->controller()->GetEntryCount()); - EXPECT_EQ(0, contents->controller()->GetCurrentEntryIndex()); - EXPECT_EQ(back_params.url, contents->controller()->GetActiveEntry()->url()); + EXPECT_EQ(2, controller()->GetEntryCount()); + EXPECT_EQ(0, controller()->GetCurrentEntryIndex()); + EXPECT_EQ(back_params.url, controller()->GetActiveEntry()->url()); // Go forward ViewHostMsg_FrameNavigate_Params forward_params(params); - contents->controller()->GoForward(); + controller()->GoForward(); forward_params.url = url2; forward_params.page_id = 1; - EXPECT_TRUE(contents->controller()->RendererDidNavigate(forward_params, + EXPECT_TRUE(controller()->RendererDidNavigate(forward_params, &details)); EXPECT_TRUE(notifications.Check1AndReset( NotificationType::NAV_ENTRY_COMMITTED)); - EXPECT_EQ(2, contents->controller()->GetEntryCount()); - EXPECT_EQ(1, contents->controller()->GetCurrentEntryIndex()); + EXPECT_EQ(2, controller()->GetEntryCount()); + EXPECT_EQ(1, controller()->GetCurrentEntryIndex()); EXPECT_EQ(forward_params.url, - contents->controller()->GetActiveEntry()->url()); + controller()->GetActiveEntry()->url()); // Now go back and forward again. This is to work around a bug where we would // compare the incoming URL with the last committed entry rather than the // one identified by an existing page ID. This would result in the second URL // losing the reference fragment when you navigate away from it and then back. - contents->controller()->GoBack(); - EXPECT_TRUE(contents->controller()->RendererDidNavigate(back_params, + controller()->GoBack(); + EXPECT_TRUE(controller()->RendererDidNavigate(back_params, &details)); - contents->controller()->GoForward(); - EXPECT_TRUE(contents->controller()->RendererDidNavigate(forward_params, + controller()->GoForward(); + EXPECT_TRUE(controller()->RendererDidNavigate(forward_params, &details)); EXPECT_EQ(forward_params.url, - contents->controller()->GetActiveEntry()->url()); -} - -TEST_F(NavigationControllerTest, SwitchTypes) { - TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); - - const GURL url1(scheme1() + ":foo"); - const GURL url2(scheme2() + ":foo"); - - contents->CompleteNavigationAsRenderer(0, url1); - EXPECT_TRUE(notifications.Check1AndReset( - NotificationType::NAV_ENTRY_COMMITTED)); - - TestTabContents* initial_contents = contents; - contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED); - - // The tab contents should have been replaced - ASSERT_TRUE(initial_contents != contents); - - contents->CompleteNavigationAsRenderer(1, url2); - EXPECT_TRUE(notifications.Check1AndReset( - NotificationType::NAV_ENTRY_COMMITTED)); - - // A second navigation entry should have been committed even though the - // PageIDs are the same. PageIDs are scoped to the tab contents type. - EXPECT_EQ(contents->controller()->GetEntryCount(), 2); - EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1); - EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); - EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); - EXPECT_FALSE(contents->controller()->GetPendingEntry()); - EXPECT_TRUE(contents->controller()->CanGoBack()); - EXPECT_FALSE(contents->controller()->CanGoForward()); - - // Navigate back... - contents->controller()->GoBack(); - ASSERT_TRUE(initial_contents == contents); // switched again! - contents->CompleteNavigationAsRenderer(0, url1); - EXPECT_TRUE(notifications.Check1AndReset( - NotificationType::NAV_ENTRY_COMMITTED)); - - EXPECT_EQ(contents->controller()->GetEntryCount(), 2); - EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); - EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); - EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); - EXPECT_FALSE(contents->controller()->GetPendingEntry()); - EXPECT_FALSE(contents->controller()->CanGoBack()); - EXPECT_TRUE(contents->controller()->CanGoForward()); - - // There may be TabContentsCollector tasks pending, so flush them from queue. - MessageLoop::current()->RunAllPending(); -} - -// Tests what happens when we begin to navigate to a new contents type, but -// then that navigation gets discarded instead. -TEST_F(NavigationControllerTest, SwitchTypes_Discard) { - TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); - - const GURL url1(scheme1() + ":foo"); - const GURL url2(scheme2() + ":foo"); - - contents->CompleteNavigationAsRenderer(0, url1); - EXPECT_TRUE(notifications.Check1AndReset( - NotificationType::NAV_ENTRY_COMMITTED)); - - TestTabContents* initial_contents = contents; - - contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED); - EXPECT_EQ(0U, notifications.size()); - - // The tab contents should have been replaced - ASSERT_TRUE(initial_contents != contents); - - contents->controller()->DiscardNonCommittedEntries(); - EXPECT_EQ(0U, notifications.size()); - - // The tab contents should have been replaced back - ASSERT_TRUE(initial_contents == contents); - - EXPECT_EQ(contents->controller()->GetEntryCount(), 1); - EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); - EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); - EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); - EXPECT_FALSE(contents->controller()->GetPendingEntry()); - EXPECT_FALSE(contents->controller()->CanGoBack()); - EXPECT_FALSE(contents->controller()->CanGoForward()); - - // There may be TabContentsCollector tasks pending, so flush them from queue. - MessageLoop::current()->RunAllPending(); -} - -// Tests that TabContentsTypes that are not in use are deleted (via a -// TabContentsCollector task). Prevents regression of bug 1296773. -TEST_F(NavigationControllerTest, SwitchTypesCleanup) { - const GURL url1(scheme1() + ":foo"); - const GURL url2(scheme2() + ":foo"); - const GURL url3(scheme2() + ":bar"); - - // Note that we need the LoadURL calls so that pending entries and the - // different tab contents types are created. "Renderer" navigations won't - // actually cross tab contents boundaries without these. - contents->controller()->LoadURL(url1, GURL(), PageTransition::TYPED); - contents->CompleteNavigationAsRenderer(0, url1); - contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED); - contents->CompleteNavigationAsRenderer(1, url2); - contents->controller()->LoadURL(url3, GURL(), PageTransition::TYPED); - contents->CompleteNavigationAsRenderer(2, url3); - - // Navigate back to the start. - contents->controller()->GoToIndex(0); - contents->CompleteNavigationAsRenderer(0, url1); - - // Now jump to the end. - contents->controller()->GoToIndex(2); - contents->CompleteNavigationAsRenderer(2, url3); - - // There may be TabContentsCollector tasks pending, so flush them from queue. - MessageLoop::current()->RunAllPending(); - - // Now that the tasks have been flushed, the first tab type should be gone. - ASSERT_TRUE( - contents->controller()->GetTabContents(type1()) == NULL); - ASSERT_EQ(contents, - contents->controller()->GetTabContents(type2())); + controller()->GetActiveEntry()->url()); } namespace { @@ -1224,27 +1010,22 @@ TEST_F(NavigationControllerTest, EnforceMaxNavigationCount) { NavigationController::set_max_entry_count(kMaxEntryCount); int url_index; - char buffer[128]; // Load up to the max count, all entries should be there. for (url_index = 0; url_index < kMaxEntryCount; url_index++) { - base::snprintf(buffer, 128, (scheme1() + "://www.a.com/%d").c_str(), - url_index); - GURL url(buffer); - contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED); - contents->CompleteNavigationAsRenderer(url_index, url); + GURL url(StringPrintf("http://www.a.com/%d", url_index)); + controller()->LoadURL(url, GURL(), PageTransition::TYPED); + rvh()->SendNavigate(url_index, url); } - EXPECT_EQ(contents->controller()->GetEntryCount(), kMaxEntryCount); + EXPECT_EQ(controller()->GetEntryCount(), kMaxEntryCount); // Created a PrunedListener to observe prune notifications. - PrunedListener listener(contents->controller()); + PrunedListener listener(controller()); // Navigate some more. - base::snprintf(buffer, 128, (scheme1() + "://www.a.com/%d").c_str(), - url_index); - GURL url(buffer); - contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED); - contents->CompleteNavigationAsRenderer(url_index, url); + GURL url(StringPrintf("http://www.a.com/%d", url_index)); + controller()->LoadURL(url, GURL(), PageTransition::TYPED); + rvh()->SendNavigate(url_index, url); url_index++; // We should have got a pruned navigation. @@ -1253,22 +1034,20 @@ TEST_F(NavigationControllerTest, EnforceMaxNavigationCount) { EXPECT_EQ(1, listener.details_.count); // We expect http://www.a.com/0 to be gone. - EXPECT_EQ(contents->controller()->GetEntryCount(), kMaxEntryCount); - EXPECT_EQ(contents->controller()->GetEntryAtIndex(0)->url(), - GURL(scheme1() + "://www.a.com/1")); + EXPECT_EQ(controller()->GetEntryCount(), kMaxEntryCount); + EXPECT_EQ(controller()->GetEntryAtIndex(0)->url(), + GURL("http:////www.a.com/1")); // More navigations. for (int i = 0; i < 3; i++) { - base::snprintf(buffer, 128, (scheme1() + "://www.a.com/%d").c_str(), - url_index); - url = GURL(buffer); - contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED); - contents->CompleteNavigationAsRenderer(url_index, url); + url = GURL(StringPrintf("http:////www.a.com/%d", url_index)); + controller()->LoadURL(url, GURL(), PageTransition::TYPED); + rvh()->SendNavigate(url_index, url); url_index++; } - EXPECT_EQ(contents->controller()->GetEntryCount(), kMaxEntryCount); - EXPECT_EQ(contents->controller()->GetEntryAtIndex(0)->url(), - GURL(scheme1() + "://www.a.com/4")); + EXPECT_EQ(controller()->GetEntryCount(), kMaxEntryCount); + EXPECT_EQ(controller()->GetEntryAtIndex(0)->url(), + GURL("http:////www.a.com/4")); NavigationController::set_max_entry_count(original_count); } @@ -1277,24 +1056,21 @@ TEST_F(NavigationControllerTest, EnforceMaxNavigationCount) { // everything is updated properly. This can be tricky since there is no // SiteInstance for the entries created initially. TEST_F(NavigationControllerTest, RestoreNavigate) { - SiteInstance* site_instance = SiteInstance::CreateSiteInstance(profile); - TestTabContents::set_site_instance(site_instance); - site_instance->AddRef(); - // Create a NavigationController with a restored set of tabs. - GURL url(scheme1() + ":foo"); + GURL url("http://foo"); std::vector<TabNavigation> navigations; navigations.push_back(TabNavigation(0, url, GURL(), ASCIIToUTF16("Title"), "state", PageTransition::LINK)); - NavigationController* controller = - new NavigationController(profile, navigations, 0); - controller->GoToIndex(0); + NavigationController* our_controller = + new NavigationController(profile(), navigations, 0, &rvh_factory_); + our_controller->GoToIndex(0); // We should now have one entry, and it should be "pending". - EXPECT_EQ(1, controller->GetEntryCount()); - EXPECT_EQ(controller->GetEntryAtIndex(0), controller->GetPendingEntry()); - EXPECT_EQ(0, controller->GetEntryAtIndex(0)->page_id()); + EXPECT_EQ(1, our_controller->GetEntryCount()); + EXPECT_EQ(our_controller->GetEntryAtIndex(0), + our_controller->GetPendingEntry()); + EXPECT_EQ(0, our_controller->GetEntryAtIndex(0)->page_id()); // Say we navigated to that entry. ViewHostMsg_FrameNavigate_Params params; @@ -1305,225 +1081,222 @@ TEST_F(NavigationControllerTest, RestoreNavigate) { params.gesture = NavigationGestureUser; params.is_post = false; NavigationController::LoadCommittedDetails details; - controller->RendererDidNavigate(params, &details); + our_controller->RendererDidNavigate(params, &details); // There should be no longer any pending entry and one committed one. This // means that we were able to locate the entry, assign its site instance, and // commit it properly. - EXPECT_EQ(1, controller->GetEntryCount()); - EXPECT_EQ(0, controller->GetLastCommittedEntryIndex()); - EXPECT_FALSE(controller->GetPendingEntry()); - EXPECT_EQ(site_instance, - controller->GetLastCommittedEntry()->site_instance()); + EXPECT_EQ(1, our_controller->GetEntryCount()); + EXPECT_EQ(0, our_controller->GetLastCommittedEntryIndex()); + EXPECT_FALSE(our_controller->GetPendingEntry()); + EXPECT_EQ(url, + our_controller->GetLastCommittedEntry()->site_instance()->site()); // Clean up the navigation controller. - ClearContents(); - controller->Destroy(); - TestTabContents::set_site_instance(NULL); - site_instance->Release(); + our_controller->Destroy(); } // Make sure that the page type and stuff is correct after an interstitial. TEST_F(NavigationControllerTest, Interstitial) { // First navigate somewhere normal. - const GURL url1(scheme1() + ":foo"); - contents->controller()->LoadURL(url1, GURL(), PageTransition::TYPED); - contents->CompleteNavigationAsRenderer(0, url1); + const GURL url1("http://foo"); + controller()->LoadURL(url1, GURL(), PageTransition::TYPED); + rvh()->SendNavigate(0, url1); // Now navigate somewhere with an interstitial. - const GURL url2(scheme1() + ":bar"); - contents->controller()->LoadURL(url1, GURL(), PageTransition::TYPED); - contents->controller()->GetPendingEntry()->set_page_type( + const GURL url2("http://bar"); + controller()->LoadURL(url1, GURL(), PageTransition::TYPED); + controller()->GetPendingEntry()->set_page_type( NavigationEntry::INTERSTITIAL_PAGE); // At this point the interstitial will be displayed and the load will still // be pending. If the user continues, the load will commit. - contents->CompleteNavigationAsRenderer(1, url2); + rvh()->SendNavigate(1, url2); // The page should be a normal page again. - EXPECT_EQ(url2, contents->controller()->GetLastCommittedEntry()->url()); + EXPECT_EQ(url2, controller()->GetLastCommittedEntry()->url()); EXPECT_EQ(NavigationEntry::NORMAL_PAGE, - contents->controller()->GetLastCommittedEntry()->page_type()); + controller()->GetLastCommittedEntry()->page_type()); } TEST_F(NavigationControllerTest, RemoveEntry) { - const GURL url1(scheme1() + ":foo1"); - const GURL url2(scheme1() + ":foo2"); - const GURL url3(scheme1() + ":foo3"); - const GURL url4(scheme1() + ":foo4"); - const GURL url5(scheme1() + ":foo5"); - const GURL pending_url(scheme1() + ":pending"); - const GURL default_url(scheme1() + ":default"); - - contents->controller()->LoadURL(url1, GURL(), PageTransition::TYPED); - contents->CompleteNavigationAsRenderer(0, url1); - contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED); - contents->CompleteNavigationAsRenderer(1, url2); - contents->controller()->LoadURL(url3, GURL(), PageTransition::TYPED); - contents->CompleteNavigationAsRenderer(2, url3); - contents->controller()->LoadURL(url4, GURL(), PageTransition::TYPED); - contents->CompleteNavigationAsRenderer(3, url4); - contents->controller()->LoadURL(url5, GURL(), PageTransition::TYPED); - contents->CompleteNavigationAsRenderer(4, url5); + const GURL url1("http://foo1"); + const GURL url2("http://foo2"); + const GURL url3("http://foo3"); + const GURL url4("http://foo4"); + const GURL url5("http://foo5"); + const GURL pending_url("http://pending"); + const GURL default_url("http://default"); + + controller()->LoadURL(url1, GURL(), PageTransition::TYPED); + rvh()->SendNavigate(0, url1); + controller()->LoadURL(url2, GURL(), PageTransition::TYPED); + rvh()->SendNavigate(1, url2); + controller()->LoadURL(url3, GURL(), PageTransition::TYPED); + rvh()->SendNavigate(2, url3); + controller()->LoadURL(url4, GURL(), PageTransition::TYPED); + rvh()->SendNavigate(3, url4); + controller()->LoadURL(url5, GURL(), PageTransition::TYPED); + rvh()->SendNavigate(4, url5); // Remove the last entry. - contents->controller()->RemoveEntryAtIndex( - contents->controller()->GetEntryCount() - 1, default_url); - EXPECT_EQ(4, contents->controller()->GetEntryCount()); - EXPECT_EQ(3, contents->controller()->GetLastCommittedEntryIndex()); - NavigationEntry* pending_entry = contents->controller()->GetPendingEntry(); + controller()->RemoveEntryAtIndex( + controller()->GetEntryCount() - 1, default_url); + EXPECT_EQ(4, controller()->GetEntryCount()); + EXPECT_EQ(3, controller()->GetLastCommittedEntryIndex()); + NavigationEntry* pending_entry = controller()->GetPendingEntry(); EXPECT_TRUE(pending_entry && pending_entry->url() == url4); // Add a pending entry. - contents->controller()->LoadURL(pending_url, GURL(), PageTransition::TYPED); + controller()->LoadURL(pending_url, GURL(), PageTransition::TYPED); // Now remove the last entry. - contents->controller()->RemoveEntryAtIndex( - contents->controller()->GetEntryCount() - 1, default_url); + controller()->RemoveEntryAtIndex( + controller()->GetEntryCount() - 1, default_url); // The pending entry should have been discarded and the last committed entry // removed. - EXPECT_EQ(3, contents->controller()->GetEntryCount()); - EXPECT_EQ(2, contents->controller()->GetLastCommittedEntryIndex()); - pending_entry = contents->controller()->GetPendingEntry(); + EXPECT_EQ(3, controller()->GetEntryCount()); + EXPECT_EQ(2, controller()->GetLastCommittedEntryIndex()); + pending_entry = controller()->GetPendingEntry(); EXPECT_TRUE(pending_entry && pending_entry->url() == url3); // Remove an entry which is not the last committed one. - contents->controller()->RemoveEntryAtIndex(0, default_url); - EXPECT_EQ(2, contents->controller()->GetEntryCount()); - EXPECT_EQ(1, contents->controller()->GetLastCommittedEntryIndex()); + controller()->RemoveEntryAtIndex(0, default_url); + EXPECT_EQ(2, controller()->GetEntryCount()); + EXPECT_EQ(1, controller()->GetLastCommittedEntryIndex()); // No navigation should have been initiated since we did not remove the // current entry. - EXPECT_FALSE(contents->controller()->GetPendingEntry()); + EXPECT_FALSE(controller()->GetPendingEntry()); // Remove the 2 remaining entries. - contents->controller()->RemoveEntryAtIndex(1, default_url); - contents->controller()->RemoveEntryAtIndex(0, default_url); + controller()->RemoveEntryAtIndex(1, default_url); + controller()->RemoveEntryAtIndex(0, default_url); // This should have created a pending default entry. - EXPECT_EQ(0, contents->controller()->GetEntryCount()); - EXPECT_EQ(-1, contents->controller()->GetLastCommittedEntryIndex()); - pending_entry = contents->controller()->GetPendingEntry(); + EXPECT_EQ(0, controller()->GetEntryCount()); + EXPECT_EQ(-1, controller()->GetLastCommittedEntryIndex()); + pending_entry = controller()->GetPendingEntry(); EXPECT_TRUE(pending_entry && pending_entry->url() == default_url); } // Tests the transient entry, making sure it goes away with all navigations. TEST_F(NavigationControllerTest, TransientEntry) { TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); + RegisterForAllNavNotifications(¬ifications, controller()); - const GURL url0(scheme1() + ":foo0"); - const GURL url1(scheme1() + ":foo1"); - const GURL url2(scheme1() + ":foo2"); - const GURL url3(scheme1() + ":foo3"); - const GURL url4(scheme1() + ":foo4"); - const GURL transient_url(scheme1() + ":transient"); + const GURL url0("http://foo0"); + const GURL url1("http://foo1"); + const GURL url2("http://foo2"); + const GURL url3("http://foo3"); + const GURL url4("http://foo4"); + const GURL transient_url("http://transient"); - contents->controller()->LoadURL(url0, GURL(), PageTransition::TYPED); - contents->CompleteNavigationAsRenderer(0, url0); - contents->controller()->LoadURL(url1, GURL(), PageTransition::TYPED); - contents->CompleteNavigationAsRenderer(1, url1); + controller()->LoadURL(url0, GURL(), PageTransition::TYPED); + rvh()->SendNavigate(0, url0); + controller()->LoadURL(url1, GURL(), PageTransition::TYPED); + rvh()->SendNavigate(1, url1); notifications.Reset(); // Adding a transient with no pending entry. NavigationEntry* transient_entry = new NavigationEntry(TAB_CONTENTS_WEB); transient_entry->set_url(transient_url); - contents->controller()->AddTransientEntry(transient_entry); + controller()->AddTransientEntry(transient_entry); // We should not have received any notifications. EXPECT_EQ(0U, notifications.size()); // Check our state. - EXPECT_EQ(transient_url, contents->controller()->GetActiveEntry()->url()); - EXPECT_EQ(contents->controller()->GetEntryCount(), 3); - EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1); - EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1); - EXPECT_TRUE(contents->controller()->GetLastCommittedEntry()); - EXPECT_FALSE(contents->controller()->GetPendingEntry()); - EXPECT_TRUE(contents->controller()->CanGoBack()); - EXPECT_FALSE(contents->controller()->CanGoForward()); - EXPECT_EQ(contents->GetMaxPageID(), 1); + EXPECT_EQ(transient_url, controller()->GetActiveEntry()->url()); + EXPECT_EQ(controller()->GetEntryCount(), 3); + EXPECT_EQ(controller()->GetLastCommittedEntryIndex(), 1); + EXPECT_EQ(controller()->GetPendingEntryIndex(), -1); + EXPECT_TRUE(controller()->GetLastCommittedEntry()); + EXPECT_FALSE(controller()->GetPendingEntry()); + EXPECT_TRUE(controller()->CanGoBack()); + EXPECT_FALSE(controller()->CanGoForward()); + EXPECT_EQ(contents()->GetMaxPageID(), 1); // Navigate. - contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED); - contents->CompleteNavigationAsRenderer(2, url2); + controller()->LoadURL(url2, GURL(), PageTransition::TYPED); + rvh()->SendNavigate(2, url2); // We should have navigated, transient entry should be gone. - EXPECT_EQ(url2, contents->controller()->GetActiveEntry()->url()); - EXPECT_EQ(contents->controller()->GetEntryCount(), 3); + EXPECT_EQ(url2, controller()->GetActiveEntry()->url()); + EXPECT_EQ(controller()->GetEntryCount(), 3); // Add a transient again, then navigate with no pending entry this time. transient_entry = new NavigationEntry(TAB_CONTENTS_WEB); transient_entry->set_url(transient_url); - contents->controller()->AddTransientEntry(transient_entry); - EXPECT_EQ(transient_url, contents->controller()->GetActiveEntry()->url()); - contents->CompleteNavigationAsRenderer(3, url3); + controller()->AddTransientEntry(transient_entry); + EXPECT_EQ(transient_url, controller()->GetActiveEntry()->url()); + rvh()->SendNavigate(3, url3); // Transient entry should be gone. - EXPECT_EQ(url3, contents->controller()->GetActiveEntry()->url()); - EXPECT_EQ(contents->controller()->GetEntryCount(), 4); + EXPECT_EQ(url3, controller()->GetActiveEntry()->url()); + EXPECT_EQ(controller()->GetEntryCount(), 4); // Initiate a navigation, add a transient then commit navigation. - contents->controller()->LoadURL(url4, GURL(), PageTransition::TYPED); + controller()->LoadURL(url4, GURL(), PageTransition::TYPED); transient_entry = new NavigationEntry(TAB_CONTENTS_WEB); transient_entry->set_url(transient_url); - contents->controller()->AddTransientEntry(transient_entry); - EXPECT_EQ(transient_url, contents->controller()->GetActiveEntry()->url()); - contents->CompleteNavigationAsRenderer(4, url4); - EXPECT_EQ(url4, contents->controller()->GetActiveEntry()->url()); - EXPECT_EQ(contents->controller()->GetEntryCount(), 5); + controller()->AddTransientEntry(transient_entry); + EXPECT_EQ(transient_url, controller()->GetActiveEntry()->url()); + rvh()->SendNavigate(4, url4); + EXPECT_EQ(url4, controller()->GetActiveEntry()->url()); + EXPECT_EQ(controller()->GetEntryCount(), 5); // Add a transient and go back. This should simply remove the transient. transient_entry = new NavigationEntry(TAB_CONTENTS_WEB); transient_entry->set_url(transient_url); - contents->controller()->AddTransientEntry(transient_entry); - EXPECT_EQ(transient_url, contents->controller()->GetActiveEntry()->url()); - EXPECT_TRUE(contents->controller()->CanGoBack()); - EXPECT_FALSE(contents->controller()->CanGoForward()); - contents->controller()->GoBack(); + controller()->AddTransientEntry(transient_entry); + EXPECT_EQ(transient_url, controller()->GetActiveEntry()->url()); + EXPECT_TRUE(controller()->CanGoBack()); + EXPECT_FALSE(controller()->CanGoForward()); + controller()->GoBack(); // Transient entry should be gone. - EXPECT_EQ(url4, contents->controller()->GetActiveEntry()->url()); - EXPECT_EQ(contents->controller()->GetEntryCount(), 5); - contents->CompleteNavigationAsRenderer(3, url3); + EXPECT_EQ(url4, controller()->GetActiveEntry()->url()); + EXPECT_EQ(controller()->GetEntryCount(), 5); + rvh()->SendNavigate(3, url3); // Add a transient and go to an entry before the current one. transient_entry = new NavigationEntry(TAB_CONTENTS_WEB); transient_entry->set_url(transient_url); - contents->controller()->AddTransientEntry(transient_entry); - EXPECT_EQ(transient_url, contents->controller()->GetActiveEntry()->url()); - contents->controller()->GoToIndex(1); + controller()->AddTransientEntry(transient_entry); + EXPECT_EQ(transient_url, controller()->GetActiveEntry()->url()); + controller()->GoToIndex(1); // The navigation should have been initiated, transient entry should be gone. - EXPECT_EQ(url1, contents->controller()->GetActiveEntry()->url()); - contents->CompleteNavigationAsRenderer(1, url1); + EXPECT_EQ(url1, controller()->GetActiveEntry()->url()); + rvh()->SendNavigate(1, url1); // Add a transient and go to an entry after the current one. transient_entry = new NavigationEntry(TAB_CONTENTS_WEB); transient_entry->set_url(transient_url); - contents->controller()->AddTransientEntry(transient_entry); - EXPECT_EQ(transient_url, contents->controller()->GetActiveEntry()->url()); - contents->controller()->GoToIndex(3); + controller()->AddTransientEntry(transient_entry); + EXPECT_EQ(transient_url, controller()->GetActiveEntry()->url()); + controller()->GoToIndex(3); // The navigation should have been initiated, transient entry should be gone. // Because of the transient entry that is removed, going to index 3 makes us // land on url2. - EXPECT_EQ(url2, contents->controller()->GetActiveEntry()->url()); - contents->CompleteNavigationAsRenderer(2, url2); + EXPECT_EQ(url2, controller()->GetActiveEntry()->url()); + rvh()->SendNavigate(2, url2); // Add a transient and go forward. transient_entry = new NavigationEntry(TAB_CONTENTS_WEB); transient_entry->set_url(transient_url); - contents->controller()->AddTransientEntry(transient_entry); - EXPECT_EQ(transient_url, contents->controller()->GetActiveEntry()->url()); - EXPECT_TRUE(contents->controller()->CanGoForward()); - contents->controller()->GoForward(); + controller()->AddTransientEntry(transient_entry); + EXPECT_EQ(transient_url, controller()->GetActiveEntry()->url()); + EXPECT_TRUE(controller()->CanGoForward()); + controller()->GoForward(); // We should have navigated, transient entry should be gone. - EXPECT_EQ(url3, contents->controller()->GetActiveEntry()->url()); - contents->CompleteNavigationAsRenderer(3, url3); + EXPECT_EQ(url3, controller()->GetActiveEntry()->url()); + rvh()->SendNavigate(3, url3); // Ensure the URLS are correct. - EXPECT_EQ(contents->controller()->GetEntryCount(), 5); - EXPECT_EQ(contents->controller()->GetEntryAtIndex(0)->url(), url0); - EXPECT_EQ(contents->controller()->GetEntryAtIndex(1)->url(), url1); - EXPECT_EQ(contents->controller()->GetEntryAtIndex(2)->url(), url2); - EXPECT_EQ(contents->controller()->GetEntryAtIndex(3)->url(), url3); - EXPECT_EQ(contents->controller()->GetEntryAtIndex(4)->url(), url4); + EXPECT_EQ(controller()->GetEntryCount(), 5); + EXPECT_EQ(controller()->GetEntryAtIndex(0)->url(), url0); + EXPECT_EQ(controller()->GetEntryAtIndex(1)->url(), url1); + EXPECT_EQ(controller()->GetEntryAtIndex(2)->url(), url2); + EXPECT_EQ(controller()->GetEntryAtIndex(3)->url(), url3); + EXPECT_EQ(controller()->GetEntryAtIndex(4)->url(), url4); } // Tests that IsInPageNavigation returns appropriate results. Prevents @@ -1531,24 +1304,24 @@ TEST_F(NavigationControllerTest, TransientEntry) { TEST_F(NavigationControllerTest, IsInPageNavigation) { // Navigate to URL with no refs. const GURL url("http://www.google.com/home.html"); - contents->CompleteNavigationAsRenderer(0, url); + rvh()->SendNavigate(0, url); // Reloading the page is not an in-page navigation. - EXPECT_FALSE(contents->controller()->IsURLInPageNavigation(url)); + EXPECT_FALSE(controller()->IsURLInPageNavigation(url)); const GURL other_url("http://www.google.com/add.html"); - EXPECT_FALSE(contents->controller()->IsURLInPageNavigation(other_url)); + EXPECT_FALSE(controller()->IsURLInPageNavigation(other_url)); const GURL url_with_ref("http://www.google.com/home.html#my_ref"); - EXPECT_TRUE(contents->controller()->IsURLInPageNavigation(url_with_ref)); + EXPECT_TRUE(controller()->IsURLInPageNavigation(url_with_ref)); // Navigate to URL with refs. - contents->CompleteNavigationAsRenderer(1, url_with_ref); + rvh()->SendNavigate(1, url_with_ref); // Reloading the page is not an in-page navigation. - EXPECT_FALSE(contents->controller()->IsURLInPageNavigation(url_with_ref)); - EXPECT_FALSE(contents->controller()->IsURLInPageNavigation(url)); - EXPECT_FALSE(contents->controller()->IsURLInPageNavigation(other_url)); + EXPECT_FALSE(controller()->IsURLInPageNavigation(url_with_ref)); + EXPECT_FALSE(controller()->IsURLInPageNavigation(url)); + EXPECT_FALSE(controller()->IsURLInPageNavigation(other_url)); const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref"); - EXPECT_TRUE(contents->controller()->IsURLInPageNavigation( + EXPECT_TRUE(controller()->IsURLInPageNavigation( other_url_with_ref)); } @@ -1559,11 +1332,11 @@ TEST_F(NavigationControllerTest, IsInPageNavigation) { TEST_F(NavigationControllerTest, SameSubframe) { // Navigate the main frame. const GURL url("http://www.google.com/"); - contents->CompleteNavigationAsRenderer(0, url); + rvh()->SendNavigate(0, url); // We should be at the first navigation entry. - EXPECT_EQ(contents->controller()->GetEntryCount(), 1); - EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); + EXPECT_EQ(controller()->GetEntryCount(), 1); + EXPECT_EQ(controller()->GetLastCommittedEntryIndex(), 0); // Navigate a subframe that would normally count as in-page. const GURL subframe("http://www.google.com/#"); @@ -1575,76 +1348,88 @@ TEST_F(NavigationControllerTest, SameSubframe) { params.gesture = NavigationGestureAuto; params.is_post = false; NavigationController::LoadCommittedDetails details; - EXPECT_FALSE(contents->controller()->RendererDidNavigate(params, &details)); + EXPECT_FALSE(controller()->RendererDidNavigate(params, &details)); // Nothing should have changed. - EXPECT_EQ(contents->controller()->GetEntryCount(), 1); - EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); + EXPECT_EQ(controller()->GetEntryCount(), 1); + EXPECT_EQ(controller()->GetLastCommittedEntryIndex(), 0); } +/* TODO(brettw) These test pass on my local machine but fail on the buildbot + cleaning up the directory after they run. This should be fixed. + // A basic test case. Navigates to a single url, and make sure the history // db matches. TEST_F(NavigationControllerHistoryTest, Basic) { - contents->controller()->LoadURL(url0, GURL(), PageTransition::LINK); - contents->CompleteNavigationAsRenderer(0, url0); + controller()->LoadURL(url0, GURL(), PageTransition::LINK); + rvh()->SendNavigate(0, url0); GetLastSession(); - helper_.AssertSingleWindowWithSingleTab(windows_, 1); - helper_.AssertTabEquals(0, 0, 1, *(windows_[0]->tabs[0])); - TabNavigation nav1(0, url0, GURL(), string16(), std::string(), + session_helper_.AssertSingleWindowWithSingleTab(windows_, 1); + session_helper_.AssertTabEquals(0, 0, 1, *(windows_[0]->tabs[0])); + TabNavigation nav1(0, url0, GURL(), string16(), + webkit_glue::CreateHistoryStateForURL(url0), PageTransition::LINK); - helper_.AssertNavigationEquals(nav1, windows_[0]->tabs[0]->navigations[0]); + session_helper_.AssertNavigationEquals(nav1, windows_[0]->tabs[0]->navigations[0]); } // Navigates to three urls, then goes back and make sure the history database // is in sync. TEST_F(NavigationControllerHistoryTest, NavigationThenBack) { - contents->CompleteNavigationAsRenderer(0, url0); - contents->CompleteNavigationAsRenderer(1, url1); - contents->CompleteNavigationAsRenderer(2, url2); + rvh()->SendNavigate(0, url0); + rvh()->SendNavigate(1, url1); + rvh()->SendNavigate(2, url2); - contents->controller()->GoBack(); - contents->CompleteNavigationAsRenderer(1, url1); + controller()->GoBack(); + rvh()->SendNavigate(1, url1); GetLastSession(); - helper_.AssertSingleWindowWithSingleTab(windows_, 3); - helper_.AssertTabEquals(0, 1, 3, *(windows_[0]->tabs[0])); + session_helper_.AssertSingleWindowWithSingleTab(windows_, 3); + session_helper_.AssertTabEquals(0, 1, 3, *(windows_[0]->tabs[0])); - TabNavigation nav(0, url0, GURL(), string16(), std::string(), + TabNavigation nav(0, url0, GURL(), string16(), + webkit_glue::CreateHistoryStateForURL(url0), PageTransition::LINK); - helper_.AssertNavigationEquals(nav, windows_[0]->tabs[0]->navigations[0]); + session_helper_.AssertNavigationEquals(nav, + windows_[0]->tabs[0]->navigations[0]); nav.set_url(url1); - helper_.AssertNavigationEquals(nav, windows_[0]->tabs[0]->navigations[1]); + session_helper_.AssertNavigationEquals(nav, + windows_[0]->tabs[0]->navigations[1]); nav.set_url(url2); - helper_.AssertNavigationEquals(nav, windows_[0]->tabs[0]->navigations[2]); + session_helper_.AssertNavigationEquals(nav, + windows_[0]->tabs[0]->navigations[2]); } // Navigates to three urls, then goes back twice, then loads a new url. TEST_F(NavigationControllerHistoryTest, NavigationPruning) { - contents->CompleteNavigationAsRenderer(0, url0); - contents->CompleteNavigationAsRenderer(1, url1); - contents->CompleteNavigationAsRenderer(2, url2); + rvh()->SendNavigate(0, url0); + rvh()->SendNavigate(1, url1); + rvh()->SendNavigate(2, url2); - contents->controller()->GoBack(); - contents->CompleteNavigationAsRenderer(1, url1); + controller()->GoBack(); + rvh()->SendNavigate(1, url1); - contents->controller()->GoBack(); - contents->CompleteNavigationAsRenderer(0, url0); + controller()->GoBack(); + rvh()->SendNavigate(0, url0); - contents->CompleteNavigationAsRenderer(3, url2); + rvh()->SendNavigate(3, url2); // Now have url0, and url2. GetLastSession(); - helper_.AssertSingleWindowWithSingleTab(windows_, 2); - helper_.AssertTabEquals(0, 1, 2, *(windows_[0]->tabs[0])); + session_helper_.AssertSingleWindowWithSingleTab(windows_, 2); + session_helper_.AssertTabEquals(0, 1, 2, *(windows_[0]->tabs[0])); - TabNavigation nav(0, url0, GURL(), string16(), std::string(), + TabNavigation nav(0, url0, GURL(), string16(), + webkit_glue::CreateHistoryStateForURL(url0), PageTransition::LINK); - helper_.AssertNavigationEquals(nav, windows_[0]->tabs[0]->navigations[0]); + session_helper_.AssertNavigationEquals(nav, + windows_[0]->tabs[0]->navigations[0]); nav.set_url(url2); - helper_.AssertNavigationEquals(nav, windows_[0]->tabs[0]->navigations[1]); + session_helper_.AssertNavigationEquals(nav, + windows_[0]->tabs[0]->navigations[1]); } +*/
\ No newline at end of file diff --git a/chrome/browser/renderer_host/mock_render_process_host.h b/chrome/browser/renderer_host/mock_render_process_host.h index 9b63653..7aea378 100644 --- a/chrome/browser/renderer_host/mock_render_process_host.h +++ b/chrome/browser/renderer_host/mock_render_process_host.h @@ -23,6 +23,9 @@ class MockRenderProcessHost : public RenderProcessHost { // renderer via this RenderProcessHost. IPC::TestSink& sink() { return sink_; } + // Provides tests access to the max page ID currently used for this process. + int max_page_id() const { return max_page_id_; } + // RenderProcessHost implementation (public portion). virtual bool Init(); virtual int GetNextRoutingID(); diff --git a/chrome/browser/renderer_host/render_view_host_unittest.cc b/chrome/browser/renderer_host/render_view_host_unittest.cc index 237b228..9e91318 100644 --- a/chrome/browser/renderer_host/render_view_host_unittest.cc +++ b/chrome/browser/renderer_host/render_view_host_unittest.cc @@ -12,6 +12,6 @@ class RenderViewHostTest : public RenderViewHostTestHarness { // See RenderViewHost::OnMsgNavigate for a discussion. TEST_F(RenderViewHostTest, FilterAbout) { rvh()->SendNavigate(1, GURL("about:cache")); - ASSERT_TRUE(controller_->GetActiveEntry()); - EXPECT_EQ(GURL("about:blank"), controller_->GetActiveEntry()->url()); + ASSERT_TRUE(controller()->GetActiveEntry()); + EXPECT_EQ(GURL("about:blank"), controller()->GetActiveEntry()->url()); } diff --git a/chrome/browser/renderer_host/test_render_view_host.cc b/chrome/browser/renderer_host/test_render_view_host.cc index 3246a4b..1d54449 100644 --- a/chrome/browser/renderer_host/test_render_view_host.cc +++ b/chrome/browser/renderer_host/test_render_view_host.cc @@ -69,6 +69,11 @@ BackingStore* TestRenderWidgetHostView::AllocBackingStore( return new BackingStore(size); } +void RenderViewHostTestHarness::NavigateAndCommit(const GURL& url) { + controller()->LoadURL(url, GURL(), 0); + rvh()->SendNavigate(process()->max_page_id() + 1, url); +} + void RenderViewHostTestHarness::SetUp() { // See comment above profile_ decl for why we check for NULL here. if (!profile_.get()) diff --git a/chrome/browser/renderer_host/test_render_view_host.h b/chrome/browser/renderer_host/test_render_view_host.h index d89ebd5..69d836e 100644 --- a/chrome/browser/renderer_host/test_render_view_host.h +++ b/chrome/browser/renderer_host/test_render_view_host.h @@ -173,7 +173,6 @@ class RenderViewHostTestHarness : public testing::Test { RenderViewHostTestHarness() : rph_factory_(), rvh_factory_(&rph_factory_), - process_(NULL), contents_(NULL), controller_(NULL) {} virtual ~RenderViewHostTestHarness() {} @@ -190,10 +189,19 @@ class RenderViewHostTestHarness : public testing::Test { return reinterpret_cast<TestRenderViewHost*>(contents_->render_view_host()); } - Profile* profile() { + TestingProfile* profile() { return profile_.get(); } + MockRenderProcessHost* process() { + return static_cast<MockRenderProcessHost*>(rvh()->process()); + } + + // Creates a pending navigation to the given oURL with the default parameters + // and the commits the load with a page ID one larger than any seen. This + // emulates what happens on a new navigation. + void NavigateAndCommit(const GURL& url); + // Marks the contents as already cleaned up. If a test calls CloseContents, // then our cleanup code shouldn't run. This function makes sure that happens. void ContentsCleanedUp() { @@ -205,19 +213,18 @@ class RenderViewHostTestHarness : public testing::Test { virtual void SetUp(); virtual void TearDown(); - MessageLoopForUI message_loop_; - // This profile will be created in SetUp if it has not already been created. // This allows tests to override the profile if they so choose in their own // SetUp function before calling the base class's (us) SetUp(). scoped_ptr<TestingProfile> profile_; + MessageLoopForUI message_loop_; + MockRenderProcessHostFactory rph_factory_; TestRenderViewHostFactory rvh_factory_; // We clean up the WebContents by calling CloseContents, which deletes itself. // This in turn causes the destruction of these other things. - MockRenderProcessHost* process_; TestWebContents* contents_; NavigationController* controller_; diff --git a/chrome/browser/sessions/tab_restore_service_unittest.cc b/chrome/browser/sessions/tab_restore_service_unittest.cc index 2cf9456..f55bdb1 100644 --- a/chrome/browser/sessions/tab_restore_service_unittest.cc +++ b/chrome/browser/sessions/tab_restore_service_unittest.cc @@ -2,67 +2,68 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "chrome/browser/renderer_host/test_render_view_host.h" #include "chrome/browser/sessions/session_types.h" #include "chrome/browser/sessions/tab_restore_service.h" #include "chrome/browser/tab_contents/navigation_entry.h" -#include "chrome/test/test_tab_contents.h" #include "chrome/test/testing_profile.h" #include "testing/gtest/include/gtest/gtest.h" -class TabRestoreServiceTest : public testing::Test { +class TabRestoreServiceTest : public RenderViewHostTestHarness { public: - TabRestoreServiceTest() - : tab_contents_factory_( - TestTabContentsFactory::CreateAndRegisterFactory()), - profile_(new TestingProfile()), - service_(new TabRestoreService(profile_.get())) { - test_contents_ = tab_contents_factory_->CreateInstanceImpl(); - test_contents_->set_commit_on_navigate(true); - controller_ = new NavigationController(test_contents_, profile_.get()); - url1_ = GURL(tab_contents_factory_->scheme() + "://1"); - url2_ = GURL(tab_contents_factory_->scheme() + "://2"); - url3_ = GURL(tab_contents_factory_->scheme() + "://3"); + TabRestoreServiceTest() { + url1_ = GURL("http://1"); + url2_ = GURL("http://2"); + url3_ = GURL("http://3"); } ~TabRestoreServiceTest() { - controller_->Destroy(); } protected: + // testing::Test overrides + virtual void SetUp() { + RenderViewHostTestHarness::SetUp(); + service_ = new TabRestoreService(profile()); + } + virtual void TearDown() { + service_ = NULL; + RenderViewHostTestHarness::TearDown(); + } + void AddThreeNavigations() { // Navigate to three URLs. - controller_->LoadURL(url1_, GURL(), PageTransition::RELOAD); - controller_->LoadURL(url2_, GURL(), PageTransition::RELOAD); - controller_->LoadURL(url3_, GURL(), PageTransition::RELOAD); + NavigateAndCommit(url1_); + NavigateAndCommit(url2_); + NavigateAndCommit(url3_); } void NavigateToIndex(int index) { // Navigate back. We have to do this song and dance as NavigationController // isn't happy if you navigate immediately while going back. - test_contents_->set_commit_on_navigate(false); - controller_->GoToIndex(index); - test_contents_->CompleteNavigationAsRenderer( - controller_->GetPendingEntry()->page_id(), - controller_->GetPendingEntry()->url()); + controller()->GoToIndex(index); + rvh()->SendNavigate(controller()->GetPendingEntry()->page_id(), + controller()->GetPendingEntry()->url()); } void RecreateService() { - // Must set service to null first so that it is destroyed. + // Must set service to null first so that it is destroyed before the new + // one is created. service_ = NULL; - service_ = new TabRestoreService(profile_.get()); + service_ = new TabRestoreService(profile()); service_->LoadTabsFromLastSession(); } // Adds a window with one tab and url to the profile's session service. void AddWindowWithOneTabToSessionService() { - SessionService* session_service = profile_->GetSessionService(); + SessionService* session_service = profile()->GetSessionService(); SessionID tab_id; SessionID window_id; session_service->SetWindowType(window_id, Browser::TYPE_NORMAL); session_service->SetTabWindow(window_id, tab_id); session_service->SetTabIndexInWindow(window_id, tab_id, 0); session_service->SetSelectedTabInWindow(window_id, 0); - NavigationEntry entry(tab_contents_factory_->type()); + NavigationEntry entry; entry.set_url(url1_); session_service->UpdateTabNavigation(window_id, tab_id, 0, entry); } @@ -72,30 +73,26 @@ class TabRestoreServiceTest : public testing::Test { // way of AddWindowWithOneTabToSessionService. void CreateSessionServiceWithOneWindow() { // The profile takes ownership of this. - SessionService* session_service = new SessionService(profile_.get()); - profile_->set_session_service(session_service); + SessionService* session_service = new SessionService(profile()); + profile()->set_session_service(session_service); AddWindowWithOneTabToSessionService(); // Set this, otherwise previous session won't be loaded. - profile_->set_last_session_exited_cleanly(false); + profile()->set_last_session_exited_cleanly(false); } GURL url1_; GURL url2_; GURL url3_; - scoped_ptr<TestTabContentsFactory> tab_contents_factory_; - scoped_ptr<TestingProfile> profile_; scoped_refptr<TabRestoreService> service_; - NavigationController* controller_; - TestTabContents* test_contents_; }; TEST_F(TabRestoreServiceTest, Basic) { AddThreeNavigations(); // Have the service record the tab. - service_->CreateHistoricalTab(controller_); + service_->CreateHistoricalTab(controller()); // Make sure an entry was created. ASSERT_EQ(1U, service_->entries().size()); @@ -113,7 +110,7 @@ TEST_F(TabRestoreServiceTest, Basic) { NavigateToIndex(1); // And check again. - service_->CreateHistoricalTab(controller_); + service_->CreateHistoricalTab(controller()); // There should be two entries now. ASSERT_EQ(2U, service_->entries().size()); @@ -132,7 +129,7 @@ TEST_F(TabRestoreServiceTest, Basic) { // Make sure TabRestoreService doesn't create an entry for a tab with no // navigations. TEST_F(TabRestoreServiceTest, DontCreateEmptyTab) { - service_->CreateHistoricalTab(controller_); + service_->CreateHistoricalTab(controller()); EXPECT_TRUE(service_->entries().empty()); } @@ -141,7 +138,7 @@ TEST_F(TabRestoreServiceTest, Restore) { AddThreeNavigations(); // Have the service record the tab. - service_->CreateHistoricalTab(controller_); + service_->CreateHistoricalTab(controller()); // Recreate the service and have it load the tabs. RecreateService(); @@ -165,7 +162,7 @@ TEST_F(TabRestoreServiceTest, DontLoadRestoredTab) { AddThreeNavigations(); // Have the service record the tab. - service_->CreateHistoricalTab(controller_); + service_->CreateHistoricalTab(controller()); ASSERT_EQ(1U, service_->entries().size()); // Restore the tab. @@ -182,12 +179,12 @@ TEST_F(TabRestoreServiceTest, DontLoadRestoredTab) { // Make sure we persist entries to disk that have post data. TEST_F(TabRestoreServiceTest, DontPersistPostData) { AddThreeNavigations(); - controller_->GetEntryAtIndex(0)->set_has_post_data(true); - controller_->GetEntryAtIndex(1)->set_has_post_data(true); - controller_->GetEntryAtIndex(2)->set_has_post_data(true); + controller()->GetEntryAtIndex(0)->set_has_post_data(true); + controller()->GetEntryAtIndex(1)->set_has_post_data(true); + controller()->GetEntryAtIndex(2)->set_has_post_data(true); // Have the service record the tab. - service_->CreateHistoricalTab(controller_); + service_->CreateHistoricalTab(controller()); ASSERT_EQ(1U, service_->entries().size()); // Recreate the service and have it load the tabs. @@ -212,7 +209,7 @@ TEST_F(TabRestoreServiceTest, DontLoadTwice) { AddThreeNavigations(); // Have the service record the tab. - service_->CreateHistoricalTab(controller_); + service_->CreateHistoricalTab(controller()); ASSERT_EQ(1U, service_->entries().size()); // Recreate the service and have it load the tabs. @@ -228,7 +225,7 @@ TEST_F(TabRestoreServiceTest, DontLoadTwice) { TEST_F(TabRestoreServiceTest, LoadPreviousSession) { CreateSessionServiceWithOneWindow(); - profile_->GetSessionService()->MoveCurrentSessionToLastSession(); + profile()->GetSessionService()->MoveCurrentSessionToLastSession(); service_->LoadTabsFromLastSession(); @@ -249,9 +246,9 @@ TEST_F(TabRestoreServiceTest, LoadPreviousSession) { TEST_F(TabRestoreServiceTest, DontLoadAfterRestore) { CreateSessionServiceWithOneWindow(); - profile_->GetSessionService()->MoveCurrentSessionToLastSession(); + profile()->GetSessionService()->MoveCurrentSessionToLastSession(); - profile_->set_restored_last_session(true); + profile()->set_restored_last_session(true); service_->LoadTabsFromLastSession(); @@ -263,9 +260,9 @@ TEST_F(TabRestoreServiceTest, DontLoadAfterRestore) { TEST_F(TabRestoreServiceTest, DontLoadAfterCleanExit) { CreateSessionServiceWithOneWindow(); - profile_->GetSessionService()->MoveCurrentSessionToLastSession(); + profile()->GetSessionService()->MoveCurrentSessionToLastSession(); - profile_->set_last_session_exited_cleanly(true); + profile()->set_last_session_exited_cleanly(true); service_->LoadTabsFromLastSession(); @@ -275,11 +272,11 @@ TEST_F(TabRestoreServiceTest, DontLoadAfterCleanExit) { TEST_F(TabRestoreServiceTest, LoadPreviousSessionAndTabs) { CreateSessionServiceWithOneWindow(); - profile_->GetSessionService()->MoveCurrentSessionToLastSession(); + profile()->GetSessionService()->MoveCurrentSessionToLastSession(); AddThreeNavigations(); - service_->CreateHistoricalTab(controller_); + service_->CreateHistoricalTab(controller()); RecreateService(); @@ -316,11 +313,11 @@ TEST_F(TabRestoreServiceTest, ManyWindowsInSessionService) { for (size_t i = 0; i < TabRestoreService::kMaxEntries; ++i) AddWindowWithOneTabToSessionService(); - profile_->GetSessionService()->MoveCurrentSessionToLastSession(); + profile()->GetSessionService()->MoveCurrentSessionToLastSession(); AddThreeNavigations(); - service_->CreateHistoricalTab(controller_); + service_->CreateHistoricalTab(controller()); RecreateService(); diff --git a/chrome/browser/ssl/ssl_manager.cc b/chrome/browser/ssl/ssl_manager.cc index 57ee3f8..42c6ec0 100644 --- a/chrome/browser/ssl/ssl_manager.cc +++ b/chrome/browser/ssl/ssl_manager.cc @@ -180,9 +180,7 @@ bool SSLManager::SetMaxSecurityStyle(SecurityStyle style) { // Delegate API method. void SSLManager::AddMessageToConsole(const WebConsoleMessage& message) { - TabContents* tab_contents = controller_->GetTabContents(TAB_CONTENTS_WEB); - if (!tab_contents) - return; + TabContents* tab_contents = controller_->tab_contents(); WebContents* web_contents = tab_contents->AsWebContents(); if (!web_contents) return; diff --git a/chrome/browser/tab_contents/navigation_controller.cc b/chrome/browser/tab_contents/navigation_controller.cc index 3dbdef8..88bc154 100644 --- a/chrome/browser/tab_contents/navigation_controller.cc +++ b/chrome/browser/tab_contents/navigation_controller.cc @@ -53,10 +53,7 @@ void NotifyPrunedEntries(NavigationController* nav_controller, // this one. We don't want that. To avoid this we create a valid state which // WebKit will not treat as a new navigation. void SetContentStateIfEmpty(NavigationEntry* entry) { - if (entry->content_state().empty() && - (entry->tab_type() == TAB_CONTENTS_WEB || - entry->tab_type() == TAB_CONTENTS_HTML_DIALOG || - entry->IsViewSourceMode())) { + if (entry->content_state().empty()) { entry->set_content_state( webkit_glue::CreateHistoryStateForURL(entry->url())); } @@ -151,6 +148,7 @@ static void CreateNavigationEntriesFromTabNavigations( NavigationController::NavigationController(TabContents* contents, Profile* profile) : profile_(profile), + rvh_factory_(NULL), pending_entry_(NULL), last_committed_entry_index_(-1), pending_entry_index_(-1), @@ -168,8 +166,10 @@ NavigationController::NavigationController(TabContents* contents, NavigationController::NavigationController( Profile* profile, const std::vector<TabNavigation>& navigations, - int selected_navigation) + int selected_navigation, + RenderViewHostFactory* rvh_factory) : profile_(profile), + rvh_factory_(rvh_factory), pending_entry_(NULL), last_committed_entry_index_(-1), pending_entry_index_(-1), @@ -1047,7 +1047,7 @@ TabContents* NavigationController::GetTabContentsCreateIfNecessary( TabContents* contents = GetTabContents(entry.tab_type()); if (!contents) { contents = TabContents::CreateWithType(entry.tab_type(), profile_, - entry.site_instance()); + entry.site_instance(), rvh_factory_); if (!contents->AsWebContents()) { // Update the max page id, otherwise the newly created TabContents may // have reset its max page id resulting in all new navigations. We only diff --git a/chrome/browser/tab_contents/navigation_controller.h b/chrome/browser/tab_contents/navigation_controller.h index 41502d6..2d1364f 100644 --- a/chrome/browser/tab_contents/navigation_controller.h +++ b/chrome/browser/tab_contents/navigation_controller.h @@ -21,6 +21,7 @@ class NavigationEntry; class GURL; class Profile; +class RenderViewHostFactory; class TabContents; class SiteInstance; class SkBitmap; @@ -128,11 +129,13 @@ class NavigationController { // Creates a NavigationController from the specified history. Processing // for this is asynchronous and handled via the RestoreHelper (in - // navigation_controller.cc). + // navigation_controller.cc). The RenderViewHostFactory will be passed to + // new TabContentses, it is non-NULL only for testing. NavigationController( Profile* profile, const std::vector<TabNavigation>& navigations, - int selected_navigation); + int selected_navigation, + RenderViewHostFactory* rvh_factory); ~NavigationController(); // Begin the destruction sequence for this NavigationController and all its @@ -310,10 +313,20 @@ class NavigationController { // Returns the currently-active TabContents associated with this controller. // You should use GetActiveEntry instead of this in most cases. + // + // TODO(brettw) this should be removed in preference to tab_contents(). TabContents* active_contents() const { return active_contents_; } + // Returns the tab contents associated with this controller. Non-NULL except + // during set-up of the tab. + TabContents* tab_contents() const { + // This currently returns the active tab contents which should be renamed to + // tab_contents. + return active_contents_; + } + // For use by TabContents ---------------------------------------------------- // Handles updating the navigation state after the renderer has navigated. @@ -481,6 +494,10 @@ class NavigationController { // The user profile associated with this controller Profile* profile_; + // Non-owning pointer to the factory to pass to new TabContentes. This will be + // NULL except in testing, where it is used to create mock RVH's. + RenderViewHostFactory* rvh_factory_; + // List of NavigationEntry for this tab typedef std::vector<linked_ptr<NavigationEntry> > NavigationEntries; NavigationEntries entries_; @@ -520,6 +537,8 @@ class NavigationController { TabContentsCollectorMap tab_contents_collector_map_; // The tab contents that is currently active. + // TODO(brettw) this should be renamed to tab_contents_ and comments clarified + // that it never changes. TabContents* active_contents_; // The max restored page ID in this controller, if it was restored. We must diff --git a/chrome/browser/tab_contents/navigation_entry.cc b/chrome/browser/tab_contents/navigation_entry.cc index e640e32..c07c08e 100644 --- a/chrome/browser/tab_contents/navigation_entry.cc +++ b/chrome/browser/tab_contents/navigation_entry.cc @@ -31,6 +31,18 @@ NavigationEntry::FaviconStatus::FaviconStatus() : valid_(false) { bitmap_ = *rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); } + +NavigationEntry::NavigationEntry() + : unique_id_(GetUniqueID()), + tab_type_(TAB_CONTENTS_WEB), + site_instance_(NULL), + page_type_(NORMAL_PAGE), + page_id_(-1), + transition_type_(PageTransition::LINK), + has_post_data_(false), + restored_(false) { +} + NavigationEntry::NavigationEntry(TabContentsType type) : unique_id_(GetUniqueID()), tab_type_(type), diff --git a/chrome/browser/tab_contents/navigation_entry.h b/chrome/browser/tab_contents/navigation_entry.h index 16801b3..9a39d14 100644 --- a/chrome/browser/tab_contents/navigation_entry.h +++ b/chrome/browser/tab_contents/navigation_entry.h @@ -174,6 +174,7 @@ class NavigationEntry { // --------------------------------------------------------------------------- + NavigationEntry(); explicit NavigationEntry(TabContentsType type); NavigationEntry(TabContentsType type, SiteInstance* instance, @@ -290,9 +291,8 @@ class NavigationEntry { // state properly when the user goes back and forward. // // WARNING: This state is saved to the file and used to restore previous - // states. If you write a custom TabContents and provide your own state make - // sure you have the ability to modify the format in the future while being - // able to deal with older versions. + // states. If the format is modified in the future, we should still be able to + // deal with older versions. void set_content_state(const std::string& state) { content_state_ = state; } diff --git a/chrome/browser/tab_contents/render_view_host_manager.h b/chrome/browser/tab_contents/render_view_host_manager.h index 9d9bb67..3754be8 100644 --- a/chrome/browser/tab_contents/render_view_host_manager.h +++ b/chrome/browser/tab_contents/render_view_host_manager.h @@ -84,6 +84,12 @@ class RenderViewHostManager : public NotificationObserver { // Schedules all RenderViewHosts for destruction. void Shutdown(); + // Returns true if there is a RenderViewHostFactory that will generate + // non-standard RenderViewHosts. + bool has_render_view_host_factory() const { + return !!render_view_factory_; + } + // Returns the currently actuive RenderViewHost. // // This will be non-NULL between Init() and Shutdown(). You may want to NULL diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index 5918191..566aab7 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -85,10 +85,12 @@ class TabContents : public PageNavigator, // (implemented in tab_contents_factory.cc) // Creates a new TabContents of the given type. Will reuse the given - // instance's renderer, if it is not null. + // instance's renderer, if it is not null. The given render view host factory + // will be passed to the new TabContents (it may be NULL). static TabContents* CreateWithType(TabContentsType type, Profile* profile, - SiteInstance* instance); + SiteInstance* instance, + RenderViewHostFactory* rvh_factory); // Returns the type of TabContents needed to handle the URL. |url| may // end up being modified to contain the _real_ url being loaded if the diff --git a/chrome/browser/tab_contents/tab_contents_factory.cc b/chrome/browser/tab_contents/tab_contents_factory.cc index c519a3f..8ed5d27 100644 --- a/chrome/browser/tab_contents/tab_contents_factory.cc +++ b/chrome/browser/tab_contents/tab_contents_factory.cc @@ -39,13 +39,14 @@ TabContentsType TabContentsFactory::NextUnusedType() { // static TabContents* TabContents::CreateWithType(TabContentsType type, Profile* profile, - SiteInstance* instance) { + SiteInstance* instance, + RenderViewHostFactory* rvh_factory) { TabContents* contents = NULL; switch (type) { case TAB_CONTENTS_WEB: - contents = new WebContents(profile, instance, NULL, MSG_ROUTING_NONE, - NULL); + contents = new WebContents(profile, instance, rvh_factory, + MSG_ROUTING_NONE, NULL); break; default: if (g_extra_types) { diff --git a/chrome/browser/tab_contents/tab_contents_type.h b/chrome/browser/tab_contents/tab_contents_type.h index 0d4e120..f918a76 100644 --- a/chrome/browser/tab_contents/tab_contents_type.h +++ b/chrome/browser/tab_contents/tab_contents_type.h @@ -13,8 +13,6 @@ enum TabContentsType { TAB_CONTENTS_UNKNOWN_TYPE = 0, TAB_CONTENTS_WEB, - TAB_CONTENTS_HTML_DIALOG, - // DO NOT EVEN THINK ABOUT ADDING MORE TAB CONTENTS TYPES HERE. SEE brettw. TAB_CONTENTS_NUM_TYPES }; diff --git a/chrome/browser/tab_contents/web_contents.h b/chrome/browser/tab_contents/web_contents.h index a6c24af..ae40d89 100644 --- a/chrome/browser/tab_contents/web_contents.h +++ b/chrome/browser/tab_contents/web_contents.h @@ -109,10 +109,8 @@ class WebContents : public TabContents, return view_.get(); } -#ifdef UNIT_TEST // Expose the render manager for testing. RenderViewHostManager* render_manager() { return &render_manager_; } -#endif // Page state getters & setters ---------------------------------------------- diff --git a/chrome/browser/tab_contents/web_contents_view_gtk.cc b/chrome/browser/tab_contents/web_contents_view_gtk.cc index 0a12082..17554f9 100644 --- a/chrome/browser/tab_contents/web_contents_view_gtk.cc +++ b/chrome/browser/tab_contents/web_contents_view_gtk.cc @@ -79,7 +79,16 @@ void WebContentsViewGtk::CreateView() { RenderWidgetHostView* WebContentsViewGtk::CreateViewForWidget( RenderWidgetHost* render_widget_host) { - DCHECK(!render_widget_host->view()); + if (render_widget_host->view()) { + // During testing, the view will already be set up in most cases to the + // test view, so we don't want to clobber it with a real one. To verify that + // this actually is happening (and somebody isn't accidentally creating the + // view twice), we check for the RVH Factory, which will be set when we're + // making special ones (which go along with the special views). + DCHECK(web_contents()->render_manager()->has_render_view_host_factory()); + return render_widget_host->view(); + } + RenderWidgetHostViewGtk* view = new RenderWidgetHostViewGtk(render_widget_host); view->InitAsChild(); diff --git a/chrome/browser/tab_contents/web_contents_view_win.cc b/chrome/browser/tab_contents/web_contents_view_win.cc index b6d4bb5..6ad4d4f 100644 --- a/chrome/browser/tab_contents/web_contents_view_win.cc +++ b/chrome/browser/tab_contents/web_contents_view_win.cc @@ -82,7 +82,16 @@ void WebContentsViewWin::CreateView() { RenderWidgetHostView* WebContentsViewWin::CreateViewForWidget( RenderWidgetHost* render_widget_host) { - DCHECK(!render_widget_host->view()); + if (render_widget_host->view()) { + // During testing, the view will already be set up in most cases to the + // test view, so we don't want to clobber it with a real one. To verify that + // this actually is happening (and somebody isn't accidentally creating the + // view twice), we check for the RVH Factory, which will be set when we're + // making special ones (which go along with the special views). + DCHECK(web_contents()->render_manager()->has_render_view_host_factory()); + return render_widget_host->view(); + } + RenderWidgetHostViewWin* view = new RenderWidgetHostViewWin(render_widget_host); view->Create(GetNativeView()); diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h index fe3848d..758b70f 100644 --- a/chrome/test/testing_profile.h +++ b/chrome/test/testing_profile.h @@ -30,10 +30,12 @@ class TestingProfile : public Profile { public: TestingProfile(); + // Creates a new profile by adding |count| to the end of the path. Use this // when you need to have more than one TestingProfile running at the same // time. explicit TestingProfile(int count); + virtual ~TestingProfile(); // Creates the history service. If |delete_file| is true, the history file is |