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

Side by Side Diff: content/browser/tab_contents/navigation_controller_unittest.cc

Issue 8224023: Don't show URL for pending new navigations initiated by the renderer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix merge conflicts. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/stl_util.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 1451 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 } 1462 }
1463 1463
1464 // Tests that we can do a restore and navigate to the restored entries and 1464 // Tests that we can do a restore and navigate to the restored entries and
1465 // everything is updated properly. This can be tricky since there is no 1465 // everything is updated properly. This can be tricky since there is no
1466 // SiteInstance for the entries created initially. 1466 // SiteInstance for the entries created initially.
1467 TEST_F(NavigationControllerTest, RestoreNavigate) { 1467 TEST_F(NavigationControllerTest, RestoreNavigate) {
1468 // Create a NavigationController with a restored set of tabs. 1468 // Create a NavigationController with a restored set of tabs.
1469 GURL url("http://foo"); 1469 GURL url("http://foo");
1470 std::vector<NavigationEntry*> entries; 1470 std::vector<NavigationEntry*> entries;
1471 NavigationEntry* entry = NavigationController::CreateNavigationEntry( 1471 NavigationEntry* entry = NavigationController::CreateNavigationEntry(
1472 url, GURL(), content::PAGE_TRANSITION_RELOAD, std::string(), profile()); 1472 url, GURL(), content::PAGE_TRANSITION_RELOAD, false, std::string(),
1473 profile());
1473 entry->set_page_id(0); 1474 entry->set_page_id(0);
1474 entry->set_title(ASCIIToUTF16("Title")); 1475 entry->set_title(ASCIIToUTF16("Title"));
1475 entry->set_content_state("state"); 1476 entry->set_content_state("state");
1476 entries.push_back(entry); 1477 entries.push_back(entry);
1477 TabContents our_contents(profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); 1478 TabContents our_contents(profile(), NULL, MSG_ROUTING_NONE, NULL, NULL);
1478 NavigationController& our_controller = our_contents.controller(); 1479 NavigationController& our_controller = our_contents.controller();
1479 our_controller.Restore(0, true, &entries); 1480 our_controller.Restore(0, true, &entries);
1480 ASSERT_EQ(0u, entries.size()); 1481 ASSERT_EQ(0u, entries.size());
1481 1482
1482 // Before navigating to the restored entry, it should have a restore_type 1483 // Before navigating to the restored entry, it should have a restore_type
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1520 our_controller.GetEntryAtIndex(0)->restore_type()); 1521 our_controller.GetEntryAtIndex(0)->restore_type());
1521 } 1522 }
1522 1523
1523 // Tests that we can still navigate to a restored entry after a different 1524 // Tests that we can still navigate to a restored entry after a different
1524 // navigation fails and clears the pending entry. http://crbug.com/90085 1525 // navigation fails and clears the pending entry. http://crbug.com/90085
1525 TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) { 1526 TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) {
1526 // Create a NavigationController with a restored set of tabs. 1527 // Create a NavigationController with a restored set of tabs.
1527 GURL url("http://foo"); 1528 GURL url("http://foo");
1528 std::vector<NavigationEntry*> entries; 1529 std::vector<NavigationEntry*> entries;
1529 NavigationEntry* entry = NavigationController::CreateNavigationEntry( 1530 NavigationEntry* entry = NavigationController::CreateNavigationEntry(
1530 url, GURL(), content::PAGE_TRANSITION_RELOAD, std::string(), profile()); 1531 url, GURL(), content::PAGE_TRANSITION_RELOAD, false, std::string(),
1532 profile());
1531 entry->set_page_id(0); 1533 entry->set_page_id(0);
1532 entry->set_title(ASCIIToUTF16("Title")); 1534 entry->set_title(ASCIIToUTF16("Title"));
1533 entry->set_content_state("state"); 1535 entry->set_content_state("state");
1534 entries.push_back(entry); 1536 entries.push_back(entry);
1535 TabContents our_contents(profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); 1537 TabContents our_contents(profile(), NULL, MSG_ROUTING_NONE, NULL, NULL);
1536 NavigationController& our_controller = our_contents.controller(); 1538 NavigationController& our_controller = our_contents.controller();
1537 our_controller.Restore(0, true, &entries); 1539 our_controller.Restore(0, true, &entries);
1538 ASSERT_EQ(0u, entries.size()); 1540 ASSERT_EQ(0u, entries.size());
1539 1541
1540 // Before navigating to the restored entry, it should have a restore_type 1542 // Before navigating to the restored entry, it should have a restore_type
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1804 1806
1805 // Ensure the URLS are correct. 1807 // Ensure the URLS are correct.
1806 EXPECT_EQ(controller().entry_count(), 5); 1808 EXPECT_EQ(controller().entry_count(), 5);
1807 EXPECT_EQ(controller().GetEntryAtIndex(0)->url(), url0); 1809 EXPECT_EQ(controller().GetEntryAtIndex(0)->url(), url0);
1808 EXPECT_EQ(controller().GetEntryAtIndex(1)->url(), url1); 1810 EXPECT_EQ(controller().GetEntryAtIndex(1)->url(), url1);
1809 EXPECT_EQ(controller().GetEntryAtIndex(2)->url(), url2); 1811 EXPECT_EQ(controller().GetEntryAtIndex(2)->url(), url2);
1810 EXPECT_EQ(controller().GetEntryAtIndex(3)->url(), url3); 1812 EXPECT_EQ(controller().GetEntryAtIndex(3)->url(), url3);
1811 EXPECT_EQ(controller().GetEntryAtIndex(4)->url(), url4); 1813 EXPECT_EQ(controller().GetEntryAtIndex(4)->url(), url4);
1812 } 1814 }
1813 1815
1816 // Tests that the URLs for renderer-initiated navigations are not displayed to
1817 // the user until the navigation commits, to prevent URL spoof attacks.
1818 // See http://crbug.com/99016.
1819 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) {
1820 TestNotificationTracker notifications;
1821 RegisterForAllNavNotifications(&notifications, &controller());
1822
1823 const GURL url0("http://foo/0");
1824 const GURL url1("http://foo/1");
1825
1826 // For typed navigations (browser-initiated), both active and visible entries
1827 // should update before commit.
1828 controller().LoadURL(url0, GURL(), content::PAGE_TRANSITION_TYPED,
1829 std::string());
1830 EXPECT_EQ(url0, controller().GetActiveEntry()->url());
1831 EXPECT_EQ(url0, controller().GetVisibleEntry()->url());
1832 rvh()->SendNavigate(0, url0);
1833
1834 // For link clicks (renderer-initiated navigations), the active entry should
1835 // update before commit but the visible should not.
1836 controller().LoadURLFromRenderer(url1, GURL(), content::PAGE_TRANSITION_LINK,
1837 std::string());
1838 EXPECT_EQ(url1, controller().GetActiveEntry()->url());
1839 EXPECT_EQ(url0, controller().GetVisibleEntry()->url());
1840 EXPECT_TRUE(controller().pending_entry()->is_renderer_initiated());
1841
1842 // After commit, both should be updated, and we should no longer treat the
1843 // entry as renderer-initiated.
1844 rvh()->SendNavigate(1, url1);
1845 EXPECT_EQ(url1, controller().GetActiveEntry()->url());
1846 EXPECT_EQ(url1, controller().GetVisibleEntry()->url());
1847 EXPECT_FALSE(controller().GetLastCommittedEntry()->is_renderer_initiated());
1848
1849 notifications.Reset();
1850 }
1851
1814 // Tests that IsInPageNavigation returns appropriate results. Prevents 1852 // Tests that IsInPageNavigation returns appropriate results. Prevents
1815 // regression for bug 1126349. 1853 // regression for bug 1126349.
1816 TEST_F(NavigationControllerTest, IsInPageNavigation) { 1854 TEST_F(NavigationControllerTest, IsInPageNavigation) {
1817 // Navigate to URL with no refs. 1855 // Navigate to URL with no refs.
1818 const GURL url("http://www.google.com/home.html"); 1856 const GURL url("http://www.google.com/home.html");
1819 rvh()->SendNavigate(0, url); 1857 rvh()->SendNavigate(0, url);
1820 1858
1821 // Reloading the page is not an in-page navigation. 1859 // Reloading the page is not an in-page navigation.
1822 EXPECT_FALSE(controller().IsURLInPageNavigation(url)); 1860 EXPECT_FALSE(controller().IsURLInPageNavigation(url));
1823 const GURL other_url("http://www.google.com/add.html"); 1861 const GURL other_url("http://www.google.com/add.html");
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
2352 TabNavigation nav(0, url0, GURL(), string16(), 2390 TabNavigation nav(0, url0, GURL(), string16(),
2353 webkit_glue::CreateHistoryStateForURL(url0), 2391 webkit_glue::CreateHistoryStateForURL(url0),
2354 content::PAGE_TRANSITION_LINK); 2392 content::PAGE_TRANSITION_LINK);
2355 session_helper_.AssertNavigationEquals(nav, 2393 session_helper_.AssertNavigationEquals(nav,
2356 windows_[0]->tabs[0]->navigations[0]); 2394 windows_[0]->tabs[0]->navigations[0]);
2357 nav.set_url(url2); 2395 nav.set_url(url2);
2358 session_helper_.AssertNavigationEquals(nav, 2396 session_helper_.AssertNavigationEquals(nav,
2359 windows_[0]->tabs[0]->navigations[1]); 2397 windows_[0]->tabs[0]->navigations[1]);
2360 } 2398 }
2361 */ 2399 */
OLDNEW
« no previous file with comments | « content/browser/tab_contents/navigation_controller.cc ('k') | content/browser/tab_contents/navigation_entry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698