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

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

Issue 10702029: Move tab functions off Browser into browser_tabstrip and browser_tabrestore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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
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/ui/browser_command_controller.h" 7 #include "chrome/browser/ui/browser_command_controller.h"
8 #include "chrome/browser/ui/browser_commands.h" 8 #include "chrome/browser/ui/browser_commands.h"
9 #include "chrome/browser/ui/browser_list.h" 9 #include "chrome/browser/ui/browser_list.h"
10 #include "chrome/browser/ui/browser_tabstrip.h"
10 #include "chrome/common/url_constants.h" 11 #include "chrome/common/url_constants.h"
11 #include "chrome/test/base/browser_with_test_window_test.h" 12 #include "chrome/test/base/browser_with_test_window_test.h"
12 #include "chrome/test/base/testing_profile.h" 13 #include "chrome/test/base/testing_profile.h"
13 #include "content/public/browser/navigation_controller.h" 14 #include "content/public/browser/navigation_controller.h"
14 #include "content/public/browser/navigation_entry.h" 15 #include "content/public/browser/navigation_entry.h"
15 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
16 #include "content/public/test/test_browser_thread.h" 17 #include "content/public/test/test_browser_thread.h"
17 18
18 #if defined(OS_CHROMEOS) 19 #if defined(OS_CHROMEOS)
19 #include "chrome/browser/chromeos/login/mock_user_manager.h" 20 #include "chrome/browser/chromeos/login/mock_user_manager.h"
20 #endif 21 #endif
21 22
22 typedef BrowserWithTestWindowTest BrowserCommandsTest; 23 typedef BrowserWithTestWindowTest BrowserCommandsTest;
23 24
24 using content::OpenURLParams; 25 using content::OpenURLParams;
25 using content::Referrer; 26 using content::Referrer;
26 using content::WebContents; 27 using content::WebContents;
27 28
28 // Tests IDC_SELECT_TAB_0, IDC_SELECT_NEXT_TAB, IDC_SELECT_PREVIOUS_TAB and 29 // Tests IDC_SELECT_TAB_0, IDC_SELECT_NEXT_TAB, IDC_SELECT_PREVIOUS_TAB and
29 // IDC_SELECT_LAST_TAB. 30 // IDC_SELECT_LAST_TAB.
30 TEST_F(BrowserCommandsTest, TabNavigationAccelerators) { 31 TEST_F(BrowserCommandsTest, TabNavigationAccelerators) {
31 GURL about_blank(chrome::kAboutBlankURL); 32 GURL about_blank(chrome::kAboutBlankURL);
32 33
33 // Create three tabs. 34 // Create three tabs.
34 AddTab(browser(), about_blank); 35 AddTab(browser(), about_blank);
35 AddTab(browser(), about_blank); 36 AddTab(browser(), about_blank);
36 AddTab(browser(), about_blank); 37 AddTab(browser(), about_blank);
37 38
38 // Select the second tab. 39 // Select the second tab.
39 browser()->ActivateTabAt(1, false); 40 chrome::ActivateTabAt(browser(), 1, false);
40 41
41 CommandUpdater* updater = browser()->command_controller()->command_updater(); 42 CommandUpdater* updater = browser()->command_controller()->command_updater();
42 43
43 // Navigate to the first tab using an accelerator. 44 // Navigate to the first tab using an accelerator.
44 updater->ExecuteCommand(IDC_SELECT_TAB_0); 45 updater->ExecuteCommand(IDC_SELECT_TAB_0);
45 ASSERT_EQ(0, browser()->active_index()); 46 ASSERT_EQ(0, browser()->active_index());
46 47
47 // Navigate to the second tab using the next accelerators. 48 // Navigate to the second tab using the next accelerators.
48 updater->ExecuteCommand(IDC_SELECT_NEXT_TAB); 49 updater->ExecuteCommand(IDC_SELECT_NEXT_TAB);
49 ASSERT_EQ(1, browser()->active_index()); 50 ASSERT_EQ(1, browser()->active_index());
(...skipping 25 matching lines...) Expand all
75 76
76 // The duplicated tab should not end up in a new window. 77 // The duplicated tab should not end up in a new window.
77 size_t window_count = BrowserList::size(); 78 size_t window_count = BrowserList::size();
78 ASSERT_EQ(initial_window_count, window_count); 79 ASSERT_EQ(initial_window_count, window_count);
79 80
80 // And we should have a newly duplicated tab. 81 // And we should have a newly duplicated tab.
81 ASSERT_EQ(2, browser()->tab_count()); 82 ASSERT_EQ(2, browser()->tab_count());
82 83
83 // Verify the stack of urls. 84 // Verify the stack of urls.
84 content::NavigationController& controller = 85 content::NavigationController& controller =
85 browser()->GetWebContentsAt(1)->GetController(); 86 chrome::GetWebContentsAt(browser(), 1)->GetController();
86 ASSERT_EQ(3, controller.GetEntryCount()); 87 ASSERT_EQ(3, controller.GetEntryCount());
87 ASSERT_EQ(2, controller.GetCurrentEntryIndex()); 88 ASSERT_EQ(2, controller.GetCurrentEntryIndex());
88 ASSERT_TRUE(url1 == controller.GetEntryAtIndex(0)->GetURL()); 89 ASSERT_TRUE(url1 == controller.GetEntryAtIndex(0)->GetURL());
89 ASSERT_TRUE(url2 == controller.GetEntryAtIndex(1)->GetURL()); 90 ASSERT_TRUE(url2 == controller.GetEntryAtIndex(1)->GetURL());
90 ASSERT_TRUE(url3 == controller.GetEntryAtIndex(2)->GetURL()); 91 ASSERT_TRUE(url3 == controller.GetEntryAtIndex(2)->GetURL());
91 } 92 }
92 93
93 TEST_F(BrowserCommandsTest, BookmarkCurrentPage) { 94 TEST_F(BrowserCommandsTest, BookmarkCurrentPage) {
94 // We use profile() here, since it's a TestingProfile. 95 // We use profile() here, since it's a TestingProfile.
95 profile()->CreateBookmarkModel(true); 96 profile()->CreateBookmarkModel(true);
(...skipping 20 matching lines...) Expand all
116 // Make a tab with the two pages navigated in it. 117 // Make a tab with the two pages navigated in it.
117 AddTab(browser(), url1); 118 AddTab(browser(), url1);
118 NavigateAndCommitActiveTab(url2); 119 NavigateAndCommitActiveTab(url2);
119 120
120 // Go back in a new background tab. 121 // Go back in a new background tab.
121 chrome::GoBack(browser(), NEW_BACKGROUND_TAB); 122 chrome::GoBack(browser(), NEW_BACKGROUND_TAB);
122 EXPECT_EQ(0, browser()->active_index()); 123 EXPECT_EQ(0, browser()->active_index());
123 ASSERT_EQ(2, browser()->tab_count()); 124 ASSERT_EQ(2, browser()->tab_count());
124 125
125 // The original tab should be unchanged. 126 // The original tab should be unchanged.
126 WebContents* zeroth = browser()->GetWebContentsAt(0); 127 WebContents* zeroth = chrome::GetWebContentsAt(browser(), 0);
127 EXPECT_EQ(url2, zeroth->GetURL()); 128 EXPECT_EQ(url2, zeroth->GetURL());
128 EXPECT_TRUE(zeroth->GetController().CanGoBack()); 129 EXPECT_TRUE(zeroth->GetController().CanGoBack());
129 EXPECT_FALSE(zeroth->GetController().CanGoForward()); 130 EXPECT_FALSE(zeroth->GetController().CanGoForward());
130 131
131 // The new tab should be like the first one but navigated back. 132 // The new tab should be like the first one but navigated back.
132 WebContents* first = browser()->GetWebContentsAt(1); 133 WebContents* first = chrome::GetWebContentsAt(browser(), 1);
133 EXPECT_EQ(url1, browser()->GetWebContentsAt(1)->GetURL()); 134 EXPECT_EQ(url1, chrome::GetWebContentsAt(browser(), 1)->GetURL());
134 EXPECT_FALSE(first->GetController().CanGoBack()); 135 EXPECT_FALSE(first->GetController().CanGoBack());
135 EXPECT_TRUE(first->GetController().CanGoForward()); 136 EXPECT_TRUE(first->GetController().CanGoForward());
136 137
137 // Select the second tab and make it go forward in a new background tab. 138 // Select the second tab and make it go forward in a new background tab.
138 browser()->ActivateTabAt(1, true); 139 chrome::ActivateTabAt(browser(), 1, true);
139 // TODO(brettw) bug 11055: It should not be necessary to commit the load here, 140 // TODO(brettw) bug 11055: It should not be necessary to commit the load here,
140 // but because of this bug, it will assert later if we don't. When the bug is 141 // but because of this bug, it will assert later if we don't. When the bug is
141 // fixed, one of the three commits here related to this bug should be removed 142 // fixed, one of the three commits here related to this bug should be removed
142 // (to test both codepaths). 143 // (to test both codepaths).
143 CommitPendingLoad(&first->GetController()); 144 CommitPendingLoad(&first->GetController());
144 EXPECT_EQ(1, browser()->active_index()); 145 EXPECT_EQ(1, browser()->active_index());
145 chrome::GoForward(browser(), NEW_BACKGROUND_TAB); 146 chrome::GoForward(browser(), NEW_BACKGROUND_TAB);
146 147
147 // The previous tab should be unchanged and still in the foreground. 148 // The previous tab should be unchanged and still in the foreground.
148 EXPECT_EQ(url1, first->GetURL()); 149 EXPECT_EQ(url1, first->GetURL());
149 EXPECT_FALSE(first->GetController().CanGoBack()); 150 EXPECT_FALSE(first->GetController().CanGoBack());
150 EXPECT_TRUE(first->GetController().CanGoForward()); 151 EXPECT_TRUE(first->GetController().CanGoForward());
151 EXPECT_EQ(1, browser()->active_index()); 152 EXPECT_EQ(1, browser()->active_index());
152 153
153 // There should be a new tab navigated forward. 154 // There should be a new tab navigated forward.
154 ASSERT_EQ(3, browser()->tab_count()); 155 ASSERT_EQ(3, browser()->tab_count());
155 WebContents* second = browser()->GetWebContentsAt(2); 156 WebContents* second = chrome::GetWebContentsAt(browser(), 2);
156 EXPECT_EQ(url2, second->GetURL()); 157 EXPECT_EQ(url2, second->GetURL());
157 EXPECT_TRUE(second->GetController().CanGoBack()); 158 EXPECT_TRUE(second->GetController().CanGoBack());
158 EXPECT_FALSE(second->GetController().CanGoForward()); 159 EXPECT_FALSE(second->GetController().CanGoForward());
159 160
160 // Now do back in a new foreground tab. Don't bother re-checking every sngle 161 // Now do back in a new foreground tab. Don't bother re-checking every sngle
161 // thing above, just validate that it's opening properly. 162 // thing above, just validate that it's opening properly.
162 browser()->ActivateTabAt(2, true); 163 chrome::ActivateTabAt(browser(), 2, true);
163 // TODO(brettw) bug 11055: see the comment above about why we need this. 164 // TODO(brettw) bug 11055: see the comment above about why we need this.
164 CommitPendingLoad(&second->GetController()); 165 CommitPendingLoad(&second->GetController());
165 chrome::GoBack(browser(), NEW_FOREGROUND_TAB); 166 chrome::GoBack(browser(), NEW_FOREGROUND_TAB);
166 ASSERT_EQ(3, browser()->active_index()); 167 ASSERT_EQ(3, browser()->active_index());
167 ASSERT_EQ(url1, browser()->GetActiveWebContents()->GetURL()); 168 ASSERT_EQ(url1, chrome::GetActiveWebContents(browser())->GetURL());
168 169
169 // Same thing again for forward. 170 // Same thing again for forward.
170 // TODO(brettw) bug 11055: see the comment above about why we need this. 171 // TODO(brettw) bug 11055: see the comment above about why we need this.
171 CommitPendingLoad(&browser()->GetActiveWebContents()->GetController()); 172 CommitPendingLoad(&chrome::GetActiveWebContents(browser())->GetController());
172 chrome::GoForward(browser(), NEW_FOREGROUND_TAB); 173 chrome::GoForward(browser(), NEW_FOREGROUND_TAB);
173 ASSERT_EQ(4, browser()->active_index()); 174 ASSERT_EQ(4, browser()->active_index());
174 ASSERT_EQ(url2, browser()->GetActiveWebContents()->GetURL()); 175 ASSERT_EQ(url2, chrome::GetActiveWebContents(browser())->GetURL());
175 } 176 }
176 177
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_utils.cc ('k') | chrome/browser/browser_encoding_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698