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