| 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 <map> | 5 #include <map> |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 ASSERT_TRUE(LoadExtension( | 217 ASSERT_TRUE(LoadExtension( |
| 218 test_data_dir_.AppendASCII("management/launch_on_install"))); | 218 test_data_dir_.AppendASCII("management/launch_on_install"))); |
| 219 ASSERT_TRUE(launcher_loaded.WaitUntilSatisfied()); | 219 ASSERT_TRUE(launcher_loaded.WaitUntilSatisfied()); |
| 220 | 220 |
| 221 // Load an app with app.launch.container = "panel". | 221 // Load an app with app.launch.container = "panel". |
| 222 std::string app_id; | 222 std::string app_id; |
| 223 LoadAndWaitForLaunch("management/launch_app_panel", &app_id); | 223 LoadAndWaitForLaunch("management/launch_app_panel", &app_id); |
| 224 ASSERT_FALSE(HasFatalFailure()); // Stop the test if any ASSERT failed. | 224 ASSERT_FALSE(HasFatalFailure()); // Stop the test if any ASSERT failed. |
| 225 | 225 |
| 226 // Find the app's browser. Check that it is a popup. | 226 // Find the app's browser. Check that it is a popup. |
| 227 ASSERT_EQ(2u, chrome::GetBrowserCount(browser()->profile(), | 227 ASSERT_EQ(2u, chrome::GetBrowserCount(browser()->profile())); |
| 228 browser()->host_desktop_type())); | |
| 229 Browser* app_browser = FindOtherBrowser(browser()); | 228 Browser* app_browser = FindOtherBrowser(browser()); |
| 230 ASSERT_TRUE(app_browser->is_type_popup()); | 229 ASSERT_TRUE(app_browser->is_type_popup()); |
| 231 ASSERT_TRUE(app_browser->is_app()); | 230 ASSERT_TRUE(app_browser->is_app()); |
| 232 | 231 |
| 233 // Close the app panel. | 232 // Close the app panel. |
| 234 content::WindowedNotificationObserver signal( | 233 content::WindowedNotificationObserver signal( |
| 235 chrome::NOTIFICATION_BROWSER_CLOSED, | 234 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 236 content::Source<Browser>(app_browser)); | 235 content::Source<Browser>(app_browser)); |
| 237 | 236 |
| 238 chrome::CloseWindow(app_browser); | 237 chrome::CloseWindow(app_browser); |
| 239 signal.Wait(); | 238 signal.Wait(); |
| 240 | 239 |
| 241 // Unload the extension. | 240 // Unload the extension. |
| 242 UninstallExtension(app_id); | 241 UninstallExtension(app_id); |
| 243 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), | 242 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile())); |
| 244 browser()->host_desktop_type())); | |
| 245 ASSERT_FALSE(service->GetExtensionById(app_id, true)); | 243 ASSERT_FALSE(service->GetExtensionById(app_id, true)); |
| 246 | 244 |
| 247 // Set a pref indicating that the user wants to launch in a regular tab. | 245 // Set a pref indicating that the user wants to launch in a regular tab. |
| 248 // This should be ignored, because panel apps always load in a popup. | 246 // This should be ignored, because panel apps always load in a popup. |
| 249 extensions::SetLaunchType(browser()->profile(), app_id, | 247 extensions::SetLaunchType(browser()->profile(), app_id, |
| 250 extensions::LAUNCH_TYPE_REGULAR); | 248 extensions::LAUNCH_TYPE_REGULAR); |
| 251 | 249 |
| 252 // Load the extension again. | 250 // Load the extension again. |
| 253 std::string app_id_new; | 251 std::string app_id_new; |
| 254 LoadAndWaitForLaunch("management/launch_app_panel", &app_id_new); | 252 LoadAndWaitForLaunch("management/launch_app_panel", &app_id_new); |
| 255 ASSERT_FALSE(HasFatalFailure()); | 253 ASSERT_FALSE(HasFatalFailure()); |
| 256 | 254 |
| 257 // If the ID changed, then the pref will not apply to the app. | 255 // If the ID changed, then the pref will not apply to the app. |
| 258 ASSERT_EQ(app_id, app_id_new); | 256 ASSERT_EQ(app_id, app_id_new); |
| 259 | 257 |
| 260 // Find the app's browser. Apps that should load in a panel ignore | 258 // Find the app's browser. Apps that should load in a panel ignore |
| 261 // prefs, so we should still see the launch in a popup. | 259 // prefs, so we should still see the launch in a popup. |
| 262 ASSERT_EQ(2u, chrome::GetBrowserCount(browser()->profile(), | 260 ASSERT_EQ(2u, chrome::GetBrowserCount(browser()->profile())); |
| 263 browser()->host_desktop_type())); | |
| 264 app_browser = FindOtherBrowser(browser()); | 261 app_browser = FindOtherBrowser(browser()); |
| 265 ASSERT_TRUE(app_browser->is_type_popup()); | 262 ASSERT_TRUE(app_browser->is_type_popup()); |
| 266 ASSERT_TRUE(app_browser->is_app()); | 263 ASSERT_TRUE(app_browser->is_app()); |
| 267 } | 264 } |
| 268 | 265 |
| 269 // Disabled: http://crbug.com/230165 | 266 // Disabled: http://crbug.com/230165 |
| 270 #if defined(OS_WIN) | 267 #if defined(OS_WIN) |
| 271 #define MAYBE_LaunchTabApp DISABLED_LaunchTabApp | 268 #define MAYBE_LaunchTabApp DISABLED_LaunchTabApp |
| 272 #else | 269 #else |
| 273 #define MAYBE_LaunchTabApp LaunchTabApp | 270 #define MAYBE_LaunchTabApp LaunchTabApp |
| 274 #endif | 271 #endif |
| 275 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, MAYBE_LaunchTabApp) { | 272 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, MAYBE_LaunchTabApp) { |
| 276 ExtensionService* service = extensions::ExtensionSystem::Get( | 273 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 277 browser()->profile())->extension_service(); | 274 browser()->profile())->extension_service(); |
| 278 | 275 |
| 279 // Load an extension that calls launchApp() on any app that gets | 276 // Load an extension that calls launchApp() on any app that gets |
| 280 // installed. | 277 // installed. |
| 281 ExtensionTestMessageListener launcher_loaded("launcher loaded", false); | 278 ExtensionTestMessageListener launcher_loaded("launcher loaded", false); |
| 282 ASSERT_TRUE(LoadExtension( | 279 ASSERT_TRUE(LoadExtension( |
| 283 test_data_dir_.AppendASCII("management/launch_on_install"))); | 280 test_data_dir_.AppendASCII("management/launch_on_install"))); |
| 284 ASSERT_TRUE(launcher_loaded.WaitUntilSatisfied()); | 281 ASSERT_TRUE(launcher_loaded.WaitUntilSatisfied()); |
| 285 | 282 |
| 286 // Code below assumes that the test starts with a single browser window | 283 // Code below assumes that the test starts with a single browser window |
| 287 // hosting one tab. | 284 // hosting one tab. |
| 288 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), | 285 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile())); |
| 289 browser()->host_desktop_type())); | |
| 290 ASSERT_EQ(1, browser()->tab_strip_model()->count()); | 286 ASSERT_EQ(1, browser()->tab_strip_model()->count()); |
| 291 | 287 |
| 292 // Load an app with app.launch.container = "tab". | 288 // Load an app with app.launch.container = "tab". |
| 293 std::string app_id; | 289 std::string app_id; |
| 294 LoadAndWaitForLaunch("management/launch_app_tab", &app_id); | 290 LoadAndWaitForLaunch("management/launch_app_tab", &app_id); |
| 295 ASSERT_FALSE(HasFatalFailure()); | 291 ASSERT_FALSE(HasFatalFailure()); |
| 296 | 292 |
| 297 // Check that the app opened in a new tab of the existing browser. | 293 // Check that the app opened in a new tab of the existing browser. |
| 298 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), | 294 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile())); |
| 299 browser()->host_desktop_type())); | |
| 300 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 295 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
| 301 | 296 |
| 302 // Unload the extension. | 297 // Unload the extension. |
| 303 UninstallExtension(app_id); | 298 UninstallExtension(app_id); |
| 304 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), | 299 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile())); |
| 305 browser()->host_desktop_type())); | |
| 306 ASSERT_FALSE(service->GetExtensionById(app_id, true)); | 300 ASSERT_FALSE(service->GetExtensionById(app_id, true)); |
| 307 | 301 |
| 308 // Set a pref indicating that the user wants to launch in a window. | 302 // Set a pref indicating that the user wants to launch in a window. |
| 309 extensions::SetLaunchType(browser()->profile(), app_id, | 303 extensions::SetLaunchType(browser()->profile(), app_id, |
| 310 extensions::LAUNCH_TYPE_WINDOW); | 304 extensions::LAUNCH_TYPE_WINDOW); |
| 311 | 305 |
| 312 std::string app_id_new; | 306 std::string app_id_new; |
| 313 LoadAndWaitForLaunch("management/launch_app_tab", &app_id_new); | 307 LoadAndWaitForLaunch("management/launch_app_tab", &app_id_new); |
| 314 ASSERT_FALSE(HasFatalFailure()); | 308 ASSERT_FALSE(HasFatalFailure()); |
| 315 | 309 |
| 316 // If the ID changed, then the pref will not apply to the app. | 310 // If the ID changed, then the pref will not apply to the app. |
| 317 ASSERT_EQ(app_id, app_id_new); | 311 ASSERT_EQ(app_id, app_id_new); |
| 318 | 312 |
| 319 unsigned expected_browser_count = 2; | 313 unsigned expected_browser_count = 2; |
| 320 #if defined(OS_MACOSX) | 314 #if defined(OS_MACOSX) |
| 321 // Without the new Bookmark Apps, Mac has no way of making standalone browser | 315 // Without the new Bookmark Apps, Mac has no way of making standalone browser |
| 322 // windows for apps, so it will add to the tabstrip instead. | 316 // windows for apps, so it will add to the tabstrip instead. |
| 323 EXPECT_FALSE(extensions::util::IsNewBookmarkAppsEnabled()); | 317 EXPECT_FALSE(extensions::util::IsNewBookmarkAppsEnabled()); |
| 324 EXPECT_FALSE(extensions::util::CanHostedAppsOpenInWindows()); | 318 EXPECT_FALSE(extensions::util::CanHostedAppsOpenInWindows()); |
| 325 expected_browser_count = 1; | 319 expected_browser_count = 1; |
| 326 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 320 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
| 327 #endif | 321 #endif |
| 328 // Find the app's browser. Opening in a new window will create | 322 // Find the app's browser. Opening in a new window will create |
| 329 // a new browser. | 323 // a new browser. |
| 330 ASSERT_EQ(expected_browser_count, | 324 ASSERT_EQ(expected_browser_count, |
| 331 chrome::GetBrowserCount(browser()->profile(), | 325 chrome::GetBrowserCount(browser()->profile())); |
| 332 browser()->host_desktop_type())); | |
| 333 if (expected_browser_count == 2) { | 326 if (expected_browser_count == 2) { |
| 334 Browser* app_browser = FindOtherBrowser(browser()); | 327 Browser* app_browser = FindOtherBrowser(browser()); |
| 335 ASSERT_TRUE(app_browser->is_app()); | 328 ASSERT_TRUE(app_browser->is_app()); |
| 336 } | 329 } |
| 337 } | 330 } |
| 338 | 331 |
| 339 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, LaunchType) { | 332 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, LaunchType) { |
| 340 LoadExtensions(); | 333 LoadExtensions(); |
| 341 base::FilePath basedir = test_data_dir_.AppendASCII("management"); | 334 base::FilePath basedir = test_data_dir_.AppendASCII("management"); |
| 342 LoadNamedExtension(basedir, "packaged_app"); | 335 LoadNamedExtension(basedir, "packaged_app"); |
| 343 | 336 |
| 344 ASSERT_TRUE(RunExtensionSubtest("management/test", "launchType.html")); | 337 ASSERT_TRUE(RunExtensionSubtest("management/test", "launchType.html")); |
| 345 } | 338 } |
| OLD | NEW |