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

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

Issue 9085006: Replace Browser::GetTabContentsAt with GetWebContentsAt and update all callers. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix mac yet again Created 8 years, 11 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 | « chrome/browser/bookmarks/bookmark_utils.cc ('k') | chrome/browser/browser_focus_uitest.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_list.h" 7 #include "chrome/browser/ui/browser_list.h"
8 #include "chrome/common/url_constants.h" 8 #include "chrome/common/url_constants.h"
9 #include "chrome/test/base/browser_with_test_window_test.h" 9 #include "chrome/test/base/browser_with_test_window_test.h"
10 #include "chrome/test/base/testing_profile.h" 10 #include "chrome/test/base/testing_profile.h"
11 #include "content/browser/tab_contents/tab_contents.h"
12 #include "content/public/browser/navigation_controller.h" 11 #include "content/public/browser/navigation_controller.h"
13 #include "content/public/browser/navigation_entry.h" 12 #include "content/public/browser/navigation_entry.h"
13 #include "content/public/browser/web_contents.h"
14 #include "content/test/test_browser_thread.h" 14 #include "content/test/test_browser_thread.h"
15 15
16 typedef BrowserWithTestWindowTest BrowserCommandsTest; 16 typedef BrowserWithTestWindowTest BrowserCommandsTest;
17 17
18 using content::OpenURLParams; 18 using content::OpenURLParams;
19 using content::Referrer; 19 using content::Referrer;
20 using content::WebContents;
20 21
21 // Tests IDC_SELECT_TAB_0, IDC_SELECT_NEXT_TAB, IDC_SELECT_PREVIOUS_TAB and 22 // Tests IDC_SELECT_TAB_0, IDC_SELECT_NEXT_TAB, IDC_SELECT_PREVIOUS_TAB and
22 // IDC_SELECT_LAST_TAB. 23 // IDC_SELECT_LAST_TAB.
23 TEST_F(BrowserCommandsTest, TabNavigationAccelerators) { 24 TEST_F(BrowserCommandsTest, TabNavigationAccelerators) {
24 GURL about_blank(chrome::kAboutBlankURL); 25 GURL about_blank(chrome::kAboutBlankURL);
25 26
26 // Create three tabs. 27 // Create three tabs.
27 AddTab(browser(), about_blank); 28 AddTab(browser(), about_blank);
28 AddTab(browser(), about_blank); 29 AddTab(browser(), about_blank);
29 AddTab(browser(), about_blank); 30 AddTab(browser(), about_blank);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 67
67 // The duplicated tab should not end up in a new window. 68 // The duplicated tab should not end up in a new window.
68 size_t window_count = BrowserList::size(); 69 size_t window_count = BrowserList::size();
69 ASSERT_EQ(initial_window_count, window_count); 70 ASSERT_EQ(initial_window_count, window_count);
70 71
71 // And we should have a newly duplicated tab. 72 // And we should have a newly duplicated tab.
72 ASSERT_EQ(2, browser()->tab_count()); 73 ASSERT_EQ(2, browser()->tab_count());
73 74
74 // Verify the stack of urls. 75 // Verify the stack of urls.
75 content::NavigationController& controller = 76 content::NavigationController& controller =
76 browser()->GetTabContentsAt(1)->GetController(); 77 browser()->GetWebContentsAt(1)->GetController();
77 ASSERT_EQ(3, controller.GetEntryCount()); 78 ASSERT_EQ(3, controller.GetEntryCount());
78 ASSERT_EQ(2, controller.GetCurrentEntryIndex()); 79 ASSERT_EQ(2, controller.GetCurrentEntryIndex());
79 ASSERT_TRUE(url1 == controller.GetEntryAtIndex(0)->GetURL()); 80 ASSERT_TRUE(url1 == controller.GetEntryAtIndex(0)->GetURL());
80 ASSERT_TRUE(url2 == controller.GetEntryAtIndex(1)->GetURL()); 81 ASSERT_TRUE(url2 == controller.GetEntryAtIndex(1)->GetURL());
81 ASSERT_TRUE(url3 == controller.GetEntryAtIndex(2)->GetURL()); 82 ASSERT_TRUE(url3 == controller.GetEntryAtIndex(2)->GetURL());
82 } 83 }
83 84
84 TEST_F(BrowserCommandsTest, BookmarkCurrentPage) { 85 TEST_F(BrowserCommandsTest, BookmarkCurrentPage) {
85 // We use profile() here, since it's a TestingProfile. 86 // We use profile() here, since it's a TestingProfile.
86 profile()->CreateBookmarkModel(true); 87 profile()->CreateBookmarkModel(true);
(...skipping 26 matching lines...) Expand all
113 // Make a tab with the two pages navigated in it. 114 // Make a tab with the two pages navigated in it.
114 AddTab(browser(), url1); 115 AddTab(browser(), url1);
115 NavigateAndCommitActiveTab(url2); 116 NavigateAndCommitActiveTab(url2);
116 117
117 // Go back in a new background tab. 118 // Go back in a new background tab.
118 browser()->GoBack(NEW_BACKGROUND_TAB); 119 browser()->GoBack(NEW_BACKGROUND_TAB);
119 EXPECT_EQ(0, browser()->active_index()); 120 EXPECT_EQ(0, browser()->active_index());
120 ASSERT_EQ(2, browser()->tab_count()); 121 ASSERT_EQ(2, browser()->tab_count());
121 122
122 // The original tab should be unchanged. 123 // The original tab should be unchanged.
123 TabContents* zeroth = browser()->GetTabContentsAt(0); 124 WebContents* zeroth = browser()->GetWebContentsAt(0);
124 EXPECT_EQ(url2, zeroth->GetURL()); 125 EXPECT_EQ(url2, zeroth->GetURL());
125 EXPECT_TRUE(zeroth->GetController().CanGoBack()); 126 EXPECT_TRUE(zeroth->GetController().CanGoBack());
126 EXPECT_FALSE(zeroth->GetController().CanGoForward()); 127 EXPECT_FALSE(zeroth->GetController().CanGoForward());
127 128
128 // The new tab should be like the first one but navigated back. 129 // The new tab should be like the first one but navigated back.
129 TabContents* first = browser()->GetTabContentsAt(1); 130 WebContents* first = browser()->GetWebContentsAt(1);
130 EXPECT_EQ(url1, browser()->GetTabContentsAt(1)->GetURL()); 131 EXPECT_EQ(url1, browser()->GetWebContentsAt(1)->GetURL());
131 EXPECT_FALSE(first->GetController().CanGoBack()); 132 EXPECT_FALSE(first->GetController().CanGoBack());
132 EXPECT_TRUE(first->GetController().CanGoForward()); 133 EXPECT_TRUE(first->GetController().CanGoForward());
133 134
134 // Select the second tab and make it go forward in a new background tab. 135 // Select the second tab and make it go forward in a new background tab.
135 browser()->ActivateTabAt(1, true); 136 browser()->ActivateTabAt(1, true);
136 // TODO(brettw) bug 11055: It should not be necessary to commit the load here, 137 // TODO(brettw) bug 11055: It should not be necessary to commit the load here,
137 // but because of this bug, it will assert later if we don't. When the bug is 138 // but because of this bug, it will assert later if we don't. When the bug is
138 // fixed, one of the three commits here related to this bug should be removed 139 // fixed, one of the three commits here related to this bug should be removed
139 // (to test both codepaths). 140 // (to test both codepaths).
140 CommitPendingLoad(&first->GetController()); 141 CommitPendingLoad(&first->GetController());
141 EXPECT_EQ(1, browser()->active_index()); 142 EXPECT_EQ(1, browser()->active_index());
142 browser()->GoForward(NEW_BACKGROUND_TAB); 143 browser()->GoForward(NEW_BACKGROUND_TAB);
143 144
144 // The previous tab should be unchanged and still in the foreground. 145 // The previous tab should be unchanged and still in the foreground.
145 EXPECT_EQ(url1, first->GetURL()); 146 EXPECT_EQ(url1, first->GetURL());
146 EXPECT_FALSE(first->GetController().CanGoBack()); 147 EXPECT_FALSE(first->GetController().CanGoBack());
147 EXPECT_TRUE(first->GetController().CanGoForward()); 148 EXPECT_TRUE(first->GetController().CanGoForward());
148 EXPECT_EQ(1, browser()->active_index()); 149 EXPECT_EQ(1, browser()->active_index());
149 150
150 // There should be a new tab navigated forward. 151 // There should be a new tab navigated forward.
151 ASSERT_EQ(3, browser()->tab_count()); 152 ASSERT_EQ(3, browser()->tab_count());
152 TabContents* second = browser()->GetTabContentsAt(2); 153 WebContents* second = browser()->GetWebContentsAt(2);
153 EXPECT_EQ(url2, second->GetURL()); 154 EXPECT_EQ(url2, second->GetURL());
154 EXPECT_TRUE(second->GetController().CanGoBack()); 155 EXPECT_TRUE(second->GetController().CanGoBack());
155 EXPECT_FALSE(second->GetController().CanGoForward()); 156 EXPECT_FALSE(second->GetController().CanGoForward());
156 157
157 // Now do back in a new foreground tab. Don't bother re-checking every sngle 158 // Now do back in a new foreground tab. Don't bother re-checking every sngle
158 // thing above, just validate that it's opening properly. 159 // thing above, just validate that it's opening properly.
159 browser()->ActivateTabAt(2, true); 160 browser()->ActivateTabAt(2, true);
160 // TODO(brettw) bug 11055: see the comment above about why we need this. 161 // TODO(brettw) bug 11055: see the comment above about why we need this.
161 CommitPendingLoad(&second->GetController()); 162 CommitPendingLoad(&second->GetController());
162 browser()->GoBack(NEW_FOREGROUND_TAB); 163 browser()->GoBack(NEW_FOREGROUND_TAB);
(...skipping 27 matching lines...) Expand all
190 191
191 // Pressing it a second time while the NTP is open shouldn't change anything. 192 // Pressing it a second time while the NTP is open shouldn't change anything.
192 browser()->Search(); 193 browser()->Search();
193 ASSERT_EQ(2, browser()->tab_count()); 194 ASSERT_EQ(2, browser()->tab_count());
194 ASSERT_EQ(1, browser()->active_index()); 195 ASSERT_EQ(1, browser()->active_index());
195 current_url = browser()->GetSelectedWebContents()->GetURL(); 196 current_url = browser()->GetSelectedWebContents()->GetURL();
196 EXPECT_TRUE(current_url.SchemeIs(chrome::kChromeUIScheme)); 197 EXPECT_TRUE(current_url.SchemeIs(chrome::kChromeUIScheme));
197 EXPECT_EQ(chrome::kChromeUINewTabHost, current_url.host()); 198 EXPECT_EQ(chrome::kChromeUINewTabHost, current_url.host());
198 } 199 }
199 #endif 200 #endif
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_utils.cc ('k') | chrome/browser/browser_focus_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698