summaryrefslogtreecommitdiffstats
path: root/chrome/browser/browser_commands_unittest.cc
diff options
context:
space:
mode:
authorcreis@chromium.org <creis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-14 18:14:50 +0000
committercreis@chromium.org <creis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-14 18:14:50 +0000
commit8fcc7bfafa0df19c6431d408c31107c406b8af41 (patch)
treee6522a3b3a1b6d16b6a6b6946ab02b83eeca537a /chrome/browser/browser_commands_unittest.cc
parent443c94a3619ff8e284723ab898938ab64ea57cc8 (diff)
downloadchromium_src-8fcc7bfafa0df19c6431d408c31107c406b8af41.zip
chromium_src-8fcc7bfafa0df19c6431d408c31107c406b8af41.tar.gz
chromium_src-8fcc7bfafa0df19c6431d408c31107c406b8af41.tar.bz2
Use the last committed entry for View Source.
BUG=138140 TEST=Ctrl+U while a page load is in progress. Review URL: https://chromiumcodereview.appspot.com/10829308 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151512 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/browser_commands_unittest.cc')
-rw-r--r--chrome/browser/browser_commands_unittest.cc57
1 files changed, 51 insertions, 6 deletions
diff --git a/chrome/browser/browser_commands_unittest.cc b/chrome/browser/browser_commands_unittest.cc
index 4fbba9a..862254c 100644
--- a/chrome/browser/browser_commands_unittest.cc
+++ b/chrome/browser/browser_commands_unittest.cc
@@ -64,11 +64,18 @@ TEST_F(BrowserCommandsTest, DuplicateTab) {
GURL url1("http://foo/1");
GURL url2("http://foo/2");
GURL url3("http://foo/3");
+ GURL url4("http://foo/4");
- // Navigate to the three urls, then go back.
+ // Navigate to three urls, plus a pending URL that hasn't committed.
AddTab(browser(), url1);
NavigateAndCommitActiveTab(url2);
NavigateAndCommitActiveTab(url3);
+ content::NavigationController& orig_controller =
+ chrome::GetWebContentsAt(browser(), 0)->GetController();
+ orig_controller.LoadURL(
+ url4, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string());
+ EXPECT_EQ(3, orig_controller.GetEntryCount());
+ EXPECT_TRUE(orig_controller.GetPendingEntry());
size_t initial_window_count = BrowserList::size();
@@ -85,11 +92,49 @@ TEST_F(BrowserCommandsTest, DuplicateTab) {
// Verify the stack of urls.
content::NavigationController& controller =
chrome::GetWebContentsAt(browser(), 1)->GetController();
- ASSERT_EQ(3, controller.GetEntryCount());
- ASSERT_EQ(2, controller.GetCurrentEntryIndex());
- ASSERT_TRUE(url1 == controller.GetEntryAtIndex(0)->GetURL());
- ASSERT_TRUE(url2 == controller.GetEntryAtIndex(1)->GetURL());
- ASSERT_TRUE(url3 == controller.GetEntryAtIndex(2)->GetURL());
+ EXPECT_EQ(3, controller.GetEntryCount());
+ EXPECT_EQ(2, controller.GetCurrentEntryIndex());
+ EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL());
+ EXPECT_EQ(url2, controller.GetEntryAtIndex(1)->GetURL());
+ EXPECT_EQ(url3, controller.GetEntryAtIndex(2)->GetURL());
+ EXPECT_FALSE(controller.GetPendingEntry());
+}
+
+// Tests IDC_VIEW_SOURCE (See http://crbug.com/138140).
+TEST_F(BrowserCommandsTest, ViewSource) {
+ GURL url1("http://foo/1");
+ GURL url2("http://foo/2");
+
+ // Navigate to a URL, plus a pending URL that hasn't committed.
+ AddTab(browser(), url1);
+ content::NavigationController& orig_controller =
+ chrome::GetWebContentsAt(browser(), 0)->GetController();
+ orig_controller.LoadURL(
+ url2, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string());
+ EXPECT_EQ(1, orig_controller.GetEntryCount());
+ EXPECT_TRUE(orig_controller.GetPendingEntry());
+
+ size_t initial_window_count = BrowserList::size();
+
+ // View Source.
+ chrome::ExecuteCommand(browser(), IDC_VIEW_SOURCE);
+
+ // The view source tab should not end up in a new window.
+ size_t window_count = BrowserList::size();
+ ASSERT_EQ(initial_window_count, window_count);
+
+ // And we should have a newly duplicated tab.
+ ASSERT_EQ(2, browser()->tab_count());
+
+ // Verify we are viewing the source of the last committed entry.
+ GURL view_source_url("view-source:http://foo/1");
+ content::NavigationController& controller =
+ chrome::GetWebContentsAt(browser(), 1)->GetController();
+ EXPECT_EQ(1, controller.GetEntryCount());
+ EXPECT_EQ(0, controller.GetCurrentEntryIndex());
+ EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL());
+ EXPECT_EQ(view_source_url, controller.GetEntryAtIndex(0)->GetVirtualURL());
+ EXPECT_FALSE(controller.GetPendingEntry());
}
TEST_F(BrowserCommandsTest, BookmarkCurrentPage) {