summaryrefslogtreecommitdiffstats
path: root/chrome/browser/navigation_controller_unittest.cc
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-13 22:42:47 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-13 22:42:47 +0000
commitcbab76d1c74c93837bc76298d1a2e43646154194 (patch)
tree7f1bdcd891e670b67eeac2993730c580698048eb /chrome/browser/navigation_controller_unittest.cc
parent3c1e4d080a8e69fb973638d1360d4d5dd0d2e4d5 (diff)
downloadchromium_src-cbab76d1c74c93837bc76298d1a2e43646154194.zip
chromium_src-cbab76d1c74c93837bc76298d1a2e43646154194.tar.gz
chromium_src-cbab76d1c74c93837bc76298d1a2e43646154194.tar.bz2
This is the first pass at refactoring the interstitial page.
The SSL and malware blocking pages were doing similar things in 2 different classes. There is now a base class called InterstitialPage that contains the common logic. As part of that refactoring, the safe browsing was changed so that the SafeBrowsingBlockingPage is only used from the UI thread. This CL also adds transient entries to the navigation controller: that type of entry gets deleted as soon as a navigation occurs. It is used by interstitial that need to create such a temporary entry while they show. BUG=3013 TEST=Run the unit tests and ui tests. Review URL: http://codereview.chromium.org/6311 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3324 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/navigation_controller_unittest.cc')
-rw-r--r--chrome/browser/navigation_controller_unittest.cc184
1 files changed, 182 insertions, 2 deletions
diff --git a/chrome/browser/navigation_controller_unittest.cc b/chrome/browser/navigation_controller_unittest.cc
index 759ad6f..ed27d84 100644
--- a/chrome/browser/navigation_controller_unittest.cc
+++ b/chrome/browser/navigation_controller_unittest.cc
@@ -429,7 +429,7 @@ TEST_F(NavigationControllerTest, LoadURL_Discarded) {
EXPECT_TRUE(notifications.Check1AndReset(NOTIFY_NAV_ENTRY_COMMITTED));
contents->controller()->LoadURL(url2, PageTransition::TYPED);
- contents->controller()->DiscardPendingEntry();
+ contents->controller()->DiscardNonCommittedEntries();
EXPECT_EQ(0, notifications.size());
// Should not have produced a new session history entry.
@@ -1140,7 +1140,7 @@ TEST_F(NavigationControllerTest, SwitchTypes_Discard) {
// The tab contents should have been replaced
ASSERT_TRUE(initial_contents != contents);
- contents->controller()->DiscardPendingEntry();
+ contents->controller()->DiscardNonCommittedEntries();
EXPECT_EQ(0, notifications.size());
// The tab contents should have been replaced back
@@ -1352,6 +1352,186 @@ TEST_F(NavigationControllerTest, Interstitial) {
contents->controller()->GetLastCommittedEntry()->page_type());
}
+TEST_F(NavigationControllerTest, RemoveEntry) {
+ const GURL url1("test1:foo1");
+ const GURL url2("test1:foo2");
+ const GURL url3("test1:foo3");
+ const GURL url4("test1:foo4");
+ const GURL url5("test1:foo5");
+ const GURL pending_url("test1:pending");
+ const GURL default_url("test1:default");
+
+ contents->controller()->LoadURL(url1, PageTransition::TYPED);
+ contents->CompleteNavigationAsRenderer(0, url1);
+ contents->controller()->LoadURL(url2, PageTransition::TYPED);
+ contents->CompleteNavigationAsRenderer(1, url2);
+ contents->controller()->LoadURL(url3, PageTransition::TYPED);
+ contents->CompleteNavigationAsRenderer(2, url3);
+ contents->controller()->LoadURL(url4, PageTransition::TYPED);
+ contents->CompleteNavigationAsRenderer(3, url4);
+ contents->controller()->LoadURL(url5, PageTransition::TYPED);
+ contents->CompleteNavigationAsRenderer(4, url5);
+
+ // Remove the last entry.
+ contents->controller()->RemoveEntryAtIndex(
+ contents->controller()->GetEntryCount() - 1, default_url);
+ EXPECT_EQ(4, contents->controller()->GetEntryCount());
+ EXPECT_EQ(3, contents->controller()->GetLastCommittedEntryIndex());
+ NavigationEntry* pending_entry = contents->controller()->GetPendingEntry();
+ EXPECT_TRUE(pending_entry && pending_entry->url() == url4);
+
+ // Add a pending entry.
+ contents->controller()->LoadURL(pending_url, PageTransition::TYPED);
+ // Now remove the last entry.
+ contents->controller()->RemoveEntryAtIndex(
+ contents->controller()->GetEntryCount() - 1, default_url);
+ // The pending entry should have been discarded and the last committed entry
+ // removed.
+ EXPECT_EQ(3, contents->controller()->GetEntryCount());
+ EXPECT_EQ(2, contents->controller()->GetLastCommittedEntryIndex());
+ pending_entry = contents->controller()->GetPendingEntry();
+ EXPECT_TRUE(pending_entry && pending_entry->url() == url3);
+
+ // Remove an entry which is not the last committed one.
+ contents->controller()->RemoveEntryAtIndex(0, default_url);
+ EXPECT_EQ(2, contents->controller()->GetEntryCount());
+ EXPECT_EQ(1, contents->controller()->GetLastCommittedEntryIndex());
+ // No navigation should have been initiated since we did not remove the
+ // current entry.
+ EXPECT_FALSE(contents->controller()->GetPendingEntry());
+
+ // Remove the 2 remaining entries.
+ contents->controller()->RemoveEntryAtIndex(1, default_url);
+ contents->controller()->RemoveEntryAtIndex(0, default_url);
+
+ // This should have created a pending default entry.
+ EXPECT_EQ(0, contents->controller()->GetEntryCount());
+ EXPECT_EQ(-1, contents->controller()->GetLastCommittedEntryIndex());
+ pending_entry = contents->controller()->GetPendingEntry();
+ EXPECT_TRUE(pending_entry && pending_entry->url() == default_url);
+}
+
+// Tests the transient entry, making sure it goes away with all navigations.
+TEST_F(NavigationControllerTest, TransientEntry) {
+ TestNotificationTracker notifications;
+ RegisterForAllNavNotifications(&notifications, contents->controller());
+
+ const GURL url0("test1:foo0");
+ const GURL url1("test1:foo1");
+ const GURL url2("test1:foo2");
+ const GURL url3("test1:foo3");
+ const GURL url4("test1:foo4");
+ const GURL transient_url("test1:transient");
+
+ contents->controller()->LoadURL(url0, PageTransition::TYPED);
+ contents->CompleteNavigationAsRenderer(0, url0);
+ contents->controller()->LoadURL(url1, PageTransition::TYPED);
+ contents->CompleteNavigationAsRenderer(1, url1);
+
+ notifications.Reset();
+
+ // Adding a transient with no pending entry.
+ NavigationEntry* transient_entry = new NavigationEntry(TAB_CONTENTS_WEB);
+ transient_entry->set_url(transient_url);
+ contents->controller()->AddTransientEntry(transient_entry);
+
+ // We should not have received any notifications.
+ EXPECT_EQ(0, notifications.size());
+
+ // Check our state.
+ EXPECT_EQ(transient_url, contents->controller()->GetActiveEntry()->url());
+ EXPECT_EQ(contents->controller()->GetEntryCount(), 3);
+ EXPECT_EQ(contents->controller()->GetLastCommittedEntryIndex(), 1);
+ EXPECT_EQ(contents->controller()->GetPendingEntryIndex(), -1);
+ EXPECT_TRUE(contents->controller()->GetLastCommittedEntry());
+ EXPECT_FALSE(contents->controller()->GetPendingEntry());
+ EXPECT_TRUE(contents->controller()->CanGoBack());
+ EXPECT_FALSE(contents->controller()->CanGoForward());
+ EXPECT_EQ(contents->GetMaxPageID(), 1);
+
+ // Navigate.
+ contents->controller()->LoadURL(url2, PageTransition::TYPED);
+ contents->CompleteNavigationAsRenderer(2, url2);
+
+ // We should have navigated, transient entry should be gone.
+ EXPECT_EQ(url2, contents->controller()->GetActiveEntry()->url());
+ EXPECT_EQ(contents->controller()->GetEntryCount(), 3);
+
+ // Add a transient again, then navigate with no pending entry this time.
+ transient_entry = new NavigationEntry(TAB_CONTENTS_WEB);
+ transient_entry->set_url(transient_url);
+ contents->controller()->AddTransientEntry(transient_entry);
+ EXPECT_EQ(transient_url, contents->controller()->GetActiveEntry()->url());
+ contents->CompleteNavigationAsRenderer(3, url3);
+ // Transient entry should be gone.
+ EXPECT_EQ(url3, contents->controller()->GetActiveEntry()->url());
+ EXPECT_EQ(contents->controller()->GetEntryCount(), 4);
+
+ // Initiate a navigation, add a transient then commit navigation.
+ contents->controller()->LoadURL(url4, PageTransition::TYPED);
+ transient_entry = new NavigationEntry(TAB_CONTENTS_WEB);
+ transient_entry->set_url(transient_url);
+ contents->controller()->AddTransientEntry(transient_entry);
+ EXPECT_EQ(transient_url, contents->controller()->GetActiveEntry()->url());
+ contents->CompleteNavigationAsRenderer(4, url4);
+ EXPECT_EQ(url4, contents->controller()->GetActiveEntry()->url());
+ EXPECT_EQ(contents->controller()->GetEntryCount(), 5);
+
+ // Add a transient and go back. This should simply remove the transient.
+ transient_entry = new NavigationEntry(TAB_CONTENTS_WEB);
+ transient_entry->set_url(transient_url);
+ contents->controller()->AddTransientEntry(transient_entry);
+ EXPECT_EQ(transient_url, contents->controller()->GetActiveEntry()->url());
+ EXPECT_TRUE(contents->controller()->CanGoBack());
+ EXPECT_FALSE(contents->controller()->CanGoForward());
+ contents->controller()->GoBack();
+ // Transient entry should be gone.
+ EXPECT_EQ(url4, contents->controller()->GetActiveEntry()->url());
+ EXPECT_EQ(contents->controller()->GetEntryCount(), 5);
+ contents->CompleteNavigationAsRenderer(3, url3);
+
+ // Add a transient and go to an entry before the current one.
+ transient_entry = new NavigationEntry(TAB_CONTENTS_WEB);
+ transient_entry->set_url(transient_url);
+ contents->controller()->AddTransientEntry(transient_entry);
+ EXPECT_EQ(transient_url, contents->controller()->GetActiveEntry()->url());
+ contents->controller()->GoToIndex(1);
+ // The navigation should have been initiated, transient entry should be gone.
+ EXPECT_EQ(url1, contents->controller()->GetActiveEntry()->url());
+ contents->CompleteNavigationAsRenderer(1, url1);
+
+ // Add a transient and go to an entry after the current one.
+ transient_entry = new NavigationEntry(TAB_CONTENTS_WEB);
+ transient_entry->set_url(transient_url);
+ contents->controller()->AddTransientEntry(transient_entry);
+ EXPECT_EQ(transient_url, contents->controller()->GetActiveEntry()->url());
+ contents->controller()->GoToIndex(3);
+ // The navigation should have been initiated, transient entry should be gone.
+ // Because of the transient entry that is removed, going to index 3 makes us
+ // land on url2.
+ EXPECT_EQ(url2, contents->controller()->GetActiveEntry()->url());
+ contents->CompleteNavigationAsRenderer(2, url2);
+
+ // Add a transient and go forward.
+ transient_entry = new NavigationEntry(TAB_CONTENTS_WEB);
+ transient_entry->set_url(transient_url);
+ contents->controller()->AddTransientEntry(transient_entry);
+ EXPECT_EQ(transient_url, contents->controller()->GetActiveEntry()->url());
+ EXPECT_TRUE(contents->controller()->CanGoForward());
+ contents->controller()->GoForward();
+ // We should have navigated, transient entry should be gone.
+ EXPECT_EQ(url3, contents->controller()->GetActiveEntry()->url());
+ contents->CompleteNavigationAsRenderer(3, url3);
+
+ // Ensure the URLS are correct.
+ EXPECT_EQ(contents->controller()->GetEntryCount(), 5);
+ EXPECT_EQ(contents->controller()->GetEntryAtIndex(0)->url(), url0);
+ EXPECT_EQ(contents->controller()->GetEntryAtIndex(1)->url(), url1);
+ EXPECT_EQ(contents->controller()->GetEntryAtIndex(2)->url(), url2);
+ EXPECT_EQ(contents->controller()->GetEntryAtIndex(3)->url(), url3);
+ EXPECT_EQ(contents->controller()->GetEntryAtIndex(4)->url(), url4);
+}
+
// Tests that IsInPageNavigation returns appropriate results. Prevents
// regression for bug 1126349.
TEST_F(NavigationControllerTest, IsInPageNavigation) {