Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 #include "content/public/browser/render_view_host.h" | 28 #include "content/public/browser/render_view_host.h" |
| 29 #include "content/public/browser/web_contents_delegate.h" | 29 #include "content/public/browser/web_contents_delegate.h" |
| 30 #include "content/public/browser/web_contents_observer.h" | 30 #include "content/public/browser/web_contents_observer.h" |
| 31 #include "content/public/common/content_switches.h" | 31 #include "content/public/common/content_switches.h" |
| 32 #include "content/public/common/page_state.h" | 32 #include "content/public/common/page_state.h" |
| 33 #include "content/public/common/page_type.h" | 33 #include "content/public/common/page_type.h" |
| 34 #include "content/public/common/url_constants.h" | 34 #include "content/public/common/url_constants.h" |
| 35 #include "content/public/test/mock_render_process_host.h" | 35 #include "content/public/test/mock_render_process_host.h" |
| 36 #include "content/public/test/test_notification_tracker.h" | 36 #include "content/public/test/test_notification_tracker.h" |
| 37 #include "content/public/test/test_utils.h" | 37 #include "content/public/test/test_utils.h" |
| 38 #include "content/test/test_navigation_url_loader.h" | |
| 38 #include "content/test/test_render_frame_host.h" | 39 #include "content/test/test_render_frame_host.h" |
| 39 #include "content/test/test_render_view_host.h" | 40 #include "content/test/test_render_view_host.h" |
| 40 #include "content/test/test_web_contents.h" | 41 #include "content/test/test_web_contents.h" |
| 41 #include "net/base/net_util.h" | 42 #include "net/base/net_util.h" |
| 42 #include "skia/ext/platform_canvas.h" | 43 #include "skia/ext/platform_canvas.h" |
| 43 #include "testing/gtest/include/gtest/gtest.h" | 44 #include "testing/gtest/include/gtest/gtest.h" |
| 44 | 45 |
| 45 using base::Time; | 46 using base::Time; |
| 46 | 47 |
| 47 namespace { | 48 namespace { |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 return navigation_request->common_params().url; | 239 return navigation_request->common_params().url; |
| 239 } | 240 } |
| 240 const IPC::Message* message = | 241 const IPC::Message* message = |
| 241 process()->sink().GetFirstMessageMatching(FrameMsg_Navigate::ID); | 242 process()->sink().GetFirstMessageMatching(FrameMsg_Navigate::ID); |
| 242 CHECK(message); | 243 CHECK(message); |
| 243 Tuple<FrameMsg_Navigate_Params> nav_params; | 244 Tuple<FrameMsg_Navigate_Params> nav_params; |
| 244 FrameMsg_Navigate::Read(message, &nav_params); | 245 FrameMsg_Navigate::Read(message, &nav_params); |
| 245 return get<0>(nav_params).common_params.url; | 246 return get<0>(nav_params).common_params.url; |
| 246 } | 247 } |
| 247 | 248 |
| 249 // PlzNavigate | |
| 250 void SimulateServerRedirect(TestRenderFrameHost* test_rfh, | |
|
clamy
2015/02/24 13:05:33
Now that I look at it, this code is very similar t
carlosk
2015/02/24 16:38:56
Done. This does looks better.
| |
| 251 const GURL& redirect_url) { | |
| 252 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 253 switches::kEnableBrowserSideNavigation)) { | |
| 254 return; | |
| 255 } | |
| 256 | |
| 257 NavigatorImpl* navigator_impl = | |
| 258 static_cast<NavigatorImpl*>(test_rfh->frame_tree_node()->navigator()); | |
| 259 NavigationRequest* request = | |
| 260 navigator_impl->GetNavigationRequestForNodeForTesting( | |
| 261 test_rfh->frame_tree_node()); | |
| 262 CHECK(request); | |
| 263 | |
| 264 if (request->state() == NavigationRequest::WAITING_FOR_RENDERER_RESPONSE) | |
| 265 test_rfh->SendBeforeUnloadACK(true); | |
| 266 CHECK(NavigationRequest::STARTED); | |
| 267 | |
| 268 TestNavigationURLLoader* loader = | |
| 269 static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); | |
| 270 CHECK(loader); | |
| 271 loader->SimulateServerRedirect(redirect_url); | |
| 272 } | |
| 273 | |
| 248 protected: | 274 protected: |
| 249 GURL navigated_url_; | 275 GURL navigated_url_; |
| 250 size_t navigation_entry_committed_counter_; | 276 size_t navigation_entry_committed_counter_; |
| 251 }; | 277 }; |
| 252 | 278 |
| 253 void RegisterForAllNavNotifications(TestNotificationTracker* tracker, | 279 void RegisterForAllNavNotifications(TestNotificationTracker* tracker, |
| 254 NavigationController* controller) { | 280 NavigationController* controller) { |
| 255 tracker->ListenFor(NOTIFICATION_NAV_LIST_PRUNED, | 281 tracker->ListenFor(NOTIFICATION_NAV_LIST_PRUNED, |
| 256 Source<NavigationController>(controller)); | 282 Source<NavigationController>(controller)); |
| 257 tracker->ListenFor(NOTIFICATION_NAV_ENTRY_CHANGED, | 283 tracker->ListenFor(NOTIFICATION_NAV_ENTRY_CHANGED, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 NavigationControllerImpl& controller = controller_impl(); | 335 NavigationControllerImpl& controller = controller_impl(); |
| 310 TestNotificationTracker notifications; | 336 TestNotificationTracker notifications; |
| 311 RegisterForAllNavNotifications(¬ifications, &controller); | 337 RegisterForAllNavNotifications(¬ifications, &controller); |
| 312 | 338 |
| 313 const int kNumUrls = 5; | 339 const int kNumUrls = 5; |
| 314 std::vector<GURL> urls(kNumUrls); | 340 std::vector<GURL> urls(kNumUrls); |
| 315 for (int i = 0; i < kNumUrls; ++i) { | 341 for (int i = 0; i < kNumUrls; ++i) { |
| 316 urls[i] = GURL(base::StringPrintf("http://www.a.com/%d", i)); | 342 urls[i] = GURL(base::StringPrintf("http://www.a.com/%d", i)); |
| 317 } | 343 } |
| 318 | 344 |
| 319 main_test_rfh()->PrepareForCommit(urls[0]); | 345 main_test_rfh()->SendRendererInitiatedNavigationRequest(urls[0], true); |
| 346 main_test_rfh()->PrepareForCommit(); | |
| 320 main_test_rfh()->SendNavigate(0, urls[0]); | 347 main_test_rfh()->SendNavigate(0, urls[0]); |
| 321 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 348 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 322 navigation_entry_committed_counter_ = 0; | 349 navigation_entry_committed_counter_ = 0; |
| 323 EXPECT_EQ(urls[0], controller.GetVisibleEntry()->GetVirtualURL()); | 350 EXPECT_EQ(urls[0], controller.GetVisibleEntry()->GetVirtualURL()); |
| 324 EXPECT_FALSE(controller.CanGoBack()); | 351 EXPECT_FALSE(controller.CanGoBack()); |
| 325 EXPECT_FALSE(controller.CanGoForward()); | 352 EXPECT_FALSE(controller.CanGoForward()); |
| 326 EXPECT_FALSE(controller.CanGoToOffset(1)); | 353 EXPECT_FALSE(controller.CanGoToOffset(1)); |
| 327 | 354 |
| 328 for (int i = 1; i <= 4; ++i) { | 355 for (int i = 1; i <= 4; ++i) { |
| 329 main_test_rfh()->PrepareForCommit(urls[i]); | 356 main_test_rfh()->SendRendererInitiatedNavigationRequest(urls[i], true); |
| 357 main_test_rfh()->PrepareForCommit(); | |
| 330 main_test_rfh()->SendNavigate(i, urls[i]); | 358 main_test_rfh()->SendNavigate(i, urls[i]); |
| 331 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 359 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 332 navigation_entry_committed_counter_ = 0; | 360 navigation_entry_committed_counter_ = 0; |
| 333 EXPECT_EQ(urls[i], controller.GetVisibleEntry()->GetVirtualURL()); | 361 EXPECT_EQ(urls[i], controller.GetVisibleEntry()->GetVirtualURL()); |
| 334 EXPECT_TRUE(controller.CanGoToOffset(-i)); | 362 EXPECT_TRUE(controller.CanGoToOffset(-i)); |
| 335 EXPECT_FALSE(controller.CanGoToOffset(-(i + 1))); | 363 EXPECT_FALSE(controller.CanGoToOffset(-(i + 1))); |
| 336 EXPECT_FALSE(controller.CanGoToOffset(1)); | 364 EXPECT_FALSE(controller.CanGoToOffset(1)); |
| 337 } | 365 } |
| 338 | 366 |
| 339 // We have loaded 5 pages, and are currently at the last-loaded page. | 367 // We have loaded 5 pages, and are currently at the last-loaded page. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 355 GO_TO_BEGINNING, | 383 GO_TO_BEGINNING, |
| 356 GO_TO_END | 384 GO_TO_END |
| 357 }; | 385 }; |
| 358 | 386 |
| 359 for (int test = 0; test < NUM_TESTS; ++test) { | 387 for (int test = 0; test < NUM_TESTS; ++test) { |
| 360 int offset = test_offsets[test]; | 388 int offset = test_offsets[test]; |
| 361 controller.GoToOffset(offset); | 389 controller.GoToOffset(offset); |
| 362 url_index += offset; | 390 url_index += offset; |
| 363 // Check that the GoToOffset will land on the expected page. | 391 // Check that the GoToOffset will land on the expected page. |
| 364 EXPECT_EQ(urls[url_index], controller.GetPendingEntry()->GetVirtualURL()); | 392 EXPECT_EQ(urls[url_index], controller.GetPendingEntry()->GetVirtualURL()); |
| 365 main_test_rfh()->PrepareForCommit(urls[url_index]); | 393 main_test_rfh()->PrepareForCommit(); |
| 366 main_test_rfh()->SendNavigate(url_index, urls[url_index]); | 394 main_test_rfh()->SendNavigate(url_index, urls[url_index]); |
| 367 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 395 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 368 navigation_entry_committed_counter_ = 0; | 396 navigation_entry_committed_counter_ = 0; |
| 369 // Check that we can go to any valid offset into the history. | 397 // Check that we can go to any valid offset into the history. |
| 370 for (size_t j = 0; j < urls.size(); ++j) | 398 for (size_t j = 0; j < urls.size(); ++j) |
| 371 EXPECT_TRUE(controller.CanGoToOffset(j - url_index)); | 399 EXPECT_TRUE(controller.CanGoToOffset(j - url_index)); |
| 372 // Check that we can't go beyond the beginning or end of the history. | 400 // Check that we can't go beyond the beginning or end of the history. |
| 373 EXPECT_FALSE(controller.CanGoToOffset(-(url_index + 1))); | 401 EXPECT_FALSE(controller.CanGoToOffset(-(url_index + 1))); |
| 374 EXPECT_FALSE(controller.CanGoToOffset(urls.size() - url_index)); | 402 EXPECT_FALSE(controller.CanGoToOffset(urls.size() - url_index)); |
| 375 } | 403 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 400 EXPECT_FALSE(controller.CanGoForward()); | 428 EXPECT_FALSE(controller.CanGoForward()); |
| 401 EXPECT_EQ(contents()->GetMaxPageID(), -1); | 429 EXPECT_EQ(contents()->GetMaxPageID(), -1); |
| 402 | 430 |
| 403 // Neither the timestamp nor the status code should have been set yet. | 431 // Neither the timestamp nor the status code should have been set yet. |
| 404 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); | 432 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); |
| 405 EXPECT_EQ(0, controller.GetPendingEntry()->GetHttpStatusCode()); | 433 EXPECT_EQ(0, controller.GetPendingEntry()->GetHttpStatusCode()); |
| 406 | 434 |
| 407 // We should have gotten no notifications from the preceeding checks. | 435 // We should have gotten no notifications from the preceeding checks. |
| 408 EXPECT_EQ(0U, notifications.size()); | 436 EXPECT_EQ(0U, notifications.size()); |
| 409 | 437 |
| 410 main_test_rfh()->PrepareForCommit(url1); | 438 main_test_rfh()->PrepareForCommit(); |
| 411 main_test_rfh()->SendNavigate(0, url1); | 439 main_test_rfh()->SendNavigate(0, url1); |
| 412 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 440 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 413 navigation_entry_committed_counter_ = 0; | 441 navigation_entry_committed_counter_ = 0; |
| 414 | 442 |
| 415 // The load should now be committed. | 443 // The load should now be committed. |
| 416 EXPECT_EQ(controller.GetEntryCount(), 1); | 444 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 417 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 445 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 418 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 446 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 419 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 447 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 420 EXPECT_FALSE(controller.GetPendingEntry()); | 448 EXPECT_FALSE(controller.GetPendingEntry()); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 440 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); | 468 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); |
| 441 // TODO(darin): maybe this should really be true? | 469 // TODO(darin): maybe this should really be true? |
| 442 EXPECT_FALSE(controller.CanGoBack()); | 470 EXPECT_FALSE(controller.CanGoBack()); |
| 443 EXPECT_FALSE(controller.CanGoForward()); | 471 EXPECT_FALSE(controller.CanGoForward()); |
| 444 EXPECT_EQ(contents()->GetMaxPageID(), 0); | 472 EXPECT_EQ(contents()->GetMaxPageID(), 0); |
| 445 | 473 |
| 446 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); | 474 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); |
| 447 | 475 |
| 448 // Simulate the beforeunload ack for the cross-site transition, and then the | 476 // Simulate the beforeunload ack for the cross-site transition, and then the |
| 449 // commit. | 477 // commit. |
| 450 main_test_rfh()->PrepareForCommit(url2); | 478 main_test_rfh()->PrepareForCommit(); |
| 451 contents()->GetPendingMainFrame()->SendNavigate(1, url2); | 479 contents()->GetPendingMainFrame()->SendNavigate(1, url2); |
| 452 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 480 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 453 navigation_entry_committed_counter_ = 0; | 481 navigation_entry_committed_counter_ = 0; |
| 454 | 482 |
| 455 // The load should now be committed. | 483 // The load should now be committed. |
| 456 EXPECT_EQ(controller.GetEntryCount(), 2); | 484 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 457 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 485 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
| 458 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 486 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 459 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 487 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 460 EXPECT_FALSE(controller.GetPendingEntry()); | 488 EXPECT_FALSE(controller.GetPendingEntry()); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 482 // Set the clock to always return a timestamp of 1. | 510 // Set the clock to always return a timestamp of 1. |
| 483 controller.SetGetTimestampCallbackForTest( | 511 controller.SetGetTimestampCallbackForTest( |
| 484 base::Bind(&GetFixedTime, base::Time::FromInternalValue(1))); | 512 base::Bind(&GetFixedTime, base::Time::FromInternalValue(1))); |
| 485 | 513 |
| 486 const GURL url1("http://foo1"); | 514 const GURL url1("http://foo1"); |
| 487 const GURL url2("http://foo2"); | 515 const GURL url2("http://foo2"); |
| 488 | 516 |
| 489 controller.LoadURL( | 517 controller.LoadURL( |
| 490 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 518 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 491 | 519 |
| 492 main_test_rfh()->PrepareForCommit(url1); | 520 main_test_rfh()->PrepareForCommit(); |
| 493 main_test_rfh()->SendNavigate(0, url1); | 521 main_test_rfh()->SendNavigate(0, url1); |
| 494 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 522 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 495 navigation_entry_committed_counter_ = 0; | 523 navigation_entry_committed_counter_ = 0; |
| 496 | 524 |
| 497 // Load another... | 525 // Load another... |
| 498 controller.LoadURL( | 526 controller.LoadURL( |
| 499 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 527 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 500 | 528 |
| 501 // Simulate the beforeunload ack for the cross-site transition, and then the | 529 // Simulate the beforeunload ack for the cross-site transition, and then the |
| 502 // commit. | 530 // commit. |
| 503 main_test_rfh()->PrepareForCommit(url2); | 531 main_test_rfh()->PrepareForCommit(); |
| 504 contents()->GetPendingMainFrame()->SendNavigate(1, url2); | 532 contents()->GetPendingMainFrame()->SendNavigate(1, url2); |
| 505 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 533 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 506 navigation_entry_committed_counter_ = 0; | 534 navigation_entry_committed_counter_ = 0; |
| 507 | 535 |
| 508 // The two loads should now be committed. | 536 // The two loads should now be committed. |
| 509 ASSERT_EQ(controller.GetEntryCount(), 2); | 537 ASSERT_EQ(controller.GetEntryCount(), 2); |
| 510 | 538 |
| 511 // Timestamps should be distinct despite the clock returning the | 539 // Timestamps should be distinct despite the clock returning the |
| 512 // same value. | 540 // same value. |
| 513 EXPECT_EQ(1u, | 541 EXPECT_EQ(1u, |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 612 TEST_F(NavigationControllerTest, LoadURL_SamePage) { | 640 TEST_F(NavigationControllerTest, LoadURL_SamePage) { |
| 613 NavigationControllerImpl& controller = controller_impl(); | 641 NavigationControllerImpl& controller = controller_impl(); |
| 614 TestNotificationTracker notifications; | 642 TestNotificationTracker notifications; |
| 615 RegisterForAllNavNotifications(¬ifications, &controller); | 643 RegisterForAllNavNotifications(¬ifications, &controller); |
| 616 | 644 |
| 617 const GURL url1("http://foo1"); | 645 const GURL url1("http://foo1"); |
| 618 | 646 |
| 619 controller.LoadURL( | 647 controller.LoadURL( |
| 620 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 648 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 621 EXPECT_EQ(0U, notifications.size()); | 649 EXPECT_EQ(0U, notifications.size()); |
| 622 main_test_rfh()->PrepareForCommit(url1); | 650 main_test_rfh()->PrepareForCommit(); |
| 623 main_test_rfh()->SendNavigate(0, url1); | 651 main_test_rfh()->SendNavigate(0, url1); |
| 624 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 652 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 625 navigation_entry_committed_counter_ = 0; | 653 navigation_entry_committed_counter_ = 0; |
| 626 | 654 |
| 627 ASSERT_TRUE(controller.GetVisibleEntry()); | 655 ASSERT_TRUE(controller.GetVisibleEntry()); |
| 628 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); | 656 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); |
| 629 EXPECT_FALSE(timestamp.is_null()); | 657 EXPECT_FALSE(timestamp.is_null()); |
| 630 | 658 |
| 631 controller.LoadURL( | 659 controller.LoadURL( |
| 632 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 660 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 633 EXPECT_EQ(0U, notifications.size()); | 661 EXPECT_EQ(0U, notifications.size()); |
| 634 main_test_rfh()->PrepareForCommit(url1); | 662 main_test_rfh()->PrepareForCommit(); |
| 635 main_test_rfh()->SendNavigate(0, url1); | 663 main_test_rfh()->SendNavigate(0, url1); |
| 636 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 664 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 637 navigation_entry_committed_counter_ = 0; | 665 navigation_entry_committed_counter_ = 0; |
| 638 | 666 |
| 639 // We should not have produced a new session history entry. | 667 // We should not have produced a new session history entry. |
| 640 EXPECT_EQ(controller.GetEntryCount(), 1); | 668 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 641 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 669 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 642 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 670 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 643 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 671 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 644 EXPECT_FALSE(controller.GetPendingEntry()); | 672 EXPECT_FALSE(controller.GetPendingEntry()); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 664 | 692 |
| 665 controller.LoadURL( | 693 controller.LoadURL( |
| 666 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 694 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 667 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 695 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
| 668 params.page_id = 0; | 696 params.page_id = 0; |
| 669 params.url = url1; | 697 params.url = url1; |
| 670 params.transition = ui::PAGE_TRANSITION_TYPED; | 698 params.transition = ui::PAGE_TRANSITION_TYPED; |
| 671 params.is_post = true; | 699 params.is_post = true; |
| 672 params.post_id = 123; | 700 params.post_id = 123; |
| 673 params.page_state = PageState::CreateForTesting(url1, false, 0, 0); | 701 params.page_state = PageState::CreateForTesting(url1, false, 0, 0); |
| 674 main_test_rfh()->PrepareForCommit(url1); | 702 main_test_rfh()->PrepareForCommit(); |
| 675 main_test_rfh()->SendNavigateWithParams(¶ms); | 703 main_test_rfh()->SendNavigateWithParams(¶ms); |
| 676 | 704 |
| 677 // The post data should be visible. | 705 // The post data should be visible. |
| 678 NavigationEntry* entry = controller.GetVisibleEntry(); | 706 NavigationEntry* entry = controller.GetVisibleEntry(); |
| 679 ASSERT_TRUE(entry); | 707 ASSERT_TRUE(entry); |
| 680 EXPECT_TRUE(entry->GetHasPostData()); | 708 EXPECT_TRUE(entry->GetHasPostData()); |
| 681 EXPECT_EQ(entry->GetPostID(), 123); | 709 EXPECT_EQ(entry->GetPostID(), 123); |
| 682 | 710 |
| 683 controller.LoadURL( | 711 controller.LoadURL( |
| 684 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 712 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 685 main_test_rfh()->PrepareForCommit(url1); | 713 main_test_rfh()->PrepareForCommit(); |
| 686 main_test_rfh()->SendNavigate(0, url1); | 714 main_test_rfh()->SendNavigate(0, url1); |
| 687 | 715 |
| 688 // We should not have produced a new session history entry. | 716 // We should not have produced a new session history entry. |
| 689 ASSERT_EQ(controller.GetVisibleEntry(), entry); | 717 ASSERT_EQ(controller.GetVisibleEntry(), entry); |
| 690 | 718 |
| 691 // The post data should have been cleared due to the GET. | 719 // The post data should have been cleared due to the GET. |
| 692 EXPECT_FALSE(entry->GetHasPostData()); | 720 EXPECT_FALSE(entry->GetHasPostData()); |
| 693 EXPECT_EQ(entry->GetPostID(), 0); | 721 EXPECT_EQ(entry->GetPostID(), 0); |
| 694 } | 722 } |
| 695 | 723 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 766 // commits. | 794 // commits. |
| 767 TEST_F(NavigationControllerTest, LoadURL_NewPending) { | 795 TEST_F(NavigationControllerTest, LoadURL_NewPending) { |
| 768 NavigationControllerImpl& controller = controller_impl(); | 796 NavigationControllerImpl& controller = controller_impl(); |
| 769 TestNotificationTracker notifications; | 797 TestNotificationTracker notifications; |
| 770 RegisterForAllNavNotifications(¬ifications, &controller); | 798 RegisterForAllNavNotifications(¬ifications, &controller); |
| 771 | 799 |
| 772 // First make an existing committed entry. | 800 // First make an existing committed entry. |
| 773 const GURL kExistingURL1("http://eh"); | 801 const GURL kExistingURL1("http://eh"); |
| 774 controller.LoadURL( | 802 controller.LoadURL( |
| 775 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 803 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 776 main_test_rfh()->PrepareForCommit(kExistingURL1); | 804 main_test_rfh()->PrepareForCommit(); |
| 777 main_test_rfh()->SendNavigate(0, kExistingURL1); | 805 main_test_rfh()->SendNavigate(0, kExistingURL1); |
| 778 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 806 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 779 navigation_entry_committed_counter_ = 0; | 807 navigation_entry_committed_counter_ = 0; |
| 780 | 808 |
| 781 // Make a pending entry to somewhere new. | 809 // Make a pending entry to somewhere new. |
| 782 const GURL kExistingURL2("http://bee"); | 810 const GURL kExistingURL2("http://bee"); |
| 783 controller.LoadURL( | 811 controller.LoadURL( |
| 784 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 812 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 785 EXPECT_EQ(0U, notifications.size()); | 813 EXPECT_EQ(0U, notifications.size()); |
| 786 | 814 |
| 787 // After the beforeunload but before it commits, do a new navigation. | 815 // After the beforeunload but before it commits, do a new navigation. |
| 788 main_test_rfh()->PrepareForCommit(kExistingURL2); | 816 main_test_rfh()->PrepareForCommit(); |
| 789 const GURL kNewURL("http://see"); | 817 const GURL kNewURL("http://see"); |
| 790 main_test_rfh()->PrepareForCommit(kNewURL); | 818 main_test_rfh()->PrepareForCommit(); |
| 791 contents()->GetMainFrame()->SendNavigate(3, kNewURL); | 819 contents()->GetMainFrame()->SendNavigate(3, kNewURL); |
| 792 | 820 |
| 793 // There should no longer be any pending entry, and the third navigation we | 821 // There should no longer be any pending entry, and the third navigation we |
| 794 // just made should be committed. | 822 // just made should be committed. |
| 795 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 823 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 796 navigation_entry_committed_counter_ = 0; | 824 navigation_entry_committed_counter_ = 0; |
| 797 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 825 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 798 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 826 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 799 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); | 827 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); |
| 800 } | 828 } |
| 801 | 829 |
| 802 // Tests navigating to a new URL when there is a pending back/forward | 830 // Tests navigating to a new URL when there is a pending back/forward |
| 803 // navigation. This will happen if the user hits back, but before that commits, | 831 // navigation. This will happen if the user hits back, but before that commits, |
| 804 // they navigate somewhere new. | 832 // they navigate somewhere new. |
| 805 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { | 833 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { |
| 806 NavigationControllerImpl& controller = controller_impl(); | 834 NavigationControllerImpl& controller = controller_impl(); |
| 807 TestNotificationTracker notifications; | 835 TestNotificationTracker notifications; |
| 808 RegisterForAllNavNotifications(¬ifications, &controller); | 836 RegisterForAllNavNotifications(¬ifications, &controller); |
| 809 | 837 |
| 810 // First make some history. | 838 // First make some history. |
| 811 const GURL kExistingURL1("http://foo/eh"); | 839 const GURL kExistingURL1("http://foo/eh"); |
| 812 controller.LoadURL( | 840 controller.LoadURL( |
| 813 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 841 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 814 main_test_rfh()->PrepareForCommit(kExistingURL1); | 842 main_test_rfh()->PrepareForCommit(); |
| 815 main_test_rfh()->SendNavigate(0, kExistingURL1); | 843 main_test_rfh()->SendNavigate(0, kExistingURL1); |
| 816 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 844 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 817 navigation_entry_committed_counter_ = 0; | 845 navigation_entry_committed_counter_ = 0; |
| 818 | 846 |
| 819 const GURL kExistingURL2("http://foo/bee"); | 847 const GURL kExistingURL2("http://foo/bee"); |
| 820 controller.LoadURL( | 848 controller.LoadURL( |
| 821 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 849 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 822 main_test_rfh()->PrepareForCommit(kExistingURL2); | 850 main_test_rfh()->PrepareForCommit(); |
| 823 main_test_rfh()->SendNavigate(1, kExistingURL2); | 851 main_test_rfh()->SendNavigate(1, kExistingURL2); |
| 824 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 852 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 825 navigation_entry_committed_counter_ = 0; | 853 navigation_entry_committed_counter_ = 0; |
| 826 | 854 |
| 827 // Now make a pending back/forward navigation. The zeroth entry should be | 855 // Now make a pending back/forward navigation. The zeroth entry should be |
| 828 // pending. | 856 // pending. |
| 829 controller.GoBack(); | 857 controller.GoBack(); |
| 830 EXPECT_EQ(0U, notifications.size()); | 858 EXPECT_EQ(0U, notifications.size()); |
| 831 EXPECT_EQ(0, controller.GetPendingEntryIndex()); | 859 EXPECT_EQ(0, controller.GetPendingEntryIndex()); |
| 832 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 860 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 833 | 861 |
| 834 // Before that commits, do a new navigation. | 862 // Before that commits, do a new navigation. |
| 835 const GURL kNewURL("http://foo/see"); | 863 const GURL kNewURL("http://foo/see"); |
| 836 main_test_rfh()->PrepareForCommit(kNewURL); | 864 main_test_rfh()->SendRendererInitiatedNavigationRequest(kNewURL, true); |
| 865 main_test_rfh()->PrepareForCommit(); | |
| 837 main_test_rfh()->SendNavigate(3, kNewURL); | 866 main_test_rfh()->SendNavigate(3, kNewURL); |
| 838 | 867 |
| 839 // There should no longer be any pending entry, and the third navigation we | 868 // There should no longer be any pending entry, and the third navigation we |
| 840 // just made should be committed. | 869 // just made should be committed. |
| 841 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 870 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 842 navigation_entry_committed_counter_ = 0; | 871 navigation_entry_committed_counter_ = 0; |
| 843 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 872 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 844 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 873 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
| 845 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); | 874 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); |
| 846 } | 875 } |
| 847 | 876 |
| 848 // Tests navigating to a new URL when there is a pending back/forward | 877 // Tests navigating to a new URL when there is a pending back/forward |
| 849 // navigation to a cross-process, privileged URL. This will happen if the user | 878 // navigation to a cross-process, privileged URL. This will happen if the user |
| 850 // hits back, but before that commits, they navigate somewhere new. | 879 // hits back, but before that commits, they navigate somewhere new. |
| 851 TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) { | 880 TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) { |
| 852 NavigationControllerImpl& controller = controller_impl(); | 881 NavigationControllerImpl& controller = controller_impl(); |
| 853 TestNotificationTracker notifications; | 882 TestNotificationTracker notifications; |
| 854 RegisterForAllNavNotifications(¬ifications, &controller); | 883 RegisterForAllNavNotifications(¬ifications, &controller); |
| 855 | 884 |
| 856 // First make some history, starting with a privileged URL. | 885 // First make some history, starting with a privileged URL. |
| 857 const GURL kExistingURL1("http://privileged"); | 886 const GURL kExistingURL1("http://privileged"); |
| 858 controller.LoadURL( | 887 controller.LoadURL( |
| 859 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 888 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 860 // Pretend it has bindings so we can tell if we incorrectly copy it. | 889 // Pretend it has bindings so we can tell if we incorrectly copy it. |
| 861 main_test_rfh()->GetRenderViewHost()->AllowBindings(2); | 890 main_test_rfh()->GetRenderViewHost()->AllowBindings(2); |
| 862 main_test_rfh()->PrepareForCommit(kExistingURL1); | 891 main_test_rfh()->PrepareForCommit(); |
| 863 main_test_rfh()->SendNavigate(0, kExistingURL1); | 892 main_test_rfh()->SendNavigate(0, kExistingURL1); |
| 864 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 893 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 865 navigation_entry_committed_counter_ = 0; | 894 navigation_entry_committed_counter_ = 0; |
| 866 | 895 |
| 867 // Navigate cross-process to a second URL. | 896 // Navigate cross-process to a second URL. |
| 868 const GURL kExistingURL2("http://foo/eh"); | 897 const GURL kExistingURL2("http://foo/eh"); |
| 869 controller.LoadURL( | 898 controller.LoadURL( |
| 870 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 899 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 871 main_test_rfh()->PrepareForCommit(kExistingURL2); | 900 main_test_rfh()->PrepareForCommit(); |
| 872 TestRenderFrameHost* foo_rfh = contents()->GetPendingMainFrame(); | 901 TestRenderFrameHost* foo_rfh = contents()->GetPendingMainFrame(); |
| 873 foo_rfh->SendNavigate(1, kExistingURL2); | 902 foo_rfh->SendNavigate(1, kExistingURL2); |
| 874 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 903 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 875 navigation_entry_committed_counter_ = 0; | 904 navigation_entry_committed_counter_ = 0; |
| 876 | 905 |
| 877 // Now make a pending back/forward navigation to a privileged entry. | 906 // Now make a pending back/forward navigation to a privileged entry. |
| 878 // The zeroth entry should be pending. | 907 // The zeroth entry should be pending. |
| 879 controller.GoBack(); | 908 controller.GoBack(); |
| 880 foo_rfh->SendBeforeUnloadACK(true); | 909 foo_rfh->SendBeforeUnloadACK(true); |
| 881 EXPECT_EQ(0U, notifications.size()); | 910 EXPECT_EQ(0U, notifications.size()); |
| 882 EXPECT_EQ(0, controller.GetPendingEntryIndex()); | 911 EXPECT_EQ(0, controller.GetPendingEntryIndex()); |
| 883 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 912 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 884 EXPECT_EQ(2, controller.GetPendingEntry()->bindings()); | 913 EXPECT_EQ(2, controller.GetPendingEntry()->bindings()); |
| 885 | 914 |
| 886 // Before that commits, do a new navigation. | 915 // Before that commits, do a new navigation. |
| 887 const GURL kNewURL("http://foo/bee"); | 916 const GURL kNewURL("http://foo/bee"); |
| 888 foo_rfh->PrepareForCommit(kNewURL); | 917 foo_rfh->SendRendererInitiatedNavigationRequest(kNewURL, true); |
| 918 foo_rfh->PrepareForCommit(); | |
| 889 foo_rfh->SendNavigate(3, kNewURL); | 919 foo_rfh->SendNavigate(3, kNewURL); |
| 890 | 920 |
| 891 // There should no longer be any pending entry, and the third navigation we | 921 // There should no longer be any pending entry, and the third navigation we |
| 892 // just made should be committed. | 922 // just made should be committed. |
| 893 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 923 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 894 navigation_entry_committed_counter_ = 0; | 924 navigation_entry_committed_counter_ = 0; |
| 895 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 925 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 896 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 926 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
| 897 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); | 927 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); |
| 898 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); | 928 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); |
| 899 } | 929 } |
| 900 | 930 |
| 901 // Tests navigating to an existing URL when there is a pending new navigation. | 931 // Tests navigating to an existing URL when there is a pending new navigation. |
| 902 // This will happen if the user enters a URL, but before that commits, the | 932 // This will happen if the user enters a URL, but before that commits, the |
| 903 // current page fires history.back(). | 933 // current page fires history.back(). |
| 904 TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { | 934 TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { |
| 905 NavigationControllerImpl& controller = controller_impl(); | 935 NavigationControllerImpl& controller = controller_impl(); |
| 906 TestNotificationTracker notifications; | 936 TestNotificationTracker notifications; |
| 907 RegisterForAllNavNotifications(¬ifications, &controller); | 937 RegisterForAllNavNotifications(¬ifications, &controller); |
| 908 | 938 |
| 909 // First make some history. | 939 // First make some history. |
| 910 const GURL kExistingURL1("http://foo/eh"); | 940 const GURL kExistingURL1("http://foo/eh"); |
| 911 controller.LoadURL( | 941 controller.LoadURL( |
| 912 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 942 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 913 main_test_rfh()->PrepareForCommit(kExistingURL1); | 943 main_test_rfh()->PrepareForCommit(); |
| 914 main_test_rfh()->SendNavigate(0, kExistingURL1); | 944 main_test_rfh()->SendNavigate(0, kExistingURL1); |
| 915 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 945 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 916 navigation_entry_committed_counter_ = 0; | 946 navigation_entry_committed_counter_ = 0; |
| 917 | 947 |
| 918 const GURL kExistingURL2("http://foo/bee"); | 948 const GURL kExistingURL2("http://foo/bee"); |
| 919 controller.LoadURL( | 949 controller.LoadURL( |
| 920 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 950 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 921 main_test_rfh()->PrepareForCommit(kExistingURL2); | 951 main_test_rfh()->PrepareForCommit(); |
| 922 main_test_rfh()->SendNavigate(1, kExistingURL2); | 952 main_test_rfh()->SendNavigate(1, kExistingURL2); |
| 923 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 953 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 924 navigation_entry_committed_counter_ = 0; | 954 navigation_entry_committed_counter_ = 0; |
| 925 | 955 |
| 926 // Now make a pending new navigation. | 956 // Now make a pending new navigation. |
| 927 const GURL kNewURL("http://foo/see"); | 957 const GURL kNewURL("http://foo/see"); |
| 928 controller.LoadURL( | 958 controller.LoadURL( |
| 929 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 959 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 930 EXPECT_EQ(0U, notifications.size()); | 960 EXPECT_EQ(0U, notifications.size()); |
| 931 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 961 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 932 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 962 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 933 | 963 |
| 934 // Before that commits, a back navigation from the renderer commits. | 964 // Before that commits, a back navigation from the renderer commits. |
| 935 main_test_rfh()->PrepareForCommit(kExistingURL1); | 965 main_test_rfh()->SendRendererInitiatedNavigationRequest(kExistingURL1, true); |
| 966 main_test_rfh()->PrepareForCommit(); | |
| 936 main_test_rfh()->SendNavigate(0, kExistingURL1); | 967 main_test_rfh()->SendNavigate(0, kExistingURL1); |
| 937 | 968 |
| 938 // There should no longer be any pending entry, and the back navigation we | 969 // There should no longer be any pending entry, and the back navigation we |
| 939 // just made should be committed. | 970 // just made should be committed. |
| 940 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 971 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 941 navigation_entry_committed_counter_ = 0; | 972 navigation_entry_committed_counter_ = 0; |
| 942 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 973 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 943 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 974 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 944 EXPECT_EQ(kExistingURL1, controller.GetVisibleEntry()->GetURL()); | 975 EXPECT_EQ(kExistingURL1, controller.GetVisibleEntry()->GetURL()); |
| 945 } | 976 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 965 controller.LoadURL( | 996 controller.LoadURL( |
| 966 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 997 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 967 EXPECT_EQ(0U, notifications.size()); | 998 EXPECT_EQ(0U, notifications.size()); |
| 968 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 999 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 969 EXPECT_TRUE(controller.GetPendingEntry()); | 1000 EXPECT_TRUE(controller.GetPendingEntry()); |
| 970 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 1001 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); |
| 971 EXPECT_EQ(1, delegate->navigation_state_change_count()); | 1002 EXPECT_EQ(1, delegate->navigation_state_change_count()); |
| 972 | 1003 |
| 973 // Before that commits, a document.write and location.reload can cause the | 1004 // Before that commits, a document.write and location.reload can cause the |
| 974 // renderer to send a FrameNavigate with page_id -1. | 1005 // renderer to send a FrameNavigate with page_id -1. |
| 975 main_test_rfh()->PrepareForCommit(kExistingURL); | 1006 main_test_rfh()->SendRendererInitiatedNavigationRequest(kExistingURL, true); |
| 1007 main_test_rfh()->PrepareForCommit(); | |
| 976 main_test_rfh()->SendNavigate(-1, kExistingURL); | 1008 main_test_rfh()->SendNavigate(-1, kExistingURL); |
| 977 | 1009 |
| 978 // This should clear the pending entry and notify of a navigation state | 1010 // This should clear the pending entry and notify of a navigation state |
| 979 // change, so that we do not keep displaying kNewURL. | 1011 // change, so that we do not keep displaying kNewURL. |
| 980 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1012 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 981 EXPECT_FALSE(controller.GetPendingEntry()); | 1013 EXPECT_FALSE(controller.GetPendingEntry()); |
| 982 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 1014 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); |
| 983 EXPECT_EQ(2, delegate->navigation_state_change_count()); | 1015 EXPECT_EQ(2, delegate->navigation_state_change_count()); |
| 984 | 1016 |
| 985 contents()->SetDelegate(NULL); | 1017 contents()->SetDelegate(NULL); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1116 const GURL url2("http://foo2"); | 1148 const GURL url2("http://foo2"); |
| 1117 | 1149 |
| 1118 // Navigate to a first, unprivileged URL. | 1150 // Navigate to a first, unprivileged URL. |
| 1119 controller.LoadURL( | 1151 controller.LoadURL( |
| 1120 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1152 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1121 EXPECT_EQ(NavigationEntryImpl::kInvalidBindings, | 1153 EXPECT_EQ(NavigationEntryImpl::kInvalidBindings, |
| 1122 controller.GetPendingEntry()->bindings()); | 1154 controller.GetPendingEntry()->bindings()); |
| 1123 | 1155 |
| 1124 // Commit. | 1156 // Commit. |
| 1125 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | 1157 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); |
| 1126 orig_rfh->PrepareForCommit(url1); | 1158 orig_rfh->PrepareForCommit(); |
| 1127 orig_rfh->SendNavigate(0, url1); | 1159 orig_rfh->SendNavigate(0, url1); |
| 1128 EXPECT_EQ(controller.GetEntryCount(), 1); | 1160 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 1129 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 1161 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 1130 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); | 1162 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); |
| 1131 | 1163 |
| 1132 // Manually increase the number of active frames in the SiteInstance | 1164 // Manually increase the number of active frames in the SiteInstance |
| 1133 // that orig_rfh belongs to, to prevent it from being destroyed when | 1165 // that orig_rfh belongs to, to prevent it from being destroyed when |
| 1134 // it gets swapped out, so that we can reuse orig_rfh when the | 1166 // it gets swapped out, so that we can reuse orig_rfh when the |
| 1135 // controller goes back. | 1167 // controller goes back. |
| 1136 orig_rfh->GetSiteInstance()->increment_active_frame_count(); | 1168 orig_rfh->GetSiteInstance()->increment_active_frame_count(); |
| 1137 | 1169 |
| 1138 // Navigate to a second URL, simulate the beforeunload ack for the cross-site | 1170 // Navigate to a second URL, simulate the beforeunload ack for the cross-site |
| 1139 // transition, and set bindings on the pending RenderViewHost to simulate a | 1171 // transition, and set bindings on the pending RenderViewHost to simulate a |
| 1140 // privileged url. | 1172 // privileged url. |
| 1141 controller.LoadURL( | 1173 controller.LoadURL( |
| 1142 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1174 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1143 orig_rfh->PrepareForCommit(url2); | 1175 orig_rfh->PrepareForCommit(); |
| 1144 TestRenderFrameHost* new_rfh = contents()->GetPendingMainFrame(); | 1176 TestRenderFrameHost* new_rfh = contents()->GetPendingMainFrame(); |
| 1145 new_rfh->GetRenderViewHost()->AllowBindings(1); | 1177 new_rfh->GetRenderViewHost()->AllowBindings(1); |
| 1146 new_rfh->SendNavigate(1, url2); | 1178 new_rfh->SendNavigate(1, url2); |
| 1147 | 1179 |
| 1148 // The second load should be committed, and bindings should be remembered. | 1180 // The second load should be committed, and bindings should be remembered. |
| 1149 EXPECT_EQ(controller.GetEntryCount(), 2); | 1181 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 1150 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 1182 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 1151 EXPECT_TRUE(controller.CanGoBack()); | 1183 EXPECT_TRUE(controller.CanGoBack()); |
| 1152 EXPECT_EQ(1, controller.GetLastCommittedEntry()->bindings()); | 1184 EXPECT_EQ(1, controller.GetLastCommittedEntry()->bindings()); |
| 1153 | 1185 |
| 1154 // Going back, the first entry should still appear unprivileged. | 1186 // Going back, the first entry should still appear unprivileged. |
| 1155 controller.GoBack(); | 1187 controller.GoBack(); |
| 1156 new_rfh->PrepareForCommit(url1); | 1188 new_rfh->PrepareForCommit(); |
| 1157 orig_rfh->SendNavigate(0, url1); | 1189 orig_rfh->SendNavigate(0, url1); |
| 1158 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 1190 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 1159 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); | 1191 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); |
| 1160 } | 1192 } |
| 1161 | 1193 |
| 1162 TEST_F(NavigationControllerTest, Reload) { | 1194 TEST_F(NavigationControllerTest, Reload) { |
| 1163 NavigationControllerImpl& controller = controller_impl(); | 1195 NavigationControllerImpl& controller = controller_impl(); |
| 1164 TestNotificationTracker notifications; | 1196 TestNotificationTracker notifications; |
| 1165 RegisterForAllNavNotifications(¬ifications, &controller); | 1197 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1166 | 1198 |
| 1167 const GURL url1("http://foo1"); | 1199 const GURL url1("http://foo1"); |
| 1168 | 1200 |
| 1169 controller.LoadURL( | 1201 controller.LoadURL( |
| 1170 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1202 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1171 EXPECT_EQ(0U, notifications.size()); | 1203 EXPECT_EQ(0U, notifications.size()); |
| 1172 main_test_rfh()->PrepareForCommit(url1); | 1204 main_test_rfh()->PrepareForCommit(); |
| 1173 main_test_rfh()->SendNavigate(0, url1); | 1205 main_test_rfh()->SendNavigate(0, url1); |
| 1174 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1206 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1175 navigation_entry_committed_counter_ = 0; | 1207 navigation_entry_committed_counter_ = 0; |
| 1176 ASSERT_TRUE(controller.GetVisibleEntry()); | 1208 ASSERT_TRUE(controller.GetVisibleEntry()); |
| 1177 controller.GetVisibleEntry()->SetTitle(base::ASCIIToUTF16("Title")); | 1209 controller.GetVisibleEntry()->SetTitle(base::ASCIIToUTF16("Title")); |
| 1178 controller.Reload(true); | 1210 controller.Reload(true); |
| 1179 EXPECT_EQ(0U, notifications.size()); | 1211 EXPECT_EQ(0U, notifications.size()); |
| 1180 | 1212 |
| 1181 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); | 1213 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); |
| 1182 EXPECT_FALSE(timestamp.is_null()); | 1214 EXPECT_FALSE(timestamp.is_null()); |
| 1183 | 1215 |
| 1184 // The reload is pending. | 1216 // The reload is pending. |
| 1185 EXPECT_EQ(controller.GetEntryCount(), 1); | 1217 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 1186 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1218 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1187 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 1219 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
| 1188 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1220 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1189 EXPECT_TRUE(controller.GetPendingEntry()); | 1221 EXPECT_TRUE(controller.GetPendingEntry()); |
| 1190 EXPECT_FALSE(controller.CanGoBack()); | 1222 EXPECT_FALSE(controller.CanGoBack()); |
| 1191 EXPECT_FALSE(controller.CanGoForward()); | 1223 EXPECT_FALSE(controller.CanGoForward()); |
| 1192 // Make sure the title has been cleared (will be redrawn just after reload). | 1224 // Make sure the title has been cleared (will be redrawn just after reload). |
| 1193 // Avoids a stale cached title when the new page being reloaded has no title. | 1225 // Avoids a stale cached title when the new page being reloaded has no title. |
| 1194 // See http://crbug.com/96041. | 1226 // See http://crbug.com/96041. |
| 1195 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); | 1227 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); |
| 1196 | 1228 |
| 1197 main_test_rfh()->PrepareForCommit(url1); | 1229 main_test_rfh()->PrepareForCommit(); |
| 1198 main_test_rfh()->SendNavigate(0, url1); | 1230 main_test_rfh()->SendNavigate(0, url1); |
| 1199 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1231 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1200 navigation_entry_committed_counter_ = 0; | 1232 navigation_entry_committed_counter_ = 0; |
| 1201 | 1233 |
| 1202 // Now the reload is committed. | 1234 // Now the reload is committed. |
| 1203 EXPECT_EQ(controller.GetEntryCount(), 1); | 1235 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 1204 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1236 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1205 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1237 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1206 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1238 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1207 EXPECT_FALSE(controller.GetPendingEntry()); | 1239 EXPECT_FALSE(controller.GetPendingEntry()); |
| 1208 EXPECT_FALSE(controller.CanGoBack()); | 1240 EXPECT_FALSE(controller.CanGoBack()); |
| 1209 EXPECT_FALSE(controller.CanGoForward()); | 1241 EXPECT_FALSE(controller.CanGoForward()); |
| 1210 | 1242 |
| 1211 // The timestamp should have been updated. | 1243 // The timestamp should have been updated. |
| 1212 ASSERT_TRUE(controller.GetVisibleEntry()); | 1244 ASSERT_TRUE(controller.GetVisibleEntry()); |
| 1213 EXPECT_GE(controller.GetVisibleEntry()->GetTimestamp(), timestamp); | 1245 EXPECT_GE(controller.GetVisibleEntry()->GetTimestamp(), timestamp); |
| 1214 } | 1246 } |
| 1215 | 1247 |
| 1216 // Tests what happens when a reload navigation produces a new page. | 1248 // Tests what happens when a reload navigation produces a new page. |
| 1217 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { | 1249 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { |
| 1218 NavigationControllerImpl& controller = controller_impl(); | 1250 NavigationControllerImpl& controller = controller_impl(); |
| 1219 TestNotificationTracker notifications; | 1251 TestNotificationTracker notifications; |
| 1220 RegisterForAllNavNotifications(¬ifications, &controller); | 1252 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1221 | 1253 |
| 1222 const GURL url1("http://foo1"); | 1254 const GURL url1("http://foo1"); |
| 1223 const GURL url2("http://foo2"); | 1255 const GURL url2("http://foo2"); |
| 1224 | 1256 |
| 1225 controller.LoadURL( | 1257 controller.LoadURL( |
| 1226 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1258 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1227 main_test_rfh()->PrepareForCommit(url1); | 1259 main_test_rfh()->PrepareForCommit(); |
| 1228 main_test_rfh()->SendNavigate(0, url1); | 1260 main_test_rfh()->SendNavigate(0, url1); |
| 1229 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1261 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1230 navigation_entry_committed_counter_ = 0; | 1262 navigation_entry_committed_counter_ = 0; |
| 1231 | 1263 |
| 1232 controller.Reload(true); | 1264 controller.Reload(true); |
| 1233 EXPECT_EQ(0U, notifications.size()); | 1265 EXPECT_EQ(0U, notifications.size()); |
| 1234 | 1266 |
| 1235 main_test_rfh()->PrepareForCommit(url2); | 1267 SimulateServerRedirect(main_test_rfh(), url2); |
| 1268 main_test_rfh()->PrepareForCommit(); | |
| 1236 main_test_rfh()->SendNavigate(1, url2); | 1269 main_test_rfh()->SendNavigate(1, url2); |
| 1237 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1270 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1238 navigation_entry_committed_counter_ = 0; | 1271 navigation_entry_committed_counter_ = 0; |
| 1239 | 1272 |
| 1240 // Now the reload is committed. | 1273 // Now the reload is committed. |
| 1241 EXPECT_EQ(controller.GetEntryCount(), 2); | 1274 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 1242 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1275 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
| 1243 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1276 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1244 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1277 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1245 EXPECT_FALSE(controller.GetPendingEntry()); | 1278 EXPECT_FALSE(controller.GetPendingEntry()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1283 TestNotificationTracker notifications; | 1316 TestNotificationTracker notifications; |
| 1284 RegisterForAllNavNotifications(¬ifications, &controller); | 1317 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1285 | 1318 |
| 1286 const GURL original_url("http://foo1"); | 1319 const GURL original_url("http://foo1"); |
| 1287 const GURL final_url("http://foo2"); | 1320 const GURL final_url("http://foo2"); |
| 1288 | 1321 |
| 1289 // Load up the original URL, but get redirected. | 1322 // Load up the original URL, but get redirected. |
| 1290 controller.LoadURL( | 1323 controller.LoadURL( |
| 1291 original_url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1324 original_url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1292 EXPECT_EQ(0U, notifications.size()); | 1325 EXPECT_EQ(0U, notifications.size()); |
| 1293 main_test_rfh()->PrepareForCommit(final_url); | 1326 SimulateServerRedirect(main_test_rfh(), final_url); |
| 1327 main_test_rfh()->PrepareForCommit(); | |
| 1294 main_test_rfh()->SendNavigateWithOriginalRequestURL( | 1328 main_test_rfh()->SendNavigateWithOriginalRequestURL( |
| 1295 0, final_url, original_url); | 1329 0, final_url, original_url); |
| 1296 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1330 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1297 navigation_entry_committed_counter_ = 0; | 1331 navigation_entry_committed_counter_ = 0; |
| 1298 | 1332 |
| 1299 // The NavigationEntry should save both the original URL and the final | 1333 // The NavigationEntry should save both the original URL and the final |
| 1300 // redirected URL. | 1334 // redirected URL. |
| 1301 EXPECT_EQ( | 1335 EXPECT_EQ( |
| 1302 original_url, controller.GetVisibleEntry()->GetOriginalRequestURL()); | 1336 original_url, controller.GetVisibleEntry()->GetOriginalRequestURL()); |
| 1303 EXPECT_EQ(final_url, controller.GetVisibleEntry()->GetURL()); | 1337 EXPECT_EQ(final_url, controller.GetVisibleEntry()->GetURL()); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1316 EXPECT_TRUE(controller.GetPendingEntry()); | 1350 EXPECT_TRUE(controller.GetPendingEntry()); |
| 1317 EXPECT_FALSE(controller.CanGoBack()); | 1351 EXPECT_FALSE(controller.CanGoBack()); |
| 1318 EXPECT_FALSE(controller.CanGoForward()); | 1352 EXPECT_FALSE(controller.CanGoForward()); |
| 1319 | 1353 |
| 1320 // Make sure the title has been cleared (will be redrawn just after reload). | 1354 // Make sure the title has been cleared (will be redrawn just after reload). |
| 1321 // Avoids a stale cached title when the new page being reloaded has no title. | 1355 // Avoids a stale cached title when the new page being reloaded has no title. |
| 1322 // See http://crbug.com/96041. | 1356 // See http://crbug.com/96041. |
| 1323 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); | 1357 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); |
| 1324 | 1358 |
| 1325 // Send that the navigation has proceeded; say it got redirected again. | 1359 // Send that the navigation has proceeded; say it got redirected again. |
| 1326 main_test_rfh()->PrepareForCommit(final_url); | 1360 SimulateServerRedirect(main_test_rfh(), final_url); |
| 1361 main_test_rfh()->PrepareForCommit(); | |
| 1327 main_test_rfh()->SendNavigate(0, final_url); | 1362 main_test_rfh()->SendNavigate(0, final_url); |
| 1328 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1363 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1329 navigation_entry_committed_counter_ = 0; | 1364 navigation_entry_committed_counter_ = 0; |
| 1330 | 1365 |
| 1331 // Now the reload is committed. | 1366 // Now the reload is committed. |
| 1332 EXPECT_EQ(controller.GetEntryCount(), 1); | 1367 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 1333 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1368 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1334 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1369 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1335 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1370 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1336 EXPECT_FALSE(controller.GetPendingEntry()); | 1371 EXPECT_FALSE(controller.GetPendingEntry()); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1480 NavigationControllerImpl& controller = controller_impl(); | 1515 NavigationControllerImpl& controller = controller_impl(); |
| 1481 TestNotificationTracker notifications; | 1516 TestNotificationTracker notifications; |
| 1482 RegisterForAllNavNotifications(¬ifications, &controller); | 1517 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1483 | 1518 |
| 1484 const GURL url1("http://foo/1"); | 1519 const GURL url1("http://foo/1"); |
| 1485 const GURL url2("http://foo/2"); | 1520 const GURL url2("http://foo/2"); |
| 1486 const GURL url3("http://foo/3"); | 1521 const GURL url3("http://foo/3"); |
| 1487 | 1522 |
| 1488 controller.LoadURL( | 1523 controller.LoadURL( |
| 1489 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1524 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1490 main_test_rfh()->PrepareForCommit(url1); | 1525 main_test_rfh()->PrepareForCommit(); |
| 1491 main_test_rfh()->SendNavigate(0, url1); | 1526 main_test_rfh()->SendNavigate(0, url1); |
| 1492 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1527 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1493 navigation_entry_committed_counter_ = 0; | 1528 navigation_entry_committed_counter_ = 0; |
| 1494 | 1529 |
| 1495 controller.LoadURL( | 1530 controller.LoadURL( |
| 1496 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1531 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1497 main_test_rfh()->PrepareForCommit(url2); | 1532 main_test_rfh()->PrepareForCommit(); |
| 1498 main_test_rfh()->SendNavigate(1, url2); | 1533 main_test_rfh()->SendNavigate(1, url2); |
| 1499 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1534 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1500 navigation_entry_committed_counter_ = 0; | 1535 navigation_entry_committed_counter_ = 0; |
| 1501 | 1536 |
| 1502 controller.GoBack(); | 1537 controller.GoBack(); |
| 1503 EXPECT_EQ(0U, notifications.size()); | 1538 EXPECT_EQ(0U, notifications.size()); |
| 1504 | 1539 |
| 1505 // We should now have a pending navigation to go back. | 1540 // We should now have a pending navigation to go back. |
| 1506 EXPECT_EQ(controller.GetEntryCount(), 2); | 1541 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 1507 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1542 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
| 1508 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 1543 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
| 1509 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1544 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1510 EXPECT_TRUE(controller.GetPendingEntry()); | 1545 EXPECT_TRUE(controller.GetPendingEntry()); |
| 1511 EXPECT_FALSE(controller.CanGoBack()); | 1546 EXPECT_FALSE(controller.CanGoBack()); |
| 1512 EXPECT_TRUE(controller.CanGoForward()); | 1547 EXPECT_TRUE(controller.CanGoForward()); |
| 1513 | 1548 |
| 1514 main_test_rfh()->PrepareForCommit(url3); | 1549 SimulateServerRedirect(main_test_rfh(), url3); |
| 1550 main_test_rfh()->PrepareForCommit(); | |
| 1515 main_test_rfh()->SendNavigate(2, url3); | 1551 main_test_rfh()->SendNavigate(2, url3); |
| 1516 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1552 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1517 navigation_entry_committed_counter_ = 0; | 1553 navigation_entry_committed_counter_ = 0; |
| 1518 | 1554 |
| 1519 // The back navigation resulted in a completely new navigation. | 1555 // The back navigation resulted in a completely new navigation. |
| 1520 // TODO(darin): perhaps this behavior will be confusing to users? | 1556 // TODO(darin): perhaps this behavior will be confusing to users? |
| 1521 EXPECT_EQ(controller.GetEntryCount(), 3); | 1557 EXPECT_EQ(controller.GetEntryCount(), 3); |
| 1522 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 2); | 1558 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 2); |
| 1523 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1559 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1524 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1560 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1562 | 1598 |
| 1563 // Receives a back message when there is a different renavigation already | 1599 // Receives a back message when there is a different renavigation already |
| 1564 // pending. | 1600 // pending. |
| 1565 TEST_F(NavigationControllerTest, Back_OtherBackPending) { | 1601 TEST_F(NavigationControllerTest, Back_OtherBackPending) { |
| 1566 NavigationControllerImpl& controller = controller_impl(); | 1602 NavigationControllerImpl& controller = controller_impl(); |
| 1567 const GURL kUrl1("http://foo/1"); | 1603 const GURL kUrl1("http://foo/1"); |
| 1568 const GURL kUrl2("http://foo/2"); | 1604 const GURL kUrl2("http://foo/2"); |
| 1569 const GURL kUrl3("http://foo/3"); | 1605 const GURL kUrl3("http://foo/3"); |
| 1570 | 1606 |
| 1571 // First navigate three places so we have some back history. | 1607 // First navigate three places so we have some back history. |
| 1572 main_test_rfh()->PrepareForCommit(kUrl1); | 1608 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl1, true); |
| 1609 main_test_rfh()->PrepareForCommit(); | |
| 1573 main_test_rfh()->SendNavigate(0, kUrl1); | 1610 main_test_rfh()->SendNavigate(0, kUrl1); |
| 1574 main_test_rfh()->PrepareForCommit(kUrl2); | 1611 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl2, true); |
| 1612 main_test_rfh()->PrepareForCommit(); | |
| 1575 main_test_rfh()->SendNavigate(1, kUrl2); | 1613 main_test_rfh()->SendNavigate(1, kUrl2); |
| 1576 main_test_rfh()->PrepareForCommit(kUrl3); | 1614 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl3, true); |
| 1615 main_test_rfh()->PrepareForCommit(); | |
| 1577 main_test_rfh()->SendNavigate(2, kUrl3); | 1616 main_test_rfh()->SendNavigate(2, kUrl3); |
| 1578 | 1617 |
| 1579 // With nothing pending, say we get a navigation to the second entry. | 1618 // With nothing pending, say we get a navigation to the second entry. |
| 1580 main_test_rfh()->PrepareForCommit(kUrl2); | 1619 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl2, true); |
| 1620 main_test_rfh()->PrepareForCommit(); | |
| 1581 main_test_rfh()->SendNavigate(1, kUrl2); | 1621 main_test_rfh()->SendNavigate(1, kUrl2); |
| 1582 | 1622 |
| 1583 // We know all the entries have the same site instance, so we can just grab | 1623 // We know all the entries have the same site instance, so we can just grab |
| 1584 // a random one for looking up other entries. | 1624 // a random one for looking up other entries. |
| 1585 SiteInstance* site_instance = | 1625 SiteInstance* site_instance = |
| 1586 controller.GetLastCommittedEntry()->site_instance(); | 1626 controller.GetLastCommittedEntry()->site_instance(); |
| 1587 | 1627 |
| 1588 // That second URL should be the last committed and it should have gotten the | 1628 // That second URL should be the last committed and it should have gotten the |
| 1589 // new title. | 1629 // new title. |
| 1590 EXPECT_EQ(kUrl2, controller.GetEntryWithPageID(site_instance, 1)->GetURL()); | 1630 EXPECT_EQ(kUrl2, controller.GetEntryWithPageID(site_instance, 1)->GetURL()); |
| 1591 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 1631 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 1592 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1632 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 1593 | 1633 |
| 1594 // Now go forward to the last item again and say it was committed. | 1634 // Now go forward to the last item again and say it was committed. |
| 1595 controller.GoForward(); | 1635 controller.GoForward(); |
| 1596 main_test_rfh()->PrepareForCommit(kUrl3); | 1636 main_test_rfh()->PrepareForCommit(); |
| 1597 main_test_rfh()->SendNavigate(2, kUrl3); | 1637 main_test_rfh()->SendNavigate(2, kUrl3); |
| 1598 | 1638 |
| 1599 // Now start going back one to the second page. It will be pending. | 1639 // Now start going back one to the second page. It will be pending. |
| 1600 controller.GoBack(); | 1640 controller.GoBack(); |
| 1601 EXPECT_EQ(1, controller.GetPendingEntryIndex()); | 1641 EXPECT_EQ(1, controller.GetPendingEntryIndex()); |
| 1602 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 1642 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
| 1603 | 1643 |
| 1604 // Not synthesize a totally new back event to the first page. This will not | 1644 // Now synthesize a totally new back event to the first page. This will not |
| 1605 // match the pending one. | 1645 // match the pending one. |
| 1606 main_test_rfh()->PrepareForCommit(kUrl1); | 1646 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl1, true); |
| 1647 main_test_rfh()->PrepareForCommit(); | |
| 1607 main_test_rfh()->SendNavigate(0, kUrl1); | 1648 main_test_rfh()->SendNavigate(0, kUrl1); |
| 1608 | 1649 |
| 1609 // The committed navigation should clear the pending entry. | 1650 // The committed navigation should clear the pending entry. |
| 1610 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1651 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 1611 | 1652 |
| 1612 // But the navigated entry should be the last committed. | 1653 // But the navigated entry should be the last committed. |
| 1613 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 1654 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 1614 EXPECT_EQ(kUrl1, controller.GetLastCommittedEntry()->GetURL()); | 1655 EXPECT_EQ(kUrl1, controller.GetLastCommittedEntry()->GetURL()); |
| 1615 } | 1656 } |
| 1616 | 1657 |
| 1617 // Tests what happens when we navigate forward successfully. | 1658 // Tests what happens when we navigate forward successfully. |
| 1618 TEST_F(NavigationControllerTest, Forward) { | 1659 TEST_F(NavigationControllerTest, Forward) { |
| 1619 NavigationControllerImpl& controller = controller_impl(); | 1660 NavigationControllerImpl& controller = controller_impl(); |
| 1620 TestNotificationTracker notifications; | 1661 TestNotificationTracker notifications; |
| 1621 RegisterForAllNavNotifications(¬ifications, &controller); | 1662 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1622 | 1663 |
| 1623 const GURL url1("http://foo1"); | 1664 const GURL url1("http://foo1"); |
| 1624 const GURL url2("http://foo2"); | 1665 const GURL url2("http://foo2"); |
| 1625 | 1666 |
| 1626 main_test_rfh()->PrepareForCommit(url1); | 1667 main_test_rfh()->PrepareForCommit(); |
| 1627 main_test_rfh()->SendNavigate(0, url1); | 1668 main_test_rfh()->SendNavigate(0, url1); |
| 1628 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1669 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1629 navigation_entry_committed_counter_ = 0; | 1670 navigation_entry_committed_counter_ = 0; |
| 1630 | 1671 |
| 1631 main_test_rfh()->PrepareForCommit(url2); | 1672 main_test_rfh()->PrepareForCommit(); |
| 1632 main_test_rfh()->SendNavigate(1, url2); | 1673 main_test_rfh()->SendNavigate(1, url2); |
| 1633 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1674 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1634 navigation_entry_committed_counter_ = 0; | 1675 navigation_entry_committed_counter_ = 0; |
| 1635 | 1676 |
| 1636 controller.GoBack(); | 1677 controller.GoBack(); |
| 1637 main_test_rfh()->PrepareForCommit(url1); | 1678 main_test_rfh()->PrepareForCommit(); |
| 1638 main_test_rfh()->SendNavigate(0, url1); | 1679 main_test_rfh()->SendNavigate(0, url1); |
| 1639 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1680 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1640 navigation_entry_committed_counter_ = 0; | 1681 navigation_entry_committed_counter_ = 0; |
| 1641 | 1682 |
| 1642 controller.GoForward(); | 1683 controller.GoForward(); |
| 1643 | 1684 |
| 1644 // We should now have a pending navigation to go forward. | 1685 // We should now have a pending navigation to go forward. |
| 1645 EXPECT_EQ(controller.GetEntryCount(), 2); | 1686 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 1646 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1687 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1647 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); | 1688 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); |
| 1648 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1689 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1649 EXPECT_TRUE(controller.GetPendingEntry()); | 1690 EXPECT_TRUE(controller.GetPendingEntry()); |
| 1650 EXPECT_TRUE(controller.CanGoBack()); | 1691 EXPECT_TRUE(controller.CanGoBack()); |
| 1651 EXPECT_TRUE(controller.CanGoToOffset(-1)); | 1692 EXPECT_TRUE(controller.CanGoToOffset(-1)); |
| 1652 EXPECT_FALSE(controller.CanGoToOffset(-2)); // Cannot go back 2 steps. | 1693 EXPECT_FALSE(controller.CanGoToOffset(-2)); // Cannot go back 2 steps. |
| 1653 EXPECT_FALSE(controller.CanGoForward()); | 1694 EXPECT_FALSE(controller.CanGoForward()); |
| 1654 EXPECT_FALSE(controller.CanGoToOffset(1)); | 1695 EXPECT_FALSE(controller.CanGoToOffset(1)); |
| 1655 | 1696 |
| 1656 // Timestamp for entry 0 should be on or after that of entry 1 | 1697 // Timestamp for entry 0 should be on or after that of entry 1 |
| 1657 // (since we went back to it). | 1698 // (since we went back to it). |
| 1658 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null()); | 1699 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null()); |
| 1659 EXPECT_GE(controller.GetEntryAtIndex(0)->GetTimestamp(), | 1700 EXPECT_GE(controller.GetEntryAtIndex(0)->GetTimestamp(), |
| 1660 controller.GetEntryAtIndex(1)->GetTimestamp()); | 1701 controller.GetEntryAtIndex(1)->GetTimestamp()); |
| 1661 | 1702 |
| 1662 main_test_rfh()->PrepareForCommit(url2); | 1703 main_test_rfh()->PrepareForCommit(); |
| 1663 main_test_rfh()->SendNavigate(1, url2); | 1704 main_test_rfh()->SendNavigate(1, url2); |
| 1664 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1705 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1665 navigation_entry_committed_counter_ = 0; | 1706 navigation_entry_committed_counter_ = 0; |
| 1666 | 1707 |
| 1667 // The forward navigation completed successfully. | 1708 // The forward navigation completed successfully. |
| 1668 EXPECT_EQ(controller.GetEntryCount(), 2); | 1709 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 1669 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1710 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
| 1670 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1711 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1671 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1712 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1672 EXPECT_FALSE(controller.GetPendingEntry()); | 1713 EXPECT_FALSE(controller.GetPendingEntry()); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1685 // Tests what happens when a forward navigation produces a new page. | 1726 // Tests what happens when a forward navigation produces a new page. |
| 1686 TEST_F(NavigationControllerTest, Forward_GeneratesNewPage) { | 1727 TEST_F(NavigationControllerTest, Forward_GeneratesNewPage) { |
| 1687 NavigationControllerImpl& controller = controller_impl(); | 1728 NavigationControllerImpl& controller = controller_impl(); |
| 1688 TestNotificationTracker notifications; | 1729 TestNotificationTracker notifications; |
| 1689 RegisterForAllNavNotifications(¬ifications, &controller); | 1730 RegisterForAllNavNotifications(¬ifications, &controller); |
| 1690 | 1731 |
| 1691 const GURL url1("http://foo1"); | 1732 const GURL url1("http://foo1"); |
| 1692 const GURL url2("http://foo2"); | 1733 const GURL url2("http://foo2"); |
| 1693 const GURL url3("http://foo3"); | 1734 const GURL url3("http://foo3"); |
| 1694 | 1735 |
| 1695 main_test_rfh()->PrepareForCommit(url1); | 1736 main_test_rfh()->PrepareForCommit(); |
| 1696 main_test_rfh()->SendNavigate(0, url1); | 1737 main_test_rfh()->SendNavigate(0, url1); |
| 1697 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1738 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1698 navigation_entry_committed_counter_ = 0; | 1739 navigation_entry_committed_counter_ = 0; |
| 1699 main_test_rfh()->PrepareForCommit(url2); | 1740 main_test_rfh()->PrepareForCommit(); |
| 1700 main_test_rfh()->SendNavigate(1, url2); | 1741 main_test_rfh()->SendNavigate(1, url2); |
| 1701 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1742 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1702 navigation_entry_committed_counter_ = 0; | 1743 navigation_entry_committed_counter_ = 0; |
| 1703 | 1744 |
| 1704 controller.GoBack(); | 1745 controller.GoBack(); |
| 1705 main_test_rfh()->PrepareForCommit(url1); | 1746 main_test_rfh()->PrepareForCommit(); |
| 1706 main_test_rfh()->SendNavigate(0, url1); | 1747 main_test_rfh()->SendNavigate(0, url1); |
| 1707 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1748 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1708 navigation_entry_committed_counter_ = 0; | 1749 navigation_entry_committed_counter_ = 0; |
| 1709 | 1750 |
| 1710 controller.GoForward(); | 1751 controller.GoForward(); |
| 1711 EXPECT_EQ(0U, notifications.size()); | 1752 EXPECT_EQ(0U, notifications.size()); |
| 1712 | 1753 |
| 1713 // Should now have a pending navigation to go forward. | 1754 // Should now have a pending navigation to go forward. |
| 1714 EXPECT_EQ(controller.GetEntryCount(), 2); | 1755 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 1715 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1756 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1716 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); | 1757 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); |
| 1717 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1758 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1718 EXPECT_TRUE(controller.GetPendingEntry()); | 1759 EXPECT_TRUE(controller.GetPendingEntry()); |
| 1719 EXPECT_TRUE(controller.CanGoBack()); | 1760 EXPECT_TRUE(controller.CanGoBack()); |
| 1720 EXPECT_FALSE(controller.CanGoForward()); | 1761 EXPECT_FALSE(controller.CanGoForward()); |
| 1721 | 1762 |
| 1722 main_test_rfh()->PrepareForCommit(url3); | 1763 main_test_rfh()->PrepareForCommit(); |
| 1723 main_test_rfh()->SendNavigate(2, url3); | 1764 main_test_rfh()->SendNavigate(2, url3); |
| 1724 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1765 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1725 navigation_entry_committed_counter_ = 0; | 1766 navigation_entry_committed_counter_ = 0; |
| 1726 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_LIST_PRUNED)); | 1767 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_LIST_PRUNED)); |
| 1727 | 1768 |
| 1728 EXPECT_EQ(controller.GetEntryCount(), 2); | 1769 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 1729 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1770 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
| 1730 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1771 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 1731 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1772 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1732 EXPECT_FALSE(controller.GetPendingEntry()); | 1773 EXPECT_FALSE(controller.GetPendingEntry()); |
| (...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2377 const int kMaxEntryCount = 5; | 2418 const int kMaxEntryCount = 5; |
| 2378 | 2419 |
| 2379 NavigationControllerImpl::set_max_entry_count_for_testing(kMaxEntryCount); | 2420 NavigationControllerImpl::set_max_entry_count_for_testing(kMaxEntryCount); |
| 2380 | 2421 |
| 2381 int url_index; | 2422 int url_index; |
| 2382 // Load up to the max count, all entries should be there. | 2423 // Load up to the max count, all entries should be there. |
| 2383 for (url_index = 0; url_index < kMaxEntryCount; url_index++) { | 2424 for (url_index = 0; url_index < kMaxEntryCount; url_index++) { |
| 2384 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); | 2425 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); |
| 2385 controller.LoadURL( | 2426 controller.LoadURL( |
| 2386 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2427 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2387 main_test_rfh()->PrepareForCommit(url); | 2428 main_test_rfh()->PrepareForCommit(); |
| 2388 main_test_rfh()->SendNavigate(url_index, url); | 2429 main_test_rfh()->SendNavigate(url_index, url); |
| 2389 } | 2430 } |
| 2390 | 2431 |
| 2391 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); | 2432 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); |
| 2392 | 2433 |
| 2393 // Created a PrunedListener to observe prune notifications. | 2434 // Created a PrunedListener to observe prune notifications. |
| 2394 PrunedListener listener(&controller); | 2435 PrunedListener listener(&controller); |
| 2395 | 2436 |
| 2396 // Navigate some more. | 2437 // Navigate some more. |
| 2397 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); | 2438 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); |
| 2398 controller.LoadURL( | 2439 controller.LoadURL( |
| 2399 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2440 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2400 main_test_rfh()->PrepareForCommit(url); | 2441 main_test_rfh()->PrepareForCommit(); |
| 2401 main_test_rfh()->SendNavigate(url_index, url); | 2442 main_test_rfh()->SendNavigate(url_index, url); |
| 2402 url_index++; | 2443 url_index++; |
| 2403 | 2444 |
| 2404 // We should have got a pruned navigation. | 2445 // We should have got a pruned navigation. |
| 2405 EXPECT_EQ(1, listener.notification_count_); | 2446 EXPECT_EQ(1, listener.notification_count_); |
| 2406 EXPECT_TRUE(listener.details_.from_front); | 2447 EXPECT_TRUE(listener.details_.from_front); |
| 2407 EXPECT_EQ(1, listener.details_.count); | 2448 EXPECT_EQ(1, listener.details_.count); |
| 2408 | 2449 |
| 2409 // We expect http://www.a.com/0 to be gone. | 2450 // We expect http://www.a.com/0 to be gone. |
| 2410 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); | 2451 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); |
| 2411 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), | 2452 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), |
| 2412 GURL("http:////www.a.com/1")); | 2453 GURL("http:////www.a.com/1")); |
| 2413 | 2454 |
| 2414 // More navigations. | 2455 // More navigations. |
| 2415 for (int i = 0; i < 3; i++) { | 2456 for (int i = 0; i < 3; i++) { |
| 2416 url = GURL(base::StringPrintf("http:////www.a.com/%d", url_index)); | 2457 url = GURL(base::StringPrintf("http:////www.a.com/%d", url_index)); |
| 2417 controller.LoadURL( | 2458 controller.LoadURL( |
| 2418 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2459 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2419 main_test_rfh()->PrepareForCommit(url); | 2460 main_test_rfh()->PrepareForCommit(); |
| 2420 main_test_rfh()->SendNavigate(url_index, url); | 2461 main_test_rfh()->SendNavigate(url_index, url); |
| 2421 url_index++; | 2462 url_index++; |
| 2422 } | 2463 } |
| 2423 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); | 2464 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); |
| 2424 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), | 2465 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), |
| 2425 GURL("http:////www.a.com/4")); | 2466 GURL("http:////www.a.com/4")); |
| 2426 | 2467 |
| 2427 NavigationControllerImpl::set_max_entry_count_for_testing(original_count); | 2468 NavigationControllerImpl::set_max_entry_count_for_testing(original_count); |
| 2428 } | 2469 } |
| 2429 | 2470 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2574 our_controller.GetEntryAtIndex(0)->restore_type()); | 2615 our_controller.GetEntryAtIndex(0)->restore_type()); |
| 2575 } | 2616 } |
| 2576 | 2617 |
| 2577 // Make sure that the page type and stuff is correct after an interstitial. | 2618 // Make sure that the page type and stuff is correct after an interstitial. |
| 2578 TEST_F(NavigationControllerTest, Interstitial) { | 2619 TEST_F(NavigationControllerTest, Interstitial) { |
| 2579 NavigationControllerImpl& controller = controller_impl(); | 2620 NavigationControllerImpl& controller = controller_impl(); |
| 2580 // First navigate somewhere normal. | 2621 // First navigate somewhere normal. |
| 2581 const GURL url1("http://foo"); | 2622 const GURL url1("http://foo"); |
| 2582 controller.LoadURL( | 2623 controller.LoadURL( |
| 2583 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2624 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2584 main_test_rfh()->PrepareForCommit(url1); | 2625 main_test_rfh()->PrepareForCommit(); |
| 2585 main_test_rfh()->SendNavigate(0, url1); | 2626 main_test_rfh()->SendNavigate(0, url1); |
| 2586 | 2627 |
| 2587 // Now navigate somewhere with an interstitial. | 2628 // Now navigate somewhere with an interstitial. |
| 2588 const GURL url2("http://bar"); | 2629 const GURL url2("http://bar"); |
| 2589 controller.LoadURL( | 2630 controller.LoadURL(url2, Referrer(), ui::PAGE_TRANSITION_TYPED, |
|
carlosk
2015/02/23 16:42:02
Replaced this at it seemed the test was not using
| |
| 2590 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2631 std::string()); |
| 2591 controller.GetPendingEntry()->set_page_type(PAGE_TYPE_INTERSTITIAL); | 2632 controller.GetPendingEntry()->set_page_type(PAGE_TYPE_INTERSTITIAL); |
| 2592 | 2633 |
| 2593 // At this point the interstitial will be displayed and the load will still | 2634 // At this point the interstitial will be displayed and the load will still |
| 2594 // be pending. If the user continues, the load will commit. | 2635 // be pending. If the user continues, the load will commit. |
| 2595 main_test_rfh()->PrepareForCommit(url2); | 2636 main_test_rfh()->PrepareForCommit(); |
| 2596 main_test_rfh()->SendNavigate(1, url2); | 2637 main_test_rfh()->SendNavigate(1, url2); |
| 2597 | 2638 |
| 2598 // The page should be a normal page again. | 2639 // The page should be a normal page again. |
| 2599 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); | 2640 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); |
| 2600 EXPECT_EQ(PAGE_TYPE_NORMAL, | 2641 EXPECT_EQ(PAGE_TYPE_NORMAL, |
| 2601 controller.GetLastCommittedEntry()->GetPageType()); | 2642 controller.GetLastCommittedEntry()->GetPageType()); |
| 2602 } | 2643 } |
| 2603 | 2644 |
| 2604 TEST_F(NavigationControllerTest, RemoveEntry) { | 2645 TEST_F(NavigationControllerTest, RemoveEntry) { |
| 2605 NavigationControllerImpl& controller = controller_impl(); | 2646 NavigationControllerImpl& controller = controller_impl(); |
| 2606 const GURL url1("http://foo/1"); | 2647 const GURL url1("http://foo/1"); |
| 2607 const GURL url2("http://foo/2"); | 2648 const GURL url2("http://foo/2"); |
| 2608 const GURL url3("http://foo/3"); | 2649 const GURL url3("http://foo/3"); |
| 2609 const GURL url4("http://foo/4"); | 2650 const GURL url4("http://foo/4"); |
| 2610 const GURL url5("http://foo/5"); | 2651 const GURL url5("http://foo/5"); |
| 2611 const GURL pending_url("http://foo/pending"); | 2652 const GURL pending_url("http://foo/pending"); |
| 2612 const GURL default_url("http://foo/default"); | 2653 const GURL default_url("http://foo/default"); |
| 2613 | 2654 |
| 2614 controller.LoadURL( | 2655 controller.LoadURL( |
| 2615 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2656 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2616 main_test_rfh()->PrepareForCommit(url1); | 2657 main_test_rfh()->PrepareForCommit(); |
| 2617 main_test_rfh()->SendNavigate(0, url1); | 2658 main_test_rfh()->SendNavigate(0, url1); |
| 2618 controller.LoadURL( | 2659 controller.LoadURL( |
| 2619 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2660 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2620 main_test_rfh()->PrepareForCommit(url2); | 2661 main_test_rfh()->PrepareForCommit(); |
| 2621 main_test_rfh()->SendNavigate(1, url2); | 2662 main_test_rfh()->SendNavigate(1, url2); |
| 2622 controller.LoadURL( | 2663 controller.LoadURL( |
| 2623 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2664 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2624 main_test_rfh()->PrepareForCommit(url3); | 2665 main_test_rfh()->PrepareForCommit(); |
| 2625 main_test_rfh()->SendNavigate(2, url3); | 2666 main_test_rfh()->SendNavigate(2, url3); |
| 2626 controller.LoadURL( | 2667 controller.LoadURL( |
| 2627 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2668 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2628 main_test_rfh()->PrepareForCommit(url4); | 2669 main_test_rfh()->PrepareForCommit(); |
| 2629 main_test_rfh()->SendNavigate(3, url4); | 2670 main_test_rfh()->SendNavigate(3, url4); |
| 2630 controller.LoadURL( | 2671 controller.LoadURL( |
| 2631 url5, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2672 url5, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2632 main_test_rfh()->PrepareForCommit(url5); | 2673 main_test_rfh()->PrepareForCommit(); |
| 2633 main_test_rfh()->SendNavigate(4, url5); | 2674 main_test_rfh()->SendNavigate(4, url5); |
| 2634 | 2675 |
| 2635 // Try to remove the last entry. Will fail because it is the current entry. | 2676 // Try to remove the last entry. Will fail because it is the current entry. |
| 2636 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); | 2677 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); |
| 2637 EXPECT_EQ(5, controller.GetEntryCount()); | 2678 EXPECT_EQ(5, controller.GetEntryCount()); |
| 2638 EXPECT_EQ(4, controller.GetLastCommittedEntryIndex()); | 2679 EXPECT_EQ(4, controller.GetLastCommittedEntryIndex()); |
| 2639 | 2680 |
| 2640 // Go back, but don't commit yet. Check that we can't delete the current | 2681 // Go back, but don't commit yet. Check that we can't delete the current |
| 2641 // and pending entries. | 2682 // and pending entries. |
| 2642 controller.GoBack(); | 2683 controller.GoBack(); |
| 2643 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); | 2684 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); |
| 2644 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 2)); | 2685 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 2)); |
| 2645 | 2686 |
| 2646 // Now commit and delete the last entry. | 2687 // Now commit and delete the last entry. |
| 2647 main_test_rfh()->PrepareForCommit(url4); | 2688 main_test_rfh()->PrepareForCommit(); |
| 2648 main_test_rfh()->SendNavigate(3, url4); | 2689 main_test_rfh()->SendNavigate(3, url4); |
| 2649 EXPECT_TRUE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); | 2690 EXPECT_TRUE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); |
| 2650 EXPECT_EQ(4, controller.GetEntryCount()); | 2691 EXPECT_EQ(4, controller.GetEntryCount()); |
| 2651 EXPECT_EQ(3, controller.GetLastCommittedEntryIndex()); | 2692 EXPECT_EQ(3, controller.GetLastCommittedEntryIndex()); |
| 2652 EXPECT_FALSE(controller.GetPendingEntry()); | 2693 EXPECT_FALSE(controller.GetPendingEntry()); |
| 2653 | 2694 |
| 2654 // Remove an entry which is not the last committed one. | 2695 // Remove an entry which is not the last committed one. |
| 2655 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); | 2696 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); |
| 2656 EXPECT_EQ(3, controller.GetEntryCount()); | 2697 EXPECT_EQ(3, controller.GetEntryCount()); |
| 2657 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 2698 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 2668 | 2709 |
| 2669 TEST_F(NavigationControllerTest, RemoveEntryWithPending) { | 2710 TEST_F(NavigationControllerTest, RemoveEntryWithPending) { |
| 2670 NavigationControllerImpl& controller = controller_impl(); | 2711 NavigationControllerImpl& controller = controller_impl(); |
| 2671 const GURL url1("http://foo/1"); | 2712 const GURL url1("http://foo/1"); |
| 2672 const GURL url2("http://foo/2"); | 2713 const GURL url2("http://foo/2"); |
| 2673 const GURL url3("http://foo/3"); | 2714 const GURL url3("http://foo/3"); |
| 2674 const GURL default_url("http://foo/default"); | 2715 const GURL default_url("http://foo/default"); |
| 2675 | 2716 |
| 2676 controller.LoadURL( | 2717 controller.LoadURL( |
| 2677 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2718 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2678 main_test_rfh()->PrepareForCommit(url1); | 2719 main_test_rfh()->PrepareForCommit(); |
| 2679 main_test_rfh()->SendNavigate(0, url1); | 2720 main_test_rfh()->SendNavigate(0, url1); |
| 2680 controller.LoadURL( | 2721 controller.LoadURL( |
| 2681 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2722 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2682 main_test_rfh()->PrepareForCommit(url2); | 2723 main_test_rfh()->PrepareForCommit(); |
| 2683 main_test_rfh()->SendNavigate(1, url2); | 2724 main_test_rfh()->SendNavigate(1, url2); |
| 2684 controller.LoadURL( | 2725 controller.LoadURL( |
| 2685 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2726 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2686 main_test_rfh()->PrepareForCommit(url3); | 2727 main_test_rfh()->PrepareForCommit(); |
| 2687 main_test_rfh()->SendNavigate(2, url3); | 2728 main_test_rfh()->SendNavigate(2, url3); |
| 2688 | 2729 |
| 2689 // Go back, but don't commit yet. Check that we can't delete the current | 2730 // Go back, but don't commit yet. Check that we can't delete the current |
| 2690 // and pending entries. | 2731 // and pending entries. |
| 2691 controller.GoBack(); | 2732 controller.GoBack(); |
| 2692 EXPECT_FALSE(controller.RemoveEntryAtIndex(2)); | 2733 EXPECT_FALSE(controller.RemoveEntryAtIndex(2)); |
| 2693 EXPECT_FALSE(controller.RemoveEntryAtIndex(1)); | 2734 EXPECT_FALSE(controller.RemoveEntryAtIndex(1)); |
| 2694 | 2735 |
| 2695 // Remove the first entry, while there is a pending entry. This is expected | 2736 // Remove the first entry, while there is a pending entry. This is expected |
| 2696 // to discard the pending entry. | 2737 // to discard the pending entry. |
| 2697 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); | 2738 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); |
| 2698 EXPECT_FALSE(controller.GetPendingEntry()); | 2739 EXPECT_FALSE(controller.GetPendingEntry()); |
| 2699 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 2740 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 2700 | 2741 |
| 2701 // We should update the last committed entry index. | 2742 // We should update the last committed entry index. |
| 2702 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 2743 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 2703 | 2744 |
| 2704 // Now commit and ensure we land on the right entry. | 2745 // Now commit and ensure we land on the right entry. |
| 2705 main_test_rfh()->PrepareForCommit(url2); | 2746 main_test_rfh()->PrepareForCommit(); |
| 2706 main_test_rfh()->SendNavigate(1, url2); | 2747 main_test_rfh()->SendNavigate(1, url2); |
| 2707 EXPECT_EQ(2, controller.GetEntryCount()); | 2748 EXPECT_EQ(2, controller.GetEntryCount()); |
| 2708 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 2749 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 2709 EXPECT_FALSE(controller.GetPendingEntry()); | 2750 EXPECT_FALSE(controller.GetPendingEntry()); |
| 2710 } | 2751 } |
| 2711 | 2752 |
| 2712 // Tests the transient entry, making sure it goes away with all navigations. | 2753 // Tests the transient entry, making sure it goes away with all navigations. |
| 2713 TEST_F(NavigationControllerTest, TransientEntry) { | 2754 TEST_F(NavigationControllerTest, TransientEntry) { |
| 2714 NavigationControllerImpl& controller = controller_impl(); | 2755 NavigationControllerImpl& controller = controller_impl(); |
| 2715 TestNotificationTracker notifications; | 2756 TestNotificationTracker notifications; |
| 2716 RegisterForAllNavNotifications(¬ifications, &controller); | 2757 RegisterForAllNavNotifications(¬ifications, &controller); |
| 2717 | 2758 |
| 2718 const GURL url0("http://foo/0"); | 2759 const GURL url0("http://foo/0"); |
| 2719 const GURL url1("http://foo/1"); | 2760 const GURL url1("http://foo/1"); |
| 2720 const GURL url2("http://foo/2"); | 2761 const GURL url2("http://foo/2"); |
| 2721 const GURL url3("http://foo/3"); | 2762 const GURL url3("http://foo/3"); |
| 2722 const GURL url3_ref("http://foo/3#bar"); | 2763 const GURL url3_ref("http://foo/3#bar"); |
| 2723 const GURL url4("http://foo/4"); | 2764 const GURL url4("http://foo/4"); |
| 2724 const GURL transient_url("http://foo/transient"); | 2765 const GURL transient_url("http://foo/transient"); |
| 2725 | 2766 |
| 2726 controller.LoadURL( | 2767 controller.LoadURL( |
| 2727 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2768 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2728 main_test_rfh()->PrepareForCommit(url0); | 2769 main_test_rfh()->PrepareForCommit(); |
| 2729 main_test_rfh()->SendNavigate(0, url0); | 2770 main_test_rfh()->SendNavigate(0, url0); |
| 2730 controller.LoadURL( | 2771 controller.LoadURL( |
| 2731 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2772 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2732 main_test_rfh()->PrepareForCommit(url1); | 2773 main_test_rfh()->PrepareForCommit(); |
| 2733 main_test_rfh()->SendNavigate(1, url1); | 2774 main_test_rfh()->SendNavigate(1, url1); |
| 2734 | 2775 |
| 2735 notifications.Reset(); | 2776 notifications.Reset(); |
| 2736 | 2777 |
| 2737 // Adding a transient with no pending entry. | 2778 // Adding a transient with no pending entry. |
| 2738 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; | 2779 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; |
| 2739 transient_entry->SetURL(transient_url); | 2780 transient_entry->SetURL(transient_url); |
| 2740 controller.SetTransientEntry(transient_entry); | 2781 controller.SetTransientEntry(transient_entry); |
| 2741 | 2782 |
| 2742 // We should not have received any notifications. | 2783 // We should not have received any notifications. |
| 2743 EXPECT_EQ(0U, notifications.size()); | 2784 EXPECT_EQ(0U, notifications.size()); |
| 2744 | 2785 |
| 2745 // Check our state. | 2786 // Check our state. |
| 2746 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2787 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2747 EXPECT_EQ(controller.GetEntryCount(), 3); | 2788 EXPECT_EQ(controller.GetEntryCount(), 3); |
| 2748 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 2789 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
| 2749 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 2790 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 2750 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 2791 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 2751 EXPECT_FALSE(controller.GetPendingEntry()); | 2792 EXPECT_FALSE(controller.GetPendingEntry()); |
| 2752 EXPECT_TRUE(controller.CanGoBack()); | 2793 EXPECT_TRUE(controller.CanGoBack()); |
| 2753 EXPECT_FALSE(controller.CanGoForward()); | 2794 EXPECT_FALSE(controller.CanGoForward()); |
| 2754 EXPECT_EQ(contents()->GetMaxPageID(), 1); | 2795 EXPECT_EQ(contents()->GetMaxPageID(), 1); |
| 2755 | 2796 |
| 2756 // Navigate. | 2797 // Navigate. |
| 2757 controller.LoadURL( | 2798 controller.LoadURL( |
| 2758 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2799 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2759 main_test_rfh()->PrepareForCommit(url2); | 2800 main_test_rfh()->PrepareForCommit(); |
| 2760 main_test_rfh()->SendNavigate(2, url2); | 2801 main_test_rfh()->SendNavigate(2, url2); |
| 2761 | 2802 |
| 2762 // We should have navigated, transient entry should be gone. | 2803 // We should have navigated, transient entry should be gone. |
| 2763 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); | 2804 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
| 2764 EXPECT_EQ(controller.GetEntryCount(), 3); | 2805 EXPECT_EQ(controller.GetEntryCount(), 3); |
| 2765 | 2806 |
| 2766 // Add a transient again, then navigate with no pending entry this time. | 2807 // Add a transient again, then navigate with no pending entry this time. |
| 2767 transient_entry = new NavigationEntryImpl; | 2808 transient_entry = new NavigationEntryImpl; |
| 2768 transient_entry->SetURL(transient_url); | 2809 transient_entry->SetURL(transient_url); |
| 2769 controller.SetTransientEntry(transient_entry); | 2810 controller.SetTransientEntry(transient_entry); |
| 2770 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2811 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2771 main_test_rfh()->PrepareForCommit(url3); | 2812 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3, true); |
| 2813 main_test_rfh()->PrepareForCommit(); | |
| 2772 main_test_rfh()->SendNavigate(3, url3); | 2814 main_test_rfh()->SendNavigate(3, url3); |
| 2773 // Transient entry should be gone. | 2815 // Transient entry should be gone. |
| 2774 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); | 2816 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); |
| 2775 EXPECT_EQ(controller.GetEntryCount(), 4); | 2817 EXPECT_EQ(controller.GetEntryCount(), 4); |
| 2776 | 2818 |
| 2777 // Initiate a navigation, add a transient then commit navigation. | 2819 // Initiate a navigation, add a transient then commit navigation. |
| 2778 controller.LoadURL( | 2820 controller.LoadURL( |
| 2779 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2821 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2780 transient_entry = new NavigationEntryImpl; | 2822 transient_entry = new NavigationEntryImpl; |
| 2781 transient_entry->SetURL(transient_url); | 2823 transient_entry->SetURL(transient_url); |
| 2782 controller.SetTransientEntry(transient_entry); | 2824 controller.SetTransientEntry(transient_entry); |
| 2783 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2825 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2784 main_test_rfh()->PrepareForCommit(url4); | 2826 main_test_rfh()->PrepareForCommit(); |
| 2785 main_test_rfh()->SendNavigate(4, url4); | 2827 main_test_rfh()->SendNavigate(4, url4); |
| 2786 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); | 2828 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
| 2787 EXPECT_EQ(controller.GetEntryCount(), 5); | 2829 EXPECT_EQ(controller.GetEntryCount(), 5); |
| 2788 | 2830 |
| 2789 // Add a transient and go back. This should simply remove the transient. | 2831 // Add a transient and go back. This should simply remove the transient. |
| 2790 transient_entry = new NavigationEntryImpl; | 2832 transient_entry = new NavigationEntryImpl; |
| 2791 transient_entry->SetURL(transient_url); | 2833 transient_entry->SetURL(transient_url); |
| 2792 controller.SetTransientEntry(transient_entry); | 2834 controller.SetTransientEntry(transient_entry); |
| 2793 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2835 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2794 EXPECT_TRUE(controller.CanGoBack()); | 2836 EXPECT_TRUE(controller.CanGoBack()); |
| 2795 EXPECT_FALSE(controller.CanGoForward()); | 2837 EXPECT_FALSE(controller.CanGoForward()); |
| 2796 controller.GoBack(); | 2838 controller.GoBack(); |
| 2797 // Transient entry should be gone. | 2839 // Transient entry should be gone. |
| 2798 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); | 2840 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
| 2799 EXPECT_EQ(controller.GetEntryCount(), 5); | 2841 EXPECT_EQ(controller.GetEntryCount(), 5); |
| 2800 main_test_rfh()->PrepareForCommit(url3); | 2842 |
| 2843 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3, false); | |
| 2844 main_test_rfh()->PrepareForCommit(); | |
| 2801 main_test_rfh()->SendNavigate(3, url3); | 2845 main_test_rfh()->SendNavigate(3, url3); |
| 2802 | 2846 |
| 2803 // Add a transient and go to an entry before the current one. | 2847 // Add a transient and go to an entry before the current one. |
| 2804 transient_entry = new NavigationEntryImpl; | 2848 transient_entry = new NavigationEntryImpl; |
| 2805 transient_entry->SetURL(transient_url); | 2849 transient_entry->SetURL(transient_url); |
| 2806 controller.SetTransientEntry(transient_entry); | 2850 controller.SetTransientEntry(transient_entry); |
| 2807 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2851 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2808 controller.GoToIndex(1); | 2852 controller.GoToIndex(1); |
| 2809 // The navigation should have been initiated, transient entry should be gone. | 2853 // The navigation should have been initiated, transient entry should be gone. |
| 2810 EXPECT_FALSE(controller.GetTransientEntry()); | 2854 EXPECT_FALSE(controller.GetTransientEntry()); |
| 2811 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 2855 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
| 2812 // Visible entry does not update for history navigations until commit. | 2856 // Visible entry does not update for history navigations until commit. |
| 2813 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); | 2857 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); |
| 2814 main_test_rfh()->PrepareForCommit(url1); | 2858 main_test_rfh()->PrepareForCommit(); |
| 2815 main_test_rfh()->SendNavigate(1, url1); | 2859 main_test_rfh()->SendNavigate(1, url1); |
| 2816 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 2860 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
| 2817 | 2861 |
| 2818 // Add a transient and go to an entry after the current one. | 2862 // Add a transient and go to an entry after the current one. |
| 2819 transient_entry = new NavigationEntryImpl; | 2863 transient_entry = new NavigationEntryImpl; |
| 2820 transient_entry->SetURL(transient_url); | 2864 transient_entry->SetURL(transient_url); |
| 2821 controller.SetTransientEntry(transient_entry); | 2865 controller.SetTransientEntry(transient_entry); |
| 2822 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2866 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2823 controller.GoToIndex(3); | 2867 controller.GoToIndex(3); |
| 2824 // The navigation should have been initiated, transient entry should be gone. | 2868 // The navigation should have been initiated, transient entry should be gone. |
| 2825 // Because of the transient entry that is removed, going to index 3 makes us | 2869 // Because of the transient entry that is removed, going to index 3 makes us |
| 2826 // land on url2 (which is visible after the commit). | 2870 // land on url2 (which is visible after the commit). |
| 2827 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); | 2871 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); |
| 2828 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 2872 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
| 2829 main_test_rfh()->PrepareForCommit(url2); | 2873 main_test_rfh()->PrepareForCommit(); |
| 2830 main_test_rfh()->SendNavigate(2, url2); | 2874 main_test_rfh()->SendNavigate(2, url2); |
| 2831 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); | 2875 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
| 2832 | 2876 |
| 2833 // Add a transient and go forward. | 2877 // Add a transient and go forward. |
| 2834 transient_entry = new NavigationEntryImpl; | 2878 transient_entry = new NavigationEntryImpl; |
| 2835 transient_entry->SetURL(transient_url); | 2879 transient_entry->SetURL(transient_url); |
| 2836 controller.SetTransientEntry(transient_entry); | 2880 controller.SetTransientEntry(transient_entry); |
| 2837 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2881 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2838 EXPECT_TRUE(controller.CanGoForward()); | 2882 EXPECT_TRUE(controller.CanGoForward()); |
| 2839 controller.GoForward(); | 2883 controller.GoForward(); |
| 2840 // We should have navigated, transient entry should be gone. | 2884 // We should have navigated, transient entry should be gone. |
| 2841 EXPECT_FALSE(controller.GetTransientEntry()); | 2885 EXPECT_FALSE(controller.GetTransientEntry()); |
| 2842 EXPECT_EQ(url3, controller.GetPendingEntry()->GetURL()); | 2886 EXPECT_EQ(url3, controller.GetPendingEntry()->GetURL()); |
| 2843 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); | 2887 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
| 2844 main_test_rfh()->PrepareForCommit(url3); | 2888 main_test_rfh()->PrepareForCommit(); |
| 2845 main_test_rfh()->SendNavigate(3, url3); | 2889 main_test_rfh()->SendNavigate(3, url3); |
| 2846 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); | 2890 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); |
| 2847 | 2891 |
| 2848 // Add a transient and do an in-page navigation, replacing the current entry. | 2892 // Add a transient and do an in-page navigation, replacing the current entry. |
| 2849 transient_entry = new NavigationEntryImpl; | 2893 transient_entry = new NavigationEntryImpl; |
| 2850 transient_entry->SetURL(transient_url); | 2894 transient_entry->SetURL(transient_url); |
| 2851 controller.SetTransientEntry(transient_entry); | 2895 controller.SetTransientEntry(transient_entry); |
| 2852 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2896 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2853 main_test_rfh()->PrepareForCommit(url3_ref); | 2897 |
| 2898 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3_ref, false); | |
| 2899 main_test_rfh()->PrepareForCommit(); | |
| 2854 main_test_rfh()->SendNavigate(3, url3_ref); | 2900 main_test_rfh()->SendNavigate(3, url3_ref); |
| 2855 // Transient entry should be gone. | 2901 // Transient entry should be gone. |
| 2856 EXPECT_FALSE(controller.GetTransientEntry()); | 2902 EXPECT_FALSE(controller.GetTransientEntry()); |
| 2857 EXPECT_EQ(url3_ref, controller.GetVisibleEntry()->GetURL()); | 2903 EXPECT_EQ(url3_ref, controller.GetVisibleEntry()->GetURL()); |
| 2858 | 2904 |
| 2859 // Ensure the URLs are correct. | 2905 // Ensure the URLs are correct. |
| 2860 EXPECT_EQ(controller.GetEntryCount(), 5); | 2906 EXPECT_EQ(controller.GetEntryCount(), 5); |
| 2861 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 2907 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
| 2862 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), url1); | 2908 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), url1); |
| 2863 EXPECT_EQ(controller.GetEntryAtIndex(2)->GetURL(), url2); | 2909 EXPECT_EQ(controller.GetEntryAtIndex(2)->GetURL(), url2); |
| 2864 EXPECT_EQ(controller.GetEntryAtIndex(3)->GetURL(), url3_ref); | 2910 EXPECT_EQ(controller.GetEntryAtIndex(3)->GetURL(), url3_ref); |
| 2865 EXPECT_EQ(controller.GetEntryAtIndex(4)->GetURL(), url4); | 2911 EXPECT_EQ(controller.GetEntryAtIndex(4)->GetURL(), url4); |
| 2866 } | 2912 } |
| 2867 | 2913 |
| 2868 // Test that Reload initiates a new navigation to a transient entry's URL. | 2914 // Test that Reload initiates a new navigation to a transient entry's URL. |
| 2869 TEST_F(NavigationControllerTest, ReloadTransient) { | 2915 TEST_F(NavigationControllerTest, ReloadTransient) { |
| 2870 NavigationControllerImpl& controller = controller_impl(); | 2916 NavigationControllerImpl& controller = controller_impl(); |
| 2871 const GURL url0("http://foo/0"); | 2917 const GURL url0("http://foo/0"); |
| 2872 const GURL url1("http://foo/1"); | 2918 const GURL url1("http://foo/1"); |
| 2873 const GURL transient_url("http://foo/transient"); | 2919 const GURL transient_url("http://foo/transient"); |
| 2874 | 2920 |
| 2875 // Load |url0|, and start a pending navigation to |url1|. | 2921 // Load |url0|, and start a pending navigation to |url1|. |
| 2876 controller.LoadURL( | 2922 controller.LoadURL( |
| 2877 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2923 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2878 main_test_rfh()->PrepareForCommit(url0); | 2924 main_test_rfh()->PrepareForCommit(); |
| 2879 main_test_rfh()->SendNavigate(0, url0); | 2925 main_test_rfh()->SendNavigate(0, url0); |
| 2880 controller.LoadURL( | 2926 controller.LoadURL( |
| 2881 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2927 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2882 | 2928 |
| 2883 // A transient entry is added, interrupting the navigation. | 2929 // A transient entry is added, interrupting the navigation. |
| 2884 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; | 2930 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; |
| 2885 transient_entry->SetURL(transient_url); | 2931 transient_entry->SetURL(transient_url); |
| 2886 controller.SetTransientEntry(transient_entry); | 2932 controller.SetTransientEntry(transient_entry); |
| 2887 EXPECT_TRUE(controller.GetTransientEntry()); | 2933 EXPECT_TRUE(controller.GetTransientEntry()); |
| 2888 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2934 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2889 | 2935 |
| 2890 // The page is reloaded, which should remove the pending entry for |url1| and | 2936 // The page is reloaded, which should remove the pending entry for |url1| and |
| 2891 // the transient entry for |transient_url|, and start a navigation to | 2937 // the transient entry for |transient_url|, and start a navigation to |
| 2892 // |transient_url|. | 2938 // |transient_url|. |
| 2893 controller.Reload(true); | 2939 controller.Reload(true); |
| 2894 EXPECT_FALSE(controller.GetTransientEntry()); | 2940 EXPECT_FALSE(controller.GetTransientEntry()); |
| 2895 EXPECT_TRUE(controller.GetPendingEntry()); | 2941 EXPECT_TRUE(controller.GetPendingEntry()); |
| 2896 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2942 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 2897 ASSERT_EQ(controller.GetEntryCount(), 1); | 2943 ASSERT_EQ(controller.GetEntryCount(), 1); |
| 2898 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 2944 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
| 2899 | 2945 |
| 2900 // Load of |transient_url| completes. | 2946 // Load of |transient_url| completes. |
| 2901 main_test_rfh()->PrepareForCommit(transient_url); | 2947 main_test_rfh()->PrepareForCommit(); |
| 2902 main_test_rfh()->SendNavigate(1, transient_url); | 2948 main_test_rfh()->SendNavigate(1, transient_url); |
| 2903 ASSERT_EQ(controller.GetEntryCount(), 2); | 2949 ASSERT_EQ(controller.GetEntryCount(), 2); |
| 2904 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 2950 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
| 2905 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), transient_url); | 2951 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), transient_url); |
| 2906 } | 2952 } |
| 2907 | 2953 |
| 2908 // Ensure that renderer initiated pending entries get replaced, so that we | 2954 // Ensure that renderer initiated pending entries get replaced, so that we |
| 2909 // don't show a stale virtual URL when a navigation commits. | 2955 // don't show a stale virtual URL when a navigation commits. |
| 2910 // See http://crbug.com/266922. | 2956 // See http://crbug.com/266922. |
| 2911 TEST_F(NavigationControllerTest, RendererInitiatedPendingEntries) { | 2957 TEST_F(NavigationControllerTest, RendererInitiatedPendingEntries) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2970 | 3016 |
| 2971 const GURL url0("http://foo/0"); | 3017 const GURL url0("http://foo/0"); |
| 2972 const GURL url1("http://foo/1"); | 3018 const GURL url1("http://foo/1"); |
| 2973 | 3019 |
| 2974 // For typed navigations (browser-initiated), both pending and visible entries | 3020 // For typed navigations (browser-initiated), both pending and visible entries |
| 2975 // should update before commit. | 3021 // should update before commit. |
| 2976 controller.LoadURL( | 3022 controller.LoadURL( |
| 2977 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 3023 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2978 EXPECT_EQ(url0, controller.GetPendingEntry()->GetURL()); | 3024 EXPECT_EQ(url0, controller.GetPendingEntry()->GetURL()); |
| 2979 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); | 3025 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); |
| 2980 main_test_rfh()->PrepareForCommit(url0); | 3026 main_test_rfh()->PrepareForCommit(); |
| 2981 main_test_rfh()->SendNavigate(0, url0); | 3027 main_test_rfh()->SendNavigate(0, url0); |
| 2982 | 3028 |
| 2983 // For link clicks (renderer-initiated navigations), the pending entry should | 3029 // For link clicks (renderer-initiated navigations), the pending entry should |
| 2984 // update before commit but the visible should not. | 3030 // update before commit but the visible should not. |
| 2985 NavigationController::LoadURLParams load_url_params(url1); | 3031 NavigationController::LoadURLParams load_url_params(url1); |
| 2986 load_url_params.is_renderer_initiated = true; | 3032 load_url_params.is_renderer_initiated = true; |
| 2987 controller.LoadURLWithParams(load_url_params); | 3033 controller.LoadURLWithParams(load_url_params); |
| 2988 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); | 3034 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); |
| 2989 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 3035 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
| 2990 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); | 3036 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); |
| 2991 | 3037 |
| 2992 // After commit, both visible should be updated, there should be no pending | 3038 // After commit, both visible should be updated, there should be no pending |
| 2993 // entry, and we should no longer treat the entry as renderer-initiated. | 3039 // entry, and we should no longer treat the entry as renderer-initiated. |
| 2994 main_test_rfh()->PrepareForCommit(url1); | 3040 main_test_rfh()->PrepareForCommit(); |
| 2995 main_test_rfh()->SendNavigate(1, url1); | 3041 main_test_rfh()->SendNavigate(1, url1); |
| 2996 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 3042 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
| 2997 EXPECT_FALSE(controller.GetPendingEntry()); | 3043 EXPECT_FALSE(controller.GetPendingEntry()); |
| 2998 EXPECT_FALSE(controller.GetLastCommittedEntry()->is_renderer_initiated()); | 3044 EXPECT_FALSE(controller.GetLastCommittedEntry()->is_renderer_initiated()); |
| 2999 | 3045 |
| 3000 notifications.Reset(); | 3046 notifications.Reset(); |
| 3001 } | 3047 } |
| 3002 | 3048 |
| 3003 // Tests that the URLs for renderer-initiated navigations in new tabs are | 3049 // Tests that the URLs for renderer-initiated navigations in new tabs are |
| 3004 // displayed to the user before commit, as long as the initial about:blank | 3050 // displayed to the user before commit, as long as the initial about:blank |
| (...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4118 | 4164 |
| 4119 // We should only have the last committed and pending entries at this point, | 4165 // We should only have the last committed and pending entries at this point, |
| 4120 // and the pending entry should still not be in the entry list. | 4166 // and the pending entry should still not be in the entry list. |
| 4121 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 4167 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 4122 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); | 4168 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); |
| 4123 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 4169 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 4124 EXPECT_TRUE(controller.GetPendingEntry()); | 4170 EXPECT_TRUE(controller.GetPendingEntry()); |
| 4125 EXPECT_EQ(1, controller.GetEntryCount()); | 4171 EXPECT_EQ(1, controller.GetEntryCount()); |
| 4126 | 4172 |
| 4127 // Try to commit the pending entry. | 4173 // Try to commit the pending entry. |
| 4128 main_test_rfh()->PrepareForCommit(url3); | 4174 main_test_rfh()->PrepareForCommit(); |
| 4129 main_test_rfh()->SendNavigate(2, url3); | 4175 main_test_rfh()->SendNavigate(2, url3); |
| 4130 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 4176 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 4131 EXPECT_FALSE(controller.GetPendingEntry()); | 4177 EXPECT_FALSE(controller.GetPendingEntry()); |
| 4132 EXPECT_EQ(2, controller.GetEntryCount()); | 4178 EXPECT_EQ(2, controller.GetEntryCount()); |
| 4133 EXPECT_EQ(url3, controller.GetEntryAtIndex(1)->GetURL()); | 4179 EXPECT_EQ(url3, controller.GetEntryAtIndex(1)->GetURL()); |
| 4134 } | 4180 } |
| 4135 | 4181 |
| 4136 // Test to ensure that when we do a history navigation back to the current | 4182 // Test to ensure that when we do a history navigation back to the current |
| 4137 // committed page (e.g., going forward to a slow-loading page, then pressing | 4183 // committed page (e.g., going forward to a slow-loading page, then pressing |
| 4138 // the back button), we just stop the navigation to prevent the throbber from | 4184 // the back button), we just stop the navigation to prevent the throbber from |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4407 | 4453 |
| 4408 // Verify that the pending entry correctly indicates that the session history | 4454 // Verify that the pending entry correctly indicates that the session history |
| 4409 // should be cleared. | 4455 // should be cleared. |
| 4410 NavigationEntryImpl* entry = controller.GetPendingEntry(); | 4456 NavigationEntryImpl* entry = controller.GetPendingEntry(); |
| 4411 ASSERT_TRUE(entry); | 4457 ASSERT_TRUE(entry); |
| 4412 EXPECT_TRUE(entry->should_clear_history_list()); | 4458 EXPECT_TRUE(entry->should_clear_history_list()); |
| 4413 | 4459 |
| 4414 // Assume that the RF correctly cleared its history and commit the navigation. | 4460 // Assume that the RF correctly cleared its history and commit the navigation. |
| 4415 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 4461 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 4416 switches::kEnableBrowserSideNavigation)) { | 4462 switches::kEnableBrowserSideNavigation)) { |
| 4417 contents()->GetMainFrame()->PrepareForCommit(entry->GetURL()); | 4463 contents()->GetMainFrame()->PrepareForCommit(); |
| 4418 } | 4464 } |
| 4419 contents()->GetPendingMainFrame()-> | 4465 contents()->GetPendingMainFrame()-> |
| 4420 set_simulate_history_list_was_cleared(true); | 4466 set_simulate_history_list_was_cleared(true); |
| 4421 contents()->CommitPendingNavigation(); | 4467 contents()->CommitPendingNavigation(); |
| 4422 | 4468 |
| 4423 // Verify that the NavigationController's session history was correctly | 4469 // Verify that the NavigationController's session history was correctly |
| 4424 // cleared. | 4470 // cleared. |
| 4425 EXPECT_EQ(1, controller.GetEntryCount()); | 4471 EXPECT_EQ(1, controller.GetEntryCount()); |
| 4426 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 4472 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
| 4427 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 4473 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4518 { | 4564 { |
| 4519 LoadCommittedDetails details; | 4565 LoadCommittedDetails details; |
| 4520 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); | 4566 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); |
| 4521 EXPECT_EQ(PAGE_TYPE_ERROR, | 4567 EXPECT_EQ(PAGE_TYPE_ERROR, |
| 4522 controller_impl().GetLastCommittedEntry()->GetPageType()); | 4568 controller_impl().GetLastCommittedEntry()->GetPageType()); |
| 4523 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type); | 4569 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type); |
| 4524 } | 4570 } |
| 4525 } | 4571 } |
| 4526 | 4572 |
| 4527 } // namespace content | 4573 } // namespace content |
| OLD | NEW |