| OLD | NEW |
| 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/files/file_path.h" | 6 #include "base/files/file_path.h" |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.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 19 matching lines...) Expand all Loading... |
| 30 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 31 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 32 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
| 33 #include "chrome/test/base/in_process_browser_test.h" | 33 #include "chrome/test/base/in_process_browser_test.h" |
| 34 #include "chrome/test/base/ui_test_utils.h" | 34 #include "chrome/test/base/ui_test_utils.h" |
| 35 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| 37 | 37 |
| 38 using extensions::Extension; | 38 using extensions::Extension; |
| 39 | 39 |
| 40 namespace { |
| 41 |
| 42 // Check that there are two browsers. Find the one that is not |browser|. |
| 43 Browser* FindOneOtherBrowser(Browser* browser) { |
| 44 // There should only be one other browser. |
| 45 EXPECT_EQ(2u, chrome::GetBrowserCount(browser->profile(), |
| 46 browser->host_desktop_type())); |
| 47 |
| 48 // Find the new browser. |
| 49 Browser* other_browser = NULL; |
| 50 for (chrome::BrowserIterator it; !it.done() && !other_browser; it.Next()) { |
| 51 if (*it != browser) |
| 52 other_browser = *it; |
| 53 } |
| 54 return other_browser; |
| 55 } |
| 56 |
| 57 } // namespace |
| 58 |
| 40 class StartupBrowserCreatorTest : public ExtensionBrowserTest { | 59 class StartupBrowserCreatorTest : public ExtensionBrowserTest { |
| 41 protected: | 60 protected: |
| 42 virtual bool SetUpUserDataDirectory() OVERRIDE { | 61 virtual bool SetUpUserDataDirectory() OVERRIDE { |
| 43 // Make sure the first run sentinel file exists before running these tests, | 62 // Make sure the first run sentinel file exists before running these tests, |
| 44 // since some of them customize the session startup pref whose value can | 63 // since some of them customize the session startup pref whose value can |
| 45 // be different than the default during the first run. | 64 // be different than the default during the first run. |
| 46 // TODO(bauerb): set the first run flag instead of creating a sentinel file. | 65 // TODO(bauerb): set the first run flag instead of creating a sentinel file. |
| 47 first_run::CreateSentinel(); | 66 first_run::CreateSentinel(); |
| 48 return ExtensionBrowserTest::SetUpUserDataDirectory(); | 67 return ExtensionBrowserTest::SetUpUserDataDirectory(); |
| 49 } | 68 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 77 browser()->host_desktop_type())); | 96 browser()->host_desktop_type())); |
| 78 } | 97 } |
| 79 | 98 |
| 80 void SetAppLaunchPref(const std::string& app_id, | 99 void SetAppLaunchPref(const std::string& app_id, |
| 81 extensions::ExtensionPrefs::LaunchType launch_type) { | 100 extensions::ExtensionPrefs::LaunchType launch_type) { |
| 82 ExtensionService* service = extensions::ExtensionSystem::Get( | 101 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 83 browser()->profile())->extension_service(); | 102 browser()->profile())->extension_service(); |
| 84 service->extension_prefs()->SetLaunchType(app_id, launch_type); | 103 service->extension_prefs()->SetLaunchType(app_id, launch_type); |
| 85 } | 104 } |
| 86 | 105 |
| 87 // Check that there are two browsers. Find the one that is not |browser()|. | |
| 88 void FindOneOtherBrowser(Browser** out_other_browser) { | |
| 89 // There should only be one other browser. | |
| 90 ASSERT_EQ(2u, chrome::GetBrowserCount(browser()->profile(), | |
| 91 browser()->host_desktop_type())); | |
| 92 | |
| 93 // Find the new browser. | |
| 94 Browser* other_browser = NULL; | |
| 95 for (chrome::BrowserIterator it; !it.done() && !other_browser; it.Next()) { | |
| 96 if (*it != browser()) | |
| 97 other_browser = *it; | |
| 98 } | |
| 99 ASSERT_TRUE(other_browser); | |
| 100 ASSERT_TRUE(other_browser != browser()); | |
| 101 *out_other_browser = other_browser; | |
| 102 } | |
| 103 | |
| 104 Browser* FindOneOtherBrowserForProfile(Profile* profile, | 106 Browser* FindOneOtherBrowserForProfile(Profile* profile, |
| 105 Browser* not_this_browser) { | 107 Browser* not_this_browser) { |
| 106 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | 108 for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
| 107 if (*it != not_this_browser && it->profile() == profile) | 109 if (*it != not_this_browser && it->profile() == profile) |
| 108 return *it; | 110 return *it; |
| 109 } | 111 } |
| 110 return NULL; | 112 return NULL; |
| 111 } | 113 } |
| 112 }; | 114 }; |
| 113 | 115 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 183 |
| 182 // Do a simple non-process-startup browser launch. | 184 // Do a simple non-process-startup browser launch. |
| 183 CommandLine dummy(CommandLine::NO_PROGRAM); | 185 CommandLine dummy(CommandLine::NO_PROGRAM); |
| 184 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? | 186 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? |
| 185 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; | 187 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; |
| 186 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run); | 188 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run); |
| 187 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); | 189 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); |
| 188 | 190 |
| 189 // This should have created a new browser window. |browser()| is still | 191 // This should have created a new browser window. |browser()| is still |
| 190 // around at this point, even though we've closed its window. | 192 // around at this point, even though we've closed its window. |
| 191 Browser* new_browser = NULL; | 193 Browser* new_browser = FindOneOtherBrowser(browser()); |
| 192 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); | 194 ASSERT_TRUE(new_browser); |
| 193 | 195 |
| 194 // The new browser should have one tab for each URL. | 196 // The new browser should have one tab for each URL. |
| 195 TabStripModel* tab_strip = new_browser->tab_strip_model(); | 197 TabStripModel* tab_strip = new_browser->tab_strip_model(); |
| 196 ASSERT_EQ(static_cast<int>(urls.size()), tab_strip->count()); | 198 ASSERT_EQ(static_cast<int>(urls.size()), tab_strip->count()); |
| 197 for (size_t i=0; i < urls.size(); i++) { | 199 for (size_t i=0; i < urls.size(); i++) { |
| 198 EXPECT_EQ(urls[i], tab_strip->GetWebContentsAt(i)->GetURL()); | 200 EXPECT_EQ(urls[i], tab_strip->GetWebContentsAt(i)->GetURL()); |
| 199 } | 201 } |
| 200 | 202 |
| 201 // The two tabs, despite having the same site, should be in different | 203 // The two tabs, despite having the same site, should be in different |
| 202 // SiteInstances. | 204 // SiteInstances. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 224 SessionStartupPref::SetStartupPref(browser()->profile(), pref); | 226 SessionStartupPref::SetStartupPref(browser()->profile(), pref); |
| 225 | 227 |
| 226 // Do a simple non-process-startup browser launch. | 228 // Do a simple non-process-startup browser launch. |
| 227 CommandLine dummy(CommandLine::NO_PROGRAM); | 229 CommandLine dummy(CommandLine::NO_PROGRAM); |
| 228 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? | 230 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? |
| 229 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; | 231 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; |
| 230 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run); | 232 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run); |
| 231 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); | 233 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); |
| 232 | 234 |
| 233 // This should have created a new browser window. | 235 // This should have created a new browser window. |
| 234 Browser* new_browser = NULL; | 236 Browser* new_browser = FindOneOtherBrowser(browser()); |
| 235 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); | 237 ASSERT_TRUE(new_browser); |
| 236 | 238 |
| 237 // The new browser should have exactly one tab (not the startup URLs). | 239 // The new browser should have exactly one tab (not the startup URLs). |
| 238 ASSERT_EQ(1, new_browser->tab_strip_model()->count()); | 240 ASSERT_EQ(1, new_browser->tab_strip_model()->count()); |
| 239 } | 241 } |
| 240 | 242 |
| 241 // App shortcuts are not implemented on mac os. | 243 // App shortcuts are not implemented on mac os. |
| 242 #if !defined(OS_MACOSX) | 244 #if !defined(OS_MACOSX) |
| 243 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutNoPref) { | 245 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutNoPref) { |
| 244 // Load an app with launch.container = 'tab'. | 246 // Load an app with launch.container = 'tab'. |
| 245 const Extension* extension_app = NULL; | 247 const Extension* extension_app = NULL; |
| 246 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app)); | 248 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app)); |
| 247 | 249 |
| 248 // Add --app-id=<extension->id()> to the command line. | 250 // Add --app-id=<extension->id()> to the command line. |
| 249 CommandLine command_line(CommandLine::NO_PROGRAM); | 251 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 250 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id()); | 252 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id()); |
| 251 | 253 |
| 252 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? | 254 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? |
| 253 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; | 255 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; |
| 254 StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run); | 256 StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run); |
| 255 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); | 257 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); |
| 256 | 258 |
| 257 // No pref was set, so the app should have opened in a window. | 259 // No pref was set, so the app should have opened in a window. |
| 258 // The launch should have created a new browser. | 260 // The launch should have created a new browser. |
| 259 Browser* new_browser = NULL; | 261 Browser* new_browser = FindOneOtherBrowser(browser()); |
| 260 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); | 262 ASSERT_TRUE(new_browser); |
| 261 | 263 |
| 262 // Expect an app window. | 264 // Expect an app window. |
| 263 EXPECT_TRUE(new_browser->is_app()); | 265 EXPECT_TRUE(new_browser->is_app()); |
| 264 | 266 |
| 265 // The browser's app_name should include the app's ID. | 267 // The browser's app_name should include the app's ID. |
| 266 EXPECT_NE( | 268 EXPECT_NE( |
| 267 new_browser->app_name_.find(extension_app->id()), | 269 new_browser->app_name_.find(extension_app->id()), |
| 268 std::string::npos) << new_browser->app_name_; | 270 std::string::npos) << new_browser->app_name_; |
| 269 } | 271 } |
| 270 | 272 |
| 271 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutWindowPref) { | 273 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutWindowPref) { |
| 272 const Extension* extension_app = NULL; | 274 const Extension* extension_app = NULL; |
| 273 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app)); | 275 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app)); |
| 274 | 276 |
| 275 // Set a pref indicating that the user wants to open this app in a window. | 277 // Set a pref indicating that the user wants to open this app in a window. |
| 276 SetAppLaunchPref(extension_app->id(), | 278 SetAppLaunchPref(extension_app->id(), |
| 277 extensions::ExtensionPrefs::LAUNCH_WINDOW); | 279 extensions::ExtensionPrefs::LAUNCH_WINDOW); |
| 278 | 280 |
| 279 CommandLine command_line(CommandLine::NO_PROGRAM); | 281 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 280 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id()); | 282 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id()); |
| 281 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? | 283 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? |
| 282 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; | 284 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; |
| 283 StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run); | 285 StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run); |
| 284 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); | 286 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); |
| 285 | 287 |
| 286 // Pref was set to open in a window, so the app should have opened in a | 288 // Pref was set to open in a window, so the app should have opened in a |
| 287 // window. The launch should have created a new browser. Find the new | 289 // window. The launch should have created a new browser. Find the new |
| 288 // browser. | 290 // browser. |
| 289 Browser* new_browser = NULL; | 291 Browser* new_browser = FindOneOtherBrowser(browser()); |
| 290 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); | 292 ASSERT_TRUE(new_browser); |
| 291 | 293 |
| 292 // Expect an app window. | 294 // Expect an app window. |
| 293 EXPECT_TRUE(new_browser->is_app()); | 295 EXPECT_TRUE(new_browser->is_app()); |
| 294 | 296 |
| 295 // The browser's app_name should include the app's ID. | 297 // The browser's app_name should include the app's ID. |
| 296 EXPECT_NE( | 298 EXPECT_NE( |
| 297 new_browser->app_name_.find(extension_app->id()), | 299 new_browser->app_name_.find(extension_app->id()), |
| 298 std::string::npos) << new_browser->app_name_; | 300 std::string::npos) << new_browser->app_name_; |
| 299 } | 301 } |
| 300 | 302 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 312 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? | 314 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? |
| 313 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; | 315 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; |
| 314 StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run); | 316 StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run); |
| 315 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); | 317 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); |
| 316 | 318 |
| 317 // When an app shortcut is open and the pref indicates a tab should | 319 // When an app shortcut is open and the pref indicates a tab should |
| 318 // open, the tab is open in a new browser window. Expect a new window. | 320 // open, the tab is open in a new browser window. Expect a new window. |
| 319 ASSERT_EQ(2u, chrome::GetBrowserCount(browser()->profile(), | 321 ASSERT_EQ(2u, chrome::GetBrowserCount(browser()->profile(), |
| 320 browser()->host_desktop_type())); | 322 browser()->host_desktop_type())); |
| 321 | 323 |
| 322 Browser* new_browser = NULL; | 324 Browser* new_browser = FindOneOtherBrowser(browser()); |
| 323 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); | 325 ASSERT_TRUE(new_browser); |
| 324 | 326 |
| 325 // The tab should be in a tabbed window. | 327 // The tab should be in a tabbed window. |
| 326 EXPECT_TRUE(new_browser->is_type_tabbed()); | 328 EXPECT_TRUE(new_browser->is_type_tabbed()); |
| 327 | 329 |
| 328 // The browser's app_name should not include the app's ID: It is in a | 330 // The browser's app_name should not include the app's ID: It is in a |
| 329 // normal browser. | 331 // normal browser. |
| 330 EXPECT_EQ( | 332 EXPECT_EQ( |
| 331 new_browser->app_name_.find(extension_app->id()), | 333 new_browser->app_name_.find(extension_app->id()), |
| 332 std::string::npos) << new_browser->app_name_; | 334 std::string::npos) << new_browser->app_name_; |
| 333 } | 335 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 browser_creator.AddFirstRunTab(test_server()->GetURL("files/title1.html")); | 367 browser_creator.AddFirstRunTab(test_server()->GetURL("files/title1.html")); |
| 366 browser_creator.AddFirstRunTab(test_server()->GetURL("files/title2.html")); | 368 browser_creator.AddFirstRunTab(test_server()->GetURL("files/title2.html")); |
| 367 | 369 |
| 368 // Do a simple non-process-startup browser launch. | 370 // Do a simple non-process-startup browser launch. |
| 369 CommandLine dummy(CommandLine::NO_PROGRAM); | 371 CommandLine dummy(CommandLine::NO_PROGRAM); |
| 370 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator, | 372 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator, |
| 371 chrome::startup::IS_FIRST_RUN); | 373 chrome::startup::IS_FIRST_RUN); |
| 372 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); | 374 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); |
| 373 | 375 |
| 374 // This should have created a new browser window. | 376 // This should have created a new browser window. |
| 375 Browser* new_browser = NULL; | 377 Browser* new_browser = FindOneOtherBrowser(browser()); |
| 376 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); | 378 ASSERT_TRUE(new_browser); |
| 377 | 379 |
| 378 TabStripModel* tab_strip = new_browser->tab_strip_model(); | 380 TabStripModel* tab_strip = new_browser->tab_strip_model(); |
| 379 EXPECT_EQ(2, tab_strip->count()); | 381 EXPECT_EQ(2, tab_strip->count()); |
| 380 | 382 |
| 381 EXPECT_EQ("title1.html", | 383 EXPECT_EQ("title1.html", |
| 382 tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName()); | 384 tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName()); |
| 383 EXPECT_EQ("title2.html", | 385 EXPECT_EQ("title2.html", |
| 384 tab_strip->GetWebContentsAt(1)->GetURL().ExtractFileName()); | 386 tab_strip->GetWebContentsAt(1)->GetURL().ExtractFileName()); |
| 385 } | 387 } |
| 386 | 388 |
| 387 // Test hard-coded special first run tabs (defined in | 389 // Test hard-coded special first run tabs (defined in |
| 388 // StartupBrowserCreatorImpl::AddStartupURLs()). | 390 // StartupBrowserCreatorImpl::AddStartupURLs()). |
| 389 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, AddCustomFirstRunTab) { | 391 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, AddCustomFirstRunTab) { |
| 390 StartupBrowserCreator browser_creator; | 392 StartupBrowserCreator browser_creator; |
| 391 browser_creator.AddFirstRunTab(test_server()->GetURL("files/title1.html")); | 393 browser_creator.AddFirstRunTab(test_server()->GetURL("files/title1.html")); |
| 392 browser_creator.AddFirstRunTab(GURL("http://new_tab_page")); | 394 browser_creator.AddFirstRunTab(GURL("http://new_tab_page")); |
| 393 browser_creator.AddFirstRunTab(test_server()->GetURL("files/title2.html")); | 395 browser_creator.AddFirstRunTab(test_server()->GetURL("files/title2.html")); |
| 394 browser_creator.AddFirstRunTab(GURL("http://welcome_page")); | 396 browser_creator.AddFirstRunTab(GURL("http://welcome_page")); |
| 395 | 397 |
| 396 // Do a simple non-process-startup browser launch. | 398 // Do a simple non-process-startup browser launch. |
| 397 CommandLine dummy(CommandLine::NO_PROGRAM); | 399 CommandLine dummy(CommandLine::NO_PROGRAM); |
| 398 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator, | 400 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator, |
| 399 chrome::startup::IS_FIRST_RUN); | 401 chrome::startup::IS_FIRST_RUN); |
| 400 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); | 402 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); |
| 401 | 403 |
| 402 // This should have created a new browser window. | 404 // This should have created a new browser window. |
| 403 Browser* new_browser = NULL; | 405 Browser* new_browser = FindOneOtherBrowser(browser()); |
| 404 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); | 406 ASSERT_TRUE(new_browser); |
| 405 | 407 |
| 406 TabStripModel* tab_strip = new_browser->tab_strip_model(); | 408 TabStripModel* tab_strip = new_browser->tab_strip_model(); |
| 407 EXPECT_EQ(4, tab_strip->count()); | 409 EXPECT_EQ(4, tab_strip->count()); |
| 408 | 410 |
| 409 EXPECT_EQ("title1.html", | 411 EXPECT_EQ("title1.html", |
| 410 tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName()); | 412 tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName()); |
| 411 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), | 413 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), |
| 412 tab_strip->GetWebContentsAt(1)->GetURL()); | 414 tab_strip->GetWebContentsAt(1)->GetURL()); |
| 413 EXPECT_EQ("title2.html", | 415 EXPECT_EQ("title2.html", |
| 414 tab_strip->GetWebContentsAt(2)->GetURL().ExtractFileName()); | 416 tab_strip->GetWebContentsAt(2)->GetURL().ExtractFileName()); |
| 415 EXPECT_EQ(internals::GetWelcomePageURL(), | 417 EXPECT_EQ(internals::GetWelcomePageURL(), |
| 416 tab_strip->GetWebContentsAt(3)->GetURL()); | 418 tab_strip->GetWebContentsAt(3)->GetURL()); |
| 417 } | 419 } |
| 418 | 420 |
| 419 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, SyncPromoNoWelcomePage) { | 421 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, SyncPromoNoWelcomePage) { |
| 420 // Trick this test into thinking the promo has been shown for this profile; so | 422 // Trick this test into thinking the promo has been shown for this profile; so |
| 421 // that it will show it again (otherwise it skips showing it since | 423 // that it will show it again (otherwise it skips showing it since |
| 422 // --no-first-run is specified in browser tests). | 424 // --no-first-run is specified in browser tests). |
| 423 SyncPromoUI::DidShowSyncPromoAtStartup(browser()->profile()); | 425 SyncPromoUI::DidShowSyncPromoAtStartup(browser()->profile()); |
| 424 | 426 |
| 425 // Do a simple non-process-startup browser launch. | 427 // Do a simple non-process-startup browser launch. |
| 426 CommandLine dummy(CommandLine::NO_PROGRAM); | 428 CommandLine dummy(CommandLine::NO_PROGRAM); |
| 427 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, | 429 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, |
| 428 chrome::startup::IS_FIRST_RUN); | 430 chrome::startup::IS_FIRST_RUN); |
| 429 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); | 431 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); |
| 430 | 432 |
| 431 // This should have created a new browser window. | 433 // This should have created a new browser window. |
| 432 Browser* new_browser = NULL; | 434 Browser* new_browser = FindOneOtherBrowser(browser()); |
| 433 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); | 435 ASSERT_TRUE(new_browser); |
| 434 | 436 |
| 435 TabStripModel* tab_strip = new_browser->tab_strip_model(); | 437 TabStripModel* tab_strip = new_browser->tab_strip_model(); |
| 436 EXPECT_EQ(1, tab_strip->count()); | 438 EXPECT_EQ(1, tab_strip->count()); |
| 437 | 439 |
| 438 if (SyncPromoUI::ShouldShowSyncPromoAtStartup(browser()->profile(), true)) { | 440 if (SyncPromoUI::ShouldShowSyncPromoAtStartup(browser()->profile(), true)) { |
| 439 EXPECT_EQ("signin", tab_strip->GetWebContentsAt(0)->GetURL().host()); | 441 EXPECT_EQ("signin", tab_strip->GetWebContentsAt(0)->GetURL().host()); |
| 440 } else { | 442 } else { |
| 441 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), | 443 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), |
| 442 tab_strip->GetWebContentsAt(0)->GetURL()); | 444 tab_strip->GetWebContentsAt(0)->GetURL()); |
| 443 } | 445 } |
| 444 } | 446 } |
| 445 | 447 |
| 446 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, SyncPromoWithWelcomePage) { | 448 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, SyncPromoWithWelcomePage) { |
| 447 // Trick this test into thinking the promo has been shown for this profile; so | 449 // Trick this test into thinking the promo has been shown for this profile; so |
| 448 // that it will show it again (otherwise it skips showing it since | 450 // that it will show it again (otherwise it skips showing it since |
| 449 // --no-first-run is specified in browser tests). | 451 // --no-first-run is specified in browser tests). |
| 450 SyncPromoUI::DidShowSyncPromoAtStartup(browser()->profile()); | 452 SyncPromoUI::DidShowSyncPromoAtStartup(browser()->profile()); |
| 451 first_run::SetShouldShowWelcomePage(); | 453 first_run::SetShouldShowWelcomePage(); |
| 452 | 454 |
| 453 // Do a simple non-process-startup browser launch. | 455 // Do a simple non-process-startup browser launch. |
| 454 CommandLine dummy(CommandLine::NO_PROGRAM); | 456 CommandLine dummy(CommandLine::NO_PROGRAM); |
| 455 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, | 457 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, |
| 456 chrome::startup::IS_FIRST_RUN); | 458 chrome::startup::IS_FIRST_RUN); |
| 457 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); | 459 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); |
| 458 | 460 |
| 459 // This should have created a new browser window. | 461 // This should have created a new browser window. |
| 460 Browser* new_browser = NULL; | 462 Browser* new_browser = FindOneOtherBrowser(browser()); |
| 461 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); | 463 ASSERT_TRUE(new_browser); |
| 462 | 464 |
| 463 TabStripModel* tab_strip = new_browser->tab_strip_model(); | 465 TabStripModel* tab_strip = new_browser->tab_strip_model(); |
| 464 EXPECT_EQ(2, tab_strip->count()); | 466 EXPECT_EQ(2, tab_strip->count()); |
| 465 | 467 |
| 466 if (SyncPromoUI::ShouldShowSyncPromoAtStartup(browser()->profile(), true)) { | 468 if (SyncPromoUI::ShouldShowSyncPromoAtStartup(browser()->profile(), true)) { |
| 467 EXPECT_EQ("signin", tab_strip->GetWebContentsAt(0)->GetURL().host()); | 469 EXPECT_EQ("signin", tab_strip->GetWebContentsAt(0)->GetURL().host()); |
| 468 } else { | 470 } else { |
| 469 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), | 471 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), |
| 470 tab_strip->GetWebContentsAt(0)->GetURL()); | 472 tab_strip->GetWebContentsAt(0)->GetURL()); |
| 471 } | 473 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 487 // more than 2 first run tabs. | 489 // more than 2 first run tabs. |
| 488 first_run::SetShouldShowWelcomePage(); | 490 first_run::SetShouldShowWelcomePage(); |
| 489 | 491 |
| 490 // Do a simple non-process-startup browser launch. | 492 // Do a simple non-process-startup browser launch. |
| 491 CommandLine dummy(CommandLine::NO_PROGRAM); | 493 CommandLine dummy(CommandLine::NO_PROGRAM); |
| 492 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator, | 494 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator, |
| 493 chrome::startup::IS_FIRST_RUN); | 495 chrome::startup::IS_FIRST_RUN); |
| 494 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); | 496 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); |
| 495 | 497 |
| 496 // This should have created a new browser window. | 498 // This should have created a new browser window. |
| 497 Browser* new_browser = NULL; | 499 Browser* new_browser = FindOneOtherBrowser(browser()); |
| 498 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); | 500 ASSERT_TRUE(new_browser); |
| 499 | 501 |
| 500 TabStripModel* tab_strip = new_browser->tab_strip_model(); | 502 TabStripModel* tab_strip = new_browser->tab_strip_model(); |
| 501 if (SyncPromoUI::ShouldShowSyncPromoAtStartup(browser()->profile(), true)) { | 503 if (SyncPromoUI::ShouldShowSyncPromoAtStartup(browser()->profile(), true)) { |
| 502 EXPECT_EQ(2, tab_strip->count()); | 504 EXPECT_EQ(2, tab_strip->count()); |
| 503 EXPECT_EQ("signin", tab_strip->GetWebContentsAt(0)->GetURL().host()); | 505 EXPECT_EQ("signin", tab_strip->GetWebContentsAt(0)->GetURL().host()); |
| 504 EXPECT_EQ("title1.html", | 506 EXPECT_EQ("title1.html", |
| 505 tab_strip->GetWebContentsAt(1)->GetURL().ExtractFileName()); | 507 tab_strip->GetWebContentsAt(1)->GetURL().ExtractFileName()); |
| 506 } else { | 508 } else { |
| 507 EXPECT_EQ(1, tab_strip->count()); | 509 EXPECT_EQ(1, tab_strip->count()); |
| 508 EXPECT_EQ("title1.html", | 510 EXPECT_EQ("title1.html", |
| (...skipping 14 matching lines...) Expand all Loading... |
| 523 // --no-first-run is specified in browser tests). | 525 // --no-first-run is specified in browser tests). |
| 524 SyncPromoUI::DidShowSyncPromoAtStartup(browser()->profile()); | 526 SyncPromoUI::DidShowSyncPromoAtStartup(browser()->profile()); |
| 525 | 527 |
| 526 // Do a simple non-process-startup browser launch. | 528 // Do a simple non-process-startup browser launch. |
| 527 CommandLine dummy(CommandLine::NO_PROGRAM); | 529 CommandLine dummy(CommandLine::NO_PROGRAM); |
| 528 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator, | 530 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator, |
| 529 chrome::startup::IS_FIRST_RUN); | 531 chrome::startup::IS_FIRST_RUN); |
| 530 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); | 532 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); |
| 531 | 533 |
| 532 // This should have created a new browser window. | 534 // This should have created a new browser window. |
| 533 Browser* new_browser = NULL; | 535 Browser* new_browser = FindOneOtherBrowser(browser()); |
| 534 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); | 536 ASSERT_TRUE(new_browser); |
| 535 | 537 |
| 536 TabStripModel* tab_strip = new_browser->tab_strip_model(); | 538 TabStripModel* tab_strip = new_browser->tab_strip_model(); |
| 537 if (SyncPromoUI::ShouldShowSyncPromoAtStartup(browser()->profile(), true)) { | 539 if (SyncPromoUI::ShouldShowSyncPromoAtStartup(browser()->profile(), true)) { |
| 538 EXPECT_EQ(3, tab_strip->count()); | 540 EXPECT_EQ(3, tab_strip->count()); |
| 539 EXPECT_EQ("signin", tab_strip->GetWebContentsAt(0)->GetURL().host()); | 541 EXPECT_EQ("signin", tab_strip->GetWebContentsAt(0)->GetURL().host()); |
| 540 EXPECT_EQ("title1.html", | 542 EXPECT_EQ("title1.html", |
| 541 tab_strip->GetWebContentsAt(1)->GetURL().ExtractFileName()); | 543 tab_strip->GetWebContentsAt(1)->GetURL().ExtractFileName()); |
| 542 EXPECT_EQ(internals::GetWelcomePageURL(), | 544 EXPECT_EQ(internals::GetWelcomePageURL(), |
| 543 tab_strip->GetWebContentsAt(2)->GetURL()); | 545 tab_strip->GetWebContentsAt(2)->GetURL()); |
| 544 } else { | 546 } else { |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 browser()->host_desktop_type())); | 887 browser()->host_desktop_type())); |
| 886 new_browser = FindOneOtherBrowserForProfile(profile_urls, NULL); | 888 new_browser = FindOneOtherBrowserForProfile(profile_urls, NULL); |
| 887 ASSERT_TRUE(new_browser); | 889 ASSERT_TRUE(new_browser); |
| 888 tab_strip = new_browser->tab_strip_model(); | 890 tab_strip = new_browser->tab_strip_model(); |
| 889 ASSERT_EQ(1, tab_strip->count()); | 891 ASSERT_EQ(1, tab_strip->count()); |
| 890 web_contents = tab_strip->GetWebContentsAt(0); | 892 web_contents = tab_strip->GetWebContentsAt(0); |
| 891 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), web_contents->GetURL()); | 893 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), web_contents->GetURL()); |
| 892 EXPECT_EQ(1U, | 894 EXPECT_EQ(1U, |
| 893 InfoBarService::FromWebContents(web_contents)->GetInfoBarCount()); | 895 InfoBarService::FromWebContents(web_contents)->GetInfoBarCount()); |
| 894 } | 896 } |
| 897 |
| 898 class ManagedModeBrowserCreatorTest : public InProcessBrowserTest { |
| 899 protected: |
| 900 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 901 InProcessBrowserTest::SetUpCommandLine(command_line); |
| 902 command_line->AppendSwitch(switches::kEnableManagedUsers); |
| 903 } |
| 904 }; |
| 905 |
| 906 IN_PROC_BROWSER_TEST_F(ManagedModeBrowserCreatorTest, |
| 907 StartupManagedModeProfile) { |
| 908 // Make this a managed profile. |
| 909 browser()->profile()->GetPrefs()->SetBoolean(prefs::kProfileIsManaged, true); |
| 910 StartupBrowserCreator browser_creator; |
| 911 |
| 912 // Do a simple non-process-startup browser launch. |
| 913 CommandLine dummy(CommandLine::NO_PROGRAM); |
| 914 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator, |
| 915 chrome::startup::IS_FIRST_RUN); |
| 916 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); |
| 917 |
| 918 // This should have created a new browser window. |
| 919 Browser* new_browser = FindOneOtherBrowser(browser()); |
| 920 ASSERT_TRUE(new_browser); |
| 921 |
| 922 TabStripModel* tab_strip = new_browser->tab_strip_model(); |
| 923 // There should be only one tab. |
| 924 EXPECT_EQ(1, tab_strip->count()); |
| 925 |
| 926 // And it should point to the managed user settings page. |
| 927 content::WebContents* web_contents = tab_strip->GetWebContentsAt(0); |
| 928 GURL expected(GURL(std::string(chrome::kChromeUISettingsURL) + |
| 929 chrome::kManagedUserSettingsSubPage)); |
| 930 EXPECT_EQ(GURL(expected), web_contents->GetURL()); |
| 931 } |
| 932 |
| 895 #endif // !OS_CHROMEOS | 933 #endif // !OS_CHROMEOS |
| OLD | NEW |