OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 void RegisterForAllNavNotifications(TestNotificationTracker* tracker, | 136 void RegisterForAllNavNotifications(TestNotificationTracker* tracker, |
137 NavigationController* controller) { | 137 NavigationController* controller) { |
138 tracker->ListenFor(NotificationType::NAV_ENTRY_COMMITTED, | 138 tracker->ListenFor(NotificationType::NAV_ENTRY_COMMITTED, |
139 Source<NavigationController>(controller)); | 139 Source<NavigationController>(controller)); |
140 tracker->ListenFor(NotificationType::NAV_LIST_PRUNED, | 140 tracker->ListenFor(NotificationType::NAV_LIST_PRUNED, |
141 Source<NavigationController>(controller)); | 141 Source<NavigationController>(controller)); |
142 tracker->ListenFor(NotificationType::NAV_ENTRY_CHANGED, | 142 tracker->ListenFor(NotificationType::NAV_ENTRY_CHANGED, |
143 Source<NavigationController>(controller)); | 143 Source<NavigationController>(controller)); |
144 } | 144 } |
145 | 145 |
| 146 class TestTabContentsDelegate : public TabContentsDelegate { |
| 147 public: |
| 148 explicit TestTabContentsDelegate() : |
| 149 navigation_state_change_count_(0) {} |
| 150 |
| 151 int navigation_state_change_count() { |
| 152 return navigation_state_change_count_; |
| 153 } |
| 154 |
| 155 virtual void OpenURLFromTab(TabContents* source, |
| 156 const GURL& url, const GURL& referrer, |
| 157 WindowOpenDisposition disposition, |
| 158 PageTransition::Type transition) {} |
| 159 |
| 160 // Keep track of whether the tab has notified us of a navigation state change. |
| 161 virtual void NavigationStateChanged(const TabContents* source, |
| 162 unsigned changed_flags) { |
| 163 navigation_state_change_count_++; |
| 164 } |
| 165 |
| 166 virtual void AddNewContents(TabContents* source, |
| 167 TabContents* new_contents, |
| 168 WindowOpenDisposition disposition, |
| 169 const gfx::Rect& initial_pos, |
| 170 bool user_gesture) {} |
| 171 virtual void ActivateContents(TabContents* contents) {} |
| 172 virtual void DeactivateContents(TabContents* contents) {} |
| 173 virtual void LoadingStateChanged(TabContents* source) {} |
| 174 virtual void CloseContents(TabContents* source) {} |
| 175 virtual void MoveContents(TabContents* source, const gfx::Rect& pos) {} |
| 176 virtual void ToolbarSizeChanged(TabContents* source, bool is_animating) {} |
| 177 virtual void UpdateTargetURL(TabContents* source, const GURL& url) {} |
| 178 |
| 179 private: |
| 180 // The number of times NavigationStateChanged has been called. |
| 181 int navigation_state_change_count_; |
| 182 }; |
| 183 |
146 // ----------------------------------------------------------------------------- | 184 // ----------------------------------------------------------------------------- |
147 | 185 |
148 TEST_F(NavigationControllerTest, Defaults) { | 186 TEST_F(NavigationControllerTest, Defaults) { |
149 EXPECT_FALSE(controller().pending_entry()); | 187 EXPECT_FALSE(controller().pending_entry()); |
150 EXPECT_FALSE(controller().GetLastCommittedEntry()); | 188 EXPECT_FALSE(controller().GetLastCommittedEntry()); |
151 EXPECT_EQ(controller().pending_entry_index(), -1); | 189 EXPECT_EQ(controller().pending_entry_index(), -1); |
152 EXPECT_EQ(controller().last_committed_entry_index(), -1); | 190 EXPECT_EQ(controller().last_committed_entry_index(), -1); |
153 EXPECT_EQ(controller().entry_count(), 0); | 191 EXPECT_EQ(controller().entry_count(), 0); |
154 EXPECT_FALSE(controller().CanGoBack()); | 192 EXPECT_FALSE(controller().CanGoBack()); |
155 EXPECT_FALSE(controller().CanGoForward()); | 193 EXPECT_FALSE(controller().CanGoForward()); |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 | 458 |
421 // There should no longer be any pending entry, and the back navigation we | 459 // There should no longer be any pending entry, and the back navigation we |
422 // just made should be committed. | 460 // just made should be committed. |
423 EXPECT_TRUE(notifications.Check1AndReset( | 461 EXPECT_TRUE(notifications.Check1AndReset( |
424 NotificationType::NAV_ENTRY_COMMITTED)); | 462 NotificationType::NAV_ENTRY_COMMITTED)); |
425 EXPECT_EQ(-1, controller().pending_entry_index()); | 463 EXPECT_EQ(-1, controller().pending_entry_index()); |
426 EXPECT_EQ(0, controller().last_committed_entry_index()); | 464 EXPECT_EQ(0, controller().last_committed_entry_index()); |
427 EXPECT_EQ(kExistingURL1, controller().GetActiveEntry()->url()); | 465 EXPECT_EQ(kExistingURL1, controller().GetActiveEntry()->url()); |
428 } | 466 } |
429 | 467 |
| 468 // Tests an ignored navigation when there is a pending new navigation. |
| 469 // This will happen if the user enters a URL, but before that commits, the |
| 470 // current blank page reloads. See http://crbug.com/77507. |
| 471 TEST_F(NavigationControllerTest, LoadURL_IgnorePreemptsPending) { |
| 472 TestNotificationTracker notifications; |
| 473 RegisterForAllNavNotifications(¬ifications, &controller()); |
| 474 |
| 475 // Set a TabContentsDelegate to listen for state changes. |
| 476 scoped_ptr<TestTabContentsDelegate> delegate(new TestTabContentsDelegate()); |
| 477 EXPECT_FALSE(contents()->delegate()); |
| 478 contents()->set_delegate(delegate.get()); |
| 479 |
| 480 // Without any navigations, the renderer starts at about:blank. |
| 481 const GURL kExistingURL("about:blank"); |
| 482 |
| 483 // Now make a pending new navigation. |
| 484 const GURL kNewURL("http://eh"); |
| 485 controller().LoadURL(kNewURL, GURL(), PageTransition::TYPED); |
| 486 EXPECT_EQ(0U, notifications.size()); |
| 487 EXPECT_EQ(-1, controller().pending_entry_index()); |
| 488 EXPECT_TRUE(controller().pending_entry()); |
| 489 EXPECT_EQ(-1, controller().last_committed_entry_index()); |
| 490 EXPECT_EQ(1, delegate->navigation_state_change_count()); |
| 491 |
| 492 // Before that commits, a document.write and location.reload can cause the |
| 493 // renderer to send a FrameNavigate with page_id -1. |
| 494 rvh()->SendNavigate(-1, kExistingURL); |
| 495 |
| 496 // This should clear the pending entry and notify of a navigation state |
| 497 // change, so that we do not keep displaying kNewURL. |
| 498 EXPECT_EQ(-1, controller().pending_entry_index()); |
| 499 EXPECT_FALSE(controller().pending_entry()); |
| 500 EXPECT_EQ(-1, controller().last_committed_entry_index()); |
| 501 EXPECT_EQ(2, delegate->navigation_state_change_count()); |
| 502 |
| 503 contents()->set_delegate(NULL); |
| 504 } |
| 505 |
430 TEST_F(NavigationControllerTest, Reload) { | 506 TEST_F(NavigationControllerTest, Reload) { |
431 TestNotificationTracker notifications; | 507 TestNotificationTracker notifications; |
432 RegisterForAllNavNotifications(¬ifications, &controller()); | 508 RegisterForAllNavNotifications(¬ifications, &controller()); |
433 | 509 |
434 const GURL url1("http://foo1"); | 510 const GURL url1("http://foo1"); |
435 | 511 |
436 controller().LoadURL(url1, GURL(), PageTransition::TYPED); | 512 controller().LoadURL(url1, GURL(), PageTransition::TYPED); |
437 EXPECT_EQ(0U, notifications.size()); | 513 EXPECT_EQ(0U, notifications.size()); |
438 rvh()->SendNavigate(0, url1); | 514 rvh()->SendNavigate(0, url1); |
439 EXPECT_TRUE(notifications.Check1AndReset( | 515 EXPECT_TRUE(notifications.Check1AndReset( |
(...skipping 1720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2160 TabNavigation nav(0, url0, GURL(), string16(), | 2236 TabNavigation nav(0, url0, GURL(), string16(), |
2161 webkit_glue::CreateHistoryStateForURL(url0), | 2237 webkit_glue::CreateHistoryStateForURL(url0), |
2162 PageTransition::LINK); | 2238 PageTransition::LINK); |
2163 session_helper_.AssertNavigationEquals(nav, | 2239 session_helper_.AssertNavigationEquals(nav, |
2164 windows_[0]->tabs[0]->navigations[0]); | 2240 windows_[0]->tabs[0]->navigations[0]); |
2165 nav.set_url(url2); | 2241 nav.set_url(url2); |
2166 session_helper_.AssertNavigationEquals(nav, | 2242 session_helper_.AssertNavigationEquals(nav, |
2167 windows_[0]->tabs[0]->navigations[1]); | 2243 windows_[0]->tabs[0]->navigations[1]); |
2168 } | 2244 } |
2169 */ | 2245 */ |
OLD | NEW |