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

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

Issue 11419276: Remove tabstrip wrappers in browser_tabstrip. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: gtk Created 8 years 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) 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"
11 #include "chrome/browser/ui/browser_tabstrip.h" 11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/common/url_constants.h" 12 #include "chrome/common/url_constants.h"
13 #include "chrome/test/base/browser_with_test_window_test.h" 13 #include "chrome/test/base/browser_with_test_window_test.h"
14 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
15 #include "content/public/browser/navigation_controller.h" 15 #include "content/public/browser/navigation_controller.h"
16 #include "content/public/browser/navigation_entry.h" 16 #include "content/public/browser/navigation_entry.h"
17 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
18 #include "content/public/test/test_browser_thread.h" 18 #include "content/public/test/test_browser_thread.h"
19 19
20 #if defined(OS_CHROMEOS) 20 #if defined(OS_CHROMEOS)
21 #include "chrome/browser/chromeos/login/mock_user_manager.h" 21 #include "chrome/browser/chromeos/login/mock_user_manager.h"
22 #endif 22 #endif
23 23
24 typedef BrowserWithTestWindowTest BrowserCommandsTest; 24 typedef BrowserWithTestWindowTest BrowserCommandsTest;
25 25
26 using content::OpenURLParams; 26 using content::OpenURLParams;
27 using content::Referrer; 27 using content::Referrer;
28 using content::WebContents; 28 using content::WebContents;
29 29
30 // Tests IDC_SELECT_TAB_0, IDC_SELECT_NEXT_TAB, IDC_SELECT_PREVIOUS_TAB and 30 // Tests IDC_SELECT_TAB_0, IDC_SELECT_NEXT_TAB, IDC_SELECT_PREVIOUS_TAB and
31 // IDC_SELECT_LAST_TAB. 31 // IDC_SELECT_LAST_TAB.
32 TEST_F(BrowserCommandsTest, TabNavigationAccelerators) { 32 TEST_F(BrowserCommandsTest, TabNavigationAccelerators) {
33 GURL about_blank(chrome::kAboutBlankURL); 33 GURL about_blank(chrome::kAboutBlankURL);
34 34
35 // Create three tabs. 35 // Create three tabs.
36 AddTab(browser(), about_blank); 36 AddTab(browser(), about_blank);
37 AddTab(browser(), about_blank); 37 AddTab(browser(), about_blank);
38 AddTab(browser(), about_blank); 38 AddTab(browser(), about_blank);
39 39
40 // Select the second tab. 40 // Select the second tab.
41 chrome::ActivateTabAt(browser(), 1, false); 41 browser()->tab_strip_model()->ActivateTabAt(1, false);
42 42
43 CommandUpdater* updater = browser()->command_controller()->command_updater(); 43 CommandUpdater* updater = browser()->command_controller()->command_updater();
44 44
45 // Navigate to the first tab using an accelerator. 45 // Navigate to the first tab using an accelerator.
46 updater->ExecuteCommand(IDC_SELECT_TAB_0); 46 updater->ExecuteCommand(IDC_SELECT_TAB_0);
47 ASSERT_EQ(0, browser()->active_index()); 47 ASSERT_EQ(0, browser()->tab_strip_model()->active_index());
48 48
49 // Navigate to the second tab using the next accelerators. 49 // Navigate to the second tab using the next accelerators.
50 updater->ExecuteCommand(IDC_SELECT_NEXT_TAB); 50 updater->ExecuteCommand(IDC_SELECT_NEXT_TAB);
51 ASSERT_EQ(1, browser()->active_index()); 51 ASSERT_EQ(1, browser()->tab_strip_model()->active_index());
52 52
53 // Navigate back to the first tab using the previous accelerators. 53 // Navigate back to the first tab using the previous accelerators.
54 updater->ExecuteCommand(IDC_SELECT_PREVIOUS_TAB); 54 updater->ExecuteCommand(IDC_SELECT_PREVIOUS_TAB);
55 ASSERT_EQ(0, browser()->active_index()); 55 ASSERT_EQ(0, browser()->tab_strip_model()->active_index());
56 56
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()->tab_strip_model()->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 GURL url4("http://foo/4");
68 68
69 // Navigate to three urls, plus a pending URL that hasn't committed. 69 // Navigate to three urls, plus a pending URL that hasn't committed.
70 AddTab(browser(), url1); 70 AddTab(browser(), url1);
71 NavigateAndCommitActiveTab(url2); 71 NavigateAndCommitActiveTab(url2);
72 NavigateAndCommitActiveTab(url3); 72 NavigateAndCommitActiveTab(url3);
73 content::NavigationController& orig_controller = 73 content::NavigationController& orig_controller =
74 chrome::GetWebContentsAt(browser(), 0)->GetController(); 74 browser()->tab_strip_model()->GetWebContentsAt(0)->GetController();
75 orig_controller.LoadURL( 75 orig_controller.LoadURL(
76 url4, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string()); 76 url4, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string());
77 EXPECT_EQ(3, orig_controller.GetEntryCount()); 77 EXPECT_EQ(3, orig_controller.GetEntryCount());
78 EXPECT_TRUE(orig_controller.GetPendingEntry()); 78 EXPECT_TRUE(orig_controller.GetPendingEntry());
79 79
80 size_t initial_window_count = BrowserList::size(); 80 size_t initial_window_count = BrowserList::size();
81 81
82 // Duplicate the tab. 82 // Duplicate the tab.
83 chrome::ExecuteCommand(browser(), IDC_DUPLICATE_TAB); 83 chrome::ExecuteCommand(browser(), IDC_DUPLICATE_TAB);
84 84
85 // The duplicated tab should not end up in a new window. 85 // The duplicated tab should not end up in a new window.
86 size_t window_count = BrowserList::size(); 86 size_t window_count = BrowserList::size();
87 ASSERT_EQ(initial_window_count, window_count); 87 ASSERT_EQ(initial_window_count, window_count);
88 88
89 // And we should have a newly duplicated tab. 89 // And we should have a newly duplicated tab.
90 ASSERT_EQ(2, browser()->tab_count()); 90 ASSERT_EQ(2, browser()->tab_strip_model()->count());
91 91
92 // Verify the stack of urls. 92 // Verify the stack of urls.
93 content::NavigationController& controller = 93 content::NavigationController& controller =
94 chrome::GetWebContentsAt(browser(), 1)->GetController(); 94 browser()->tab_strip_model()->GetWebContentsAt(1)->GetController();
95 EXPECT_EQ(3, controller.GetEntryCount()); 95 EXPECT_EQ(3, controller.GetEntryCount());
96 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); 96 EXPECT_EQ(2, controller.GetCurrentEntryIndex());
97 EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL()); 97 EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL());
98 EXPECT_EQ(url2, controller.GetEntryAtIndex(1)->GetURL()); 98 EXPECT_EQ(url2, controller.GetEntryAtIndex(1)->GetURL());
99 EXPECT_EQ(url3, controller.GetEntryAtIndex(2)->GetURL()); 99 EXPECT_EQ(url3, controller.GetEntryAtIndex(2)->GetURL());
100 EXPECT_FALSE(controller.GetPendingEntry()); 100 EXPECT_FALSE(controller.GetPendingEntry());
101 } 101 }
102 102
103 // Tests IDC_VIEW_SOURCE (See http://crbug.com/138140). 103 // Tests IDC_VIEW_SOURCE (See http://crbug.com/138140).
104 TEST_F(BrowserCommandsTest, ViewSource) { 104 TEST_F(BrowserCommandsTest, ViewSource) {
105 GURL url1("http://foo/1"); 105 GURL url1("http://foo/1");
106 GURL url2("http://foo/2"); 106 GURL url2("http://foo/2");
107 107
108 // Navigate to a URL, plus a pending URL that hasn't committed. 108 // Navigate to a URL, plus a pending URL that hasn't committed.
109 AddTab(browser(), url1); 109 AddTab(browser(), url1);
110 content::NavigationController& orig_controller = 110 content::NavigationController& orig_controller =
111 chrome::GetWebContentsAt(browser(), 0)->GetController(); 111 browser()->tab_strip_model()->GetWebContentsAt(0)->GetController();
112 orig_controller.LoadURL( 112 orig_controller.LoadURL(
113 url2, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string()); 113 url2, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string());
114 EXPECT_EQ(1, orig_controller.GetEntryCount()); 114 EXPECT_EQ(1, orig_controller.GetEntryCount());
115 EXPECT_TRUE(orig_controller.GetPendingEntry()); 115 EXPECT_TRUE(orig_controller.GetPendingEntry());
116 116
117 size_t initial_window_count = BrowserList::size(); 117 size_t initial_window_count = BrowserList::size();
118 118
119 // View Source. 119 // View Source.
120 chrome::ExecuteCommand(browser(), IDC_VIEW_SOURCE); 120 chrome::ExecuteCommand(browser(), IDC_VIEW_SOURCE);
121 121
122 // The view source tab should not end up in a new window. 122 // The view source tab should not end up in a new window.
123 size_t window_count = BrowserList::size(); 123 size_t window_count = BrowserList::size();
124 ASSERT_EQ(initial_window_count, window_count); 124 ASSERT_EQ(initial_window_count, window_count);
125 125
126 // And we should have a newly duplicated tab. 126 // And we should have a newly duplicated tab.
127 ASSERT_EQ(2, browser()->tab_count()); 127 ASSERT_EQ(2, browser()->tab_strip_model()->count());
128 128
129 // Verify we are viewing the source of the last committed entry. 129 // Verify we are viewing the source of the last committed entry.
130 GURL view_source_url("view-source:http://foo/1"); 130 GURL view_source_url("view-source:http://foo/1");
131 content::NavigationController& controller = 131 content::NavigationController& controller =
132 chrome::GetWebContentsAt(browser(), 1)->GetController(); 132 browser()->tab_strip_model()->GetWebContentsAt(1)->GetController();
133 EXPECT_EQ(1, controller.GetEntryCount()); 133 EXPECT_EQ(1, controller.GetEntryCount());
134 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 134 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
135 EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL()); 135 EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL());
136 EXPECT_EQ(view_source_url, controller.GetEntryAtIndex(0)->GetVirtualURL()); 136 EXPECT_EQ(view_source_url, controller.GetEntryAtIndex(0)->GetVirtualURL());
137 EXPECT_FALSE(controller.GetPendingEntry()); 137 EXPECT_FALSE(controller.GetPendingEntry());
138 } 138 }
139 139
140 TEST_F(BrowserCommandsTest, BookmarkCurrentPage) { 140 TEST_F(BrowserCommandsTest, BookmarkCurrentPage) {
141 // We use profile() here, since it's a TestingProfile. 141 // We use profile() here, since it's a TestingProfile.
142 profile()->CreateBookmarkModel(true); 142 profile()->CreateBookmarkModel(true);
(...skipping 17 matching lines...) Expand all
160 TEST_F(BrowserCommandsTest, BackForwardInNewTab) { 160 TEST_F(BrowserCommandsTest, BackForwardInNewTab) {
161 GURL url1("http://foo/1"); 161 GURL url1("http://foo/1");
162 GURL url2("http://foo/2"); 162 GURL url2("http://foo/2");
163 163
164 // Make a tab with the two pages navigated in it. 164 // Make a tab with the two pages navigated in it.
165 AddTab(browser(), url1); 165 AddTab(browser(), url1);
166 NavigateAndCommitActiveTab(url2); 166 NavigateAndCommitActiveTab(url2);
167 167
168 // Go back in a new background tab. 168 // Go back in a new background tab.
169 chrome::GoBack(browser(), NEW_BACKGROUND_TAB); 169 chrome::GoBack(browser(), NEW_BACKGROUND_TAB);
170 EXPECT_EQ(0, browser()->active_index()); 170 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
171 ASSERT_EQ(2, browser()->tab_count()); 171 ASSERT_EQ(2, browser()->tab_strip_model()->count());
172 172
173 // The original tab should be unchanged. 173 // The original tab should be unchanged.
174 WebContents* zeroth = chrome::GetWebContentsAt(browser(), 0); 174 WebContents* zeroth = browser()->tab_strip_model()->GetWebContentsAt(0);
175 EXPECT_EQ(url2, zeroth->GetURL()); 175 EXPECT_EQ(url2, zeroth->GetURL());
176 EXPECT_TRUE(zeroth->GetController().CanGoBack()); 176 EXPECT_TRUE(zeroth->GetController().CanGoBack());
177 EXPECT_FALSE(zeroth->GetController().CanGoForward()); 177 EXPECT_FALSE(zeroth->GetController().CanGoForward());
178 178
179 // The new tab should be like the first one but navigated back. 179 // The new tab should be like the first one but navigated back.
180 WebContents* first = chrome::GetWebContentsAt(browser(), 1); 180 WebContents* first = browser()->tab_strip_model()->GetWebContentsAt(1);
181 EXPECT_EQ(url1, chrome::GetWebContentsAt(browser(), 1)->GetURL()); 181 EXPECT_EQ(url1, browser()->tab_strip_model()->GetWebContentsAt(1)->GetURL());
182 EXPECT_FALSE(first->GetController().CanGoBack()); 182 EXPECT_FALSE(first->GetController().CanGoBack());
183 EXPECT_TRUE(first->GetController().CanGoForward()); 183 EXPECT_TRUE(first->GetController().CanGoForward());
184 184
185 // Select the second tab and make it go forward in a new background tab. 185 // Select the second tab and make it go forward in a new background tab.
186 chrome::ActivateTabAt(browser(), 1, true); 186 browser()->tab_strip_model()->ActivateTabAt(1, true);
187 // TODO(brettw) bug 11055: It should not be necessary to commit the load here, 187 // TODO(brettw) bug 11055: It should not be necessary to commit the load here,
188 // but because of this bug, it will assert later if we don't. When the bug is 188 // but because of this bug, it will assert later if we don't. When the bug is
189 // fixed, one of the three commits here related to this bug should be removed 189 // fixed, one of the three commits here related to this bug should be removed
190 // (to test both codepaths). 190 // (to test both codepaths).
191 CommitPendingLoad(&first->GetController()); 191 CommitPendingLoad(&first->GetController());
192 EXPECT_EQ(1, browser()->active_index()); 192 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
193 chrome::GoForward(browser(), NEW_BACKGROUND_TAB); 193 chrome::GoForward(browser(), NEW_BACKGROUND_TAB);
194 194
195 // The previous tab should be unchanged and still in the foreground. 195 // The previous tab should be unchanged and still in the foreground.
196 EXPECT_EQ(url1, first->GetURL()); 196 EXPECT_EQ(url1, first->GetURL());
197 EXPECT_FALSE(first->GetController().CanGoBack()); 197 EXPECT_FALSE(first->GetController().CanGoBack());
198 EXPECT_TRUE(first->GetController().CanGoForward()); 198 EXPECT_TRUE(first->GetController().CanGoForward());
199 EXPECT_EQ(1, browser()->active_index()); 199 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
200 200
201 // There should be a new tab navigated forward. 201 // There should be a new tab navigated forward.
202 ASSERT_EQ(3, browser()->tab_count()); 202 ASSERT_EQ(3, browser()->tab_strip_model()->count());
203 WebContents* second = chrome::GetWebContentsAt(browser(), 2); 203 WebContents* second = browser()->tab_strip_model()->GetWebContentsAt(2);
204 EXPECT_EQ(url2, second->GetURL()); 204 EXPECT_EQ(url2, second->GetURL());
205 EXPECT_TRUE(second->GetController().CanGoBack()); 205 EXPECT_TRUE(second->GetController().CanGoBack());
206 EXPECT_FALSE(second->GetController().CanGoForward()); 206 EXPECT_FALSE(second->GetController().CanGoForward());
207 207
208 // Now do back in a new foreground tab. Don't bother re-checking every sngle 208 // Now do back in a new foreground tab. Don't bother re-checking every sngle
209 // thing above, just validate that it's opening properly. 209 // thing above, just validate that it's opening properly.
210 chrome::ActivateTabAt(browser(), 2, true); 210 browser()->tab_strip_model()->ActivateTabAt(2, true);
211 // TODO(brettw) bug 11055: see the comment above about why we need this. 211 // TODO(brettw) bug 11055: see the comment above about why we need this.
212 CommitPendingLoad(&second->GetController()); 212 CommitPendingLoad(&second->GetController());
213 chrome::GoBack(browser(), NEW_FOREGROUND_TAB); 213 chrome::GoBack(browser(), NEW_FOREGROUND_TAB);
214 ASSERT_EQ(3, browser()->active_index()); 214 ASSERT_EQ(3, browser()->tab_strip_model()->active_index());
215 ASSERT_EQ(url1, chrome::GetActiveWebContents(browser())->GetURL()); 215 ASSERT_EQ(url1,
216 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
216 217
217 // Same thing again for forward. 218 // Same thing again for forward.
218 // TODO(brettw) bug 11055: see the comment above about why we need this. 219 // TODO(brettw) bug 11055: see the comment above about why we need this.
219 CommitPendingLoad(&chrome::GetActiveWebContents(browser())->GetController()); 220 CommitPendingLoad(&
221 browser()->tab_strip_model()->GetActiveWebContents()->GetController());
220 chrome::GoForward(browser(), NEW_FOREGROUND_TAB); 222 chrome::GoForward(browser(), NEW_FOREGROUND_TAB);
221 ASSERT_EQ(4, browser()->active_index()); 223 ASSERT_EQ(4, browser()->tab_strip_model()->active_index());
222 ASSERT_EQ(url2, chrome::GetActiveWebContents(browser())->GetURL()); 224 ASSERT_EQ(url2,
225 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
223 } 226 }
224 227
OLDNEW
« no previous file with comments | « chrome/browser/automation/testing_automation_provider.cc ('k') | chrome/browser/download/download_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698