diff options
author | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-15 21:18:04 +0000 |
---|---|---|
committer | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-15 21:18:04 +0000 |
commit | b5e3bbf106f2bda83900e526d07dfa10a2164c82 (patch) | |
tree | 99d2c9ee87e04955573ed91a2b1256e489f63eb6 /chrome/browser/navigation_controller_unittest.cc | |
parent | 2168a720764a1a223b3ebae4bdc748b83784320c (diff) | |
download | chromium_src-b5e3bbf106f2bda83900e526d07dfa10a2164c82.zip chromium_src-b5e3bbf106f2bda83900e526d07dfa10a2164c82.tar.gz chromium_src-b5e3bbf106f2bda83900e526d07dfa10a2164c82.tar.bz2 |
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@963 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/navigation_controller_unittest.cc')
-rw-r--r-- | chrome/browser/navigation_controller_unittest.cc | 136 |
1 files changed, 5 insertions, 131 deletions
diff --git a/chrome/browser/navigation_controller_unittest.cc b/chrome/browser/navigation_controller_unittest.cc index 5cc0402..cce2cf9 100644 --- a/chrome/browser/navigation_controller_unittest.cc +++ b/chrome/browser/navigation_controller_unittest.cc @@ -39,9 +39,7 @@ #include "chrome/browser/tab_contents.h" #include "chrome/browser/tab_contents_delegate.h" #include "chrome/browser/tab_contents_factory.h" -#include "chrome/common/notification_types.h" #include "chrome/common/stl_util-inl.h" -#include "chrome/test/test_notification_tracker.h" #include "chrome/test/testing_profile.h" #include "net/base/net_util.h" #include "testing/gtest/include/gtest/gtest.h" @@ -291,16 +289,6 @@ class NavigationControllerHistoryTest : public NavigationControllerTest { std::wstring profile_path_; }; -void RegisterForAllNavNotifications(TestNotificationTracker* tracker, - NavigationController* controller) { - tracker->ListenFor(NOTIFY_NAV_ENTRY_COMMITTED, - Source<NavigationController>(controller)); - tracker->ListenFor(NOTIFY_NAV_LIST_PRUNED, - Source<NavigationController>(controller)); - tracker->ListenFor(NOTIFY_NAV_ENTRY_CHANGED, - Source<NavigationController>(controller)); -} - } // namespace TEST_F(NavigationControllerTest, Defaults) { @@ -317,18 +305,12 @@ TEST_F(NavigationControllerTest, Defaults) { } TEST_F(NavigationControllerTest, LoadURL) { - TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); - const GURL url1("test1:foo1"); const GURL url2("test1:foo2"); contents->controller()->LoadURL(url1, PageTransition::TYPED); - // Creating a pending notification should not have issued any of the - // notifications we're listening for. - EXPECT_EQ(0, notifications.size()); - // The load should now be pending. + // the load should now be pending EXPECT_TRUE(contents->pending_entry()); EXPECT_EQ(contents->controller()->GetEntryCount(), 0); EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), -1); @@ -339,14 +321,9 @@ TEST_F(NavigationControllerTest, LoadURL) { EXPECT_FALSE(contents->controller()->CanGoForward()); EXPECT_EQ(contents->GetMaxPageID(), -1); - // We should have gotten no notifications from the preceeding checks. - EXPECT_EQ(0, notifications.size()); - contents->CompleteNavigation(0); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); - // The load should now be 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); @@ -356,10 +333,10 @@ TEST_F(NavigationControllerTest, LoadURL) { EXPECT_FALSE(contents->controller()->CanGoForward()); EXPECT_EQ(contents->GetMaxPageID(), 0); - // Load another... + // load another... contents->controller()->LoadURL(url2, PageTransition::TYPED); - // The load should now be pending. + // the load should now be pending EXPECT_TRUE(contents->pending_entry()); EXPECT_EQ(contents->controller()->GetEntryCount(), 1); EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); @@ -372,10 +349,8 @@ TEST_F(NavigationControllerTest, LoadURL) { EXPECT_EQ(contents->GetMaxPageID(), 0); contents->CompleteNavigation(1); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); - // The load should now be 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); @@ -389,23 +364,13 @@ TEST_F(NavigationControllerTest, LoadURL) { // Tests what happens when the same page is loaded again. Should not create a // new session history entry. TEST_F(NavigationControllerTest, LoadURL_SamePage) { - TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); - const GURL url1("test1:foo1"); contents->controller()->LoadURL(url1, PageTransition::TYPED); - EXPECT_EQ(0, notifications.size()); contents->CompleteNavigation(0); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); - contents->controller()->LoadURL(url1, PageTransition::TYPED); - EXPECT_EQ(0, notifications.size()); contents->CompleteNavigation(0); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); // should not have produced a new session history entry EXPECT_EQ(contents->controller()->GetEntryCount(), 1); @@ -418,21 +383,14 @@ TEST_F(NavigationControllerTest, LoadURL_SamePage) { } TEST_F(NavigationControllerTest, LoadURL_Discarded) { - TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); - const GURL url1("test1:foo1"); const GURL url2("test1:foo2"); contents->controller()->LoadURL(url1, PageTransition::TYPED); - EXPECT_EQ(0, notifications.size()); contents->CompleteNavigation(0); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); contents->controller()->LoadURL(url2, PageTransition::TYPED); contents->controller()->DiscardPendingEntry(); - EXPECT_EQ(0, notifications.size()); // should not have produced a new session history entry EXPECT_EQ(contents->controller()->GetEntryCount(), 1); @@ -445,19 +403,12 @@ TEST_F(NavigationControllerTest, LoadURL_Discarded) { } TEST_F(NavigationControllerTest, Reload) { - TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); - const GURL url1("test1:foo1"); contents->controller()->LoadURL(url1, PageTransition::TYPED); - EXPECT_EQ(0, notifications.size()); contents->CompleteNavigation(0); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); contents->controller()->Reload(); - EXPECT_EQ(0, notifications.size()); // the reload is pending... EXPECT_EQ(contents->controller()->GetEntryCount(), 1); @@ -469,8 +420,6 @@ TEST_F(NavigationControllerTest, Reload) { EXPECT_FALSE(contents->controller()->CanGoForward()); contents->CompleteNavigation(0); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); // now the reload is committed... EXPECT_EQ(contents->controller()->GetEntryCount(), 1); @@ -484,25 +433,17 @@ TEST_F(NavigationControllerTest, Reload) { // Tests what happens when a reload navigation produces a new page. TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { - TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); - const GURL url1("test1:foo1"); const GURL url2("test1:foo2"); contents->controller()->LoadURL(url1, PageTransition::TYPED); contents->CompleteNavigation(0); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); contents->controller()->Reload(); - EXPECT_EQ(0, notifications.size()); contents->pending_entry()->SetURL(url2); contents->pending_entry()->SetTransitionType(PageTransition::LINK); contents->CompleteNavigation(1); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); // now the reload is committed... EXPECT_EQ(contents->controller()->GetEntryCount(), 2); @@ -516,24 +457,16 @@ TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { // Tests what happens when we navigate back successfully TEST_F(NavigationControllerTest, Back) { - TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); - const GURL url1("test1:foo1"); const GURL url2("test1:foo2"); contents->controller()->LoadURL(url1, PageTransition::TYPED); contents->CompleteNavigation(0); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); contents->controller()->LoadURL(url2, PageTransition::TYPED); contents->CompleteNavigation(1); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); contents->controller()->GoBack(); - EXPECT_EQ(0, notifications.size()); // should now have a pending navigation to go back... EXPECT_EQ(contents->controller()->GetEntryCount(), 2); @@ -545,8 +478,6 @@ TEST_F(NavigationControllerTest, Back) { EXPECT_TRUE(contents->controller()->CanGoForward()); contents->CompleteNavigation(0); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); // the back navigation completed successfully EXPECT_EQ(contents->controller()->GetEntryCount(), 2); @@ -560,25 +491,17 @@ TEST_F(NavigationControllerTest, Back) { // Tests what happens when a back navigation produces a new page. TEST_F(NavigationControllerTest, Back_GeneratesNewPage) { - TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); - const GURL url1("test1:foo1"); const GURL url2("test1:foo2"); const GURL url3("test1:foo3"); contents->controller()->LoadURL(url1, PageTransition::TYPED); contents->CompleteNavigation(0); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); contents->controller()->LoadURL(url2, PageTransition::TYPED); contents->CompleteNavigation(1); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); contents->controller()->GoBack(); - EXPECT_EQ(0, notifications.size()); // should now have a pending navigation to go back... EXPECT_EQ(contents->controller()->GetEntryCount(), 2); @@ -592,8 +515,6 @@ TEST_F(NavigationControllerTest, Back_GeneratesNewPage) { contents->pending_entry()->SetURL(url3); contents->pending_entry()->SetTransitionType(PageTransition::LINK); contents->CompleteNavigation(2); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); // the back navigation resulted in a completely new navigation. // TODO(darin): perhaps this behavior will be confusing to users? @@ -608,26 +529,17 @@ TEST_F(NavigationControllerTest, Back_GeneratesNewPage) { // Tests what happens when we navigate forward successfully TEST_F(NavigationControllerTest, Forward) { - TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); - const GURL url1("test1:foo1"); const GURL url2("test1:foo2"); contents->controller()->LoadURL(url1, PageTransition::TYPED); contents->CompleteNavigation(0); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); contents->controller()->LoadURL(url2, PageTransition::TYPED); contents->CompleteNavigation(1); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); contents->controller()->GoBack(); contents->CompleteNavigation(0); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); contents->controller()->GoForward(); @@ -641,8 +553,6 @@ TEST_F(NavigationControllerTest, Forward) { EXPECT_FALSE(contents->controller()->CanGoForward()); contents->CompleteNavigation(1); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); // the forward navigation completed successfully EXPECT_EQ(contents->controller()->GetEntryCount(), 2); @@ -656,30 +566,20 @@ TEST_F(NavigationControllerTest, Forward) { // Tests what happens when a forward navigation produces a new page. TEST_F(NavigationControllerTest, Forward_GeneratesNewPage) { - TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); - const GURL url1("test1:foo1"); const GURL url2("test1:foo2"); const GURL url3("test1:foo3"); contents->controller()->LoadURL(url1, PageTransition::TYPED); contents->CompleteNavigation(0); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); contents->controller()->LoadURL(url2, PageTransition::TYPED); contents->CompleteNavigation(1); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); contents->controller()->GoBack(); contents->CompleteNavigation(0); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); contents->controller()->GoForward(); - EXPECT_EQ(0, notifications.size()); // should now have a pending navigation to go forward... EXPECT_EQ(contents->controller()->GetEntryCount(), 2); @@ -693,9 +593,6 @@ TEST_F(NavigationControllerTest, Forward_GeneratesNewPage) { contents->pending_entry()->SetURL(url3); contents->pending_entry()->SetTransitionType(PageTransition::LINK); contents->CompleteNavigation(2); - EXPECT_TRUE(notifications.Check3AndReset(NOTIFY_NAV_LIST_PRUNED, - NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); EXPECT_EQ(contents->controller()->GetEntryCount(), 2); EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1); @@ -707,24 +604,17 @@ TEST_F(NavigationControllerTest, Forward_GeneratesNewPage) { } TEST_F(NavigationControllerTest, LinkClick) { - TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); - const GURL url1("test1:foo1"); const GURL url2("test1:foo2"); contents->controller()->LoadURL(url1, PageTransition::TYPED); contents->CompleteNavigation(0); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); contents->set_pending_entry(new NavigationEntry(kTestContentsType1, NULL, 0, url2, std::wstring(), PageTransition::LINK)); contents->CompleteNavigation(1); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); // should not have produced a new session history entry EXPECT_EQ(contents->controller()->GetEntryCount(), 2); @@ -737,16 +627,11 @@ TEST_F(NavigationControllerTest, LinkClick) { } TEST_F(NavigationControllerTest, SwitchTypes) { - TestNotificationTracker notifications; - RegisterForAllNavNotifications(¬ifications, contents->controller()); - const GURL url1("test1:foo"); const GURL url2("test2:foo"); contents->controller()->LoadURL(url1, PageTransition::TYPED); contents->CompleteNavigation(0); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); TestContents* initial_contents = contents; @@ -756,8 +641,6 @@ TEST_F(NavigationControllerTest, SwitchTypes) { ASSERT_TRUE(initial_contents != contents); contents->CompleteNavigation(0); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); // A second navigation entry should have been committed even though the // PageIDs are the same. PageIDs are scoped to the tab contents type. @@ -773,8 +656,6 @@ TEST_F(NavigationControllerTest, SwitchTypes) { contents->controller()->GoBack(); ASSERT_TRUE(initial_contents == contents); // switched again! contents->CompleteNavigation(0); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); EXPECT_EQ(contents->controller()->GetEntryCount(), 2); EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 0); @@ -791,27 +672,20 @@ TEST_F(NavigationControllerTest, SwitchTypes) { // 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("test1:foo"); const GURL url2("test2:foo"); contents->controller()->LoadURL(url1, PageTransition::TYPED); contents->CompleteNavigation(0); - EXPECT_TRUE(notifications.Check2AndReset(NOTIFY_NAV_ENTRY_COMMITTED, - NOTIFY_NAV_ENTRY_CHANGED)); TestContents* initial_contents = contents; contents->controller()->LoadURL(url2, PageTransition::TYPED); - EXPECT_EQ(0, notifications.size()); // The tab contents should have been replaced ASSERT_TRUE(initial_contents != contents); contents->controller()->DiscardPendingEntry(); - EXPECT_EQ(0, notifications.size()); // The tab contents should have been replaced back ASSERT_TRUE(initial_contents == contents); |