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

Side by Side Diff: chrome/browser/ui/startup/startup_browser_creator_browsertest.cc

Issue 10690060: startup: Put it in chrome namespace. (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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/file_path.h" 6 #include "base/file_path.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/extensions/extension_browsertest.h" 9 #include "chrome/browser/extensions/extension_browsertest.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 127
128 OpenURLsPopupObserver observer; 128 OpenURLsPopupObserver observer;
129 BrowserList::AddObserver(&observer); 129 BrowserList::AddObserver(&observer);
130 130
131 Browser* popup = Browser::CreateWithParams( 131 Browser* popup = Browser::CreateWithParams(
132 Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile())); 132 Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile()));
133 ASSERT_TRUE(popup->is_type_popup()); 133 ASSERT_TRUE(popup->is_type_popup());
134 ASSERT_EQ(popup, observer.added_browser_); 134 ASSERT_EQ(popup, observer.added_browser_);
135 135
136 CommandLine dummy(CommandLine::NO_PROGRAM); 136 CommandLine dummy(CommandLine::NO_PROGRAM);
137 browser::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? 137 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ?
138 browser::startup::IS_FIRST_RUN : 138 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
139 browser::startup::IS_NOT_FIRST_RUN;
140 StartupBrowserCreatorImpl launch(FilePath(), dummy, first_run); 139 StartupBrowserCreatorImpl launch(FilePath(), dummy, first_run);
141 // This should create a new window, but re-use the profile from |popup|. If 140 // This should create a new window, but re-use the profile from |popup|. If
142 // it used a NULL or invalid profile, it would crash. 141 // it used a NULL or invalid profile, it would crash.
143 launch.OpenURLsInBrowser(popup, false, urls); 142 launch.OpenURLsInBrowser(popup, false, urls);
144 ASSERT_NE(popup, observer.added_browser_); 143 ASSERT_NE(popup, observer.added_browser_);
145 BrowserList::RemoveObserver(&observer); 144 BrowserList::RemoveObserver(&observer);
146 } 145 }
147 146
148 // We don't do non-process-startup browser launches on ChromeOS. 147 // We don't do non-process-startup browser launches on ChromeOS.
149 // Session restore for process-startup browser launches is tested 148 // Session restore for process-startup browser launches is tested
(...skipping 13 matching lines...) Expand all
163 // Set the startup preference to open these URLs. 162 // Set the startup preference to open these URLs.
164 SessionStartupPref pref(SessionStartupPref::URLS); 163 SessionStartupPref pref(SessionStartupPref::URLS);
165 pref.urls = urls; 164 pref.urls = urls;
166 SessionStartupPref::SetStartupPref(browser()->profile(), pref); 165 SessionStartupPref::SetStartupPref(browser()->profile(), pref);
167 166
168 // Close the browser. 167 // Close the browser.
169 browser()->window()->Close(); 168 browser()->window()->Close();
170 169
171 // Do a simple non-process-startup browser launch. 170 // Do a simple non-process-startup browser launch.
172 CommandLine dummy(CommandLine::NO_PROGRAM); 171 CommandLine dummy(CommandLine::NO_PROGRAM);
173 browser::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? 172 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ?
174 browser::startup::IS_FIRST_RUN : 173 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
175 browser::startup::IS_NOT_FIRST_RUN;
176 StartupBrowserCreatorImpl launch(FilePath(), dummy, first_run); 174 StartupBrowserCreatorImpl launch(FilePath(), dummy, first_run);
177 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); 175 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false));
178 176
179 // This should have created a new browser window. |browser()| is still 177 // This should have created a new browser window. |browser()| is still
180 // around at this point, even though we've closed its window. 178 // around at this point, even though we've closed its window.
181 Browser* new_browser = NULL; 179 Browser* new_browser = NULL;
182 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); 180 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser));
183 181
184 // The new browser should have one tab for each URL. 182 // The new browser should have one tab for each URL.
185 ASSERT_EQ(static_cast<int>(urls.size()), new_browser->tab_count()); 183 ASSERT_EQ(static_cast<int>(urls.size()), new_browser->tab_count());
(...skipping 21 matching lines...) Expand all
207 FilePath(FilePath::kCurrentDirectory), 205 FilePath(FilePath::kCurrentDirectory),
208 FilePath(FILE_PATH_LITERAL("title2.html")))); 206 FilePath(FILE_PATH_LITERAL("title2.html"))));
209 207
210 // Set the startup preference to open these URLs. 208 // Set the startup preference to open these URLs.
211 SessionStartupPref pref(SessionStartupPref::URLS); 209 SessionStartupPref pref(SessionStartupPref::URLS);
212 pref.urls = urls; 210 pref.urls = urls;
213 SessionStartupPref::SetStartupPref(browser()->profile(), pref); 211 SessionStartupPref::SetStartupPref(browser()->profile(), pref);
214 212
215 // Do a simple non-process-startup browser launch. 213 // Do a simple non-process-startup browser launch.
216 CommandLine dummy(CommandLine::NO_PROGRAM); 214 CommandLine dummy(CommandLine::NO_PROGRAM);
217 browser::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? 215 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ?
218 browser::startup::IS_FIRST_RUN : browser::startup::IS_NOT_FIRST_RUN; 216 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
219 StartupBrowserCreatorImpl launch(FilePath(), dummy, first_run); 217 StartupBrowserCreatorImpl launch(FilePath(), dummy, first_run);
220 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); 218 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false));
221 219
222 // This should have created a new browser window. 220 // This should have created a new browser window.
223 Browser* new_browser = NULL; 221 Browser* new_browser = NULL;
224 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); 222 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser));
225 223
226 // The new browser should have exactly one tab (not the startup URLs). 224 // The new browser should have exactly one tab (not the startup URLs).
227 ASSERT_EQ(1, new_browser->tab_count()); 225 ASSERT_EQ(1, new_browser->tab_count());
228 } 226 }
229 227
230 // App shortcuts are not implemented on mac os. 228 // App shortcuts are not implemented on mac os.
231 #if !defined(OS_MACOSX) 229 #if !defined(OS_MACOSX)
232 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutNoPref) { 230 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutNoPref) {
233 // Load an app with launch.container = 'tab'. 231 // Load an app with launch.container = 'tab'.
234 const Extension* extension_app = NULL; 232 const Extension* extension_app = NULL;
235 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app)); 233 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app));
236 234
237 // Add --app-id=<extension->id()> to the command line. 235 // Add --app-id=<extension->id()> to the command line.
238 CommandLine command_line(CommandLine::NO_PROGRAM); 236 CommandLine command_line(CommandLine::NO_PROGRAM);
239 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id()); 237 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id());
240 238
241 browser::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? 239 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ?
242 browser::startup::IS_FIRST_RUN : browser::startup::IS_NOT_FIRST_RUN; 240 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
243 StartupBrowserCreatorImpl launch(FilePath(), command_line, first_run); 241 StartupBrowserCreatorImpl launch(FilePath(), command_line, first_run);
244 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); 242 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false));
245 243
246 // No pref was set, so the app should have opened in a window. 244 // No pref was set, so the app should have opened in a window.
247 // The launch should have created a new browser. 245 // The launch should have created a new browser.
248 Browser* new_browser = NULL; 246 Browser* new_browser = NULL;
249 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); 247 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser));
250 248
251 // Expect an app window. 249 // Expect an app window.
252 EXPECT_TRUE(new_browser->is_app()); 250 EXPECT_TRUE(new_browser->is_app());
253 251
254 // The browser's app_name should include the app's ID. 252 // The browser's app_name should include the app's ID.
255 EXPECT_NE( 253 EXPECT_NE(
256 new_browser->app_name_.find(extension_app->id()), 254 new_browser->app_name_.find(extension_app->id()),
257 std::string::npos) << new_browser->app_name_; 255 std::string::npos) << new_browser->app_name_;
258 } 256 }
259 257
260 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutWindowPref) { 258 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutWindowPref) {
261 const Extension* extension_app = NULL; 259 const Extension* extension_app = NULL;
262 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app)); 260 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app));
263 261
264 // Set a pref indicating that the user wants to open this app in a window. 262 // Set a pref indicating that the user wants to open this app in a window.
265 SetAppLaunchPref(extension_app->id(), ExtensionPrefs::LAUNCH_WINDOW); 263 SetAppLaunchPref(extension_app->id(), ExtensionPrefs::LAUNCH_WINDOW);
266 264
267 CommandLine command_line(CommandLine::NO_PROGRAM); 265 CommandLine command_line(CommandLine::NO_PROGRAM);
268 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id()); 266 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id());
269 browser::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? 267 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ?
270 browser::startup::IS_FIRST_RUN : browser::startup::IS_NOT_FIRST_RUN; 268 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
271 StartupBrowserCreatorImpl launch(FilePath(), command_line, first_run); 269 StartupBrowserCreatorImpl launch(FilePath(), command_line, first_run);
272 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); 270 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false));
273 271
274 // Pref was set to open in a window, so the app should have opened in a 272 // Pref was set to open in a window, so the app should have opened in a
275 // window. The launch should have created a new browser. Find the new 273 // window. The launch should have created a new browser. Find the new
276 // browser. 274 // browser.
277 Browser* new_browser = NULL; 275 Browser* new_browser = NULL;
278 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); 276 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser));
279 277
280 // Expect an app window. 278 // Expect an app window.
281 EXPECT_TRUE(new_browser->is_app()); 279 EXPECT_TRUE(new_browser->is_app());
282 280
283 // The browser's app_name should include the app's ID. 281 // The browser's app_name should include the app's ID.
284 EXPECT_NE( 282 EXPECT_NE(
285 new_browser->app_name_.find(extension_app->id()), 283 new_browser->app_name_.find(extension_app->id()),
286 std::string::npos) << new_browser->app_name_; 284 std::string::npos) << new_browser->app_name_;
287 } 285 }
288 286
289 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutTabPref) { 287 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutTabPref) {
290 // Load an app with launch.container = 'tab'. 288 // Load an app with launch.container = 'tab'.
291 const Extension* extension_app = NULL; 289 const Extension* extension_app = NULL;
292 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app)); 290 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app));
293 291
294 // Set a pref indicating that the user wants to open this app in a window. 292 // Set a pref indicating that the user wants to open this app in a window.
295 SetAppLaunchPref(extension_app->id(), ExtensionPrefs::LAUNCH_REGULAR); 293 SetAppLaunchPref(extension_app->id(), ExtensionPrefs::LAUNCH_REGULAR);
296 294
297 CommandLine command_line(CommandLine::NO_PROGRAM); 295 CommandLine command_line(CommandLine::NO_PROGRAM);
298 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id()); 296 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id());
299 browser::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? 297 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ?
300 browser::startup::IS_FIRST_RUN : browser::startup::IS_NOT_FIRST_RUN; 298 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
301 StartupBrowserCreatorImpl launch(FilePath(), command_line, first_run); 299 StartupBrowserCreatorImpl launch(FilePath(), command_line, first_run);
302 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); 300 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false));
303 301
304 // When an app shortcut is open and the pref indicates a tab should 302 // When an app shortcut is open and the pref indicates a tab should
305 // open, the tab is open in a new browser window. Expect a new window. 303 // open, the tab is open in a new browser window. Expect a new window.
306 ASSERT_EQ(2u, browser::GetBrowserCount(browser()->profile())); 304 ASSERT_EQ(2u, browser::GetBrowserCount(browser()->profile()));
307 305
308 Browser* new_browser = NULL; 306 Browser* new_browser = NULL;
309 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); 307 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser));
310 308
311 // The tab should be in a tabbed window. 309 // The tab should be in a tabbed window.
312 EXPECT_TRUE(new_browser->is_type_tabbed()); 310 EXPECT_TRUE(new_browser->is_type_tabbed());
313 311
314 // The browser's app_name should not include the app's ID: It is in a 312 // The browser's app_name should not include the app's ID: It is in a
315 // normal browser. 313 // normal browser.
316 EXPECT_EQ( 314 EXPECT_EQ(
317 new_browser->app_name_.find(extension_app->id()), 315 new_browser->app_name_.find(extension_app->id()),
318 std::string::npos) << new_browser->app_name_; 316 std::string::npos) << new_browser->app_name_;
319 } 317 }
320 318
321 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutPanel) { 319 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutPanel) {
322 // Load an app with launch.container = 'panel'. 320 // Load an app with launch.container = 'panel'.
323 const Extension* extension_app = NULL; 321 const Extension* extension_app = NULL;
324 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_panel_container", &extension_app)); 322 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_panel_container", &extension_app));
325 323
326 CommandLine command_line(CommandLine::NO_PROGRAM); 324 CommandLine command_line(CommandLine::NO_PROGRAM);
327 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id()); 325 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id());
328 browser::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? 326 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ?
329 browser::startup::IS_FIRST_RUN : browser::startup::IS_NOT_FIRST_RUN; 327 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
330 StartupBrowserCreatorImpl launch(FilePath(), command_line, first_run); 328 StartupBrowserCreatorImpl launch(FilePath(), command_line, first_run);
331 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); 329 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false));
332 330
333 // The launch should have created a new browser, with a panel type. 331 // The launch should have created a new browser, with a panel type.
334 Browser* new_browser = NULL; 332 Browser* new_browser = NULL;
335 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); 333 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser));
336 334
337 // Expect an app panel. 335 // Expect an app panel.
338 EXPECT_TRUE(new_browser->is_type_panel() && new_browser->is_app()); 336 EXPECT_TRUE(new_browser->is_type_panel() && new_browser->is_app());
339 337
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 ASSERT_EQ(1u, browser::GetBrowserCount(profile_urls)); 683 ASSERT_EQ(1u, browser::GetBrowserCount(profile_urls));
686 new_browser = FindOneOtherBrowserForProfile(profile_urls, NULL); 684 new_browser = FindOneOtherBrowserForProfile(profile_urls, NULL);
687 ASSERT_TRUE(new_browser); 685 ASSERT_TRUE(new_browser);
688 ASSERT_EQ(1, new_browser->tab_count()); 686 ASSERT_EQ(1, new_browser->tab_count());
689 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), 687 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
690 chrome::GetWebContentsAt(new_browser, 0)->GetURL()); 688 chrome::GetWebContentsAt(new_browser, 0)->GetURL());
691 EXPECT_EQ(1U, chrome::GetTabContentsAt(new_browser, 0)->infobar_tab_helper()-> 689 EXPECT_EQ(1U, chrome::GetTabContentsAt(new_browser, 0)->infobar_tab_helper()->
692 infobar_count()); 690 infobar_count());
693 } 691 }
694 #endif // !OS_CHROMEOS 692 #endif // !OS_CHROMEOS
OLDNEW
« no previous file with comments | « chrome/browser/ui/startup/startup_browser_creator.cc ('k') | chrome/browser/ui/startup/startup_browser_creator_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698