Commit 8fcc7bfa authored by creis@chromium.org's avatar creis@chromium.org

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
parent 443c94a3
......@@ -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) {
......
......@@ -876,13 +876,14 @@ bool IsDebuggerAttachedToCurrentTab(Browser* browser) {
void ViewSource(Browser* browser, TabContents* contents) {
DCHECK(contents);
NavigationEntry* active_entry =
contents->web_contents()->GetController().GetActiveEntry();
if (!active_entry)
// Use the last committed entry, since the pending entry hasn't loaded yet and
// won't be copied into the cloned tab.
NavigationEntry* entry =
contents->web_contents()->GetController().GetLastCommittedEntry();
if (!entry)
return;
ViewSource(browser, contents, active_entry->GetURL(),
active_entry->GetContentState());
ViewSource(browser, contents, entry->GetURL(), entry->GetContentState());
}
void ViewSource(Browser* browser,
......@@ -892,6 +893,8 @@ void ViewSource(Browser* browser,
content::RecordAction(UserMetricsAction("ViewSource"));
DCHECK(contents);
// Note that Clone does not copy the pending or transient entries, so the
// active entry in view_source_contents will be the last committed entry.
TabContents* view_source_contents = contents->Clone();
view_source_contents->web_contents()->GetController().PruneAllButActive();
NavigationEntry* active_entry =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment