| OLD | NEW |
| 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 "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/extensions/extension_browsertest.h" | 8 #include "chrome/browser/extensions/extension_browsertest.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/first_run/first_run.h" |
| 10 #include "chrome/browser/prefs/session_startup_pref.h" | 11 #include "chrome/browser/prefs/session_startup_pref.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/browser_init.h" | 14 #include "chrome/browser/ui/browser_init.h" |
| 14 #include "chrome/browser/ui/browser_list.h" | 15 #include "chrome/browser/ui/browser_list.h" |
| 15 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
| 16 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
| 18 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
| 19 #include "content/browser/tab_contents/tab_contents.h" | 20 #include "content/browser/tab_contents/tab_contents.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 89 |
| 89 OpenURLsPopupObserver observer; | 90 OpenURLsPopupObserver observer; |
| 90 BrowserList::AddObserver(&observer); | 91 BrowserList::AddObserver(&observer); |
| 91 | 92 |
| 92 Browser* popup = Browser::CreateForType(Browser::TYPE_POPUP, | 93 Browser* popup = Browser::CreateForType(Browser::TYPE_POPUP, |
| 93 browser()->profile()); | 94 browser()->profile()); |
| 94 ASSERT_TRUE(popup->is_type_popup()); | 95 ASSERT_TRUE(popup->is_type_popup()); |
| 95 ASSERT_EQ(popup, observer.added_browser_); | 96 ASSERT_EQ(popup, observer.added_browser_); |
| 96 | 97 |
| 97 CommandLine dummy(CommandLine::NO_PROGRAM); | 98 CommandLine dummy(CommandLine::NO_PROGRAM); |
| 98 BrowserInit::LaunchWithProfile launch(FilePath(), dummy); | 99 BrowserInit::IsFirstRun first_run = FirstRun::IsChromeFirstRun() ? |
| 100 BrowserInit::IS_FIRST_RUN : BrowserInit::IS_NOT_FIRST_RUN; |
| 101 BrowserInit::LaunchWithProfile launch(FilePath(), dummy, first_run); |
| 99 // This should create a new window, but re-use the profile from |popup|. If | 102 // This should create a new window, but re-use the profile from |popup|. If |
| 100 // it used a NULL or invalid profile, it would crash. | 103 // it used a NULL or invalid profile, it would crash. |
| 101 launch.OpenURLsInBrowser(popup, false, urls); | 104 launch.OpenURLsInBrowser(popup, false, urls); |
| 102 ASSERT_NE(popup, observer.added_browser_); | 105 ASSERT_NE(popup, observer.added_browser_); |
| 103 BrowserList::RemoveObserver(&observer); | 106 BrowserList::RemoveObserver(&observer); |
| 104 } | 107 } |
| 105 | 108 |
| 106 // Verify that startup URLs are honored when the process already exists but has | 109 // Verify that startup URLs are honored when the process already exists but has |
| 107 // no tabbed browser windows (eg. as if the process is running only due to a | 110 // no tabbed browser windows (eg. as if the process is running only due to a |
| 108 // background application. | 111 // background application. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 120 // Set the startup preference to open these URLs. | 123 // Set the startup preference to open these URLs. |
| 121 SessionStartupPref pref(SessionStartupPref::URLS); | 124 SessionStartupPref pref(SessionStartupPref::URLS); |
| 122 pref.urls = urls; | 125 pref.urls = urls; |
| 123 SessionStartupPref::SetStartupPref(browser()->profile(), pref); | 126 SessionStartupPref::SetStartupPref(browser()->profile(), pref); |
| 124 | 127 |
| 125 // Close the browser. | 128 // Close the browser. |
| 126 browser()->window()->Close(); | 129 browser()->window()->Close(); |
| 127 | 130 |
| 128 // Do a simple non-process-startup browser launch. | 131 // Do a simple non-process-startup browser launch. |
| 129 CommandLine dummy(CommandLine::NO_PROGRAM); | 132 CommandLine dummy(CommandLine::NO_PROGRAM); |
| 130 BrowserInit::LaunchWithProfile launch(FilePath(), dummy); | 133 BrowserInit::IsFirstRun first_run = FirstRun::IsChromeFirstRun() ? |
| 134 BrowserInit::IS_FIRST_RUN : BrowserInit::IS_NOT_FIRST_RUN; |
| 135 BrowserInit::LaunchWithProfile launch(FilePath(), dummy, first_run); |
| 131 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); | 136 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); |
| 132 | 137 |
| 133 // This should have created a new browser window. |browser()| is still | 138 // This should have created a new browser window. |browser()| is still |
| 134 // around at this point, even though we've closed it's window. | 139 // around at this point, even though we've closed it's window. |
| 135 Browser* new_browser = NULL; | 140 Browser* new_browser = NULL; |
| 136 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); | 141 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); |
| 137 | 142 |
| 138 // The new browser should have one tab for each URL. | 143 // The new browser should have one tab for each URL. |
| 139 ASSERT_EQ(static_cast<int>(urls.size()), new_browser->tab_count()); | 144 ASSERT_EQ(static_cast<int>(urls.size()), new_browser->tab_count()); |
| 140 for (size_t i=0; i < urls.size(); i++) { | 145 for (size_t i=0; i < urls.size(); i++) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 156 FilePath(FilePath::kCurrentDirectory), | 161 FilePath(FilePath::kCurrentDirectory), |
| 157 FilePath(FILE_PATH_LITERAL("title2.html")))); | 162 FilePath(FILE_PATH_LITERAL("title2.html")))); |
| 158 | 163 |
| 159 // Set the startup preference to open these URLs. | 164 // Set the startup preference to open these URLs. |
| 160 SessionStartupPref pref(SessionStartupPref::URLS); | 165 SessionStartupPref pref(SessionStartupPref::URLS); |
| 161 pref.urls = urls; | 166 pref.urls = urls; |
| 162 SessionStartupPref::SetStartupPref(browser()->profile(), pref); | 167 SessionStartupPref::SetStartupPref(browser()->profile(), pref); |
| 163 | 168 |
| 164 // Do a simple non-process-startup browser launch. | 169 // Do a simple non-process-startup browser launch. |
| 165 CommandLine dummy(CommandLine::NO_PROGRAM); | 170 CommandLine dummy(CommandLine::NO_PROGRAM); |
| 166 BrowserInit::LaunchWithProfile launch(FilePath(), dummy); | 171 BrowserInit::IsFirstRun first_run = FirstRun::IsChromeFirstRun() ? |
| 172 BrowserInit::IS_FIRST_RUN : BrowserInit::IS_NOT_FIRST_RUN; |
| 173 BrowserInit::LaunchWithProfile launch(FilePath(), dummy, first_run); |
| 167 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); | 174 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); |
| 168 | 175 |
| 169 // This should have created a new browser window. | 176 // This should have created a new browser window. |
| 170 Browser* new_browser = NULL; | 177 Browser* new_browser = NULL; |
| 171 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); | 178 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); |
| 172 | 179 |
| 173 // The new browser should have exactly one tab (not the startup URLs). | 180 // The new browser should have exactly one tab (not the startup URLs). |
| 174 ASSERT_EQ(1, new_browser->tab_count()); | 181 ASSERT_EQ(1, new_browser->tab_count()); |
| 175 } | 182 } |
| 176 | 183 |
| 177 // App shortcuts are not implemented on mac os. | 184 // App shortcuts are not implemented on mac os. |
| 178 #if !defined(OS_MACOSX) | 185 #if !defined(OS_MACOSX) |
| 179 IN_PROC_BROWSER_TEST_F(BrowserInitTest, OpenAppShortcutNoPref) { | 186 IN_PROC_BROWSER_TEST_F(BrowserInitTest, OpenAppShortcutNoPref) { |
| 180 // Load an app with launch.container = 'tab'. | 187 // Load an app with launch.container = 'tab'. |
| 181 const Extension* extension_app = NULL; | 188 const Extension* extension_app = NULL; |
| 182 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app)); | 189 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app)); |
| 183 | 190 |
| 184 // Add --app-id=<extension->id()> to the command line. | 191 // Add --app-id=<extension->id()> to the command line. |
| 185 CommandLine command_line(CommandLine::NO_PROGRAM); | 192 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 186 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id()); | 193 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id()); |
| 187 | 194 |
| 188 BrowserInit::LaunchWithProfile launch(FilePath(), command_line); | 195 BrowserInit::IsFirstRun first_run = FirstRun::IsChromeFirstRun() ? |
| 196 BrowserInit::IS_FIRST_RUN : BrowserInit::IS_NOT_FIRST_RUN; |
| 197 BrowserInit::LaunchWithProfile launch(FilePath(), command_line, first_run); |
| 189 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); | 198 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); |
| 190 | 199 |
| 191 // No pref was set, so the app should have opened in a window. | 200 // No pref was set, so the app should have opened in a window. |
| 192 // The launch should have created a new browser. | 201 // The launch should have created a new browser. |
| 193 Browser* new_browser = NULL; | 202 Browser* new_browser = NULL; |
| 194 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); | 203 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); |
| 195 | 204 |
| 196 // Expect an app window. | 205 // Expect an app window. |
| 197 EXPECT_TRUE(new_browser->is_app()); | 206 EXPECT_TRUE(new_browser->is_app()); |
| 198 | 207 |
| 199 // The browser's app_name should include the app's ID. | 208 // The browser's app_name should include the app's ID. |
| 200 EXPECT_NE( | 209 EXPECT_NE( |
| 201 new_browser->app_name_.find(extension_app->id()), | 210 new_browser->app_name_.find(extension_app->id()), |
| 202 std::string::npos) << new_browser->app_name_; | 211 std::string::npos) << new_browser->app_name_; |
| 203 } | 212 } |
| 204 | 213 |
| 205 IN_PROC_BROWSER_TEST_F(BrowserInitTest, OpenAppShortcutWindowPref) { | 214 IN_PROC_BROWSER_TEST_F(BrowserInitTest, OpenAppShortcutWindowPref) { |
| 206 const Extension* extension_app = NULL; | 215 const Extension* extension_app = NULL; |
| 207 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app)); | 216 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app)); |
| 208 | 217 |
| 209 // Set a pref indicating that the user wants to open this app in a window. | 218 // Set a pref indicating that the user wants to open this app in a window. |
| 210 SetAppLaunchPref(extension_app->id(), ExtensionPrefs::LAUNCH_WINDOW); | 219 SetAppLaunchPref(extension_app->id(), ExtensionPrefs::LAUNCH_WINDOW); |
| 211 | 220 |
| 212 CommandLine command_line(CommandLine::NO_PROGRAM); | 221 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 213 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id()); | 222 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id()); |
| 214 BrowserInit::LaunchWithProfile launch(FilePath(), command_line); | 223 BrowserInit::IsFirstRun first_run = FirstRun::IsChromeFirstRun() ? |
| 224 BrowserInit::IS_FIRST_RUN : BrowserInit::IS_NOT_FIRST_RUN; |
| 225 BrowserInit::LaunchWithProfile launch(FilePath(), command_line, first_run); |
| 215 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); | 226 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); |
| 216 | 227 |
| 217 // Pref was set to open in a window, so the app should have opened in a | 228 // Pref was set to open in a window, so the app should have opened in a |
| 218 // window. The launch should have created a new browser. Find the new | 229 // window. The launch should have created a new browser. Find the new |
| 219 // browser. | 230 // browser. |
| 220 Browser* new_browser = NULL; | 231 Browser* new_browser = NULL; |
| 221 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); | 232 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); |
| 222 | 233 |
| 223 // Expect an app window. | 234 // Expect an app window. |
| 224 EXPECT_TRUE(new_browser->is_app()); | 235 EXPECT_TRUE(new_browser->is_app()); |
| 225 | 236 |
| 226 // The browser's app_name should include the app's ID. | 237 // The browser's app_name should include the app's ID. |
| 227 EXPECT_NE( | 238 EXPECT_NE( |
| 228 new_browser->app_name_.find(extension_app->id()), | 239 new_browser->app_name_.find(extension_app->id()), |
| 229 std::string::npos) << new_browser->app_name_; | 240 std::string::npos) << new_browser->app_name_; |
| 230 } | 241 } |
| 231 | 242 |
| 232 IN_PROC_BROWSER_TEST_F(BrowserInitTest, OpenAppShortcutTabPref) { | 243 IN_PROC_BROWSER_TEST_F(BrowserInitTest, OpenAppShortcutTabPref) { |
| 233 // Load an app with launch.container = 'tab'. | 244 // Load an app with launch.container = 'tab'. |
| 234 const Extension* extension_app = NULL; | 245 const Extension* extension_app = NULL; |
| 235 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app)); | 246 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app)); |
| 236 | 247 |
| 237 // Set a pref indicating that the user wants to open this app in a window. | 248 // Set a pref indicating that the user wants to open this app in a window. |
| 238 SetAppLaunchPref(extension_app->id(), ExtensionPrefs::LAUNCH_REGULAR); | 249 SetAppLaunchPref(extension_app->id(), ExtensionPrefs::LAUNCH_REGULAR); |
| 239 | 250 |
| 240 CommandLine command_line(CommandLine::NO_PROGRAM); | 251 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 241 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id()); | 252 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id()); |
| 242 BrowserInit::LaunchWithProfile launch(FilePath(), command_line); | 253 BrowserInit::IsFirstRun first_run = FirstRun::IsChromeFirstRun() ? |
| 254 BrowserInit::IS_FIRST_RUN : BrowserInit::IS_NOT_FIRST_RUN; |
| 255 BrowserInit::LaunchWithProfile launch(FilePath(), command_line, first_run); |
| 243 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); | 256 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); |
| 244 | 257 |
| 245 // When an app shortcut is open and the pref indicates a tab should | 258 // When an app shortcut is open and the pref indicates a tab should |
| 246 // open, the tab is open in a new browser window. Expect a new window. | 259 // open, the tab is open in a new browser window. Expect a new window. |
| 247 ASSERT_EQ(2u, BrowserList::GetBrowserCount(browser()->profile())); | 260 ASSERT_EQ(2u, BrowserList::GetBrowserCount(browser()->profile())); |
| 248 | 261 |
| 249 Browser* new_browser = NULL; | 262 Browser* new_browser = NULL; |
| 250 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); | 263 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); |
| 251 | 264 |
| 252 // The tab should be in a tabbed window. | 265 // The tab should be in a tabbed window. |
| 253 EXPECT_TRUE(new_browser->is_type_tabbed()); | 266 EXPECT_TRUE(new_browser->is_type_tabbed()); |
| 254 | 267 |
| 255 // The browser's app_name should not include the app's ID: It is in a | 268 // The browser's app_name should not include the app's ID: It is in a |
| 256 // normal browser. | 269 // normal browser. |
| 257 EXPECT_EQ( | 270 EXPECT_EQ( |
| 258 new_browser->app_name_.find(extension_app->id()), | 271 new_browser->app_name_.find(extension_app->id()), |
| 259 std::string::npos) << new_browser->app_name_; | 272 std::string::npos) << new_browser->app_name_; |
| 260 } | 273 } |
| 261 | 274 |
| 262 IN_PROC_BROWSER_TEST_F(BrowserInitTest, OpenAppShortcutPanel) { | 275 IN_PROC_BROWSER_TEST_F(BrowserInitTest, OpenAppShortcutPanel) { |
| 263 // Load an app with launch.container = 'panel'. | 276 // Load an app with launch.container = 'panel'. |
| 264 const Extension* extension_app = NULL; | 277 const Extension* extension_app = NULL; |
| 265 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_panel_container", &extension_app)); | 278 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_panel_container", &extension_app)); |
| 266 | 279 |
| 267 CommandLine command_line(CommandLine::NO_PROGRAM); | 280 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 268 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id()); | 281 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id()); |
| 269 BrowserInit::LaunchWithProfile launch(FilePath(), command_line); | 282 BrowserInit::IsFirstRun first_run = FirstRun::IsChromeFirstRun() ? |
| 283 BrowserInit::IS_FIRST_RUN : BrowserInit::IS_NOT_FIRST_RUN; |
| 284 BrowserInit::LaunchWithProfile launch(FilePath(), command_line, first_run); |
| 270 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); | 285 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); |
| 271 | 286 |
| 272 // The launch should have created a new browser, with a panel type. | 287 // The launch should have created a new browser, with a panel type. |
| 273 Browser* new_browser = NULL; | 288 Browser* new_browser = NULL; |
| 274 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); | 289 ASSERT_NO_FATAL_FAILURE(FindOneOtherBrowser(&new_browser)); |
| 275 | 290 |
| 276 // Expect an app panel. | 291 // Expect an app panel. |
| 277 #if defined(OS_CHROMEOS) | 292 #if defined(OS_CHROMEOS) |
| 278 EXPECT_TRUE(new_browser->is_type_panel() && new_browser->is_app()); | 293 EXPECT_TRUE(new_browser->is_type_panel() && new_browser->is_app()); |
| 279 #else | 294 #else |
| 280 EXPECT_TRUE(new_browser->is_type_popup() && new_browser->is_app()); | 295 EXPECT_TRUE(new_browser->is_type_popup() && new_browser->is_app()); |
| 281 #endif | 296 #endif |
| 282 | 297 |
| 283 // The new browser's app_name should include the app's ID. | 298 // The new browser's app_name should include the app's ID. |
| 284 EXPECT_NE( | 299 EXPECT_NE( |
| 285 new_browser->app_name_.find(extension_app->id()), | 300 new_browser->app_name_.find(extension_app->id()), |
| 286 std::string::npos) << new_browser->app_name_; | 301 std::string::npos) << new_browser->app_name_; |
| 287 } | 302 } |
| 288 | 303 |
| 289 #endif // !defined(OS_MACOSX) | 304 #endif // !defined(OS_MACOSX) |
| OLD | NEW |