diff options
author | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-15 20:10:49 +0000 |
---|---|---|
committer | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-15 20:10:49 +0000 |
commit | 849890b62b75f95cf91ebd3fe49f1525ff6595bd (patch) | |
tree | d41eef8bb5a3e52ef3a8e356d08d99dd3baacd9f /chrome/browser | |
parent | 3a453fa1f16dfa4168e52790e329148366abb05f (diff) | |
download | chromium_src-849890b62b75f95cf91ebd3fe49f1525ff6595bd.zip chromium_src-849890b62b75f95cf91ebd3fe49f1525ff6595bd.tar.gz chromium_src-849890b62b75f95cf91ebd3fe49f1525ff6595bd.tar.bz2 |
Cleans up notifications for the NavigationController. There were several
notifications before and some of them were very unclear and misused
(STATE_CHANGED). This one, and PRUNED were called unnecessarily in some cases
as well.
I replaced STATE_CHANGED and INDEX_CHANGED with ENTRY_COMMITTED which is more
clear and covers (I think!) all the cases that the callers care about.
I added a simple notification testing helper class, and used in the navigation
controller unit tests to make sure we get the proper notifications. I had to
change NotificationSource/Details to have a = and copy constructor so I can
track them easily in my helper. I don't see why this would be bad.
As part of this, I got very frustrated recompiling the world whenever
navigation_types.h changed. So I removed this dependency from the notification
service which everybody includes. Most of the changed files are adding
notification_types.h in the .cc file where it's needed.
BUG=1325636,1321376,1325779
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@956 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/alternate_nav_url_fetcher.cc | 6 | ||||
-rw-r--r-- | chrome/browser/jsmessage_box_handler.cc | 6 | ||||
-rw-r--r-- | chrome/browser/navigation_controller.cc | 33 | ||||
-rw-r--r-- | chrome/browser/navigation_controller.h | 5 | ||||
-rw-r--r-- | chrome/browser/navigation_controller_base.cc | 25 | ||||
-rw-r--r-- | chrome/browser/navigation_controller_base.h | 2 | ||||
-rw-r--r-- | chrome/browser/navigation_controller_unittest.cc | 136 | ||||
-rw-r--r-- | chrome/browser/session_service.cc | 6 | ||||
-rw-r--r-- | chrome/browser/ssl_manager.cc | 5 | ||||
-rw-r--r-- | chrome/browser/ssl_policy.cc | 1 |
10 files changed, 166 insertions, 59 deletions
diff --git a/chrome/browser/alternate_nav_url_fetcher.cc b/chrome/browser/alternate_nav_url_fetcher.cc index a791106..e86105b 100644 --- a/chrome/browser/alternate_nav_url_fetcher.cc +++ b/chrome/browser/alternate_nav_url_fetcher.cc @@ -41,14 +41,14 @@ AlternateNavURLFetcher::AlternateNavURLFetcher( state_(NOT_STARTED), navigated_to_entry_(false) { NotificationService::current()->AddObserver(this, - NOTIFY_NAV_STATE_CHANGED, NotificationService::AllSources()); + NOTIFY_NAV_ENTRY_PENDING, NotificationService::AllSources()); } AlternateNavURLFetcher::~AlternateNavURLFetcher() { if (state_ == NOT_STARTED) { // Never caught the NavigationController notification. NotificationService::current()->RemoveObserver(this, - NOTIFY_NAV_STATE_CHANGED, NotificationService::AllSources()); + NOTIFY_NAV_ENTRY_PENDING, NotificationService::AllSources()); } // Otherwise, Observe() removed the observer already. } @@ -69,7 +69,7 @@ void AlternateNavURLFetcher::Observe(NotificationType type, controller_->SetAlternateNavURLFetcher(this); NotificationService::current()->RemoveObserver(this, - NOTIFY_NAV_STATE_CHANGED, NotificationService::AllSources()); + NOTIFY_NAV_ENTRY_PENDING, NotificationService::AllSources()); DCHECK_EQ(NOT_STARTED, state_); state_ = IN_PROGRESS; diff --git a/chrome/browser/jsmessage_box_handler.cc b/chrome/browser/jsmessage_box_handler.cc index 09b9757..549981a 100644 --- a/chrome/browser/jsmessage_box_handler.cc +++ b/chrome/browser/jsmessage_box_handler.cc @@ -63,7 +63,7 @@ void JavascriptMessageBoxHandler::RunJavascriptMessageBox( JavascriptMessageBoxHandler::~JavascriptMessageBoxHandler() { NotificationService::current()-> - RemoveObserver(this, NOTIFY_NAV_STATE_CHANGED, + RemoveObserver(this, NOTIFY_NAV_ENTRY_COMMITTED, NotificationService::AllSources()); NotificationService::current()-> RemoveObserver(this, NOTIFY_TAB_CONTENTS_DESTROYED, @@ -188,7 +188,7 @@ void JavascriptMessageBoxHandler::Observe(NotificationType type, if (!web_contents_) return; - if (type == NOTIFY_NAV_STATE_CHANGED && + if (type == NOTIFY_NAV_ENTRY_COMMITTED && Source<NavigationController>(source).ptr() == web_contents_->controller()) web_contents_gone = true; @@ -230,7 +230,7 @@ JavascriptMessageBoxHandler::JavascriptMessageBoxHandler( // Make sure we get navigation notifications so we know when our parent // contents will disappear or navigate to a different page. NotificationService::current()-> - AddObserver(this, NOTIFY_NAV_STATE_CHANGED, + AddObserver(this, NOTIFY_NAV_ENTRY_COMMITTED, NotificationService::AllSources()); NotificationService::current()-> AddObserver(this, NOTIFY_TAB_CONTENTS_DESTROYED, diff --git a/chrome/browser/navigation_controller.cc b/chrome/browser/navigation_controller.cc index ac4392f..5bb5fa5 100644 --- a/chrome/browser/navigation_controller.cc +++ b/chrome/browser/navigation_controller.cc @@ -349,13 +349,6 @@ const SkBitmap& NavigationController::GetLazyFavIcon() const { } } -void NavigationController::EntryUpdated(NavigationEntry* entry) { - if (entry == GetActiveEntry()) { - // Someone has modified our active navigation entry. - NotifyNavigationStateChanged(); - } -} - void NavigationController::SetAlternateNavURLFetcher( AlternateNavURLFetcher* alternate_nav_url_fetcher) { DCHECK(!alternate_nav_url_fetcher_.get()); @@ -423,17 +416,10 @@ void NavigationController::DiscardPendingEntry() { DCHECK(from_contents != active_contents_); ScheduleTabContentsCollection(from_contents->type()); } - - // Note: this may be redundant in some cases. we may want to optimize away - // the redundant notifications. - NotifyNavigationStateChanged(); } void NavigationController::InsertEntry(NavigationEntry* entry) { NavigationControllerBase::InsertEntry(entry); - NotificationService::current()->Notify(NOTIFY_NAV_INDEX_CHANGED, - Source<NavigationController>(this), - NotificationService::NoDetails()); active_contents_->NotifyDidNavigate(NAVIGATION_NEW, 0); } @@ -473,19 +459,16 @@ void NavigationController::NavigateToPendingEntry(bool reload) { from_contents->delegate()->ReplaceContents(from_contents, contents); } - if (contents->Navigate(*pending_entry_, reload)) { - // Note: this is redundant if navigation completed synchronously because - // DidNavigateToEntry call this as well. - NotifyNavigationStateChanged(); - } else { + if (!contents->Navigate(*pending_entry_, reload)) DiscardPendingEntry(); - } } -void NavigationController::NotifyNavigationStateChanged() { +void NavigationController::NotifyNavigationEntryCommitted() { // Reset the Alternate Nav URL Fetcher if we're loading some page it doesn't // care about. We must do this before calling Notify() below as that may // result in the creation of a new fetcher. + // + // TODO(brettw) bug 1324500: this logic should be moved out of the controller! const NavigationEntry* const entry = GetActiveEntry(); if (!entry || (entry->unique_id() != alternate_nav_url_fetcher_entry_unique_id_)) { @@ -500,7 +483,7 @@ void NavigationController::NotifyNavigationStateChanged() { active_contents_->NotifyNavigationStateChanged( TabContents::INVALIDATE_EVERYTHING); - NotificationService::current()->Notify(NOTIFY_NAV_STATE_CHANGED, + NotificationService::current()->Notify(NOTIFY_NAV_ENTRY_COMMITTED, Source<NavigationController>(this), NotificationService::NoDetails()); } @@ -520,12 +503,6 @@ void NavigationController::IndexOfActiveEntryChanged( nav_type = NAVIGATION_REPLACE; } active_contents_->NotifyDidNavigate(nav_type, relative_navigation_offset); - if (GetCurrentEntryIndex() != -1) { - NotificationService::current()->Notify( - NOTIFY_NAV_INDEX_CHANGED, - Source<NavigationController>(this), - NotificationService::NoDetails()); - } } TabContents* NavigationController::GetTabContentsCreateIfNecessary( diff --git a/chrome/browser/navigation_controller.h b/chrome/browser/navigation_controller.h index 070abfa..09bdadf 100644 --- a/chrome/browser/navigation_controller.h +++ b/chrome/browser/navigation_controller.h @@ -135,9 +135,6 @@ class NavigationController : public NavigationControllerBase { const std::wstring& GetLazyTitle() const; const SkBitmap& GetLazyFavIcon() const; - // Called when |entry| has been updated outside its NavigationController. - void EntryUpdated(NavigationEntry* entry); - void SetAlternateNavURLFetcher( AlternateNavURLFetcher* alternate_nav_url_fetcher); @@ -202,7 +199,7 @@ class NavigationController : public NavigationControllerBase { virtual int GetMaxPageID() const; virtual void NavigateToPendingEntry(bool reload); - virtual void NotifyNavigationStateChanged(); + virtual void NotifyNavigationEntryCommitted(); // Lets the history database know navigation entries have been removed. virtual void NotifyPrunedEntries(); diff --git a/chrome/browser/navigation_controller_base.cc b/chrome/browser/navigation_controller_base.cc index f34876d..76371a5 100644 --- a/chrome/browser/navigation_controller_base.cc +++ b/chrome/browser/navigation_controller_base.cc @@ -33,6 +33,8 @@ #include "base/logging.h" #include "chrome/browser/navigation_entry.h" +#include "chrome/common/notification_service.h" +#include "chrome/common/notification_types.h" #include "webkit/glue/webkit_glue.h" // The maximum number of entries that a navigation controller can store. @@ -209,6 +211,12 @@ void NavigationControllerBase::LoadEntry(NavigationEntry* entry) { // TODO(pkasting): http://b/1113085 Should this use DiscardPendingEntry()? DiscardPendingEntryInternal(); pending_entry_ = entry; + // TODO(brettw) the reinterpret cast can be removed once we combine the + // NavigationController and the NavigationControllerBase. + NotificationService::current()->Notify( + NOTIFY_NAV_ENTRY_PENDING, + Source<NavigationController>(reinterpret_cast<NavigationController*>(this)), + NotificationService::NoDetails()); NavigateToPendingEntry(false); } @@ -241,6 +249,7 @@ void NavigationControllerBase::DidNavigateToEntry(NavigationEntry* entry) { // active WebContents, because we have just navigated to it. if (entry->GetPageID() > GetMaxPageID()) { InsertEntry(entry); + NotifyNavigationEntryCommitted(); return; } @@ -296,7 +305,7 @@ void NavigationControllerBase::DidNavigateToEntry(NavigationEntry* entry) { delete entry; - NotifyNavigationStateChanged(); + NotifyNavigationEntryCommitted(); } void NavigationControllerBase::DiscardPendingEntry() { @@ -335,12 +344,15 @@ void NavigationControllerBase::InsertEntry(NavigationEntry* entry) { // Prune any entries which are in front of the current entry. if (current_size > 0) { + bool pruned = false; while (last_committed_entry_index_ < (current_size - 1)) { + pruned = true; delete entries_[current_size - 1]; entries_.pop_back(); current_size--; } - NotifyPrunedEntries(); + if (pruned) // Only notify if we did prune something. + NotifyPrunedEntries(); } if (entries_.size() >= max_entry_count_) @@ -348,8 +360,6 @@ void NavigationControllerBase::InsertEntry(NavigationEntry* entry) { entries_.push_back(entry); last_committed_entry_index_ = static_cast<int>(entries_.size()) - 1; - - NotifyNavigationStateChanged(); } void NavigationControllerBase::RemoveLastEntry() { @@ -368,10 +378,11 @@ void NavigationControllerBase::RemoveLastEntry() { NotifyPrunedEntries(); } - NotifyNavigationStateChanged(); } void NavigationControllerBase::RemoveEntryAtIndex(int index) { + // TODO(brettw) this is only called to remove the first one when we've got + // too many entries. It should probably be more specific for this case. if (index >= static_cast<int>(entries_.size()) || index == pending_entry_index_ || index == last_committed_entry_index_) { NOTREACHED(); @@ -388,8 +399,8 @@ void NavigationControllerBase::RemoveEntryAtIndex(int index) { last_committed_entry_index_ = -1; } - NotifyPrunedEntries(); - NotifyNavigationStateChanged(); + // TODO(brettw) bug 1324021: we probably need some notification here so the + // session service can stay in sync. } void NavigationControllerBase::ResetInternal() { diff --git a/chrome/browser/navigation_controller_base.h b/chrome/browser/navigation_controller_base.h index 6b33a58..bcc894b 100644 --- a/chrome/browser/navigation_controller_base.h +++ b/chrome/browser/navigation_controller_base.h @@ -178,7 +178,7 @@ class NavigationControllerBase { // Allows the derived class to issue notifications that a load has been // committed. - virtual void NotifyNavigationStateChanged() {} + virtual void NotifyNavigationEntryCommitted() {} // Invoked when entries have been pruned, or removed. For example, if the // current entries are [google, digg, yahoo], with the current entry google, diff --git a/chrome/browser/navigation_controller_unittest.cc b/chrome/browser/navigation_controller_unittest.cc index cce2cf9..5cc0402 100644 --- a/chrome/browser/navigation_controller_unittest.cc +++ b/chrome/browser/navigation_controller_unittest.cc @@ -39,7 +39,9 @@ #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" @@ -289,6 +291,16 @@ 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) { @@ -305,12 +317,18 @@ 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); @@ -321,9 +339,14 @@ 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); @@ -333,10 +356,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); @@ -349,8 +372,10 @@ 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); @@ -364,13 +389,23 @@ 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); @@ -383,14 +418,21 @@ 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); @@ -403,12 +445,19 @@ 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); @@ -420,6 +469,8 @@ 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); @@ -433,17 +484,25 @@ 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); @@ -457,16 +516,24 @@ 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); @@ -478,6 +545,8 @@ 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); @@ -491,17 +560,25 @@ 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); @@ -515,6 +592,8 @@ 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? @@ -529,17 +608,26 @@ 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(); @@ -553,6 +641,8 @@ 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); @@ -566,20 +656,30 @@ 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); @@ -593,6 +693,9 @@ 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); @@ -604,17 +707,24 @@ 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); @@ -627,11 +737,16 @@ 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; @@ -641,6 +756,8 @@ 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. @@ -656,6 +773,8 @@ 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); @@ -672,20 +791,27 @@ 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); diff --git a/chrome/browser/session_service.cc b/chrome/browser/session_service.cc index 9ed3d9f..da72060 100644 --- a/chrome/browser/session_service.cc +++ b/chrome/browser/session_service.cc @@ -160,7 +160,7 @@ SessionService::~SessionService() { NotificationService::current()->RemoveObserver( this, NOTIFY_NAV_ENTRY_CHANGED, NotificationService::AllSources()); NotificationService::current()->RemoveObserver( - this, NOTIFY_NAV_INDEX_CHANGED, NotificationService::AllSources()); + this, NOTIFY_NAV_ENTRY_COMMITTED, NotificationService::AllSources()); } void SessionService::ResetFromCurrentBrowsers() { @@ -417,7 +417,7 @@ void SessionService::Init(const std::wstring& path) { NotificationService::current()->AddObserver( this, NOTIFY_NAV_ENTRY_CHANGED, NotificationService::AllSources()); NotificationService::current()->AddObserver( - this, NOTIFY_NAV_INDEX_CHANGED, NotificationService::AllSources()); + this, NOTIFY_NAV_ENTRY_COMMITTED, NotificationService::AllSources()); DCHECK(!path.empty()); commands_since_reset_ = 0; @@ -450,7 +450,7 @@ void SessionService::Observe(NotificationType type, changed->index, *changed->changed_entry); break; } - case NOTIFY_NAV_INDEX_CHANGED: + case NOTIFY_NAV_ENTRY_COMMITTED: SetSelectedNavigationIndex(controller->window_id(), controller->session_id(), controller->GetCurrentEntryIndex()); diff --git a/chrome/browser/ssl_manager.cc b/chrome/browser/ssl_manager.cc index 0e9b16a..c1ecf1d 100644 --- a/chrome/browser/ssl_manager.cc +++ b/chrome/browser/ssl_manager.cc @@ -247,10 +247,8 @@ void SSLManager::SetMaxSecurityStyle(SecurityStyle style) { return; } - if (entry->GetSecurityStyle() > style) { + if (entry->GetSecurityStyle() > style) entry->SetSecurityStyle(style); - controller_->EntryUpdated(entry); - } } // Delegate API method. @@ -653,7 +651,6 @@ void SSLManager::DidCommitProvisionalLoad(ProvisionalLoadDetails* details) { entry->SetSSLCertID(details->ssl_cert_id()); entry->SetSSLCertStatus(details->ssl_cert_status()); entry->SetSSLSecurityBits(details->ssl_security_bits()); - controller_->EntryUpdated(entry); } if (details->interstitial_page()) { diff --git a/chrome/browser/ssl_policy.cc b/chrome/browser/ssl_policy.cc index 1ae9ae1..4f5f914 100644 --- a/chrome/browser/ssl_policy.cc +++ b/chrome/browser/ssl_policy.cc @@ -346,7 +346,6 @@ class DefaultPolicy : public SSLPolicy { NavigationEntry* entry = navigation_controller->GetActiveEntry(); entry->SetHasMixedContent(); - navigation_controller->EntryUpdated(entry); } void OnDenyCertificate(SSLManager::CertError* error) { |