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

Side by Side Diff: chrome/browser/browser_commands_unittest.cc

Issue 10829308: Use the last committed entry for View Source. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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
« no previous file with comments | « no previous file | chrome/browser/ui/browser_commands.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/app/chrome_command_ids.h" 5 #include "chrome/app/chrome_command_ids.h"
6 #include "chrome/browser/bookmarks/bookmark_model.h" 6 #include "chrome/browser/bookmarks/bookmark_model.h"
7 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 7 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
8 #include "chrome/browser/ui/browser_command_controller.h" 8 #include "chrome/browser/ui/browser_command_controller.h"
9 #include "chrome/browser/ui/browser_commands.h" 9 #include "chrome/browser/ui/browser_commands.h"
10 #include "chrome/browser/ui/browser_list.h" 10 #include "chrome/browser/ui/browser_list.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // Navigate to the last tab using the select last accelerator. 57 // Navigate to the last tab using the select last accelerator.
58 updater->ExecuteCommand(IDC_SELECT_LAST_TAB); 58 updater->ExecuteCommand(IDC_SELECT_LAST_TAB);
59 ASSERT_EQ(2, browser()->active_index()); 59 ASSERT_EQ(2, browser()->active_index());
60 } 60 }
61 61
62 // Tests IDC_DUPLICATE_TAB. 62 // Tests IDC_DUPLICATE_TAB.
63 TEST_F(BrowserCommandsTest, DuplicateTab) { 63 TEST_F(BrowserCommandsTest, DuplicateTab) {
64 GURL url1("http://foo/1"); 64 GURL url1("http://foo/1");
65 GURL url2("http://foo/2"); 65 GURL url2("http://foo/2");
66 GURL url3("http://foo/3"); 66 GURL url3("http://foo/3");
67 GURL url4("http://foo/4");
67 68
68 // Navigate to the three urls, then go back. 69 // Navigate to three urls, plus a pending URL that hasn't committed.
69 AddTab(browser(), url1); 70 AddTab(browser(), url1);
70 NavigateAndCommitActiveTab(url2); 71 NavigateAndCommitActiveTab(url2);
71 NavigateAndCommitActiveTab(url3); 72 NavigateAndCommitActiveTab(url3);
73 content::NavigationController& orig_controller =
74 chrome::GetWebContentsAt(browser(), 0)->GetController();
75 orig_controller.LoadURL(
76 url4, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string());
77 EXPECT_EQ(3, orig_controller.GetEntryCount());
78 EXPECT_TRUE(orig_controller.GetPendingEntry());
72 79
73 size_t initial_window_count = BrowserList::size(); 80 size_t initial_window_count = BrowserList::size();
74 81
75 // Duplicate the tab. 82 // Duplicate the tab.
76 chrome::ExecuteCommand(browser(), IDC_DUPLICATE_TAB); 83 chrome::ExecuteCommand(browser(), IDC_DUPLICATE_TAB);
77 84
78 // The duplicated tab should not end up in a new window. 85 // The duplicated tab should not end up in a new window.
79 size_t window_count = BrowserList::size(); 86 size_t window_count = BrowserList::size();
80 ASSERT_EQ(initial_window_count, window_count); 87 ASSERT_EQ(initial_window_count, window_count);
81 88
82 // And we should have a newly duplicated tab. 89 // And we should have a newly duplicated tab.
83 ASSERT_EQ(2, browser()->tab_count()); 90 ASSERT_EQ(2, browser()->tab_count());
84 91
85 // Verify the stack of urls. 92 // Verify the stack of urls.
86 content::NavigationController& controller = 93 content::NavigationController& controller =
87 chrome::GetWebContentsAt(browser(), 1)->GetController(); 94 chrome::GetWebContentsAt(browser(), 1)->GetController();
88 ASSERT_EQ(3, controller.GetEntryCount()); 95 EXPECT_EQ(3, controller.GetEntryCount());
89 ASSERT_EQ(2, controller.GetCurrentEntryIndex()); 96 EXPECT_EQ(2, controller.GetCurrentEntryIndex());
90 ASSERT_TRUE(url1 == controller.GetEntryAtIndex(0)->GetURL()); 97 EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL());
91 ASSERT_TRUE(url2 == controller.GetEntryAtIndex(1)->GetURL()); 98 EXPECT_EQ(url2, controller.GetEntryAtIndex(1)->GetURL());
92 ASSERT_TRUE(url3 == controller.GetEntryAtIndex(2)->GetURL()); 99 EXPECT_EQ(url3, controller.GetEntryAtIndex(2)->GetURL());
100 EXPECT_FALSE(controller.GetPendingEntry());
101 }
102
103 // Tests IDC_VIEW_SOURCE (See http://crbug.com/138140).
104 TEST_F(BrowserCommandsTest, ViewSource) {
105 GURL url1("http://foo/1");
106 GURL url2("http://foo/2");
107
108 // Navigate to a URL, plus a pending URL that hasn't committed.
109 AddTab(browser(), url1);
110 content::NavigationController& orig_controller =
111 chrome::GetWebContentsAt(browser(), 0)->GetController();
112 orig_controller.LoadURL(
113 url2, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string());
114 EXPECT_EQ(1, orig_controller.GetEntryCount());
115 EXPECT_TRUE(orig_controller.GetPendingEntry());
116
117 size_t initial_window_count = BrowserList::size();
118
119 // View Source.
120 chrome::ExecuteCommand(browser(), IDC_VIEW_SOURCE);
121
122 // The view source tab should not end up in a new window.
123 size_t window_count = BrowserList::size();
124 ASSERT_EQ(initial_window_count, window_count);
125
126 // And we should have a newly duplicated tab.
127 ASSERT_EQ(2, browser()->tab_count());
128
129 // Verify we are viewing the source of the last committed entry.
130 GURL view_source_url("view-source:http://foo/1");
131 content::NavigationController& controller =
132 chrome::GetWebContentsAt(browser(), 1)->GetController();
133 EXPECT_EQ(1, controller.GetEntryCount());
134 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
135 EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL());
136 EXPECT_EQ(view_source_url, controller.GetEntryAtIndex(0)->GetVirtualURL());
137 EXPECT_FALSE(controller.GetPendingEntry());
93 } 138 }
94 139
95 TEST_F(BrowserCommandsTest, BookmarkCurrentPage) { 140 TEST_F(BrowserCommandsTest, BookmarkCurrentPage) {
96 // We use profile() here, since it's a TestingProfile. 141 // We use profile() here, since it's a TestingProfile.
97 profile()->CreateBookmarkModel(true); 142 profile()->CreateBookmarkModel(true);
98 profile()->BlockUntilBookmarkModelLoaded(); 143 profile()->BlockUntilBookmarkModelLoaded();
99 144
100 // Navigate to a url. 145 // Navigate to a url.
101 GURL url1("http://foo/1"); 146 GURL url1("http://foo/1");
102 AddTab(browser(), url1); 147 AddTab(browser(), url1);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 ASSERT_EQ(url1, chrome::GetActiveWebContents(browser())->GetURL()); 215 ASSERT_EQ(url1, chrome::GetActiveWebContents(browser())->GetURL());
171 216
172 // Same thing again for forward. 217 // Same thing again for forward.
173 // TODO(brettw) bug 11055: see the comment above about why we need this. 218 // TODO(brettw) bug 11055: see the comment above about why we need this.
174 CommitPendingLoad(&chrome::GetActiveWebContents(browser())->GetController()); 219 CommitPendingLoad(&chrome::GetActiveWebContents(browser())->GetController());
175 chrome::GoForward(browser(), NEW_FOREGROUND_TAB); 220 chrome::GoForward(browser(), NEW_FOREGROUND_TAB);
176 ASSERT_EQ(4, browser()->active_index()); 221 ASSERT_EQ(4, browser()->active_index());
177 ASSERT_EQ(url2, chrome::GetActiveWebContents(browser())->GetURL()); 222 ASSERT_EQ(url2, chrome::GetActiveWebContents(browser())->GetURL());
178 } 223 }
179 224
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/browser_commands.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698