Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 483 // This should clear the pending entry and notify of a navigation state | 483 // This should clear the pending entry and notify of a navigation state |
| 484 // change, so that we do not keep displaying kNewURL. | 484 // change, so that we do not keep displaying kNewURL. |
| 485 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 485 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 486 EXPECT_FALSE(controller.GetPendingEntry()); | 486 EXPECT_FALSE(controller.GetPendingEntry()); |
| 487 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 487 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); |
| 488 EXPECT_EQ(2, delegate->navigation_state_change_count()); | 488 EXPECT_EQ(2, delegate->navigation_state_change_count()); |
| 489 | 489 |
| 490 contents()->SetDelegate(NULL); | 490 contents()->SetDelegate(NULL); |
| 491 } | 491 } |
| 492 | 492 |
| 493 // Tests that the pending entry state is correct after a redirect and abort. | |
| 494 // http://crbug.com/83031. | |
|
Charlie Reis
2012/05/17 23:42:55
This is a regression test for a security bug. It'
cbentzel
2012/05/18 00:23:57
Sorry about LGTM'ing with this change.
| |
| 495 TEST_F(NavigationControllerTest, LoadURL_RedirectAbortCancelsPending) { | |
| 496 NavigationControllerImpl& controller = controller_impl(); | |
| 497 TestNotificationTracker notifications; | |
| 498 RegisterForAllNavNotifications(¬ifications, &controller); | |
| 499 | |
| 500 // Set a WebContentsDelegate to listen for state changes. | |
| 501 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); | |
| 502 EXPECT_FALSE(contents()->GetDelegate()); | |
| 503 contents()->SetDelegate(delegate.get()); | |
| 504 | |
| 505 // Without any navigations, the renderer starts at about:blank. | |
| 506 const GURL kExistingURL("about:blank"); | |
| 507 | |
| 508 // Now make a pending new navigation. | |
| 509 const GURL kNewURL("http://eh"); | |
| 510 controller.LoadURL( | |
| 511 kNewURL, content::Referrer(), content::PAGE_TRANSITION_TYPED, | |
| 512 std::string()); | |
| 513 EXPECT_EQ(0U, notifications.size()); | |
| 514 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | |
| 515 EXPECT_TRUE(controller.GetPendingEntry()); | |
| 516 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | |
| 517 EXPECT_EQ(1, delegate->navigation_state_change_count()); | |
| 518 | |
| 519 // Now the navigation redirects. | |
| 520 const GURL kRedirectURL("http://bee"); | |
| 521 test_rvh()->OnMessageReceived( | |
| 522 ViewHostMsg_DidRedirectProvisionalLoad(0, // routing_id | |
| 523 -1, // pending page_id | |
| 524 GURL(), // opener | |
| 525 kNewURL, // old url | |
| 526 kRedirectURL)); // new url | |
| 527 | |
| 528 // We don't want to change the NavigationEntry's url, in case it cancels. | |
| 529 // Prevents regression of http://crbug.com/77786. | |
| 530 EXPECT_EQ(kNewURL, controller.GetPendingEntry()->GetURL()); | |
| 531 | |
| 532 // It may abort before committing, if it's a download or due to a stop or | |
| 533 // a new navigation from the user. | |
| 534 ViewHostMsg_DidFailProvisionalLoadWithError_Params params; | |
| 535 params.frame_id = 1; | |
| 536 params.is_main_frame = true; | |
| 537 params.error_code = net::ERR_ABORTED; | |
| 538 params.error_description = string16(); | |
| 539 params.url = kRedirectURL; | |
| 540 params.showing_repost_interstitial = false; | |
| 541 test_rvh()->OnMessageReceived( | |
| 542 ViewHostMsg_DidFailProvisionalLoadWithError(0, // routing_id | |
| 543 params)); | |
| 544 | |
| 545 // This should clear the pending entry and notify of a navigation state | |
| 546 // change, so that we do not keep displaying kNewURL. | |
| 547 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | |
| 548 EXPECT_FALSE(controller.GetPendingEntry()); | |
| 549 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | |
| 550 EXPECT_EQ(2, delegate->navigation_state_change_count()); | |
| 551 | |
| 552 contents()->SetDelegate(NULL); | |
| 553 } | |
| 554 | |
| 555 TEST_F(NavigationControllerTest, Reload) { | 493 TEST_F(NavigationControllerTest, Reload) { |
| 556 NavigationControllerImpl& controller = controller_impl(); | 494 NavigationControllerImpl& controller = controller_impl(); |
| 557 TestNotificationTracker notifications; | 495 TestNotificationTracker notifications; |
| 558 RegisterForAllNavNotifications(¬ifications, &controller); | 496 RegisterForAllNavNotifications(¬ifications, &controller); |
| 559 | 497 |
| 560 const GURL url1("http://foo1"); | 498 const GURL url1("http://foo1"); |
| 561 | 499 |
| 562 controller.LoadURL( | 500 controller.LoadURL( |
| 563 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 501 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 564 EXPECT_EQ(0U, notifications.size()); | 502 EXPECT_EQ(0U, notifications.size()); |
| (...skipping 2054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2619 TabNavigation nav(0, url0, GURL(), string16(), | 2557 TabNavigation nav(0, url0, GURL(), string16(), |
| 2620 webkit_glue::CreateHistoryStateForURL(url0), | 2558 webkit_glue::CreateHistoryStateForURL(url0), |
| 2621 content::PAGE_TRANSITION_LINK); | 2559 content::PAGE_TRANSITION_LINK); |
| 2622 session_helper_.AssertNavigationEquals(nav, | 2560 session_helper_.AssertNavigationEquals(nav, |
| 2623 windows_[0]->tabs[0]->navigations[0]); | 2561 windows_[0]->tabs[0]->navigations[0]); |
| 2624 nav.set_url(url2); | 2562 nav.set_url(url2); |
| 2625 session_helper_.AssertNavigationEquals(nav, | 2563 session_helper_.AssertNavigationEquals(nav, |
| 2626 windows_[0]->tabs[0]->navigations[1]); | 2564 windows_[0]->tabs[0]->navigations[1]); |
| 2627 } | 2565 } |
| 2628 */ | 2566 */ |
| OLD | NEW |