| 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 "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/extensions/extension_system.h" | 9 #include "chrome/browser/extensions/extension_system.h" |
| 10 #include "chrome/browser/extensions/extension_test_message_listener.h" | 10 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 ASSERT_TRUE(LoadExtension( | 169 ASSERT_TRUE(LoadExtension( |
| 170 test_data_dir_.AppendASCII("management/launch_on_install"))); | 170 test_data_dir_.AppendASCII("management/launch_on_install"))); |
| 171 ASSERT_TRUE(launcher_loaded.WaitUntilSatisfied()); | 171 ASSERT_TRUE(launcher_loaded.WaitUntilSatisfied()); |
| 172 | 172 |
| 173 // Load an app with app.launch.container = "panel". | 173 // Load an app with app.launch.container = "panel". |
| 174 std::string app_id; | 174 std::string app_id; |
| 175 LoadAndWaitForLaunch("management/launch_app_panel", &app_id); | 175 LoadAndWaitForLaunch("management/launch_app_panel", &app_id); |
| 176 ASSERT_FALSE(HasFatalFailure()); // Stop the test if any ASSERT failed. | 176 ASSERT_FALSE(HasFatalFailure()); // Stop the test if any ASSERT failed. |
| 177 | 177 |
| 178 // Find the app's browser. Check that it is a popup. | 178 // Find the app's browser. Check that it is a popup. |
| 179 ASSERT_EQ(2u, chrome::GetBrowserCount(browser()->profile())); | 179 ASSERT_EQ(2u, chrome::GetBrowserCount(browser()->profile(), |
| 180 browser()->host_desktop_type())); |
| 180 Browser* app_browser = FindOtherBrowser(browser()); | 181 Browser* app_browser = FindOtherBrowser(browser()); |
| 181 ASSERT_TRUE(app_browser->is_type_popup()); | 182 ASSERT_TRUE(app_browser->is_type_popup()); |
| 182 ASSERT_TRUE(app_browser->is_app()); | 183 ASSERT_TRUE(app_browser->is_app()); |
| 183 | 184 |
| 184 // Close the app panel. | 185 // Close the app panel. |
| 185 content::WindowedNotificationObserver signal( | 186 content::WindowedNotificationObserver signal( |
| 186 chrome::NOTIFICATION_BROWSER_CLOSED, | 187 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 187 content::Source<Browser>(app_browser)); | 188 content::Source<Browser>(app_browser)); |
| 188 | 189 |
| 189 chrome::CloseWindow(app_browser); | 190 chrome::CloseWindow(app_browser); |
| 190 signal.Wait(); | 191 signal.Wait(); |
| 191 | 192 |
| 192 // Unload the extension. | 193 // Unload the extension. |
| 193 UninstallExtension(app_id); | 194 UninstallExtension(app_id); |
| 194 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile())); | 195 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), |
| 196 browser()->host_desktop_type())); |
| 195 ASSERT_FALSE(service->GetExtensionById(app_id, true)); | 197 ASSERT_FALSE(service->GetExtensionById(app_id, true)); |
| 196 | 198 |
| 197 // Set a pref indicating that the user wants to launch in a regular tab. | 199 // Set a pref indicating that the user wants to launch in a regular tab. |
| 198 // This should be ignored, because panel apps always load in a popup. | 200 // This should be ignored, because panel apps always load in a popup. |
| 199 service->extension_prefs()->SetLaunchType( | 201 service->extension_prefs()->SetLaunchType( |
| 200 app_id, extensions::ExtensionPrefs::LAUNCH_REGULAR); | 202 app_id, extensions::ExtensionPrefs::LAUNCH_REGULAR); |
| 201 | 203 |
| 202 // Load the extension again. | 204 // Load the extension again. |
| 203 std::string app_id_new; | 205 std::string app_id_new; |
| 204 LoadAndWaitForLaunch("management/launch_app_panel", &app_id_new); | 206 LoadAndWaitForLaunch("management/launch_app_panel", &app_id_new); |
| 205 ASSERT_FALSE(HasFatalFailure()); | 207 ASSERT_FALSE(HasFatalFailure()); |
| 206 | 208 |
| 207 // If the ID changed, then the pref will not apply to the app. | 209 // If the ID changed, then the pref will not apply to the app. |
| 208 ASSERT_EQ(app_id, app_id_new); | 210 ASSERT_EQ(app_id, app_id_new); |
| 209 | 211 |
| 210 // Find the app's browser. Apps that should load in a panel ignore | 212 // Find the app's browser. Apps that should load in a panel ignore |
| 211 // prefs, so we should still see the launch in a popup. | 213 // prefs, so we should still see the launch in a popup. |
| 212 ASSERT_EQ(2u, chrome::GetBrowserCount(browser()->profile())); | 214 ASSERT_EQ(2u, chrome::GetBrowserCount(browser()->profile(), |
| 215 browser()->host_desktop_type())); |
| 213 app_browser = FindOtherBrowser(browser()); | 216 app_browser = FindOtherBrowser(browser()); |
| 214 ASSERT_TRUE(app_browser->is_type_popup()); | 217 ASSERT_TRUE(app_browser->is_type_popup()); |
| 215 ASSERT_TRUE(app_browser->is_app()); | 218 ASSERT_TRUE(app_browser->is_app()); |
| 216 } | 219 } |
| 217 | 220 |
| 218 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, LaunchTabApp) { | 221 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, LaunchTabApp) { |
| 219 ExtensionService* service = extensions::ExtensionSystem::Get( | 222 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 220 browser()->profile())->extension_service(); | 223 browser()->profile())->extension_service(); |
| 221 | 224 |
| 222 // Load an extension that calls launchApp() on any app that gets | 225 // Load an extension that calls launchApp() on any app that gets |
| 223 // installed. | 226 // installed. |
| 224 ExtensionTestMessageListener launcher_loaded("launcher loaded", false); | 227 ExtensionTestMessageListener launcher_loaded("launcher loaded", false); |
| 225 ASSERT_TRUE(LoadExtension( | 228 ASSERT_TRUE(LoadExtension( |
| 226 test_data_dir_.AppendASCII("management/launch_on_install"))); | 229 test_data_dir_.AppendASCII("management/launch_on_install"))); |
| 227 ASSERT_TRUE(launcher_loaded.WaitUntilSatisfied()); | 230 ASSERT_TRUE(launcher_loaded.WaitUntilSatisfied()); |
| 228 | 231 |
| 229 // Code below assumes that the test starts with a single browser window | 232 // Code below assumes that the test starts with a single browser window |
| 230 // hosting one tab. | 233 // hosting one tab. |
| 231 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile())); | 234 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), |
| 235 browser()->host_desktop_type())); |
| 232 ASSERT_EQ(1, browser()->tab_strip_model()->count()); | 236 ASSERT_EQ(1, browser()->tab_strip_model()->count()); |
| 233 | 237 |
| 234 // Load an app with app.launch.container = "tab". | 238 // Load an app with app.launch.container = "tab". |
| 235 std::string app_id; | 239 std::string app_id; |
| 236 LoadAndWaitForLaunch("management/launch_app_tab", &app_id); | 240 LoadAndWaitForLaunch("management/launch_app_tab", &app_id); |
| 237 ASSERT_FALSE(HasFatalFailure()); | 241 ASSERT_FALSE(HasFatalFailure()); |
| 238 | 242 |
| 239 // Check that the app opened in a new tab of the existing browser. | 243 // Check that the app opened in a new tab of the existing browser. |
| 240 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile())); | 244 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), |
| 245 browser()->host_desktop_type())); |
| 241 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 246 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
| 242 | 247 |
| 243 // Unload the extension. | 248 // Unload the extension. |
| 244 UninstallExtension(app_id); | 249 UninstallExtension(app_id); |
| 245 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile())); | 250 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), |
| 251 browser()->host_desktop_type())); |
| 246 ASSERT_FALSE(service->GetExtensionById(app_id, true)); | 252 ASSERT_FALSE(service->GetExtensionById(app_id, true)); |
| 247 | 253 |
| 248 // Set a pref indicating that the user wants to launch in a window. | 254 // Set a pref indicating that the user wants to launch in a window. |
| 249 service->extension_prefs()->SetLaunchType( | 255 service->extension_prefs()->SetLaunchType( |
| 250 app_id, extensions::ExtensionPrefs::LAUNCH_WINDOW); | 256 app_id, extensions::ExtensionPrefs::LAUNCH_WINDOW); |
| 251 | 257 |
| 252 std::string app_id_new; | 258 std::string app_id_new; |
| 253 LoadAndWaitForLaunch("management/launch_app_tab", &app_id_new); | 259 LoadAndWaitForLaunch("management/launch_app_tab", &app_id_new); |
| 254 ASSERT_FALSE(HasFatalFailure()); | 260 ASSERT_FALSE(HasFatalFailure()); |
| 255 | 261 |
| 256 // If the ID changed, then the pref will not apply to the app. | 262 // If the ID changed, then the pref will not apply to the app. |
| 257 ASSERT_EQ(app_id, app_id_new); | 263 ASSERT_EQ(app_id, app_id_new); |
| 258 | 264 |
| 259 #if defined(OS_MACOSX) | 265 #if defined(OS_MACOSX) |
| 260 // App windows are not yet implemented on mac os. We should fall back | 266 // App windows are not yet implemented on mac os. We should fall back |
| 261 // to a normal tab. | 267 // to a normal tab. |
| 262 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile())); | 268 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), |
| 269 browser()->host_desktop_type())); |
| 263 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 270 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
| 264 #else | 271 #else |
| 265 // Find the app's browser. Opening in a new window will create | 272 // Find the app's browser. Opening in a new window will create |
| 266 // a new browser. | 273 // a new browser. |
| 267 ASSERT_EQ(2u, chrome::GetBrowserCount(browser()->profile())); | 274 ASSERT_EQ(2u, chrome::GetBrowserCount(browser()->profile(), |
| 275 browser()->host_desktop_type())); |
| 268 Browser* app_browser = FindOtherBrowser(browser()); | 276 Browser* app_browser = FindOtherBrowser(browser()); |
| 269 ASSERT_TRUE(app_browser->is_app()); | 277 ASSERT_TRUE(app_browser->is_app()); |
| 270 ASSERT_FALSE(app_browser->is_type_panel()); | 278 ASSERT_FALSE(app_browser->is_type_panel()); |
| 271 #endif | 279 #endif |
| 272 } | 280 } |
| OLD | NEW |