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

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

Issue 23022006: Remove GetActiveEntry usage from content. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 // The number of times NavigationStateChanged has been called. 246 // The number of times NavigationStateChanged has been called.
247 int navigation_state_change_count_; 247 int navigation_state_change_count_;
248 }; 248 };
249 249
250 // ----------------------------------------------------------------------------- 250 // -----------------------------------------------------------------------------
251 251
252 TEST_F(NavigationControllerTest, Defaults) { 252 TEST_F(NavigationControllerTest, Defaults) {
253 NavigationControllerImpl& controller = controller_impl(); 253 NavigationControllerImpl& controller = controller_impl();
254 254
255 EXPECT_FALSE(controller.GetPendingEntry()); 255 EXPECT_FALSE(controller.GetPendingEntry());
256 EXPECT_FALSE(controller.GetActiveEntry()); 256 EXPECT_FALSE(controller.GetVisibleEntry());
Charlie Reis 2013/08/16 22:10:14 Redundant with next line.
nasko 2013/09/12 17:56:31 Done.
257 EXPECT_FALSE(controller.GetVisibleEntry()); 257 EXPECT_FALSE(controller.GetVisibleEntry());
258 EXPECT_FALSE(controller.GetLastCommittedEntry()); 258 EXPECT_FALSE(controller.GetLastCommittedEntry());
259 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 259 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
260 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), -1); 260 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), -1);
261 EXPECT_EQ(controller.GetEntryCount(), 0); 261 EXPECT_EQ(controller.GetEntryCount(), 0);
262 EXPECT_FALSE(controller.CanGoBack()); 262 EXPECT_FALSE(controller.CanGoBack());
263 EXPECT_FALSE(controller.CanGoForward()); 263 EXPECT_FALSE(controller.CanGoForward());
264 } 264 }
265 265
266 TEST_F(NavigationControllerTest, GoToOffset) { 266 TEST_F(NavigationControllerTest, GoToOffset) {
267 NavigationControllerImpl& controller = controller_impl(); 267 NavigationControllerImpl& controller = controller_impl();
268 TestNotificationTracker notifications; 268 TestNotificationTracker notifications;
269 RegisterForAllNavNotifications(&notifications, &controller); 269 RegisterForAllNavNotifications(&notifications, &controller);
270 270
271 const int kNumUrls = 5; 271 const int kNumUrls = 5;
272 std::vector<GURL> urls(kNumUrls); 272 std::vector<GURL> urls(kNumUrls);
273 for (int i = 0; i < kNumUrls; ++i) { 273 for (int i = 0; i < kNumUrls; ++i) {
274 urls[i] = GURL(base::StringPrintf("http://www.a.com/%d", i)); 274 urls[i] = GURL(base::StringPrintf("http://www.a.com/%d", i));
275 } 275 }
276 276
277 test_rvh()->SendNavigate(0, urls[0]); 277 test_rvh()->SendNavigate(0, urls[0]);
278 EXPECT_EQ(1U, navigation_entry_committed_counter_); 278 EXPECT_EQ(1U, navigation_entry_committed_counter_);
279 navigation_entry_committed_counter_ = 0; 279 navigation_entry_committed_counter_ = 0;
280 EXPECT_EQ(urls[0], controller.GetActiveEntry()->GetVirtualURL()); 280 EXPECT_EQ(urls[0], controller.GetVisibleEntry()->GetVirtualURL());
281 EXPECT_FALSE(controller.CanGoBack()); 281 EXPECT_FALSE(controller.CanGoBack());
282 EXPECT_FALSE(controller.CanGoForward()); 282 EXPECT_FALSE(controller.CanGoForward());
283 EXPECT_FALSE(controller.CanGoToOffset(1)); 283 EXPECT_FALSE(controller.CanGoToOffset(1));
284 284
285 for (int i = 1; i <= 4; ++i) { 285 for (int i = 1; i <= 4; ++i) {
286 test_rvh()->SendNavigate(i, urls[i]); 286 test_rvh()->SendNavigate(i, urls[i]);
287 EXPECT_EQ(1U, navigation_entry_committed_counter_); 287 EXPECT_EQ(1U, navigation_entry_committed_counter_);
288 navigation_entry_committed_counter_ = 0; 288 navigation_entry_committed_counter_ = 0;
289 EXPECT_EQ(urls[i], controller.GetActiveEntry()->GetVirtualURL()); 289 EXPECT_EQ(urls[i], controller.GetVisibleEntry()->GetVirtualURL());
290 EXPECT_TRUE(controller.CanGoToOffset(-i)); 290 EXPECT_TRUE(controller.CanGoToOffset(-i));
291 EXPECT_FALSE(controller.CanGoToOffset(-(i + 1))); 291 EXPECT_FALSE(controller.CanGoToOffset(-(i + 1)));
292 EXPECT_FALSE(controller.CanGoToOffset(1)); 292 EXPECT_FALSE(controller.CanGoToOffset(1));
293 } 293 }
294 294
295 // We have loaded 5 pages, and are currently at the last-loaded page. 295 // We have loaded 5 pages, and are currently at the last-loaded page.
296 int url_index = 4; 296 int url_index = 4;
297 297
298 enum Tests { 298 enum Tests {
299 GO_TO_MIDDLE_PAGE = -2, 299 GO_TO_MIDDLE_PAGE = -2,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 // Creating a pending notification should not have issued any of the 342 // Creating a pending notification should not have issued any of the
343 // notifications we're listening for. 343 // notifications we're listening for.
344 EXPECT_EQ(0U, notifications.size()); 344 EXPECT_EQ(0U, notifications.size());
345 345
346 // The load should now be pending. 346 // The load should now be pending.
347 EXPECT_EQ(controller.GetEntryCount(), 0); 347 EXPECT_EQ(controller.GetEntryCount(), 0);
348 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), -1); 348 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), -1);
349 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 349 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
350 EXPECT_FALSE(controller.GetLastCommittedEntry()); 350 EXPECT_FALSE(controller.GetLastCommittedEntry());
351 ASSERT_TRUE(controller.GetPendingEntry()); 351 ASSERT_TRUE(controller.GetPendingEntry());
352 EXPECT_EQ(controller.GetPendingEntry(), controller.GetActiveEntry()); 352 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry());
Charlie Reis 2013/08/16 22:10:14 Redundant with next line.
nasko 2013/09/12 17:56:31 Done.
353 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); 353 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry());
354 EXPECT_FALSE(controller.CanGoBack()); 354 EXPECT_FALSE(controller.CanGoBack());
355 EXPECT_FALSE(controller.CanGoForward()); 355 EXPECT_FALSE(controller.CanGoForward());
356 EXPECT_EQ(contents()->GetMaxPageID(), -1); 356 EXPECT_EQ(contents()->GetMaxPageID(), -1);
357 357
358 // The timestamp should not have been set yet. 358 // The timestamp should not have been set yet.
359 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); 359 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null());
360 360
361 // We should have gotten no notifications from the preceeding checks. 361 // We should have gotten no notifications from the preceeding checks.
362 EXPECT_EQ(0U, notifications.size()); 362 EXPECT_EQ(0U, notifications.size());
363 363
364 test_rvh()->SendNavigate(0, url1); 364 test_rvh()->SendNavigate(0, url1);
365 EXPECT_EQ(1U, navigation_entry_committed_counter_); 365 EXPECT_EQ(1U, navigation_entry_committed_counter_);
366 navigation_entry_committed_counter_ = 0; 366 navigation_entry_committed_counter_ = 0;
367 367
368 // The load should now be committed. 368 // The load should now be committed.
369 EXPECT_EQ(controller.GetEntryCount(), 1); 369 EXPECT_EQ(controller.GetEntryCount(), 1);
370 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 370 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
371 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 371 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
372 EXPECT_TRUE(controller.GetLastCommittedEntry()); 372 EXPECT_TRUE(controller.GetLastCommittedEntry());
373 EXPECT_FALSE(controller.GetPendingEntry()); 373 EXPECT_FALSE(controller.GetPendingEntry());
374 ASSERT_TRUE(controller.GetActiveEntry()); 374 ASSERT_TRUE(controller.GetVisibleEntry());
375 EXPECT_EQ(controller.GetActiveEntry(), controller.GetVisibleEntry()); 375 EXPECT_EQ(controller.GetVisibleEntry(), controller.GetVisibleEntry());
376 EXPECT_FALSE(controller.CanGoBack()); 376 EXPECT_FALSE(controller.CanGoBack());
377 EXPECT_FALSE(controller.CanGoForward()); 377 EXPECT_FALSE(controller.CanGoForward());
378 EXPECT_EQ(contents()->GetMaxPageID(), 0); 378 EXPECT_EQ(contents()->GetMaxPageID(), 0);
379 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( 379 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry(
380 controller.GetLastCommittedEntry())->bindings()); 380 controller.GetLastCommittedEntry())->bindings());
381 381
382 // The timestamp should have been set. 382 // The timestamp should have been set.
383 EXPECT_FALSE(controller.GetActiveEntry()->GetTimestamp().is_null()); 383 EXPECT_FALSE(controller.GetVisibleEntry()->GetTimestamp().is_null());
384 384
385 // Load another... 385 // Load another...
386 controller.LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 386 controller.LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string());
387 387
388 // The load should now be pending. 388 // The load should now be pending.
389 EXPECT_EQ(controller.GetEntryCount(), 1); 389 EXPECT_EQ(controller.GetEntryCount(), 1);
390 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 390 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
391 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 391 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
392 EXPECT_TRUE(controller.GetLastCommittedEntry()); 392 EXPECT_TRUE(controller.GetLastCommittedEntry());
393 ASSERT_TRUE(controller.GetPendingEntry()); 393 ASSERT_TRUE(controller.GetPendingEntry());
394 EXPECT_EQ(controller.GetPendingEntry(), controller.GetActiveEntry()); 394 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry());
Charlie Reis 2013/08/16 22:10:14 Redundant.
nasko 2013/09/12 17:56:31 Done.
395 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); 395 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry());
396 // TODO(darin): maybe this should really be true? 396 // TODO(darin): maybe this should really be true?
397 EXPECT_FALSE(controller.CanGoBack()); 397 EXPECT_FALSE(controller.CanGoBack());
398 EXPECT_FALSE(controller.CanGoForward()); 398 EXPECT_FALSE(controller.CanGoForward());
399 EXPECT_EQ(contents()->GetMaxPageID(), 0); 399 EXPECT_EQ(contents()->GetMaxPageID(), 0);
400 400
401 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); 401 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null());
402 402
403 // Simulate the beforeunload ack for the cross-site transition, and then the 403 // Simulate the beforeunload ack for the cross-site transition, and then the
404 // commit. 404 // commit.
405 test_rvh()->SendShouldCloseACK(true); 405 test_rvh()->SendShouldCloseACK(true);
406 static_cast<TestRenderViewHost*>( 406 static_cast<TestRenderViewHost*>(
407 contents()->GetPendingRenderViewHost())->SendNavigate(1, url2); 407 contents()->GetPendingRenderViewHost())->SendNavigate(1, url2);
408 EXPECT_EQ(1U, navigation_entry_committed_counter_); 408 EXPECT_EQ(1U, navigation_entry_committed_counter_);
409 navigation_entry_committed_counter_ = 0; 409 navigation_entry_committed_counter_ = 0;
410 410
411 // The load should now be committed. 411 // The load should now be committed.
412 EXPECT_EQ(controller.GetEntryCount(), 2); 412 EXPECT_EQ(controller.GetEntryCount(), 2);
413 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); 413 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1);
414 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 414 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
415 EXPECT_TRUE(controller.GetLastCommittedEntry()); 415 EXPECT_TRUE(controller.GetLastCommittedEntry());
416 EXPECT_FALSE(controller.GetPendingEntry()); 416 EXPECT_FALSE(controller.GetPendingEntry());
417 ASSERT_TRUE(controller.GetActiveEntry()); 417 ASSERT_TRUE(controller.GetVisibleEntry());
418 EXPECT_EQ(controller.GetActiveEntry(), controller.GetVisibleEntry()); 418 EXPECT_EQ(controller.GetVisibleEntry(), controller.GetVisibleEntry());
419 EXPECT_TRUE(controller.CanGoBack()); 419 EXPECT_TRUE(controller.CanGoBack());
420 EXPECT_FALSE(controller.CanGoForward()); 420 EXPECT_FALSE(controller.CanGoForward());
421 EXPECT_EQ(contents()->GetMaxPageID(), 1); 421 EXPECT_EQ(contents()->GetMaxPageID(), 1);
422 422
423 EXPECT_FALSE(controller.GetActiveEntry()->GetTimestamp().is_null()); 423 EXPECT_FALSE(controller.GetVisibleEntry()->GetTimestamp().is_null());
424 } 424 }
425 425
426 namespace { 426 namespace {
427 427
428 base::Time GetFixedTime(base::Time time) { 428 base::Time GetFixedTime(base::Time time) {
429 return time; 429 return time;
430 } 430 }
431 431
432 } // namespace 432 } // namespace
433 433
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 RegisterForAllNavNotifications(&notifications, &controller); 575 RegisterForAllNavNotifications(&notifications, &controller);
576 576
577 const GURL url1("http://foo1"); 577 const GURL url1("http://foo1");
578 578
579 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 579 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string());
580 EXPECT_EQ(0U, notifications.size()); 580 EXPECT_EQ(0U, notifications.size());
581 test_rvh()->SendNavigate(0, url1); 581 test_rvh()->SendNavigate(0, url1);
582 EXPECT_EQ(1U, navigation_entry_committed_counter_); 582 EXPECT_EQ(1U, navigation_entry_committed_counter_);
583 navigation_entry_committed_counter_ = 0; 583 navigation_entry_committed_counter_ = 0;
584 584
585 ASSERT_TRUE(controller.GetActiveEntry()); 585 ASSERT_TRUE(controller.GetVisibleEntry());
586 const base::Time timestamp = controller.GetActiveEntry()->GetTimestamp(); 586 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp();
587 EXPECT_FALSE(timestamp.is_null()); 587 EXPECT_FALSE(timestamp.is_null());
588 588
589 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 589 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string());
590 EXPECT_EQ(0U, notifications.size()); 590 EXPECT_EQ(0U, notifications.size());
591 test_rvh()->SendNavigate(0, url1); 591 test_rvh()->SendNavigate(0, url1);
592 EXPECT_EQ(1U, navigation_entry_committed_counter_); 592 EXPECT_EQ(1U, navigation_entry_committed_counter_);
593 navigation_entry_committed_counter_ = 0; 593 navigation_entry_committed_counter_ = 0;
594 594
595 // We should not have produced a new session history entry. 595 // We should not have produced a new session history entry.
596 EXPECT_EQ(controller.GetEntryCount(), 1); 596 EXPECT_EQ(controller.GetEntryCount(), 1);
597 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 597 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
598 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 598 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
599 EXPECT_TRUE(controller.GetLastCommittedEntry()); 599 EXPECT_TRUE(controller.GetLastCommittedEntry());
600 EXPECT_FALSE(controller.GetPendingEntry()); 600 EXPECT_FALSE(controller.GetPendingEntry());
601 ASSERT_TRUE(controller.GetActiveEntry()); 601 ASSERT_TRUE(controller.GetVisibleEntry());
602 EXPECT_FALSE(controller.CanGoBack()); 602 EXPECT_FALSE(controller.CanGoBack());
603 EXPECT_FALSE(controller.CanGoForward()); 603 EXPECT_FALSE(controller.CanGoForward());
604 604
605 // The timestamp should have been updated. 605 // The timestamp should have been updated.
606 // 606 //
607 // TODO(akalin): Change this EXPECT_GE (and other similar ones) to 607 // TODO(akalin): Change this EXPECT_GE (and other similar ones) to
608 // EXPECT_GT once we guarantee that timestamps are unique. 608 // EXPECT_GT once we guarantee that timestamps are unique.
609 EXPECT_GE(controller.GetActiveEntry()->GetTimestamp(), timestamp); 609 EXPECT_GE(controller.GetVisibleEntry()->GetTimestamp(), timestamp);
610 } 610 }
611 611
612 // Tests loading a URL but discarding it before the load commits. 612 // Tests loading a URL but discarding it before the load commits.
613 TEST_F(NavigationControllerTest, LoadURL_Discarded) { 613 TEST_F(NavigationControllerTest, LoadURL_Discarded) {
614 NavigationControllerImpl& controller = controller_impl(); 614 NavigationControllerImpl& controller = controller_impl();
615 TestNotificationTracker notifications; 615 TestNotificationTracker notifications;
616 RegisterForAllNavNotifications(&notifications, &controller); 616 RegisterForAllNavNotifications(&notifications, &controller);
617 617
618 const GURL url1("http://foo1"); 618 const GURL url1("http://foo1");
619 const GURL url2("http://foo2"); 619 const GURL url2("http://foo2");
620 620
621 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 621 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string());
622 EXPECT_EQ(0U, notifications.size()); 622 EXPECT_EQ(0U, notifications.size());
623 test_rvh()->SendNavigate(0, url1); 623 test_rvh()->SendNavigate(0, url1);
624 EXPECT_EQ(1U, navigation_entry_committed_counter_); 624 EXPECT_EQ(1U, navigation_entry_committed_counter_);
625 navigation_entry_committed_counter_ = 0; 625 navigation_entry_committed_counter_ = 0;
626 626
627 ASSERT_TRUE(controller.GetActiveEntry()); 627 ASSERT_TRUE(controller.GetVisibleEntry());
628 const base::Time timestamp = controller.GetActiveEntry()->GetTimestamp(); 628 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp();
629 EXPECT_FALSE(timestamp.is_null()); 629 EXPECT_FALSE(timestamp.is_null());
630 630
631 controller.LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 631 controller.LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string());
632 controller.DiscardNonCommittedEntries(); 632 controller.DiscardNonCommittedEntries();
633 EXPECT_EQ(0U, notifications.size()); 633 EXPECT_EQ(0U, notifications.size());
634 634
635 // Should not have produced a new session history entry. 635 // Should not have produced a new session history entry.
636 EXPECT_EQ(controller.GetEntryCount(), 1); 636 EXPECT_EQ(controller.GetEntryCount(), 1);
637 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 637 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
638 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 638 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
639 EXPECT_TRUE(controller.GetLastCommittedEntry()); 639 EXPECT_TRUE(controller.GetLastCommittedEntry());
640 EXPECT_FALSE(controller.GetPendingEntry()); 640 EXPECT_FALSE(controller.GetPendingEntry());
641 ASSERT_TRUE(controller.GetActiveEntry()); 641 ASSERT_TRUE(controller.GetVisibleEntry());
642 EXPECT_FALSE(controller.CanGoBack()); 642 EXPECT_FALSE(controller.CanGoBack());
643 EXPECT_FALSE(controller.CanGoForward()); 643 EXPECT_FALSE(controller.CanGoForward());
644 644
645 // Timestamp should not have changed. 645 // Timestamp should not have changed.
646 EXPECT_EQ(timestamp, controller.GetActiveEntry()->GetTimestamp()); 646 EXPECT_EQ(timestamp, controller.GetVisibleEntry()->GetTimestamp());
647 } 647 }
648 648
649 // Tests navigations that come in unrequested. This happens when the user 649 // Tests navigations that come in unrequested. This happens when the user
650 // navigates from the web page, and here we test that there is no pending entry. 650 // navigates from the web page, and here we test that there is no pending entry.
651 TEST_F(NavigationControllerTest, LoadURL_NoPending) { 651 TEST_F(NavigationControllerTest, LoadURL_NoPending) {
652 NavigationControllerImpl& controller = controller_impl(); 652 NavigationControllerImpl& controller = controller_impl();
653 TestNotificationTracker notifications; 653 TestNotificationTracker notifications;
654 RegisterForAllNavNotifications(&notifications, &controller); 654 RegisterForAllNavNotifications(&notifications, &controller);
655 655
656 // First make an existing committed entry. 656 // First make an existing committed entry.
657 const GURL kExistingURL1("http://eh"); 657 const GURL kExistingURL1("http://eh");
658 controller.LoadURL( 658 controller.LoadURL(
659 kExistingURL1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 659 kExistingURL1, Referrer(), PAGE_TRANSITION_TYPED, std::string());
660 test_rvh()->SendNavigate(0, kExistingURL1); 660 test_rvh()->SendNavigate(0, kExistingURL1);
661 EXPECT_EQ(1U, navigation_entry_committed_counter_); 661 EXPECT_EQ(1U, navigation_entry_committed_counter_);
662 navigation_entry_committed_counter_ = 0; 662 navigation_entry_committed_counter_ = 0;
663 663
664 // Do a new navigation without making a pending one. 664 // Do a new navigation without making a pending one.
665 const GURL kNewURL("http://see"); 665 const GURL kNewURL("http://see");
666 test_rvh()->SendNavigate(99, kNewURL); 666 test_rvh()->SendNavigate(99, kNewURL);
667 667
668 // There should no longer be any pending entry, and the third navigation we 668 // There should no longer be any pending entry, and the third navigation we
669 // just made should be committed. 669 // just made should be committed.
670 EXPECT_EQ(1U, navigation_entry_committed_counter_); 670 EXPECT_EQ(1U, navigation_entry_committed_counter_);
671 navigation_entry_committed_counter_ = 0; 671 navigation_entry_committed_counter_ = 0;
672 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 672 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
673 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 673 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
674 EXPECT_EQ(kNewURL, controller.GetActiveEntry()->GetURL()); 674 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL());
675 } 675 }
676 676
677 // Tests navigating to a new URL when there is a new pending navigation that is 677 // Tests navigating to a new URL when there is a new pending navigation that is
678 // not the one that just loaded. This will happen if the user types in a URL to 678 // not the one that just loaded. This will happen if the user types in a URL to
679 // somewhere slow, and then navigates the current page before the typed URL 679 // somewhere slow, and then navigates the current page before the typed URL
680 // commits. 680 // commits.
681 TEST_F(NavigationControllerTest, LoadURL_NewPending) { 681 TEST_F(NavigationControllerTest, LoadURL_NewPending) {
682 NavigationControllerImpl& controller = controller_impl(); 682 NavigationControllerImpl& controller = controller_impl();
683 TestNotificationTracker notifications; 683 TestNotificationTracker notifications;
684 RegisterForAllNavNotifications(&notifications, &controller); 684 RegisterForAllNavNotifications(&notifications, &controller);
(...skipping 17 matching lines...) Expand all
702 const GURL kNewURL("http://see"); 702 const GURL kNewURL("http://see");
703 static_cast<TestRenderViewHost*>( 703 static_cast<TestRenderViewHost*>(
704 contents()->GetPendingRenderViewHost())->SendNavigate(3, kNewURL); 704 contents()->GetPendingRenderViewHost())->SendNavigate(3, kNewURL);
705 705
706 // There should no longer be any pending entry, and the third navigation we 706 // There should no longer be any pending entry, and the third navigation we
707 // just made should be committed. 707 // just made should be committed.
708 EXPECT_EQ(1U, navigation_entry_committed_counter_); 708 EXPECT_EQ(1U, navigation_entry_committed_counter_);
709 navigation_entry_committed_counter_ = 0; 709 navigation_entry_committed_counter_ = 0;
710 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 710 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
711 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 711 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
712 EXPECT_EQ(kNewURL, controller.GetActiveEntry()->GetURL()); 712 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL());
713 } 713 }
714 714
715 // Tests navigating to a new URL when there is a pending back/forward 715 // Tests navigating to a new URL when there is a pending back/forward
716 // navigation. This will happen if the user hits back, but before that commits, 716 // navigation. This will happen if the user hits back, but before that commits,
717 // they navigate somewhere new. 717 // they navigate somewhere new.
718 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { 718 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) {
719 NavigationControllerImpl& controller = controller_impl(); 719 NavigationControllerImpl& controller = controller_impl();
720 TestNotificationTracker notifications; 720 TestNotificationTracker notifications;
721 RegisterForAllNavNotifications(&notifications, &controller); 721 RegisterForAllNavNotifications(&notifications, &controller);
722 722
(...skipping 23 matching lines...) Expand all
746 const GURL kNewURL("http://foo/see"); 746 const GURL kNewURL("http://foo/see");
747 LoadCommittedDetails details; 747 LoadCommittedDetails details;
748 test_rvh()->SendNavigate(3, kNewURL); 748 test_rvh()->SendNavigate(3, kNewURL);
749 749
750 // There should no longer be any pending entry, and the third navigation we 750 // There should no longer be any pending entry, and the third navigation we
751 // just made should be committed. 751 // just made should be committed.
752 EXPECT_EQ(1U, navigation_entry_committed_counter_); 752 EXPECT_EQ(1U, navigation_entry_committed_counter_);
753 navigation_entry_committed_counter_ = 0; 753 navigation_entry_committed_counter_ = 0;
754 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 754 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
755 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); 755 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex());
756 EXPECT_EQ(kNewURL, controller.GetActiveEntry()->GetURL()); 756 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL());
757 } 757 }
758 758
759 // Tests navigating to a new URL when there is a pending back/forward 759 // Tests navigating to a new URL when there is a pending back/forward
760 // navigation to a cross-process, privileged URL. This will happen if the user 760 // navigation to a cross-process, privileged URL. This will happen if the user
761 // hits back, but before that commits, they navigate somewhere new. 761 // hits back, but before that commits, they navigate somewhere new.
762 TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) { 762 TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) {
763 NavigationControllerImpl& controller = controller_impl(); 763 NavigationControllerImpl& controller = controller_impl();
764 TestNotificationTracker notifications; 764 TestNotificationTracker notifications;
765 RegisterForAllNavNotifications(&notifications, &controller); 765 RegisterForAllNavNotifications(&notifications, &controller);
766 766
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 const GURL kNewURL("http://foo/bee"); 799 const GURL kNewURL("http://foo/bee");
800 LoadCommittedDetails details; 800 LoadCommittedDetails details;
801 foo_rvh->SendNavigate(3, kNewURL); 801 foo_rvh->SendNavigate(3, kNewURL);
802 802
803 // There should no longer be any pending entry, and the third navigation we 803 // There should no longer be any pending entry, and the third navigation we
804 // just made should be committed. 804 // just made should be committed.
805 EXPECT_EQ(1U, navigation_entry_committed_counter_); 805 EXPECT_EQ(1U, navigation_entry_committed_counter_);
806 navigation_entry_committed_counter_ = 0; 806 navigation_entry_committed_counter_ = 0;
807 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 807 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
808 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); 808 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex());
809 EXPECT_EQ(kNewURL, controller.GetActiveEntry()->GetURL()); 809 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL());
810 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry( 810 EXPECT_EQ(0, NavigationEntryImpl::FromNavigationEntry(
811 controller.GetLastCommittedEntry())->bindings()); 811 controller.GetLastCommittedEntry())->bindings());
812 } 812 }
813 813
814 // Tests navigating to an existing URL when there is a pending new navigation. 814 // Tests navigating to an existing URL when there is a pending new navigation.
815 // This will happen if the user enters a URL, but before that commits, the 815 // This will happen if the user enters a URL, but before that commits, the
816 // current page fires history.back(). 816 // current page fires history.back().
817 TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { 817 TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) {
818 NavigationControllerImpl& controller = controller_impl(); 818 NavigationControllerImpl& controller = controller_impl();
819 TestNotificationTracker notifications; 819 TestNotificationTracker notifications;
(...skipping 24 matching lines...) Expand all
844 844
845 // Before that commits, a back navigation from the renderer commits. 845 // Before that commits, a back navigation from the renderer commits.
846 test_rvh()->SendNavigate(0, kExistingURL1); 846 test_rvh()->SendNavigate(0, kExistingURL1);
847 847
848 // There should no longer be any pending entry, and the back navigation we 848 // There should no longer be any pending entry, and the back navigation we
849 // just made should be committed. 849 // just made should be committed.
850 EXPECT_EQ(1U, navigation_entry_committed_counter_); 850 EXPECT_EQ(1U, navigation_entry_committed_counter_);
851 navigation_entry_committed_counter_ = 0; 851 navigation_entry_committed_counter_ = 0;
852 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 852 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
853 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 853 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
854 EXPECT_EQ(kExistingURL1, controller.GetActiveEntry()->GetURL()); 854 EXPECT_EQ(kExistingURL1, controller.GetVisibleEntry()->GetURL());
855 } 855 }
856 856
857 // Tests an ignored navigation when there is a pending new navigation. 857 // Tests an ignored navigation when there is a pending new navigation.
858 // This will happen if the user enters a URL, but before that commits, the 858 // This will happen if the user enters a URL, but before that commits, the
859 // current blank page reloads. See http://crbug.com/77507. 859 // current blank page reloads. See http://crbug.com/77507.
860 TEST_F(NavigationControllerTest, LoadURL_IgnorePreemptsPending) { 860 TEST_F(NavigationControllerTest, LoadURL_IgnorePreemptsPending) {
861 NavigationControllerImpl& controller = controller_impl(); 861 NavigationControllerImpl& controller = controller_impl();
862 TestNotificationTracker notifications; 862 TestNotificationTracker notifications;
863 RegisterForAllNavNotifications(&notifications, &controller); 863 RegisterForAllNavNotifications(&notifications, &controller);
864 864
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 TestNotificationTracker notifications; 1082 TestNotificationTracker notifications;
1083 RegisterForAllNavNotifications(&notifications, &controller); 1083 RegisterForAllNavNotifications(&notifications, &controller);
1084 1084
1085 const GURL url1("http://foo1"); 1085 const GURL url1("http://foo1");
1086 1086
1087 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 1087 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string());
1088 EXPECT_EQ(0U, notifications.size()); 1088 EXPECT_EQ(0U, notifications.size());
1089 test_rvh()->SendNavigate(0, url1); 1089 test_rvh()->SendNavigate(0, url1);
1090 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1090 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1091 navigation_entry_committed_counter_ = 0; 1091 navigation_entry_committed_counter_ = 0;
1092 ASSERT_TRUE(controller.GetActiveEntry()); 1092 ASSERT_TRUE(controller.GetVisibleEntry());
1093 controller.GetActiveEntry()->SetTitle(ASCIIToUTF16("Title")); 1093 controller.GetVisibleEntry()->SetTitle(ASCIIToUTF16("Title"));
1094 controller.Reload(true); 1094 controller.Reload(true);
1095 EXPECT_EQ(0U, notifications.size()); 1095 EXPECT_EQ(0U, notifications.size());
1096 1096
1097 const base::Time timestamp = controller.GetActiveEntry()->GetTimestamp(); 1097 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp();
1098 EXPECT_FALSE(timestamp.is_null()); 1098 EXPECT_FALSE(timestamp.is_null());
1099 1099
1100 // The reload is pending. 1100 // The reload is pending.
1101 EXPECT_EQ(controller.GetEntryCount(), 1); 1101 EXPECT_EQ(controller.GetEntryCount(), 1);
1102 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1102 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1103 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); 1103 EXPECT_EQ(controller.GetPendingEntryIndex(), 0);
1104 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1104 EXPECT_TRUE(controller.GetLastCommittedEntry());
1105 EXPECT_TRUE(controller.GetPendingEntry()); 1105 EXPECT_TRUE(controller.GetPendingEntry());
1106 EXPECT_FALSE(controller.CanGoBack()); 1106 EXPECT_FALSE(controller.CanGoBack());
1107 EXPECT_FALSE(controller.CanGoForward()); 1107 EXPECT_FALSE(controller.CanGoForward());
1108 // Make sure the title has been cleared (will be redrawn just after reload). 1108 // Make sure the title has been cleared (will be redrawn just after reload).
1109 // Avoids a stale cached title when the new page being reloaded has no title. 1109 // Avoids a stale cached title when the new page being reloaded has no title.
1110 // See http://crbug.com/96041. 1110 // See http://crbug.com/96041.
1111 EXPECT_TRUE(controller.GetActiveEntry()->GetTitle().empty()); 1111 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty());
1112 1112
1113 test_rvh()->SendNavigate(0, url1); 1113 test_rvh()->SendNavigate(0, url1);
1114 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1114 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1115 navigation_entry_committed_counter_ = 0; 1115 navigation_entry_committed_counter_ = 0;
1116 1116
1117 // Now the reload is committed. 1117 // Now the reload is committed.
1118 EXPECT_EQ(controller.GetEntryCount(), 1); 1118 EXPECT_EQ(controller.GetEntryCount(), 1);
1119 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1119 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1120 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1120 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1121 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1121 EXPECT_TRUE(controller.GetLastCommittedEntry());
1122 EXPECT_FALSE(controller.GetPendingEntry()); 1122 EXPECT_FALSE(controller.GetPendingEntry());
1123 EXPECT_FALSE(controller.CanGoBack()); 1123 EXPECT_FALSE(controller.CanGoBack());
1124 EXPECT_FALSE(controller.CanGoForward()); 1124 EXPECT_FALSE(controller.CanGoForward());
1125 1125
1126 // The timestamp should have been updated. 1126 // The timestamp should have been updated.
1127 ASSERT_TRUE(controller.GetActiveEntry()); 1127 ASSERT_TRUE(controller.GetVisibleEntry());
1128 EXPECT_GE(controller.GetActiveEntry()->GetTimestamp(), timestamp); 1128 EXPECT_GE(controller.GetVisibleEntry()->GetTimestamp(), timestamp);
1129 } 1129 }
1130 1130
1131 // Tests what happens when a reload navigation produces a new page. 1131 // Tests what happens when a reload navigation produces a new page.
1132 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { 1132 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) {
1133 NavigationControllerImpl& controller = controller_impl(); 1133 NavigationControllerImpl& controller = controller_impl();
1134 TestNotificationTracker notifications; 1134 TestNotificationTracker notifications;
1135 RegisterForAllNavNotifications(&notifications, &controller); 1135 RegisterForAllNavNotifications(&notifications, &controller);
1136 1136
1137 const GURL url1("http://foo1"); 1137 const GURL url1("http://foo1");
1138 const GURL url2("http://foo2"); 1138 const GURL url2("http://foo2");
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 // Load up the original URL, but get redirected. 1191 // Load up the original URL, but get redirected.
1192 controller.LoadURL( 1192 controller.LoadURL(
1193 original_url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 1193 original_url, Referrer(), PAGE_TRANSITION_TYPED, std::string());
1194 EXPECT_EQ(0U, notifications.size()); 1194 EXPECT_EQ(0U, notifications.size());
1195 test_rvh()->SendNavigateWithOriginalRequestURL(0, final_url, original_url); 1195 test_rvh()->SendNavigateWithOriginalRequestURL(0, final_url, original_url);
1196 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1196 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1197 navigation_entry_committed_counter_ = 0; 1197 navigation_entry_committed_counter_ = 0;
1198 1198
1199 // The NavigationEntry should save both the original URL and the final 1199 // The NavigationEntry should save both the original URL and the final
1200 // redirected URL. 1200 // redirected URL.
1201 EXPECT_EQ(original_url, controller.GetActiveEntry()->GetOriginalRequestURL()); 1201 EXPECT_EQ(
1202 EXPECT_EQ(final_url, controller.GetActiveEntry()->GetURL()); 1202 original_url, controller.GetVisibleEntry()->GetOriginalRequestURL());
1203 EXPECT_EQ(final_url, controller.GetVisibleEntry()->GetURL());
1203 1204
1204 // Reload using the original URL. 1205 // Reload using the original URL.
1205 controller.GetActiveEntry()->SetTitle(ASCIIToUTF16("Title")); 1206 controller.GetVisibleEntry()->SetTitle(ASCIIToUTF16("Title"));
1206 controller.ReloadOriginalRequestURL(false); 1207 controller.ReloadOriginalRequestURL(false);
1207 EXPECT_EQ(0U, notifications.size()); 1208 EXPECT_EQ(0U, notifications.size());
1208 1209
1209 // The reload is pending. The request should point to the original URL. 1210 // The reload is pending. The request should point to the original URL.
1210 EXPECT_EQ(original_url, observer.navigated_url()); 1211 EXPECT_EQ(original_url, observer.navigated_url());
1211 EXPECT_EQ(controller.GetEntryCount(), 1); 1212 EXPECT_EQ(controller.GetEntryCount(), 1);
1212 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1213 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1213 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); 1214 EXPECT_EQ(controller.GetPendingEntryIndex(), 0);
1214 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1215 EXPECT_TRUE(controller.GetLastCommittedEntry());
1215 EXPECT_TRUE(controller.GetPendingEntry()); 1216 EXPECT_TRUE(controller.GetPendingEntry());
1216 EXPECT_FALSE(controller.CanGoBack()); 1217 EXPECT_FALSE(controller.CanGoBack());
1217 EXPECT_FALSE(controller.CanGoForward()); 1218 EXPECT_FALSE(controller.CanGoForward());
1218 1219
1219 // Make sure the title has been cleared (will be redrawn just after reload). 1220 // Make sure the title has been cleared (will be redrawn just after reload).
1220 // Avoids a stale cached title when the new page being reloaded has no title. 1221 // Avoids a stale cached title when the new page being reloaded has no title.
1221 // See http://crbug.com/96041. 1222 // See http://crbug.com/96041.
1222 EXPECT_TRUE(controller.GetActiveEntry()->GetTitle().empty()); 1223 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty());
1223 1224
1224 // Send that the navigation has proceeded; say it got redirected again. 1225 // Send that the navigation has proceeded; say it got redirected again.
1225 test_rvh()->SendNavigate(0, final_url); 1226 test_rvh()->SendNavigate(0, final_url);
1226 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1227 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1227 navigation_entry_committed_counter_ = 0; 1228 navigation_entry_committed_counter_ = 0;
1228 1229
1229 // Now the reload is committed. 1230 // Now the reload is committed.
1230 EXPECT_EQ(controller.GetEntryCount(), 1); 1231 EXPECT_EQ(controller.GetEntryCount(), 1);
1231 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1232 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1232 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1233 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1553 EXPECT_EQ(0U, notifications.size()); 1554 EXPECT_EQ(0U, notifications.size());
1554 test_rvh()->SendNavigate(0, url2); 1555 test_rvh()->SendNavigate(0, url2);
1555 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1556 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1556 navigation_entry_committed_counter_ = 0; 1557 navigation_entry_committed_counter_ = 0;
1557 1558
1558 // Second request 1559 // Second request
1559 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 1560 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string());
1560 1561
1561 EXPECT_TRUE(controller.GetPendingEntry()); 1562 EXPECT_TRUE(controller.GetPendingEntry());
1562 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1563 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1563 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); 1564 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
1564 1565
1565 ViewHostMsg_FrameNavigate_Params params; 1566 ViewHostMsg_FrameNavigate_Params params;
1566 params.page_id = 0; 1567 params.page_id = 0;
1567 params.url = url2; 1568 params.url = url2;
1568 params.transition = PAGE_TRANSITION_SERVER_REDIRECT; 1569 params.transition = PAGE_TRANSITION_SERVER_REDIRECT;
1569 params.redirects.push_back(GURL("http://foo1")); 1570 params.redirects.push_back(GURL("http://foo1"));
1570 params.redirects.push_back(GURL("http://foo2")); 1571 params.redirects.push_back(GURL("http://foo2"));
1571 params.should_update_history = false; 1572 params.should_update_history = false;
1572 params.gesture = NavigationGestureAuto; 1573 params.gesture = NavigationGestureAuto;
1573 params.is_post = false; 1574 params.is_post = false;
1574 params.page_state = PageState::CreateFromURL(url2); 1575 params.page_state = PageState::CreateFromURL(url2);
1575 1576
1576 LoadCommittedDetails details; 1577 LoadCommittedDetails details;
1577 1578
1578 EXPECT_EQ(0U, notifications.size()); 1579 EXPECT_EQ(0U, notifications.size());
1579 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); 1580 EXPECT_TRUE(controller.RendererDidNavigate(params, &details));
1580 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1581 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1581 navigation_entry_committed_counter_ = 0; 1582 navigation_entry_committed_counter_ = 0;
1582 1583
1583 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); 1584 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE);
1584 EXPECT_EQ(controller.GetEntryCount(), 1); 1585 EXPECT_EQ(controller.GetEntryCount(), 1);
1585 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1586 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1586 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1587 EXPECT_TRUE(controller.GetLastCommittedEntry());
1587 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1588 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1588 EXPECT_FALSE(controller.GetPendingEntry()); 1589 EXPECT_FALSE(controller.GetPendingEntry());
1589 EXPECT_EQ(url2, controller.GetActiveEntry()->GetURL()); 1590 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
1590 1591
1591 EXPECT_FALSE(controller.CanGoBack()); 1592 EXPECT_FALSE(controller.CanGoBack());
1592 EXPECT_FALSE(controller.CanGoForward()); 1593 EXPECT_FALSE(controller.CanGoForward());
1593 } 1594 }
1594 1595
1595 // Similar to Redirect above, but the first URL is requested by POST, 1596 // Similar to Redirect above, but the first URL is requested by POST,
1596 // the second URL is requested by GET. NavigationEntry::has_post_data_ 1597 // the second URL is requested by GET. NavigationEntry::has_post_data_
1597 // must be cleared. http://crbug.com/21245 1598 // must be cleared. http://crbug.com/21245
1598 TEST_F(NavigationControllerTest, PostThenRedirect) { 1599 TEST_F(NavigationControllerTest, PostThenRedirect) {
1599 NavigationControllerImpl& controller = controller_impl(); 1600 NavigationControllerImpl& controller = controller_impl();
1600 TestNotificationTracker notifications; 1601 TestNotificationTracker notifications;
1601 RegisterForAllNavNotifications(&notifications, &controller); 1602 RegisterForAllNavNotifications(&notifications, &controller);
1602 1603
1603 const GURL url1("http://foo1"); 1604 const GURL url1("http://foo1");
1604 const GURL url2("http://foo2"); // Redirection target 1605 const GURL url2("http://foo2"); // Redirection target
1605 1606
1606 // First request as POST 1607 // First request as POST
1607 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 1608 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string());
1608 controller.GetActiveEntry()->SetHasPostData(true); 1609 controller.GetVisibleEntry()->SetHasPostData(true);
1609 1610
1610 EXPECT_EQ(0U, notifications.size()); 1611 EXPECT_EQ(0U, notifications.size());
1611 test_rvh()->SendNavigate(0, url2); 1612 test_rvh()->SendNavigate(0, url2);
1612 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1613 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1613 navigation_entry_committed_counter_ = 0; 1614 navigation_entry_committed_counter_ = 0;
1614 1615
1615 // Second request 1616 // Second request
1616 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 1617 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string());
1617 1618
1618 EXPECT_TRUE(controller.GetPendingEntry()); 1619 EXPECT_TRUE(controller.GetPendingEntry());
1619 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1620 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1620 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); 1621 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
1621 1622
1622 ViewHostMsg_FrameNavigate_Params params; 1623 ViewHostMsg_FrameNavigate_Params params;
1623 params.page_id = 0; 1624 params.page_id = 0;
1624 params.url = url2; 1625 params.url = url2;
1625 params.transition = PAGE_TRANSITION_SERVER_REDIRECT; 1626 params.transition = PAGE_TRANSITION_SERVER_REDIRECT;
1626 params.redirects.push_back(GURL("http://foo1")); 1627 params.redirects.push_back(GURL("http://foo1"));
1627 params.redirects.push_back(GURL("http://foo2")); 1628 params.redirects.push_back(GURL("http://foo2"));
1628 params.should_update_history = false; 1629 params.should_update_history = false;
1629 params.gesture = NavigationGestureAuto; 1630 params.gesture = NavigationGestureAuto;
1630 params.is_post = false; 1631 params.is_post = false;
1631 params.page_state = PageState::CreateFromURL(url2); 1632 params.page_state = PageState::CreateFromURL(url2);
1632 1633
1633 LoadCommittedDetails details; 1634 LoadCommittedDetails details;
1634 1635
1635 EXPECT_EQ(0U, notifications.size()); 1636 EXPECT_EQ(0U, notifications.size());
1636 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); 1637 EXPECT_TRUE(controller.RendererDidNavigate(params, &details));
1637 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1638 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1638 navigation_entry_committed_counter_ = 0; 1639 navigation_entry_committed_counter_ = 0;
1639 1640
1640 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); 1641 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE);
1641 EXPECT_EQ(controller.GetEntryCount(), 1); 1642 EXPECT_EQ(controller.GetEntryCount(), 1);
1642 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1643 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1643 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1644 EXPECT_TRUE(controller.GetLastCommittedEntry());
1644 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1645 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1645 EXPECT_FALSE(controller.GetPendingEntry()); 1646 EXPECT_FALSE(controller.GetPendingEntry());
1646 EXPECT_EQ(url2, controller.GetActiveEntry()->GetURL()); 1647 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
1647 EXPECT_FALSE(controller.GetActiveEntry()->GetHasPostData()); 1648 EXPECT_FALSE(controller.GetVisibleEntry()->GetHasPostData());
1648 1649
1649 EXPECT_FALSE(controller.CanGoBack()); 1650 EXPECT_FALSE(controller.CanGoBack());
1650 EXPECT_FALSE(controller.CanGoForward()); 1651 EXPECT_FALSE(controller.CanGoForward());
1651 } 1652 }
1652 1653
1653 // A redirect right off the bat should be a NEW_PAGE. 1654 // A redirect right off the bat should be a NEW_PAGE.
1654 TEST_F(NavigationControllerTest, ImmediateRedirect) { 1655 TEST_F(NavigationControllerTest, ImmediateRedirect) {
1655 NavigationControllerImpl& controller = controller_impl(); 1656 NavigationControllerImpl& controller = controller_impl();
1656 TestNotificationTracker notifications; 1657 TestNotificationTracker notifications;
1657 RegisterForAllNavNotifications(&notifications, &controller); 1658 RegisterForAllNavNotifications(&notifications, &controller);
1658 1659
1659 const GURL url1("http://foo1"); 1660 const GURL url1("http://foo1");
1660 const GURL url2("http://foo2"); // Redirection target 1661 const GURL url2("http://foo2"); // Redirection target
1661 1662
1662 // First request 1663 // First request
1663 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 1664 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string());
1664 1665
1665 EXPECT_TRUE(controller.GetPendingEntry()); 1666 EXPECT_TRUE(controller.GetPendingEntry());
1666 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1667 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1667 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); 1668 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
1668 1669
1669 ViewHostMsg_FrameNavigate_Params params; 1670 ViewHostMsg_FrameNavigate_Params params;
1670 params.page_id = 0; 1671 params.page_id = 0;
1671 params.url = url2; 1672 params.url = url2;
1672 params.transition = PAGE_TRANSITION_SERVER_REDIRECT; 1673 params.transition = PAGE_TRANSITION_SERVER_REDIRECT;
1673 params.redirects.push_back(GURL("http://foo1")); 1674 params.redirects.push_back(GURL("http://foo1"));
1674 params.redirects.push_back(GURL("http://foo2")); 1675 params.redirects.push_back(GURL("http://foo2"));
1675 params.should_update_history = false; 1676 params.should_update_history = false;
1676 params.gesture = NavigationGestureAuto; 1677 params.gesture = NavigationGestureAuto;
1677 params.is_post = false; 1678 params.is_post = false;
1678 params.page_state = PageState::CreateFromURL(url2); 1679 params.page_state = PageState::CreateFromURL(url2);
1679 1680
1680 LoadCommittedDetails details; 1681 LoadCommittedDetails details;
1681 1682
1682 EXPECT_EQ(0U, notifications.size()); 1683 EXPECT_EQ(0U, notifications.size());
1683 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); 1684 EXPECT_TRUE(controller.RendererDidNavigate(params, &details));
1684 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1685 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1685 navigation_entry_committed_counter_ = 0; 1686 navigation_entry_committed_counter_ = 0;
1686 1687
1687 EXPECT_TRUE(details.type == NAVIGATION_TYPE_NEW_PAGE); 1688 EXPECT_TRUE(details.type == NAVIGATION_TYPE_NEW_PAGE);
1688 EXPECT_EQ(controller.GetEntryCount(), 1); 1689 EXPECT_EQ(controller.GetEntryCount(), 1);
1689 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1690 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1690 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1691 EXPECT_TRUE(controller.GetLastCommittedEntry());
1691 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1692 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1692 EXPECT_FALSE(controller.GetPendingEntry()); 1693 EXPECT_FALSE(controller.GetPendingEntry());
1693 EXPECT_EQ(url2, controller.GetActiveEntry()->GetURL()); 1694 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
1694 1695
1695 EXPECT_FALSE(controller.CanGoBack()); 1696 EXPECT_FALSE(controller.CanGoBack());
1696 EXPECT_FALSE(controller.CanGoForward()); 1697 EXPECT_FALSE(controller.CanGoForward());
1697 } 1698 }
1698 1699
1699 // Tests navigation via link click within a subframe. A new navigation entry 1700 // Tests navigation via link click within a subframe. A new navigation entry
1700 // should be created. 1701 // should be created.
1701 TEST_F(NavigationControllerTest, NewSubframe) { 1702 TEST_F(NavigationControllerTest, NewSubframe) {
1702 NavigationControllerImpl& controller = controller_impl(); 1703 NavigationControllerImpl& controller = controller_impl();
1703 TestNotificationTracker notifications; 1704 TestNotificationTracker notifications;
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1936 ViewHostMsg_FrameNavigate_Params back_params(params); 1937 ViewHostMsg_FrameNavigate_Params back_params(params);
1937 controller.GoBack(); 1938 controller.GoBack();
1938 back_params.url = url1; 1939 back_params.url = url1;
1939 back_params.page_id = 0; 1940 back_params.page_id = 0;
1940 EXPECT_TRUE(controller.RendererDidNavigate(back_params, &details)); 1941 EXPECT_TRUE(controller.RendererDidNavigate(back_params, &details));
1941 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1942 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1942 navigation_entry_committed_counter_ = 0; 1943 navigation_entry_committed_counter_ = 0;
1943 EXPECT_TRUE(details.is_in_page); 1944 EXPECT_TRUE(details.is_in_page);
1944 EXPECT_EQ(2, controller.GetEntryCount()); 1945 EXPECT_EQ(2, controller.GetEntryCount());
1945 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 1946 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
1946 EXPECT_EQ(back_params.url, controller.GetActiveEntry()->GetURL()); 1947 EXPECT_EQ(back_params.url, controller.GetVisibleEntry()->GetURL());
1947 1948
1948 // Go forward 1949 // Go forward
1949 ViewHostMsg_FrameNavigate_Params forward_params(params); 1950 ViewHostMsg_FrameNavigate_Params forward_params(params);
1950 controller.GoForward(); 1951 controller.GoForward();
1951 forward_params.url = url2; 1952 forward_params.url = url2;
1952 forward_params.page_id = 1; 1953 forward_params.page_id = 1;
1953 EXPECT_TRUE(controller.RendererDidNavigate(forward_params, &details)); 1954 EXPECT_TRUE(controller.RendererDidNavigate(forward_params, &details));
1954 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1955 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1955 navigation_entry_committed_counter_ = 0; 1956 navigation_entry_committed_counter_ = 0;
1956 EXPECT_TRUE(details.is_in_page); 1957 EXPECT_TRUE(details.is_in_page);
1957 EXPECT_EQ(2, controller.GetEntryCount()); 1958 EXPECT_EQ(2, controller.GetEntryCount());
1958 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); 1959 EXPECT_EQ(1, controller.GetCurrentEntryIndex());
1959 EXPECT_EQ(forward_params.url, 1960 EXPECT_EQ(forward_params.url,
1960 controller.GetActiveEntry()->GetURL()); 1961 controller.GetVisibleEntry()->GetURL());
1961 1962
1962 // Now go back and forward again. This is to work around a bug where we would 1963 // Now go back and forward again. This is to work around a bug where we would
1963 // compare the incoming URL with the last committed entry rather than the 1964 // compare the incoming URL with the last committed entry rather than the
1964 // one identified by an existing page ID. This would result in the second URL 1965 // one identified by an existing page ID. This would result in the second URL
1965 // losing the reference fragment when you navigate away from it and then back. 1966 // losing the reference fragment when you navigate away from it and then back.
1966 controller.GoBack(); 1967 controller.GoBack();
1967 EXPECT_TRUE(controller.RendererDidNavigate(back_params, &details)); 1968 EXPECT_TRUE(controller.RendererDidNavigate(back_params, &details));
1968 controller.GoForward(); 1969 controller.GoForward();
1969 EXPECT_TRUE(controller.RendererDidNavigate(forward_params, &details)); 1970 EXPECT_TRUE(controller.RendererDidNavigate(forward_params, &details));
1970 EXPECT_EQ(forward_params.url, 1971 EXPECT_EQ(forward_params.url,
1971 controller.GetActiveEntry()->GetURL()); 1972 controller.GetVisibleEntry()->GetURL());
1972 1973
1973 // Finally, navigate to an unrelated URL to make sure in_page is not sticky. 1974 // Finally, navigate to an unrelated URL to make sure in_page is not sticky.
1974 const GURL url3("http://bar"); 1975 const GURL url3("http://bar");
1975 params.page_id = 2; 1976 params.page_id = 2;
1976 params.url = url3; 1977 params.url = url3;
1977 navigation_entry_committed_counter_ = 0; 1978 navigation_entry_committed_counter_ = 0;
1978 EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); 1979 EXPECT_TRUE(controller.RendererDidNavigate(params, &details));
1979 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1980 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1980 navigation_entry_committed_counter_ = 0; 1981 navigation_entry_committed_counter_ = 0;
1981 EXPECT_FALSE(details.is_in_page); 1982 EXPECT_FALSE(details.is_in_page);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
2088 EXPECT_EQ(3, controller.GetEntryCount()); 2089 EXPECT_EQ(3, controller.GetEntryCount());
2089 } 2090 }
2090 2091
2091 // Verify that BACK brings us back to http://foo2/. 2092 // Verify that BACK brings us back to http://foo2/.
2092 { 2093 {
2093 const GURL url("http://foo2/"); 2094 const GURL url("http://foo2/");
2094 controller.GoBack(); 2095 controller.GoBack();
2095 test_rvh()->SendNavigate(1, url); 2096 test_rvh()->SendNavigate(1, url);
2096 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2097 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2097 navigation_entry_committed_counter_ = 0; 2098 navigation_entry_committed_counter_ = 0;
2098 EXPECT_EQ(url, controller.GetActiveEntry()->GetURL()); 2099 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL());
2099 } 2100 }
2100 } 2101 }
2101 2102
2102 // NotificationObserver implementation used in verifying we've received the 2103 // NotificationObserver implementation used in verifying we've received the
2103 // NOTIFICATION_NAV_LIST_PRUNED method. 2104 // NOTIFICATION_NAV_LIST_PRUNED method.
2104 class PrunedListener : public NotificationObserver { 2105 class PrunedListener : public NotificationObserver {
2105 public: 2106 public:
2106 explicit PrunedListener(NavigationControllerImpl* controller) 2107 explicit PrunedListener(NavigationControllerImpl* controller)
2107 : notification_count_(0) { 2108 : notification_count_(0) {
2108 registrar_.Add(this, NOTIFICATION_NAV_LIST_PRUNED, 2109 registrar_.Add(this, NOTIFICATION_NAV_LIST_PRUNED,
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
2455 2456
2456 // Adding a transient with no pending entry. 2457 // Adding a transient with no pending entry.
2457 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; 2458 NavigationEntryImpl* transient_entry = new NavigationEntryImpl;
2458 transient_entry->SetURL(transient_url); 2459 transient_entry->SetURL(transient_url);
2459 controller.SetTransientEntry(transient_entry); 2460 controller.SetTransientEntry(transient_entry);
2460 2461
2461 // We should not have received any notifications. 2462 // We should not have received any notifications.
2462 EXPECT_EQ(0U, notifications.size()); 2463 EXPECT_EQ(0U, notifications.size());
2463 2464
2464 // Check our state. 2465 // Check our state.
2465 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); 2466 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
2466 EXPECT_EQ(controller.GetEntryCount(), 3); 2467 EXPECT_EQ(controller.GetEntryCount(), 3);
2467 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); 2468 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1);
2468 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 2469 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
2469 EXPECT_TRUE(controller.GetLastCommittedEntry()); 2470 EXPECT_TRUE(controller.GetLastCommittedEntry());
2470 EXPECT_FALSE(controller.GetPendingEntry()); 2471 EXPECT_FALSE(controller.GetPendingEntry());
2471 EXPECT_TRUE(controller.CanGoBack()); 2472 EXPECT_TRUE(controller.CanGoBack());
2472 EXPECT_FALSE(controller.CanGoForward()); 2473 EXPECT_FALSE(controller.CanGoForward());
2473 EXPECT_EQ(contents()->GetMaxPageID(), 1); 2474 EXPECT_EQ(contents()->GetMaxPageID(), 1);
2474 2475
2475 // Navigate. 2476 // Navigate.
2476 controller.LoadURL( 2477 controller.LoadURL(
2477 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 2478 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string());
2478 test_rvh()->SendNavigate(2, url2); 2479 test_rvh()->SendNavigate(2, url2);
2479 2480
2480 // We should have navigated, transient entry should be gone. 2481 // We should have navigated, transient entry should be gone.
2481 EXPECT_EQ(url2, controller.GetActiveEntry()->GetURL()); 2482 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
2482 EXPECT_EQ(controller.GetEntryCount(), 3); 2483 EXPECT_EQ(controller.GetEntryCount(), 3);
2483 2484
2484 // Add a transient again, then navigate with no pending entry this time. 2485 // Add a transient again, then navigate with no pending entry this time.
2485 transient_entry = new NavigationEntryImpl; 2486 transient_entry = new NavigationEntryImpl;
2486 transient_entry->SetURL(transient_url); 2487 transient_entry->SetURL(transient_url);
2487 controller.SetTransientEntry(transient_entry); 2488 controller.SetTransientEntry(transient_entry);
2488 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); 2489 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
2489 test_rvh()->SendNavigate(3, url3); 2490 test_rvh()->SendNavigate(3, url3);
2490 // Transient entry should be gone. 2491 // Transient entry should be gone.
2491 EXPECT_EQ(url3, controller.GetActiveEntry()->GetURL()); 2492 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL());
2492 EXPECT_EQ(controller.GetEntryCount(), 4); 2493 EXPECT_EQ(controller.GetEntryCount(), 4);
2493 2494
2494 // Initiate a navigation, add a transient then commit navigation. 2495 // Initiate a navigation, add a transient then commit navigation.
2495 controller.LoadURL( 2496 controller.LoadURL(
2496 url4, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 2497 url4, Referrer(), PAGE_TRANSITION_TYPED, std::string());
2497 transient_entry = new NavigationEntryImpl; 2498 transient_entry = new NavigationEntryImpl;
2498 transient_entry->SetURL(transient_url); 2499 transient_entry->SetURL(transient_url);
2499 controller.SetTransientEntry(transient_entry); 2500 controller.SetTransientEntry(transient_entry);
2500 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); 2501 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
2501 test_rvh()->SendNavigate(4, url4); 2502 test_rvh()->SendNavigate(4, url4);
2502 EXPECT_EQ(url4, controller.GetActiveEntry()->GetURL()); 2503 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL());
2503 EXPECT_EQ(controller.GetEntryCount(), 5); 2504 EXPECT_EQ(controller.GetEntryCount(), 5);
2504 2505
2505 // Add a transient and go back. This should simply remove the transient. 2506 // Add a transient and go back. This should simply remove the transient.
2506 transient_entry = new NavigationEntryImpl; 2507 transient_entry = new NavigationEntryImpl;
2507 transient_entry->SetURL(transient_url); 2508 transient_entry->SetURL(transient_url);
2508 controller.SetTransientEntry(transient_entry); 2509 controller.SetTransientEntry(transient_entry);
2509 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); 2510 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
2510 EXPECT_TRUE(controller.CanGoBack()); 2511 EXPECT_TRUE(controller.CanGoBack());
2511 EXPECT_FALSE(controller.CanGoForward()); 2512 EXPECT_FALSE(controller.CanGoForward());
2512 controller.GoBack(); 2513 controller.GoBack();
2513 // Transient entry should be gone. 2514 // Transient entry should be gone.
2514 EXPECT_EQ(url4, controller.GetActiveEntry()->GetURL()); 2515 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL());
2515 EXPECT_EQ(controller.GetEntryCount(), 5); 2516 EXPECT_EQ(controller.GetEntryCount(), 5);
2516 test_rvh()->SendNavigate(3, url3); 2517 test_rvh()->SendNavigate(3, url3);
2517 2518
2518 // Add a transient and go to an entry before the current one. 2519 // Add a transient and go to an entry before the current one.
2519 transient_entry = new NavigationEntryImpl; 2520 transient_entry = new NavigationEntryImpl;
2520 transient_entry->SetURL(transient_url); 2521 transient_entry->SetURL(transient_url);
2521 controller.SetTransientEntry(transient_entry); 2522 controller.SetTransientEntry(transient_entry);
2522 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); 2523 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
2523 controller.GoToIndex(1); 2524 controller.GoToIndex(1);
2524 // The navigation should have been initiated, transient entry should be gone. 2525 // The navigation should have been initiated, transient entry should be gone.
2525 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); 2526 EXPECT_FALSE(controller.GetTransientEntry());
2527 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL());
2526 // Visible entry does not update for history navigations until commit. 2528 // Visible entry does not update for history navigations until commit.
2527 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); 2529 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL());
2528 test_rvh()->SendNavigate(1, url1); 2530 test_rvh()->SendNavigate(1, url1);
2529 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); 2531 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
2530 2532
2531 // Add a transient and go to an entry after the current one. 2533 // Add a transient and go to an entry after the current one.
2532 transient_entry = new NavigationEntryImpl; 2534 transient_entry = new NavigationEntryImpl;
2533 transient_entry->SetURL(transient_url); 2535 transient_entry->SetURL(transient_url);
2534 controller.SetTransientEntry(transient_entry); 2536 controller.SetTransientEntry(transient_entry);
2535 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); 2537 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
2536 controller.GoToIndex(3); 2538 controller.GoToIndex(3);
2537 // The navigation should have been initiated, transient entry should be gone. 2539 // The navigation should have been initiated, transient entry should be gone.
2538 // Because of the transient entry that is removed, going to index 3 makes us 2540 // Because of the transient entry that is removed, going to index 3 makes us
2539 // land on url2 (which is visible after the commit). 2541 // land on url2 (which is visible after the commit).
2540 EXPECT_EQ(url2, controller.GetActiveEntry()->GetURL()); 2542 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL());
2541 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); 2543 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
2542 test_rvh()->SendNavigate(2, url2); 2544 test_rvh()->SendNavigate(2, url2);
2543 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); 2545 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
2544 2546
2545 // Add a transient and go forward. 2547 // Add a transient and go forward.
2546 transient_entry = new NavigationEntryImpl; 2548 transient_entry = new NavigationEntryImpl;
2547 transient_entry->SetURL(transient_url); 2549 transient_entry->SetURL(transient_url);
2548 controller.SetTransientEntry(transient_entry); 2550 controller.SetTransientEntry(transient_entry);
2549 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); 2551 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
2550 EXPECT_TRUE(controller.CanGoForward()); 2552 EXPECT_TRUE(controller.CanGoForward());
2551 controller.GoForward(); 2553 controller.GoForward();
2552 // We should have navigated, transient entry should be gone. 2554 // We should have navigated, transient entry should be gone.
2553 EXPECT_EQ(url3, controller.GetActiveEntry()->GetURL()); 2555 EXPECT_FALSE(controller.GetTransientEntry());
2556 EXPECT_EQ(url3, controller.GetPendingEntry()->GetURL());
2554 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); 2557 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
2555 test_rvh()->SendNavigate(3, url3); 2558 test_rvh()->SendNavigate(3, url3);
2556 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); 2559 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL());
2557 2560
2558 // Add a transient and do an in-page navigation, replacing the current entry. 2561 // Add a transient and do an in-page navigation, replacing the current entry.
2559 transient_entry = new NavigationEntryImpl; 2562 transient_entry = new NavigationEntryImpl;
2560 transient_entry->SetURL(transient_url); 2563 transient_entry->SetURL(transient_url);
2561 controller.SetTransientEntry(transient_entry); 2564 controller.SetTransientEntry(transient_entry);
2562 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); 2565 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
2563 test_rvh()->SendNavigate(3, url3_ref); 2566 test_rvh()->SendNavigate(3, url3_ref);
2564 // Transient entry should be gone. 2567 // Transient entry should be gone.
2565 EXPECT_EQ(url3_ref, controller.GetActiveEntry()->GetURL()); 2568 EXPECT_FALSE(controller.GetTransientEntry());
2569 EXPECT_EQ(url3_ref, controller.GetVisibleEntry()->GetURL());
2566 2570
2567 // Ensure the URLs are correct. 2571 // Ensure the URLs are correct.
2568 EXPECT_EQ(controller.GetEntryCount(), 5); 2572 EXPECT_EQ(controller.GetEntryCount(), 5);
2569 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); 2573 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0);
2570 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), url1); 2574 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), url1);
2571 EXPECT_EQ(controller.GetEntryAtIndex(2)->GetURL(), url2); 2575 EXPECT_EQ(controller.GetEntryAtIndex(2)->GetURL(), url2);
2572 EXPECT_EQ(controller.GetEntryAtIndex(3)->GetURL(), url3_ref); 2576 EXPECT_EQ(controller.GetEntryAtIndex(3)->GetURL(), url3_ref);
2573 EXPECT_EQ(controller.GetEntryAtIndex(4)->GetURL(), url4); 2577 EXPECT_EQ(controller.GetEntryAtIndex(4)->GetURL(), url4);
2574 } 2578 }
2575 2579
2576 // Test that Reload initiates a new navigation to a transient entry's URL. 2580 // Test that Reload initiates a new navigation to a transient entry's URL.
2577 TEST_F(NavigationControllerTest, ReloadTransient) { 2581 TEST_F(NavigationControllerTest, ReloadTransient) {
2578 NavigationControllerImpl& controller = controller_impl(); 2582 NavigationControllerImpl& controller = controller_impl();
2579 const GURL url0("http://foo/0"); 2583 const GURL url0("http://foo/0");
2580 const GURL url1("http://foo/1"); 2584 const GURL url1("http://foo/1");
2581 const GURL transient_url("http://foo/transient"); 2585 const GURL transient_url("http://foo/transient");
2582 2586
2583 // Load |url0|, and start a pending navigation to |url1|. 2587 // Load |url0|, and start a pending navigation to |url1|.
2584 controller.LoadURL( 2588 controller.LoadURL(
2585 url0, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 2589 url0, Referrer(), PAGE_TRANSITION_TYPED, std::string());
2586 test_rvh()->SendNavigate(0, url0); 2590 test_rvh()->SendNavigate(0, url0);
2587 controller.LoadURL( 2591 controller.LoadURL(
2588 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 2592 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string());
2589 2593
2590 // A transient entry is added, interrupting the navigation. 2594 // A transient entry is added, interrupting the navigation.
2591 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; 2595 NavigationEntryImpl* transient_entry = new NavigationEntryImpl;
2592 transient_entry->SetURL(transient_url); 2596 transient_entry->SetURL(transient_url);
2593 controller.SetTransientEntry(transient_entry); 2597 controller.SetTransientEntry(transient_entry);
2594 EXPECT_TRUE(controller.GetTransientEntry()); 2598 EXPECT_TRUE(controller.GetTransientEntry());
2595 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); 2599 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
2596 2600
2597 // The page is reloaded, which should remove the pending entry for |url1| and 2601 // The page is reloaded, which should remove the pending entry for |url1| and
2598 // the transient entry for |transient_url|, and start a navigation to 2602 // the transient entry for |transient_url|, and start a navigation to
2599 // |transient_url|. 2603 // |transient_url|.
2600 controller.Reload(true); 2604 controller.Reload(true);
2601 EXPECT_FALSE(controller.GetTransientEntry()); 2605 EXPECT_FALSE(controller.GetTransientEntry());
2602 EXPECT_TRUE(controller.GetPendingEntry()); 2606 EXPECT_TRUE(controller.GetPendingEntry());
2603 EXPECT_EQ(transient_url, controller.GetActiveEntry()->GetURL()); 2607 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
2604 ASSERT_EQ(controller.GetEntryCount(), 1); 2608 ASSERT_EQ(controller.GetEntryCount(), 1);
2605 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); 2609 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0);
2606 2610
2607 // Load of |transient_url| completes. 2611 // Load of |transient_url| completes.
2608 test_rvh()->SendNavigate(1, transient_url); 2612 test_rvh()->SendNavigate(1, transient_url);
2609 ASSERT_EQ(controller.GetEntryCount(), 2); 2613 ASSERT_EQ(controller.GetEntryCount(), 2);
2610 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); 2614 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0);
2611 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), transient_url); 2615 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), transient_url);
2612 } 2616 }
2613 2617
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2661 // the user until the navigation commits, to prevent URL spoof attacks. 2665 // the user until the navigation commits, to prevent URL spoof attacks.
2662 // See http://crbug.com/99016. 2666 // See http://crbug.com/99016.
2663 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { 2667 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) {
2664 NavigationControllerImpl& controller = controller_impl(); 2668 NavigationControllerImpl& controller = controller_impl();
2665 TestNotificationTracker notifications; 2669 TestNotificationTracker notifications;
2666 RegisterForAllNavNotifications(&notifications, &controller); 2670 RegisterForAllNavNotifications(&notifications, &controller);
2667 2671
2668 const GURL url0("http://foo/0"); 2672 const GURL url0("http://foo/0");
2669 const GURL url1("http://foo/1"); 2673 const GURL url1("http://foo/1");
2670 2674
2671 // For typed navigations (browser-initiated), both active and visible entries 2675 // For typed navigations (browser-initiated), both pending and visible entries
2672 // should update before commit. 2676 // should update before commit.
2673 controller.LoadURL(url0, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 2677 controller.LoadURL(url0, Referrer(), PAGE_TRANSITION_TYPED, std::string());
2674 EXPECT_EQ(url0, controller.GetActiveEntry()->GetURL()); 2678 EXPECT_EQ(url0, controller.GetPendingEntry()->GetURL());
2675 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); 2679 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL());
2676 test_rvh()->SendNavigate(0, url0); 2680 test_rvh()->SendNavigate(0, url0);
2677 2681
2678 // For link clicks (renderer-initiated navigations), the active entry should 2682 // For link clicks (renderer-initiated navigations), the pending entry should
2679 // update before commit but the visible should not. 2683 // update before commit but the visible should not.
2680 NavigationController::LoadURLParams load_url_params(url1); 2684 NavigationController::LoadURLParams load_url_params(url1);
2681 load_url_params.is_renderer_initiated = true; 2685 load_url_params.is_renderer_initiated = true;
2682 controller.LoadURLWithParams(load_url_params); 2686 controller.LoadURLWithParams(load_url_params);
2683 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL());
2684 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); 2687 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL());
2688 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL());
2685 EXPECT_TRUE( 2689 EXPECT_TRUE(
2686 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> 2690 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())->
2687 is_renderer_initiated()); 2691 is_renderer_initiated());
2688 2692
2689 // After commit, both should be updated, and we should no longer treat the 2693 // After commit, both visible should be updated, there should be no pending
2690 // entry as renderer-initiated. 2694 // entry, and we should no longer treat the entry as renderer-initiated.
2691 test_rvh()->SendNavigate(1, url1); 2695 test_rvh()->SendNavigate(1, url1);
2692 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL());
2693 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); 2696 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
2697 EXPECT_FALSE(controller.GetPendingEntry());
2694 EXPECT_FALSE( 2698 EXPECT_FALSE(
2695 NavigationEntryImpl::FromNavigationEntry( 2699 NavigationEntryImpl::FromNavigationEntry(
2696 controller.GetLastCommittedEntry())->is_renderer_initiated()); 2700 controller.GetLastCommittedEntry())->is_renderer_initiated());
2697 2701
2698 notifications.Reset(); 2702 notifications.Reset();
2699 } 2703 }
2700 2704
2701 // Tests that the URLs for renderer-initiated navigations in new tabs are 2705 // Tests that the URLs for renderer-initiated navigations in new tabs are
2702 // displayed to the user before commit, as long as the initial about:blank 2706 // displayed to the user before commit, as long as the initial about:blank
2703 // page has not been modified. If so, we must revert to showing about:blank. 2707 // page has not been modified. If so, we must revert to showing about:blank.
2704 // See http://crbug.com/9682. 2708 // See http://crbug.com/9682.
2705 TEST_F(NavigationControllerTest, ShowRendererURLInNewTabUntilModified) { 2709 TEST_F(NavigationControllerTest, ShowRendererURLInNewTabUntilModified) {
2706 NavigationControllerImpl& controller = controller_impl(); 2710 NavigationControllerImpl& controller = controller_impl();
2707 TestNotificationTracker notifications; 2711 TestNotificationTracker notifications;
2708 RegisterForAllNavNotifications(&notifications, &controller); 2712 RegisterForAllNavNotifications(&notifications, &controller);
2709 2713
2710 const GURL url("http://foo"); 2714 const GURL url("http://foo");
2711 2715
2712 // For renderer-initiated navigations in new tabs (with no committed entries), 2716 // For renderer-initiated navigations in new tabs (with no committed entries),
2713 // we show the pending entry's URL as long as the about:blank page is not 2717 // we show the pending entry's URL as long as the about:blank page is not
2714 // modified. 2718 // modified.
2715 NavigationController::LoadURLParams load_url_params(url); 2719 NavigationController::LoadURLParams load_url_params(url);
2716 load_url_params.transition_type = PAGE_TRANSITION_LINK; 2720 load_url_params.transition_type = PAGE_TRANSITION_LINK;
2717 load_url_params.is_renderer_initiated = true; 2721 load_url_params.is_renderer_initiated = true;
2718 controller.LoadURLWithParams(load_url_params); 2722 controller.LoadURLWithParams(load_url_params);
2719 EXPECT_EQ(url, controller.GetActiveEntry()->GetURL());
2720 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); 2723 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL());
2724 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL());
2721 EXPECT_TRUE( 2725 EXPECT_TRUE(
2722 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> 2726 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())->
2723 is_renderer_initiated()); 2727 is_renderer_initiated());
2724 EXPECT_TRUE(controller.IsInitialNavigation()); 2728 EXPECT_TRUE(controller.IsInitialNavigation());
2725 EXPECT_FALSE(test_rvh()->has_accessed_initial_document()); 2729 EXPECT_FALSE(test_rvh()->has_accessed_initial_document());
2726 2730
2727 // There should be no title yet. 2731 // There should be no title yet.
2728 EXPECT_TRUE(contents()->GetTitle().empty()); 2732 EXPECT_TRUE(contents()->GetTitle().empty());
2729 2733
2730 // If something else modifies the contents of the about:blank page, then 2734 // If something else modifies the contents of the about:blank page, then
2731 // we must revert to showing about:blank to avoid a URL spoof. 2735 // we must revert to showing about:blank to avoid a URL spoof.
2732 test_rvh()->OnMessageReceived( 2736 test_rvh()->OnMessageReceived(
2733 ViewHostMsg_DidAccessInitialDocument(0)); 2737 ViewHostMsg_DidAccessInitialDocument(0));
2734 EXPECT_TRUE(test_rvh()->has_accessed_initial_document()); 2738 EXPECT_TRUE(test_rvh()->has_accessed_initial_document());
2735 EXPECT_FALSE(controller.GetVisibleEntry()); 2739 EXPECT_FALSE(controller.GetVisibleEntry());
2736 EXPECT_EQ(url, controller.GetActiveEntry()->GetURL()); 2740 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL());
2737 2741
2738 notifications.Reset(); 2742 notifications.Reset();
2739 } 2743 }
2740 2744
2741 TEST_F(NavigationControllerTest, DontShowRendererURLInNewTabAfterCommit) { 2745 TEST_F(NavigationControllerTest, DontShowRendererURLInNewTabAfterCommit) {
2742 NavigationControllerImpl& controller = controller_impl(); 2746 NavigationControllerImpl& controller = controller_impl();
2743 TestNotificationTracker notifications; 2747 TestNotificationTracker notifications;
2744 RegisterForAllNavNotifications(&notifications, &controller); 2748 RegisterForAllNavNotifications(&notifications, &controller);
2745 2749
2746 const GURL url1("http://foo/eh"); 2750 const GURL url1("http://foo/eh");
2747 const GURL url2("http://foo/bee"); 2751 const GURL url2("http://foo/bee");
2748 2752
2749 // For renderer-initiated navigations in new tabs (with no committed entries), 2753 // For renderer-initiated navigations in new tabs (with no committed entries),
2750 // we show the pending entry's URL as long as the about:blank page is not 2754 // we show the pending entry's URL as long as the about:blank page is not
2751 // modified. 2755 // modified.
2752 NavigationController::LoadURLParams load_url_params(url1); 2756 NavigationController::LoadURLParams load_url_params(url1);
2753 load_url_params.transition_type = PAGE_TRANSITION_LINK; 2757 load_url_params.transition_type = PAGE_TRANSITION_LINK;
2754 load_url_params.is_renderer_initiated = true; 2758 load_url_params.is_renderer_initiated = true;
2755 controller.LoadURLWithParams(load_url_params); 2759 controller.LoadURLWithParams(load_url_params);
2756 EXPECT_EQ(url1, controller.GetActiveEntry()->GetURL()); 2760 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
Charlie Reis 2013/08/16 22:10:14 Redundant.
nasko 2013/09/12 17:56:31 Done.
2757 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); 2761 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
2758 EXPECT_TRUE( 2762 EXPECT_TRUE(
2759 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> 2763 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())->
2760 is_renderer_initiated()); 2764 is_renderer_initiated());
2761 EXPECT_TRUE(controller.IsInitialNavigation()); 2765 EXPECT_TRUE(controller.IsInitialNavigation());
2762 EXPECT_FALSE(test_rvh()->has_accessed_initial_document()); 2766 EXPECT_FALSE(test_rvh()->has_accessed_initial_document());
2763 2767
2764 // Simulate a commit and then starting a new pending navigation. 2768 // Simulate a commit and then starting a new pending navigation.
2765 test_rvh()->SendNavigate(0, url1); 2769 test_rvh()->SendNavigate(0, url1);
2766 NavigationController::LoadURLParams load_url2_params(url2); 2770 NavigationController::LoadURLParams load_url2_params(url2);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
2848 2852
2849 // Make sure that on cloning a WebContentsImpl and going back needs_reload is 2853 // Make sure that on cloning a WebContentsImpl and going back needs_reload is
2850 // false. 2854 // false.
2851 TEST_F(NavigationControllerTest, CloneAndGoBack) { 2855 TEST_F(NavigationControllerTest, CloneAndGoBack) {
2852 NavigationControllerImpl& controller = controller_impl(); 2856 NavigationControllerImpl& controller = controller_impl();
2853 const GURL url1("http://foo1"); 2857 const GURL url1("http://foo1");
2854 const GURL url2("http://foo2"); 2858 const GURL url2("http://foo2");
2855 const string16 title(ASCIIToUTF16("Title")); 2859 const string16 title(ASCIIToUTF16("Title"));
2856 2860
2857 NavigateAndCommit(url1); 2861 NavigateAndCommit(url1);
2858 controller.GetActiveEntry()->SetTitle(title); 2862 controller.GetVisibleEntry()->SetTitle(title);
2859 NavigateAndCommit(url2); 2863 NavigateAndCommit(url2);
2860 2864
2861 scoped_ptr<WebContents> clone(controller.GetWebContents()->Clone()); 2865 scoped_ptr<WebContents> clone(controller.GetWebContents()->Clone());
2862 2866
2863 ASSERT_EQ(2, clone->GetController().GetEntryCount()); 2867 ASSERT_EQ(2, clone->GetController().GetEntryCount());
2864 EXPECT_TRUE(clone->GetController().NeedsReload()); 2868 EXPECT_TRUE(clone->GetController().NeedsReload());
2865 clone->GetController().GoBack(); 2869 clone->GetController().GoBack();
2866 // Navigating back should have triggered needs_reload_ to go false. 2870 // Navigating back should have triggered needs_reload_ to go false.
2867 EXPECT_FALSE(clone->GetController().NeedsReload()); 2871 EXPECT_FALSE(clone->GetController().NeedsReload());
2868 2872
2869 // Ensure that the pending URL and its title are visible. 2873 // Ensure that the pending URL and its title are visible.
2870 EXPECT_EQ(url1, clone->GetController().GetVisibleEntry()->GetURL()); 2874 EXPECT_EQ(url1, clone->GetController().GetVisibleEntry()->GetURL());
2871 EXPECT_EQ(title, clone->GetTitle()); 2875 EXPECT_EQ(title, clone->GetTitle());
2872 } 2876 }
2873 2877
2874 // Make sure that reloading a cloned tab doesn't change its pending entry index. 2878 // Make sure that reloading a cloned tab doesn't change its pending entry index.
2875 // See http://crbug.com/234491. 2879 // See http://crbug.com/234491.
2876 TEST_F(NavigationControllerTest, CloneAndReload) { 2880 TEST_F(NavigationControllerTest, CloneAndReload) {
2877 NavigationControllerImpl& controller = controller_impl(); 2881 NavigationControllerImpl& controller = controller_impl();
2878 const GURL url1("http://foo1"); 2882 const GURL url1("http://foo1");
2879 const GURL url2("http://foo2"); 2883 const GURL url2("http://foo2");
2880 const string16 title(ASCIIToUTF16("Title")); 2884 const string16 title(ASCIIToUTF16("Title"));
2881 2885
2882 NavigateAndCommit(url1); 2886 NavigateAndCommit(url1);
2883 controller.GetActiveEntry()->SetTitle(title); 2887 controller.GetVisibleEntry()->SetTitle(title);
2884 NavigateAndCommit(url2); 2888 NavigateAndCommit(url2);
2885 2889
2886 scoped_ptr<WebContents> clone(controller.GetWebContents()->Clone()); 2890 scoped_ptr<WebContents> clone(controller.GetWebContents()->Clone());
2887 clone->GetController().LoadIfNecessary(); 2891 clone->GetController().LoadIfNecessary();
2888 2892
2889 ASSERT_EQ(2, clone->GetController().GetEntryCount()); 2893 ASSERT_EQ(2, clone->GetController().GetEntryCount());
2890 EXPECT_EQ(1, clone->GetController().GetPendingEntryIndex()); 2894 EXPECT_EQ(1, clone->GetController().GetPendingEntryIndex());
2891 2895
2892 clone->GetController().Reload(true); 2896 clone->GetController().Reload(true);
2893 EXPECT_EQ(1, clone->GetController().GetPendingEntryIndex()); 2897 EXPECT_EQ(1, clone->GetController().GetPendingEntryIndex());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2939 LoadCommittedDetails details; 2943 LoadCommittedDetails details;
2940 2944
2941 // This should return false meaning that nothing was actually updated. 2945 // This should return false meaning that nothing was actually updated.
2942 EXPECT_FALSE(controller.RendererDidNavigate(params, &details)); 2946 EXPECT_FALSE(controller.RendererDidNavigate(params, &details));
2943 2947
2944 // The notification should have updated the last committed one, and not 2948 // The notification should have updated the last committed one, and not
2945 // the pending load. 2949 // the pending load.
2946 EXPECT_EQ(url1, controller.GetLastCommittedEntry()->GetURL()); 2950 EXPECT_EQ(url1, controller.GetLastCommittedEntry()->GetURL());
2947 2951
2948 // The active entry should be unchanged by the subframe load. 2952 // The active entry should be unchanged by the subframe load.
2949 EXPECT_EQ(url2, controller.GetActiveEntry()->GetURL()); 2953 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
2950 } 2954 }
2951 2955
2952 // Test CopyStateFrom with 2 urls, the first selected and nothing in the target. 2956 // Test CopyStateFrom with 2 urls, the first selected and nothing in the target.
2953 TEST_F(NavigationControllerTest, CopyStateFrom) { 2957 TEST_F(NavigationControllerTest, CopyStateFrom) {
2954 NavigationControllerImpl& controller = controller_impl(); 2958 NavigationControllerImpl& controller = controller_impl();
2955 const GURL url1("http://foo1"); 2959 const GURL url1("http://foo1");
2956 const GURL url2("http://foo2"); 2960 const GURL url2("http://foo2");
2957 2961
2958 NavigateAndCommit(url1); 2962 NavigateAndCommit(url1);
2959 NavigateAndCommit(url2); 2963 NavigateAndCommit(url2);
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
3769 contents()->CommitPendingNavigation(); 3773 contents()->CommitPendingNavigation();
3770 3774
3771 // Verify that the NavigationController's session history was correctly 3775 // Verify that the NavigationController's session history was correctly
3772 // cleared. 3776 // cleared.
3773 EXPECT_EQ(1, controller.GetEntryCount()); 3777 EXPECT_EQ(1, controller.GetEntryCount());
3774 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 3778 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
3775 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 3779 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
3776 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 3780 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
3777 EXPECT_FALSE(controller.CanGoBack()); 3781 EXPECT_FALSE(controller.CanGoBack());
3778 EXPECT_FALSE(controller.CanGoForward()); 3782 EXPECT_FALSE(controller.CanGoForward());
3779 EXPECT_EQ(url4, controller.GetActiveEntry()->GetURL()); 3783 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL());
3780 } 3784 }
3781 3785
3782 /* TODO(brettw) These test pass on my local machine but fail on the XP buildbot 3786 /* TODO(brettw) These test pass on my local machine but fail on the XP buildbot
3783 (but not Vista) cleaning up the directory after they run. 3787 (but not Vista) cleaning up the directory after they run.
3784 This should be fixed. 3788 This should be fixed.
3785 3789
3786 // NavigationControllerHistoryTest --------------------------------------------- 3790 // NavigationControllerHistoryTest ---------------------------------------------
3787 3791
3788 class NavigationControllerHistoryTest : public NavigationControllerTest { 3792 class NavigationControllerHistoryTest : public NavigationControllerTest {
3789 public: 3793 public:
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
3951 PAGE_TRANSITION_LINK); 3955 PAGE_TRANSITION_LINK);
3952 session_helper_.AssertNavigationEquals(nav, 3956 session_helper_.AssertNavigationEquals(nav,
3953 windows_[0]->tabs[0]->navigations[0]); 3957 windows_[0]->tabs[0]->navigations[0]);
3954 nav.set_url(url2); 3958 nav.set_url(url2);
3955 session_helper_.AssertNavigationEquals(nav, 3959 session_helper_.AssertNavigationEquals(nav,
3956 windows_[0]->tabs[0]->navigations[1]); 3960 windows_[0]->tabs[0]->navigations[1]);
3957 } 3961 }
3958 */ 3962 */
3959 3963
3960 } // namespace content 3964 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698