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 <algorithm> | 5 #include <algorithm> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/extensions/extension_browsertest.h" | 13 #include "chrome/browser/extensions/extension_browsertest.h" |
14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
15 #include "chrome/browser/extensions/extension_system.h" | 15 #include "chrome/browser/extensions/extension_system.h" |
| 16 #include "chrome/browser/extensions/launch_util.h" |
16 #include "chrome/browser/first_run/first_run.h" | 17 #include "chrome/browser/first_run/first_run.h" |
17 #include "chrome/browser/infobars/infobar_service.h" | 18 #include "chrome/browser/infobars/infobar_service.h" |
18 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h" | 19 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h" |
19 #include "chrome/browser/managed_mode/managed_user_service.h" | 20 #include "chrome/browser/managed_mode/managed_user_service.h" |
20 #include "chrome/browser/managed_mode/managed_user_service_factory.h" | 21 #include "chrome/browser/managed_mode/managed_user_service_factory.h" |
21 #include "chrome/browser/prefs/session_startup_pref.h" | 22 #include "chrome/browser/prefs/session_startup_pref.h" |
22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/profiles/profile_impl.h" | 24 #include "chrome/browser/profiles/profile_impl.h" |
24 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
25 #include "chrome/browser/sessions/session_restore.h" | 26 #include "chrome/browser/sessions/session_restore.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 *out_app_extension = service->GetExtensionById( | 111 *out_app_extension = service->GetExtensionById( |
111 last_loaded_extension_id(), false); | 112 last_loaded_extension_id(), false); |
112 ASSERT_TRUE(*out_app_extension); | 113 ASSERT_TRUE(*out_app_extension); |
113 | 114 |
114 // Code that opens a new browser assumes we start with exactly one. | 115 // Code that opens a new browser assumes we start with exactly one. |
115 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), | 116 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), |
116 browser()->host_desktop_type())); | 117 browser()->host_desktop_type())); |
117 } | 118 } |
118 | 119 |
119 void SetAppLaunchPref(const std::string& app_id, | 120 void SetAppLaunchPref(const std::string& app_id, |
120 extensions::ExtensionPrefs::LaunchType launch_type) { | 121 extensions::LaunchType launch_type) { |
121 ExtensionService* service = extensions::ExtensionSystem::Get( | 122 ExtensionService* service = extensions::ExtensionSystem::Get( |
122 browser()->profile())->extension_service(); | 123 browser()->profile())->extension_service(); |
123 service->extension_prefs()->SetLaunchType(app_id, launch_type); | 124 extensions::SetLaunchType(service->extension_prefs(), app_id, launch_type); |
124 } | 125 } |
125 | 126 |
126 Browser* FindOneOtherBrowserForProfile(Profile* profile, | 127 Browser* FindOneOtherBrowserForProfile(Profile* profile, |
127 Browser* not_this_browser) { | 128 Browser* not_this_browser) { |
128 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | 129 for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
129 if (*it != not_this_browser && it->profile() == profile) | 130 if (*it != not_this_browser && it->profile() == profile) |
130 return *it; | 131 return *it; |
131 } | 132 } |
132 return NULL; | 133 return NULL; |
133 } | 134 } |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 EXPECT_NE( | 292 EXPECT_NE( |
292 new_browser->app_name_.find(extension_app->id()), | 293 new_browser->app_name_.find(extension_app->id()), |
293 std::string::npos) << new_browser->app_name_; | 294 std::string::npos) << new_browser->app_name_; |
294 } | 295 } |
295 | 296 |
296 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutWindowPref) { | 297 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutWindowPref) { |
297 const Extension* extension_app = NULL; | 298 const Extension* extension_app = NULL; |
298 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app)); | 299 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app)); |
299 | 300 |
300 // Set a pref indicating that the user wants to open this app in a window. | 301 // Set a pref indicating that the user wants to open this app in a window. |
301 SetAppLaunchPref(extension_app->id(), | 302 SetAppLaunchPref(extension_app->id(), extensions::LAUNCH_TYPE_WINDOW); |
302 extensions::ExtensionPrefs::LAUNCH_TYPE_WINDOW); | |
303 | 303 |
304 CommandLine command_line(CommandLine::NO_PROGRAM); | 304 CommandLine command_line(CommandLine::NO_PROGRAM); |
305 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id()); | 305 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id()); |
306 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? | 306 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? |
307 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; | 307 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; |
308 StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run); | 308 StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run); |
309 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false, | 309 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false, |
310 browser()->host_desktop_type())); | 310 browser()->host_desktop_type())); |
311 | 311 |
312 // Pref was set to open in a window, so the app should have opened in a | 312 // Pref was set to open in a window, so the app should have opened in a |
(...skipping 10 matching lines...) Expand all Loading... |
323 new_browser->app_name_.find(extension_app->id()), | 323 new_browser->app_name_.find(extension_app->id()), |
324 std::string::npos) << new_browser->app_name_; | 324 std::string::npos) << new_browser->app_name_; |
325 } | 325 } |
326 | 326 |
327 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutTabPref) { | 327 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutTabPref) { |
328 // Load an app with launch.container = 'tab'. | 328 // Load an app with launch.container = 'tab'. |
329 const Extension* extension_app = NULL; | 329 const Extension* extension_app = NULL; |
330 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app)); | 330 ASSERT_NO_FATAL_FAILURE(LoadApp("app_with_tab_container", &extension_app)); |
331 | 331 |
332 // Set a pref indicating that the user wants to open this app in a window. | 332 // Set a pref indicating that the user wants to open this app in a window. |
333 SetAppLaunchPref(extension_app->id(), | 333 SetAppLaunchPref(extension_app->id(), extensions::LAUNCH_TYPE_REGULAR); |
334 extensions::ExtensionPrefs::LAUNCH_TYPE_REGULAR); | |
335 | 334 |
336 CommandLine command_line(CommandLine::NO_PROGRAM); | 335 CommandLine command_line(CommandLine::NO_PROGRAM); |
337 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id()); | 336 command_line.AppendSwitchASCII(switches::kAppId, extension_app->id()); |
338 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? | 337 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? |
339 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; | 338 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; |
340 StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run); | 339 StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run); |
341 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false, | 340 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false, |
342 browser()->host_desktop_type())); | 341 browser()->host_desktop_type())); |
343 | 342 |
344 // When an app shortcut is open and the pref indicates a tab should | 343 // When an app shortcut is open and the pref indicates a tab should |
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1402 ASSERT_EQ(1, tab_strip->count()); | 1401 ASSERT_EQ(1, tab_strip->count()); |
1403 EXPECT_EQ("title1.html", | 1402 EXPECT_EQ("title1.html", |
1404 tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName()); | 1403 tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName()); |
1405 } | 1404 } |
1406 #endif // defined(ENABLE_CONFIGURATION_POLICY) | 1405 #endif // defined(ENABLE_CONFIGURATION_POLICY) |
1407 | 1406 |
1408 #endif // !defined(OS_LINUX) || !defined(GOOGLE_CHROME_BUILD) || | 1407 #endif // !defined(OS_LINUX) || !defined(GOOGLE_CHROME_BUILD) || |
1409 // defined(ENABLE_CONFIGURATION_POLICY) | 1408 // defined(ENABLE_CONFIGURATION_POLICY) |
1410 | 1409 |
1411 #endif // !defined(OS_CHROMEOS) | 1410 #endif // !defined(OS_CHROMEOS) |
OLD | NEW |