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

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

Issue 3734003: Add support for SINGLETON_TAB disposition to BrowserNavigator.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 2 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/browser/browser.h" 5 #include "chrome/browser/browser.h"
6 #include "chrome/browser/browser_list.h" 6 #include "chrome/browser/browser_list.h"
7 #include "chrome/browser/browser_navigator.h" 7 #include "chrome/browser/browser_navigator.h"
8 #include "chrome/browser/browser_window.h" 8 #include "chrome/browser/browser_window.h"
9 #include "chrome/browser/profile.h" 9 #include "chrome/browser/profile.h"
10 #include "chrome/browser/tab_contents/tab_contents.h" 10 #include "chrome/browser/tab_contents/tab_contents.h"
11 #include "chrome/browser/tab_contents/tab_contents_view.h" 11 #include "chrome/browser/tab_contents/tab_contents_view.h"
12 #include "chrome/browser/tabs/tab_strip_model.h" 12 #include "chrome/browser/tabs/tab_strip_model.h"
13 #include "chrome/test/in_process_browser_test.h" 13 #include "chrome/test/in_process_browser_test.h"
14 #include "chrome/test/ui_test_utils.h" 14 #include "chrome/test/ui_test_utils.h"
15 #include "ipc/ipc_message.h" 15 #include "ipc/ipc_message.h"
16 16
17 namespace { 17 namespace {
18 18
19 class BrowserNavigatorTest : public InProcessBrowserTest, 19 class BrowserNavigatorTest : public InProcessBrowserTest {
20 public NavigatorDelegate {
21 public:
22 // Overridden from NavigatorDelegate:
23 virtual void UpdateUIForNavigationInTab(TabContents* contents,
24 PageTransition::Type transition,
25 bool user_initiated) {
26 // Nothing needed.
27 }
28 virtual GURL GetHomePage() const {
29 return GURL("http://www.google.com/ig");
30 }
31
32 protected: 20 protected:
33 GURL GetGoogleURL() const { 21 GURL GetGoogleURL() const {
34 return GURL("http://www.google.com/"); 22 return GURL("http://www.google.com/");
35 } 23 }
36 24
37 browser::NavigateParams MakeNavigateParams() const { 25 browser::NavigateParams MakeNavigateParams() const {
38 return MakeNavigateParams(browser()); 26 return MakeNavigateParams(browser());
39 } 27 }
40 browser::NavigateParams MakeNavigateParams(Browser* browser) const { 28 browser::NavigateParams MakeNavigateParams(Browser* browser) const {
41 browser::NavigateParams params(browser, GetGoogleURL(), 29 browser::NavigateParams params(browser, GetGoogleURL(),
(...skipping 13 matching lines...) Expand all
55 NULL, 43 NULL,
56 MSG_ROUTING_NONE, 44 MSG_ROUTING_NONE,
57 browser()->GetSelectedTabContents(), 45 browser()->GetSelectedTabContents(),
58 NULL); 46 NULL);
59 } 47 }
60 48
61 void RunSuppressTest(WindowOpenDisposition disposition) { 49 void RunSuppressTest(WindowOpenDisposition disposition) {
62 GURL old_url = browser()->GetSelectedTabContents()->GetURL(); 50 GURL old_url = browser()->GetSelectedTabContents()->GetURL();
63 browser::NavigateParams p(MakeNavigateParams()); 51 browser::NavigateParams p(MakeNavigateParams());
64 p.disposition = disposition; 52 p.disposition = disposition;
65 browser::Navigate(&p, this); 53 browser::Navigate(&p);
66 54
67 // Nothing should have happened as a result of Navigate(); 55 // Nothing should have happened as a result of Navigate();
68 EXPECT_EQ(1, browser()->tab_count()); 56 EXPECT_EQ(1, browser()->tab_count());
69 EXPECT_EQ(1u, BrowserList::size()); 57 EXPECT_EQ(1u, BrowserList::size());
70 EXPECT_EQ(old_url, browser()->GetSelectedTabContents()->GetURL()); 58 EXPECT_EQ(old_url, browser()->GetSelectedTabContents()->GetURL());
71 } 59 }
72 }; 60 };
73 61
74 } // namespace 62 } // namespace
75 63
76 // This test verifies that when a navigation occurs within a tab, the tab count 64 // This test verifies that when a navigation occurs within a tab, the tab count
77 // of the Browser remains the same and the current tab bears the loaded URL. 65 // of the Browser remains the same and the current tab bears the loaded URL.
78 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) { 66 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
79 browser::NavigateParams p(MakeNavigateParams()); 67 browser::NavigateParams p(MakeNavigateParams());
80 browser::Navigate(&p, this); 68 browser::Navigate(&p);
81 ui_test_utils::WaitForNavigationInCurrentTab(browser()); 69 ui_test_utils::WaitForNavigationInCurrentTab(browser());
82 EXPECT_EQ(GetGoogleURL(), browser()->GetSelectedTabContents()->GetURL()); 70 EXPECT_EQ(GetGoogleURL(), browser()->GetSelectedTabContents()->GetURL());
83 // We should have one window with one tab. 71 // We should have one window with one tab.
84 EXPECT_EQ(1u, BrowserList::size()); 72 EXPECT_EQ(1u, BrowserList::size());
85 EXPECT_EQ(1, browser()->tab_count()); 73 EXPECT_EQ(1, browser()->tab_count());
86 } 74 }
87 75
88 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTab) { 76 // This test verifies that a singleton tab is refocused if one is already open
89 // TODO(beng): TBD 77 // in another or an existing window, or added if it is not.
78 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
79 GURL url("http://www.google.com/");
80 GURL singleton_url1("http://maps.google.com/");
81 browser()->AddSelectedTabWithURL(singleton_url1, PageTransition::LINK);
82 browser()->AddSelectedTabWithURL(url, PageTransition::LINK);
83
84 // We should have one browser with 3 tabs, the 3rd selected.
85 EXPECT_EQ(1u, BrowserList::size());
86 EXPECT_EQ(2, browser()->selected_index());
87
88 // Navigate to singleton_url1.
89 browser::NavigateParams p(MakeNavigateParams());
90 p.disposition = SINGLETON_TAB;
91 p.url = singleton_url1;
92 browser::Navigate(&p);
93
94 // The middle tab should now be selected.
95 EXPECT_EQ(browser(), p.browser);
96 EXPECT_EQ(1, browser()->selected_index());
97 }
98
99 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
100 Disposition_SingletonTabNoneExisting) {
101 GURL url("http://www.google.com/");
102 GURL singleton_url1("http://maps.google.com/");
103
104 // We should have one browser with 3 tabs, the 3rd selected.
105 EXPECT_EQ(1u, BrowserList::size());
106 EXPECT_EQ(0, browser()->selected_index());
107
108 // Navigate to singleton_url1.
109 browser::NavigateParams p(MakeNavigateParams());
110 p.disposition = SINGLETON_TAB;
111 p.url = singleton_url1;
112 browser::Navigate(&p);
113
114 // We should now have 2 tabs, the 2nd one selected.
115 EXPECT_EQ(browser(), p.browser);
116 EXPECT_EQ(2, browser()->tab_count());
117 EXPECT_EQ(1, browser()->selected_index());
90 } 118 }
91 119
92 // This test verifies that when a navigation results in a foreground tab, the 120 // This test verifies that when a navigation results in a foreground tab, the
93 // tab count of the Browser increases and the selected tab shifts to the new 121 // tab count of the Browser increases and the selected tab shifts to the new
94 // foreground tab. 122 // foreground tab.
95 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) { 123 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) {
96 TabContents* old_contents = browser()->GetSelectedTabContents(); 124 TabContents* old_contents = browser()->GetSelectedTabContents();
97 browser::NavigateParams p(MakeNavigateParams()); 125 browser::NavigateParams p(MakeNavigateParams());
98 p.disposition = NEW_FOREGROUND_TAB; 126 p.disposition = NEW_FOREGROUND_TAB;
99 browser::Navigate(&p, this); 127 browser::Navigate(&p);
100 EXPECT_NE(old_contents, browser()->GetSelectedTabContents()); 128 EXPECT_NE(old_contents, browser()->GetSelectedTabContents());
101 EXPECT_EQ(browser()->GetSelectedTabContents(), p.target_contents); 129 EXPECT_EQ(browser()->GetSelectedTabContents(), p.target_contents);
102 EXPECT_EQ(2, browser()->tab_count()); 130 EXPECT_EQ(2, browser()->tab_count());
103 } 131 }
104 132
105 // This test verifies that when a navigation results in a background tab, the 133 // This test verifies that when a navigation results in a background tab, the
106 // tab count of the Browser increases but the selected tab remains the same. 134 // tab count of the Browser increases but the selected tab remains the same.
107 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) { 135 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) {
108 TabContents* old_contents = browser()->GetSelectedTabContents(); 136 TabContents* old_contents = browser()->GetSelectedTabContents();
109 browser::NavigateParams p(MakeNavigateParams()); 137 browser::NavigateParams p(MakeNavigateParams());
110 p.disposition = NEW_BACKGROUND_TAB; 138 p.disposition = NEW_BACKGROUND_TAB;
111 browser::Navigate(&p, this); 139 browser::Navigate(&p);
112 TabContents* new_contents = browser()->GetSelectedTabContents(); 140 TabContents* new_contents = browser()->GetSelectedTabContents();
113 // The selected tab should have remained unchanged, since the new tab was 141 // The selected tab should have remained unchanged, since the new tab was
114 // opened in the background. 142 // opened in the background.
115 EXPECT_EQ(old_contents, new_contents); 143 EXPECT_EQ(old_contents, new_contents);
116 EXPECT_EQ(2, browser()->tab_count()); 144 EXPECT_EQ(2, browser()->tab_count());
117 } 145 }
118 146
119 // This test verifies that when a navigation requiring a new foreground tab 147 // This test verifies that when a navigation requiring a new foreground tab
120 // occurs in a Browser that cannot host multiple tabs, the new foreground tab 148 // occurs in a Browser that cannot host multiple tabs, the new foreground tab
121 // is created in an existing compatible Browser. 149 // is created in an existing compatible Browser.
122 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, 150 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
123 Disposition_IncompatibleWindow_Existing) { 151 Disposition_IncompatibleWindow_Existing) {
124 // Open a foreground tab in a window that cannot open popups when there is an 152 // Open a foreground tab in a window that cannot open popups when there is an
125 // existing compatible window somewhere else that they can be opened within. 153 // existing compatible window somewhere else that they can be opened within.
126 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP, 154 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP,
127 browser()->profile()); 155 browser()->profile());
128 browser::NavigateParams p(MakeNavigateParams(popup)); 156 browser::NavigateParams p(MakeNavigateParams(popup));
129 p.disposition = NEW_FOREGROUND_TAB; 157 p.disposition = NEW_FOREGROUND_TAB;
130 browser::Navigate(&p, this); 158 browser::Navigate(&p);
131 159
132 // Navigate() should have opened the tab in a different browser since the 160 // Navigate() should have opened the tab in a different browser since the
133 // one we supplied didn't support additional tabs. 161 // one we supplied didn't support additional tabs.
134 EXPECT_NE(popup, p.browser); 162 EXPECT_NE(popup, p.browser);
135 163
136 // Since browser() is an existing compatible tabbed browser, it should have 164 // Since browser() is an existing compatible tabbed browser, it should have
137 // opened the tab there. 165 // opened the tab there.
138 EXPECT_EQ(browser(), p.browser); 166 EXPECT_EQ(browser(), p.browser);
139 167
140 // We should be left with 2 windows, the popup with one tab and the browser() 168 // We should be left with 2 windows, the popup with one tab and the browser()
(...skipping 11 matching lines...) Expand all
152 // We want to simulate not being able to find an existing window compatible 180 // We want to simulate not being able to find an existing window compatible
153 // with our non-tabbed browser window so Navigate() is forced to create a 181 // with our non-tabbed browser window so Navigate() is forced to create a
154 // new compatible window. Because browser() supplied by the in-process 182 // new compatible window. Because browser() supplied by the in-process
155 // browser testing framework is compatible with browser()->profile(), we 183 // browser testing framework is compatible with browser()->profile(), we
156 // need a different profile, and creating a popup window with an incognito 184 // need a different profile, and creating a popup window with an incognito
157 // profile is a quick and dirty way of achieving this. 185 // profile is a quick and dirty way of achieving this.
158 Browser* popup = CreateEmptyBrowserForType( 186 Browser* popup = CreateEmptyBrowserForType(
159 Browser::TYPE_POPUP, browser()->profile()->GetOffTheRecordProfile()); 187 Browser::TYPE_POPUP, browser()->profile()->GetOffTheRecordProfile());
160 browser::NavigateParams p(MakeNavigateParams(popup)); 188 browser::NavigateParams p(MakeNavigateParams(popup));
161 p.disposition = NEW_FOREGROUND_TAB; 189 p.disposition = NEW_FOREGROUND_TAB;
162 browser::Navigate(&p, this); 190 browser::Navigate(&p);
163 191
164 // Navigate() should have opened the tab in a different browser since the 192 // Navigate() should have opened the tab in a different browser since the
165 // one we supplied didn't support additional tabs. 193 // one we supplied didn't support additional tabs.
166 EXPECT_NE(popup, p.browser); 194 EXPECT_NE(popup, p.browser);
167 195
168 // This time, browser() is _not_ compatible with popup since it is not an 196 // This time, browser() is _not_ compatible with popup since it is not an
169 // incognito window. 197 // incognito window.
170 EXPECT_NE(browser(), p.browser); 198 EXPECT_NE(browser(), p.browser);
171 199
172 // We should have three windows, each with one tab: 200 // We should have three windows, each with one tab:
173 // 1. the browser() provided by the framework (unchanged in this test) 201 // 1. the browser() provided by the framework (unchanged in this test)
174 // 2. the incognito popup we created originally 202 // 2. the incognito popup we created originally
175 // 3. the new incognito tabbed browser that was created by Navigate(). 203 // 3. the new incognito tabbed browser that was created by Navigate().
176 EXPECT_EQ(3u, BrowserList::size()); 204 EXPECT_EQ(3u, BrowserList::size());
177 EXPECT_EQ(1, browser()->tab_count()); 205 EXPECT_EQ(1, browser()->tab_count());
178 EXPECT_EQ(1, popup->tab_count()); 206 EXPECT_EQ(1, popup->tab_count());
179 EXPECT_EQ(1, p.browser->tab_count()); 207 EXPECT_EQ(1, p.browser->tab_count());
180 EXPECT_EQ(Browser::TYPE_NORMAL, p.browser->type()); 208 EXPECT_EQ(Browser::TYPE_NORMAL, p.browser->type());
181 } 209 }
182 210
183 // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP 211 // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
184 // from a normal Browser results in a new Browser with TYPE_POPUP. 212 // from a normal Browser results in a new Browser with TYPE_POPUP.
185 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) { 213 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) {
186 browser::NavigateParams p(MakeNavigateParams()); 214 browser::NavigateParams p(MakeNavigateParams());
187 p.disposition = NEW_POPUP; 215 p.disposition = NEW_POPUP;
188 browser::Navigate(&p, this); 216 browser::Navigate(&p);
189 217
190 // Navigate() should have opened a new popup window. 218 // Navigate() should have opened a new popup window.
191 EXPECT_NE(browser(), p.browser); 219 EXPECT_NE(browser(), p.browser);
192 EXPECT_EQ(Browser::TYPE_POPUP, p.browser->type()); 220 EXPECT_EQ(Browser::TYPE_POPUP, p.browser->type());
193 221
194 // We should have two windows, the browser() provided by the framework and the 222 // We should have two windows, the browser() provided by the framework and the
195 // new popup window. 223 // new popup window.
196 EXPECT_EQ(2u, BrowserList::size()); 224 EXPECT_EQ(2u, BrowserList::size());
197 EXPECT_EQ(1, browser()->tab_count()); 225 EXPECT_EQ(1, browser()->tab_count());
198 EXPECT_EQ(1, p.browser->tab_count()); 226 EXPECT_EQ(1, p.browser->tab_count());
199 } 227 }
200 228
201 // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP 229 // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
202 // from an app frame results in a new Browser with TYPE_APP_POPUP. 230 // from an app frame results in a new Browser with TYPE_APP_POPUP.
203 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, 231 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
204 Disposition_NewPopupFromAppWindow) { 232 Disposition_NewPopupFromAppWindow) {
205 Browser* app_browser = CreateEmptyBrowserForType(Browser::TYPE_APP, 233 Browser* app_browser = CreateEmptyBrowserForType(Browser::TYPE_APP,
206 browser()->profile()); 234 browser()->profile());
207 browser::NavigateParams p(MakeNavigateParams(app_browser)); 235 browser::NavigateParams p(MakeNavigateParams(app_browser));
208 p.disposition = NEW_POPUP; 236 p.disposition = NEW_POPUP;
209 browser::Navigate(&p, this); 237 browser::Navigate(&p);
210 238
211 // Navigate() should have opened a new popup app window. 239 // Navigate() should have opened a new popup app window.
212 EXPECT_NE(app_browser, p.browser); 240 EXPECT_NE(app_browser, p.browser);
213 EXPECT_NE(browser(), p.browser); 241 EXPECT_NE(browser(), p.browser);
214 EXPECT_EQ(Browser::TYPE_APP_POPUP, p.browser->type()); 242 EXPECT_EQ(Browser::TYPE_APP_POPUP, p.browser->type());
215 243
216 // We should now have three windows, the app window, the app popup it created, 244 // We should now have three windows, the app window, the app popup it created,
217 // and the original browser() provided by the framework. 245 // and the original browser() provided by the framework.
218 EXPECT_EQ(3u, BrowserList::size()); 246 EXPECT_EQ(3u, BrowserList::size());
219 EXPECT_EQ(1, browser()->tab_count()); 247 EXPECT_EQ(1, browser()->tab_count());
220 EXPECT_EQ(1, app_browser->tab_count()); 248 EXPECT_EQ(1, app_browser->tab_count());
221 EXPECT_EQ(1, p.browser->tab_count()); 249 EXPECT_EQ(1, p.browser->tab_count());
222 } 250 }
223 251
224 // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP 252 // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
225 // from an extension app tab results in a new Browser with TYPE_APP_POPUP. 253 // from an extension app tab results in a new Browser with TYPE_APP_POPUP.
226 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, 254 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
227 Disposition_NewPopupFromExtensionApp) { 255 Disposition_NewPopupFromExtensionApp) {
228 // TODO(beng): TBD. 256 // TODO(beng): TBD.
229 } 257 }
230 258
231 // This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW 259 // This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
232 // always opens a new window. 260 // always opens a new window.
233 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) { 261 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) {
234 browser::NavigateParams p(MakeNavigateParams()); 262 browser::NavigateParams p(MakeNavigateParams());
235 p.disposition = NEW_WINDOW; 263 p.disposition = NEW_WINDOW;
236 browser::Navigate(&p, this); 264 browser::Navigate(&p);
237 265
238 // Navigate() should have opened a new toplevel window. 266 // Navigate() should have opened a new toplevel window.
239 EXPECT_NE(browser(), p.browser); 267 EXPECT_NE(browser(), p.browser);
240 EXPECT_EQ(Browser::TYPE_NORMAL, p.browser->type()); 268 EXPECT_EQ(Browser::TYPE_NORMAL, p.browser->type());
241 269
242 // We should now have two windows, the browser() provided by the framework and 270 // We should now have two windows, the browser() provided by the framework and
243 // the new normal window. 271 // the new normal window.
244 EXPECT_EQ(2u, BrowserList::size()); 272 EXPECT_EQ(2u, BrowserList::size());
245 EXPECT_EQ(1, browser()->tab_count()); 273 EXPECT_EQ(1, browser()->tab_count());
246 EXPECT_EQ(1, p.browser->tab_count()); 274 EXPECT_EQ(1, p.browser->tab_count());
247 } 275 }
248 276
249 // This test verifies that navigating with WindowOpenDisposition = INCOGNITO 277 // This test verifies that navigating with WindowOpenDisposition = INCOGNITO
250 // opens a new incognito window if no existing incognito window is present. 278 // opens a new incognito window if no existing incognito window is present.
251 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) { 279 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) {
252 browser::NavigateParams p(MakeNavigateParams()); 280 browser::NavigateParams p(MakeNavigateParams());
253 p.disposition = OFF_THE_RECORD; 281 p.disposition = OFF_THE_RECORD;
254 browser::Navigate(&p, this); 282 browser::Navigate(&p);
255 283
256 // Navigate() should have opened a new toplevel incognito window. 284 // Navigate() should have opened a new toplevel incognito window.
257 EXPECT_NE(browser(), p.browser); 285 EXPECT_NE(browser(), p.browser);
258 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(), 286 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
259 p.browser->profile()); 287 p.browser->profile());
260 288
261 // We should now have two windows, the browser() provided by the framework and 289 // We should now have two windows, the browser() provided by the framework and
262 // the new incognito window. 290 // the new incognito window.
263 EXPECT_EQ(2u, BrowserList::size()); 291 EXPECT_EQ(2u, BrowserList::size());
264 EXPECT_EQ(1, browser()->tab_count()); 292 EXPECT_EQ(1, browser()->tab_count());
265 EXPECT_EQ(1, p.browser->tab_count()); 293 EXPECT_EQ(1, p.browser->tab_count());
266 } 294 }
267 295
268 // This test verifies that navigating with WindowOpenDisposition = INCOGNITO 296 // This test verifies that navigating with WindowOpenDisposition = INCOGNITO
269 // reuses an existing incognito window when possible. 297 // reuses an existing incognito window when possible.
270 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) { 298 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) {
271 Browser* incognito_browser = 299 Browser* incognito_browser =
272 CreateEmptyBrowserForType(Browser::TYPE_NORMAL, 300 CreateEmptyBrowserForType(Browser::TYPE_NORMAL,
273 browser()->profile()->GetOffTheRecordProfile()); 301 browser()->profile()->GetOffTheRecordProfile());
274 browser::NavigateParams p(MakeNavigateParams()); 302 browser::NavigateParams p(MakeNavigateParams());
275 p.disposition = OFF_THE_RECORD; 303 p.disposition = OFF_THE_RECORD;
276 browser::Navigate(&p, this); 304 browser::Navigate(&p);
277 305
278 // Navigate() should have opened a new tab in the existing incognito window. 306 // Navigate() should have opened a new tab in the existing incognito window.
279 EXPECT_NE(browser(), p.browser); 307 EXPECT_NE(browser(), p.browser);
280 EXPECT_EQ(p.browser, incognito_browser); 308 EXPECT_EQ(p.browser, incognito_browser);
281 309
282 // We should now have two windows, the browser() provided by the framework and 310 // We should now have two windows, the browser() provided by the framework and
283 // the incognito window we opened earlier. 311 // the incognito window we opened earlier.
284 EXPECT_EQ(2u, BrowserList::size()); 312 EXPECT_EQ(2u, BrowserList::size());
285 EXPECT_EQ(1, browser()->tab_count()); 313 EXPECT_EQ(1, browser()->tab_count());
286 EXPECT_EQ(2, incognito_browser->tab_count()); 314 EXPECT_EQ(2, incognito_browser->tab_count());
(...skipping 15 matching lines...) Expand all
302 // WindowOpenDisposition = IGNORE_ACTION. 330 // WindowOpenDisposition = IGNORE_ACTION.
303 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) { 331 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) {
304 RunSuppressTest(IGNORE_ACTION); 332 RunSuppressTest(IGNORE_ACTION);
305 } 333 }
306 334
307 // This tests adding a foreground tab with a predefined TabContents. 335 // This tests adding a foreground tab with a predefined TabContents.
308 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) { 336 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) {
309 browser::NavigateParams p(MakeNavigateParams()); 337 browser::NavigateParams p(MakeNavigateParams());
310 p.disposition = NEW_FOREGROUND_TAB; 338 p.disposition = NEW_FOREGROUND_TAB;
311 p.target_contents = CreateTabContents(); 339 p.target_contents = CreateTabContents();
312 browser::Navigate(&p, this); 340 browser::Navigate(&p);
313 341
314 // Navigate() should have opened the contents in a new foreground in the 342 // Navigate() should have opened the contents in a new foreground in the
315 // current Browser. 343 // current Browser.
316 EXPECT_EQ(browser(), p.browser); 344 EXPECT_EQ(browser(), p.browser);
317 EXPECT_EQ(browser()->GetSelectedTabContents(), p.target_contents); 345 EXPECT_EQ(browser()->GetSelectedTabContents(), p.target_contents);
318 346
319 // We should have one window, with two tabs. 347 // We should have one window, with two tabs.
320 EXPECT_EQ(1u, BrowserList::size()); 348 EXPECT_EQ(1u, BrowserList::size());
321 EXPECT_EQ(2, browser()->tab_count()); 349 EXPECT_EQ(2, browser()->tab_count());
322 } 350 }
323 351
324 #if defined(OS_WIN) 352 #if defined(OS_WIN)
325 // This tests adding a popup with a predefined TabContents. 353 // This tests adding a popup with a predefined TabContents.
326 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_Popup) { 354 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_Popup) {
327 browser::NavigateParams p(MakeNavigateParams()); 355 browser::NavigateParams p(MakeNavigateParams());
328 p.disposition = NEW_POPUP; 356 p.disposition = NEW_POPUP;
329 p.target_contents = CreateTabContents(); 357 p.target_contents = CreateTabContents();
330 p.window_bounds = gfx::Rect(10, 10, 500, 500); 358 p.window_bounds = gfx::Rect(10, 10, 500, 500);
331 browser::Navigate(&p, this); 359 browser::Navigate(&p);
332 360
333 // Navigate() should have opened a new popup window. 361 // Navigate() should have opened a new popup window.
334 EXPECT_NE(browser(), p.browser); 362 EXPECT_NE(browser(), p.browser);
335 EXPECT_EQ(Browser::TYPE_POPUP, p.browser->type()); 363 EXPECT_EQ(Browser::TYPE_POPUP, p.browser->type());
336 364
337 // The web platform is weird. The window bounds specified in 365 // The web platform is weird. The window bounds specified in
338 // |p.window_bounds| are used as follows: 366 // |p.window_bounds| are used as follows:
339 // - the origin is used to position the window 367 // - the origin is used to position the window
340 // - the size is used to size the TabContents of the window. 368 // - the size is used to size the TabContents of the window.
341 // As such the position of the resulting window will always match 369 // As such the position of the resulting window will always match
(...skipping 20 matching lines...) Expand all
362 // This tests adding a tab at a specific index. 390 // This tests adding a tab at a specific index.
363 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) { 391 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) {
364 // This is not meant to be a comprehensive test of whether or not the tab 392 // This is not meant to be a comprehensive test of whether or not the tab
365 // implementation of the browser observes the insertion index. That is 393 // implementation of the browser observes the insertion index. That is
366 // covered by the unit tests for TabStripModel. This merely verifies that 394 // covered by the unit tests for TabStripModel. This merely verifies that
367 // insertion index preference is reflected in common cases. 395 // insertion index preference is reflected in common cases.
368 browser::NavigateParams p(MakeNavigateParams()); 396 browser::NavigateParams p(MakeNavigateParams());
369 p.disposition = NEW_FOREGROUND_TAB; 397 p.disposition = NEW_FOREGROUND_TAB;
370 p.tabstrip_index = 0; 398 p.tabstrip_index = 0;
371 p.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX; 399 p.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX;
372 browser::Navigate(&p, this); 400 browser::Navigate(&p);
373 401
374 // Navigate() should have inserted a new tab at slot 0 in the tabstrip. 402 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
375 EXPECT_EQ(browser(), p.browser); 403 EXPECT_EQ(browser(), p.browser);
376 EXPECT_EQ(0, browser()->tabstrip_model()->GetIndexOfTabContents( 404 EXPECT_EQ(0, browser()->tabstrip_model()->GetIndexOfTabContents(
377 static_cast<const TabContents*>(p.target_contents))); 405 static_cast<const TabContents*>(p.target_contents)));
378 406
379 // We should have one window - the browser() provided by the framework. 407 // We should have one window - the browser() provided by the framework.
380 EXPECT_EQ(1u, BrowserList::size()); 408 EXPECT_EQ(1u, BrowserList::size());
381 EXPECT_EQ(2, browser()->tab_count()); 409 EXPECT_EQ(2, browser()->tab_count());
382 } 410 }
383 411
OLDNEW
« chrome/browser/browser.h ('K') | « chrome/browser/browser_navigator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698