| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/test/test_timeouts.h" | 6 #include "base/test/test_timeouts.h" |
| 7 #include "base/threading/platform_thread.h" | 7 #include "base/threading/platform_thread.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
| 10 #include "chrome/browser/automation/automation_util.h" | 10 #include "chrome/browser/automation/automation_util.h" |
| 11 #include "chrome/browser/debugger/devtools_window.h" | 11 #include "chrome/browser/debugger/devtools_window.h" |
| 12 #include "chrome/browser/extensions/api/permissions/permissions_api.h" | 12 #include "chrome/browser/extensions/api/permissions/permissions_api.h" |
| 13 #include "chrome/browser/extensions/app_restore_service_factory.h" | 13 #include "chrome/browser/extensions/app_restore_service_factory.h" |
| 14 #include "chrome/browser/extensions/app_restore_service.h" | 14 #include "chrome/browser/extensions/app_restore_service.h" |
| 15 #include "chrome/browser/extensions/extension_browsertest.h" | 15 #include "chrome/browser/extensions/extension_browsertest.h" |
| 16 #include "chrome/browser/extensions/extension_prefs.h" | 16 #include "chrome/browser/extensions/extension_prefs.h" |
| 17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/extensions/extension_system.h" | 18 #include "chrome/browser/extensions/extension_system.h" |
| 19 #include "chrome/browser/extensions/extension_test_message_listener.h" | 19 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 20 #include "chrome/browser/extensions/platform_app_browsertest_util.h" | 20 #include "chrome/browser/extensions/platform_app_browsertest_util.h" |
| 21 #include "chrome/browser/extensions/platform_app_launcher.h" | 21 #include "chrome/browser/extensions/platform_app_launcher.h" |
| 22 #include "chrome/browser/extensions/shell_window_registry.h" | 22 #include "chrome/browser/extensions/shell_window_registry.h" |
| 23 #include "chrome/browser/lifetime/application_lifetime.h" |
| 23 #include "chrome/browser/prefs/pref_service.h" | 24 #include "chrome/browser/prefs/pref_service.h" |
| 24 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 25 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
| 25 #include "chrome/browser/ui/browser.h" | 26 #include "chrome/browser/ui/browser.h" |
| 26 #include "chrome/browser/ui/browser_tabstrip.h" | 27 #include "chrome/browser/ui/browser_tabstrip.h" |
| 28 #include "chrome/browser/ui/browser_window.h" |
| 27 #include "chrome/browser/ui/constrained_window_tab_helper.h" | 29 #include "chrome/browser/ui/constrained_window_tab_helper.h" |
| 28 #include "chrome/browser/ui/extensions/application_launch.h" | 30 #include "chrome/browser/ui/extensions/application_launch.h" |
| 29 #include "chrome/browser/ui/extensions/shell_window.h" | 31 #include "chrome/browser/ui/extensions/shell_window.h" |
| 30 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 32 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 31 #include "chrome/common/chrome_notification_types.h" | 33 #include "chrome/common/chrome_notification_types.h" |
| 32 #include "chrome/common/url_constants.h" | 34 #include "chrome/common/url_constants.h" |
| 33 #include "chrome/test/base/ui_test_utils.h" | 35 #include "chrome/test/base/ui_test_utils.h" |
| 34 #include "content/public/browser/devtools_agent_host_registry.h" | 36 #include "content/public/browser/devtools_agent_host_registry.h" |
| 35 #include "content/public/browser/render_process_host.h" | 37 #include "content/public/browser/render_process_host.h" |
| 36 #include "content/public/browser/web_intents_dispatcher.h" | 38 #include "content/public/browser/web_intents_dispatcher.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 size_t observations_; | 141 size_t observations_; |
| 140 std::vector<content::WebContents*> observed_tabs_; | 142 std::vector<content::WebContents*> observed_tabs_; |
| 141 | 143 |
| 142 DISALLOW_COPY_AND_ASSIGN(TabsAddedNotificationObserver); | 144 DISALLOW_COPY_AND_ASSIGN(TabsAddedNotificationObserver); |
| 143 }; | 145 }; |
| 144 | 146 |
| 145 const char kTestFilePath[] = "platform_apps/launch_files/test.txt"; | 147 const char kTestFilePath[] = "platform_apps/launch_files/test.txt"; |
| 146 | 148 |
| 147 } // namespace | 149 } // namespace |
| 148 | 150 |
| 151 // TODO(benwells): Break up this file into some sensible smaller files. |
| 152 |
| 149 // Tests that CreateShellWindow doesn't crash if you close it straight away. | 153 // Tests that CreateShellWindow doesn't crash if you close it straight away. |
| 150 // LauncherPlatformAppBrowserTest relies on this behaviour, but is only run for | 154 // LauncherPlatformAppBrowserTest relies on this behaviour, but is only run for |
| 151 // ash, so we test that it works here. | 155 // ash, so we test that it works here. |
| 152 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, CreateAndCloseShellWindow) { | 156 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, CreateAndCloseShellWindow) { |
| 153 const Extension* extension = LoadAndLaunchPlatformApp("minimal"); | 157 const Extension* extension = LoadAndLaunchPlatformApp("minimal"); |
| 154 ShellWindow* window = CreateShellWindow(extension); | 158 ShellWindow* window = CreateShellWindow(extension); |
| 155 CloseShellWindow(window); | 159 CloseShellWindow(window); |
| 160 CloseShellWindowsAndWaitForAppToExit(); |
| 156 } | 161 } |
| 157 | 162 |
| 158 // Tests that platform apps can be launched in incognito mode without crashing. | 163 // Tests that platform apps can be launched in incognito mode without crashing. |
| 159 // Times out on ChromeOS: http://crbug.com/159392 | 164 // Times out on ChromeOS: http://crbug.com/159392 |
| 160 #if defined(OS_CHROMEOS) | 165 #if defined(OS_CHROMEOS) |
| 161 #define MAYBE_LaunchAppIncognito DISABLED_LaunchAppIncognito | 166 #define MAYBE_LaunchAppIncognito DISABLED_LaunchAppIncognito |
| 162 #else | 167 #else |
| 163 #define MAYBE_LaunchAppIncognito LaunchAppIncognito | 168 #define MAYBE_LaunchAppIncognito LaunchAppIncognito |
| 164 #endif | 169 #endif |
| 165 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_LaunchAppIncognito) { | 170 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_LaunchAppIncognito) { |
| 166 Browser* browser_incognito = ui_test_utils::OpenURLOffTheRecord( | 171 Browser* browser_incognito = ui_test_utils::OpenURLOffTheRecord( |
| 167 browser()->profile(), GURL("about:blank")); | 172 browser()->profile(), GURL("about:blank")); |
| 168 | 173 |
| 169 ExtensionTestMessageListener launched_listener("Launched", false); | 174 ExtensionTestMessageListener launched_listener("Launched", false); |
| 170 | 175 |
| 171 const Extension* extension = LoadExtensionIncognito( | 176 const Extension* extension = LoadExtensionIncognito( |
| 172 test_data_dir_.AppendASCII("platform_apps").AppendASCII("minimal")); | 177 test_data_dir_.AppendASCII("platform_apps").AppendASCII("minimal")); |
| 173 EXPECT_TRUE(extension); | 178 EXPECT_TRUE(extension); |
| 174 | 179 |
| 175 application_launch::OpenApplication(application_launch::LaunchParams( | 180 application_launch::OpenApplication(application_launch::LaunchParams( |
| 176 browser_incognito->profile(), extension, extension_misc::LAUNCH_NONE, | 181 browser_incognito->profile(), extension, extension_misc::LAUNCH_NONE, |
| 177 NEW_WINDOW)); | 182 NEW_WINDOW)); |
| 178 | 183 |
| 179 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 184 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 185 CloseShellWindowsAndWaitForAppToExit(); |
| 186 } |
| 187 |
| 188 // Tests that the browser process is kept alive by the platform app's background |
| 189 // page. |
| 190 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppEventPageKeepsBrowserAlive) { |
| 191 LoadAndLaunchPlatformApp("minimal"); |
| 192 browser()->window()->Close(); |
| 193 ASSERT_TRUE(browser::WillKeepAlive()); |
| 194 CloseShellWindowsAndWaitForAppToExit(); |
| 180 } | 195 } |
| 181 | 196 |
| 182 // Tests that platform apps received the "launch" event when launched. | 197 // Tests that platform apps received the "launch" event when launched. |
| 183 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) { | 198 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) { |
| 184 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_; | 199 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_; |
| 185 } | 200 } |
| 186 | 201 |
| 187 // Tests that platform apps can reply to "launch" events that contain a Web | 202 // Tests that platform apps can reply to "launch" events that contain a Web |
| 188 // Intent. This test does not test the mechanics of invoking a Web Intent | 203 // Intent. This test does not test the mechanics of invoking a Web Intent |
| 189 // from a source page, and short-circuits to LaunchPlatformAppWithWebIntent. | 204 // from a source page, and short-circuits to LaunchPlatformAppWithWebIntent. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 204 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 219 WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
| 205 ASSERT_TRUE(web_contents); | 220 ASSERT_TRUE(web_contents); |
| 206 | 221 |
| 207 extensions::LaunchPlatformAppWithWebIntent( | 222 extensions::LaunchPlatformAppWithWebIntent( |
| 208 browser()->profile(), | 223 browser()->profile(), |
| 209 extension, | 224 extension, |
| 210 handler.intents_dispatcher(), | 225 handler.intents_dispatcher(), |
| 211 web_contents); | 226 web_contents); |
| 212 | 227 |
| 213 ASSERT_TRUE(handler.WaitUntilReply()); | 228 ASSERT_TRUE(handler.WaitUntilReply()); |
| 229 CloseShellWindowsAndWaitForAppToExit(); |
| 214 } | 230 } |
| 215 | 231 |
| 216 // Tests that platform apps cannot use certain disabled window properties, but | 232 // Tests that platform apps cannot use certain disabled window properties, but |
| 217 // can override them and then use them. | 233 // can override them and then use them. |
| 218 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisabledWindowProperties) { | 234 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisabledWindowProperties) { |
| 219 ASSERT_TRUE(RunPlatformAppTest("platform_apps/disabled_window_properties")) | 235 ASSERT_TRUE(RunPlatformAppTest("platform_apps/disabled_window_properties")) |
| 220 << message_; | 236 << message_; |
| 221 } | 237 } |
| 222 | 238 |
| 223 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) { | 239 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) { |
| 224 ExtensionTestMessageListener launched_listener("Launched", false); | |
| 225 LoadAndLaunchPlatformApp("minimal"); | 240 LoadAndLaunchPlatformApp("minimal"); |
| 226 | 241 |
| 227 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
| 228 | |
| 229 // The empty app doesn't add any context menu items, so its menu should | 242 // The empty app doesn't add any context menu items, so its menu should |
| 230 // only include the developer tools. | 243 // only include the developer tools. |
| 231 WebContents* web_contents = GetFirstShellWindowWebContents(); | 244 WebContents* web_contents = GetFirstShellWindowWebContents(); |
| 232 ASSERT_TRUE(web_contents); | 245 ASSERT_TRUE(web_contents); |
| 233 WebKit::WebContextMenuData data; | 246 WebKit::WebContextMenuData data; |
| 234 content::ContextMenuParams params(data); | 247 content::ContextMenuParams params(data); |
| 235 scoped_ptr<PlatformAppContextMenu> menu; | 248 scoped_ptr<PlatformAppContextMenu> menu; |
| 236 menu.reset(new PlatformAppContextMenu(web_contents, params)); | 249 menu.reset(new PlatformAppContextMenu(web_contents, params)); |
| 237 menu->Init(); | 250 menu->Init(); |
| 238 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); | 251 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
| 239 ASSERT_TRUE( | 252 ASSERT_TRUE( |
| 240 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); | 253 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
| 241 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); | 254 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); |
| 242 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); | 255 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 243 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); | 256 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
| 257 CloseShellWindowsAndWaitForAppToExit(); |
| 244 } | 258 } |
| 245 | 259 |
| 246 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) { | 260 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) { |
| 247 ExtensionTestMessageListener launched_listener("Launched", false); | |
| 248 LoadAndLaunchPlatformApp("context_menu"); | 261 LoadAndLaunchPlatformApp("context_menu"); |
| 249 | 262 |
| 250 // Wait for the extension to tell us it's initialized its context menus and | |
| 251 // launched a window. | |
| 252 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
| 253 | |
| 254 // The context_menu app has two context menu items. These, along with a | 263 // The context_menu app has two context menu items. These, along with a |
| 255 // separator and the developer tools, is all that should be in the menu. | 264 // separator and the developer tools, is all that should be in the menu. |
| 256 WebContents* web_contents = GetFirstShellWindowWebContents(); | 265 WebContents* web_contents = GetFirstShellWindowWebContents(); |
| 257 ASSERT_TRUE(web_contents); | 266 ASSERT_TRUE(web_contents); |
| 258 WebKit::WebContextMenuData data; | 267 WebKit::WebContextMenuData data; |
| 259 content::ContextMenuParams params(data); | 268 content::ContextMenuParams params(data); |
| 260 scoped_ptr<PlatformAppContextMenu> menu; | 269 scoped_ptr<PlatformAppContextMenu> menu; |
| 261 menu.reset(new PlatformAppContextMenu(web_contents, params)); | 270 menu.reset(new PlatformAppContextMenu(web_contents, params)); |
| 262 menu->Init(); | 271 menu->Init(); |
| 263 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); | 272 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
| 264 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1)); | 273 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1)); |
| 265 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); | 274 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
| 266 ASSERT_TRUE( | 275 ASSERT_TRUE( |
| 267 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); | 276 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
| 268 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); | 277 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); |
| 269 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); | 278 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 270 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); | 279 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
| 271 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); | 280 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
| 281 CloseShellWindowsAndWaitForAppToExit(); |
| 272 } | 282 } |
| 273 | 283 |
| 274 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, InstalledAppWithContextMenu) { | 284 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, InstalledAppWithContextMenu) { |
| 275 ExtensionTestMessageListener launched_listener("Launched", false); | |
| 276 InstallAndLaunchPlatformApp("context_menu"); | 285 InstallAndLaunchPlatformApp("context_menu"); |
| 277 | 286 |
| 278 // Wait for the extension to tell us it's initialized its context menus and | |
| 279 // launched a window. | |
| 280 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
| 281 | |
| 282 // The context_menu app has two context menu items. For an installed app | 287 // The context_menu app has two context menu items. For an installed app |
| 283 // these are all that should be in the menu. | 288 // these are all that should be in the menu. |
| 284 WebContents* web_contents = GetFirstShellWindowWebContents(); | 289 WebContents* web_contents = GetFirstShellWindowWebContents(); |
| 285 ASSERT_TRUE(web_contents); | 290 ASSERT_TRUE(web_contents); |
| 286 WebKit::WebContextMenuData data; | 291 WebKit::WebContextMenuData data; |
| 287 content::ContextMenuParams params(data); | 292 content::ContextMenuParams params(data); |
| 288 scoped_ptr<PlatformAppContextMenu> menu; | 293 scoped_ptr<PlatformAppContextMenu> menu; |
| 289 menu.reset(new PlatformAppContextMenu(web_contents, params)); | 294 menu.reset(new PlatformAppContextMenu(web_contents, params)); |
| 290 menu->Init(); | 295 menu->Init(); |
| 291 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); | 296 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
| 292 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1)); | 297 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1)); |
| 293 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); | 298 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
| 294 ASSERT_FALSE( | 299 ASSERT_FALSE( |
| 295 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); | 300 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
| 296 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); | 301 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); |
| 297 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); | 302 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 298 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); | 303 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
| 299 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); | 304 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
| 305 CloseShellWindowsAndWaitForAppToExit(); |
| 300 } | 306 } |
| 301 | 307 |
| 302 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuTextField) { | 308 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuTextField) { |
| 303 ExtensionTestMessageListener launched_listener("Launched", false); | |
| 304 LoadAndLaunchPlatformApp("context_menu"); | 309 LoadAndLaunchPlatformApp("context_menu"); |
| 305 | 310 |
| 306 // Wait for the extension to tell us it's initialized its context menus and | |
| 307 // launched a window. | |
| 308 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
| 309 | |
| 310 // The context_menu app has one context menu item. This, along with a | 311 // The context_menu app has one context menu item. This, along with a |
| 311 // separator and the developer tools, is all that should be in the menu. | 312 // separator and the developer tools, is all that should be in the menu. |
| 312 WebContents* web_contents = GetFirstShellWindowWebContents(); | 313 WebContents* web_contents = GetFirstShellWindowWebContents(); |
| 313 ASSERT_TRUE(web_contents); | 314 ASSERT_TRUE(web_contents); |
| 314 WebKit::WebContextMenuData data; | 315 WebKit::WebContextMenuData data; |
| 315 content::ContextMenuParams params(data); | 316 content::ContextMenuParams params(data); |
| 316 params.is_editable = true; | 317 params.is_editable = true; |
| 317 scoped_ptr<PlatformAppContextMenu> menu; | 318 scoped_ptr<PlatformAppContextMenu> menu; |
| 318 menu.reset(new PlatformAppContextMenu(web_contents, params)); | 319 menu.reset(new PlatformAppContextMenu(web_contents, params)); |
| 319 menu->Init(); | 320 menu->Init(); |
| 320 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); | 321 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
| 321 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); | 322 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
| 322 ASSERT_TRUE( | 323 ASSERT_TRUE( |
| 323 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); | 324 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
| 324 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); | 325 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); |
| 325 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); | 326 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
| 326 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); | 327 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); |
| 327 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); | 328 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 328 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); | 329 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
| 330 CloseShellWindowsAndWaitForAppToExit(); |
| 329 } | 331 } |
| 330 | 332 |
| 331 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuSelection) { | 333 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuSelection) { |
| 332 ExtensionTestMessageListener launched_listener("Launched", false); | |
| 333 LoadAndLaunchPlatformApp("context_menu"); | 334 LoadAndLaunchPlatformApp("context_menu"); |
| 334 | 335 |
| 335 // Wait for the extension to tell us it's initialized its context menus and | |
| 336 // launched a window. | |
| 337 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
| 338 | |
| 339 // The context_menu app has one context menu item. This, along with a | 336 // The context_menu app has one context menu item. This, along with a |
| 340 // separator and the developer tools, is all that should be in the menu. | 337 // separator and the developer tools, is all that should be in the menu. |
| 341 WebContents* web_contents = GetFirstShellWindowWebContents(); | 338 WebContents* web_contents = GetFirstShellWindowWebContents(); |
| 342 ASSERT_TRUE(web_contents); | 339 ASSERT_TRUE(web_contents); |
| 343 WebKit::WebContextMenuData data; | 340 WebKit::WebContextMenuData data; |
| 344 content::ContextMenuParams params(data); | 341 content::ContextMenuParams params(data); |
| 345 params.selection_text = ASCIIToUTF16("Hello World"); | 342 params.selection_text = ASCIIToUTF16("Hello World"); |
| 346 scoped_ptr<PlatformAppContextMenu> menu; | 343 scoped_ptr<PlatformAppContextMenu> menu; |
| 347 menu.reset(new PlatformAppContextMenu(web_contents, params)); | 344 menu.reset(new PlatformAppContextMenu(web_contents, params)); |
| 348 menu->Init(); | 345 menu->Init(); |
| 349 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); | 346 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
| 350 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); | 347 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
| 351 ASSERT_TRUE( | 348 ASSERT_TRUE( |
| 352 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); | 349 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
| 353 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); | 350 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); |
| 354 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); | 351 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
| 355 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); | 352 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); |
| 356 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); | 353 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 357 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); | 354 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
| 355 CloseShellWindowsAndWaitForAppToExit(); |
| 358 } | 356 } |
| 359 | 357 |
| 360 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuClicked) { | 358 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuClicked) { |
| 361 ExtensionTestMessageListener launched_listener("Launched", false); | |
| 362 LoadAndLaunchPlatformApp("context_menu_click"); | 359 LoadAndLaunchPlatformApp("context_menu_click"); |
| 363 | 360 |
| 364 // Wait for the extension to tell us it's initialized its context menus and | |
| 365 // launched a window. | |
| 366 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
| 367 | |
| 368 // Test that the menu item shows up | 361 // Test that the menu item shows up |
| 369 WebContents* web_contents = GetFirstShellWindowWebContents(); | 362 WebContents* web_contents = GetFirstShellWindowWebContents(); |
| 370 ASSERT_TRUE(web_contents); | 363 ASSERT_TRUE(web_contents); |
| 371 WebKit::WebContextMenuData data; | 364 WebKit::WebContextMenuData data; |
| 372 content::ContextMenuParams params(data); | 365 content::ContextMenuParams params(data); |
| 373 params.page_url = GURL("http://foo.bar"); | 366 params.page_url = GURL("http://foo.bar"); |
| 374 scoped_ptr<PlatformAppContextMenu> menu; | 367 scoped_ptr<PlatformAppContextMenu> menu; |
| 375 menu.reset(new PlatformAppContextMenu(web_contents, params)); | 368 menu.reset(new PlatformAppContextMenu(web_contents, params)); |
| 376 menu->Init(); | 369 menu->Init(); |
| 377 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); | 370 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
| 378 | 371 |
| 379 // Execute the menu item | 372 // Execute the menu item |
| 380 ExtensionTestMessageListener onclicked_listener("onClicked fired for id1", | 373 ExtensionTestMessageListener onclicked_listener("onClicked fired for id1", |
| 381 false); | 374 false); |
| 382 menu->ExecuteCommand(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST); | 375 menu->ExecuteCommand(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST); |
| 383 | 376 |
| 384 ASSERT_TRUE(onclicked_listener.WaitUntilSatisfied()); | 377 ASSERT_TRUE(onclicked_listener.WaitUntilSatisfied()); |
| 378 CloseShellWindowsAndWaitForAppToExit(); |
| 385 } | 379 } |
| 386 | 380 |
| 387 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowNavigation) { | 381 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowNavigation) { |
| 388 TabsAddedNotificationObserver observer(2); | 382 TabsAddedNotificationObserver observer(2); |
| 389 | 383 |
| 390 ASSERT_TRUE(StartTestServer()); | 384 ASSERT_TRUE(StartTestServer()); |
| 391 ASSERT_TRUE(RunPlatformAppTest("platform_apps/navigation")) << message_; | 385 ASSERT_TRUE(RunPlatformAppTestReturnImmediately("platform_apps/navigation")) |
| 386 << message_; |
| 392 | 387 |
| 393 observer.Wait(); | 388 observer.Wait(); |
| 394 ASSERT_EQ(2U, observer.tabs().size()); | 389 ASSERT_EQ(2U, observer.tabs().size()); |
| 395 EXPECT_EQ(std::string(chrome::kExtensionInvalidRequestURL), | 390 EXPECT_EQ(std::string(chrome::kExtensionInvalidRequestURL), |
| 396 observer.tabs()[0]->GetURL().spec()); | 391 observer.tabs()[0]->GetURL().spec()); |
| 397 EXPECT_EQ("http://chromium.org/", | 392 EXPECT_EQ("http://chromium.org/", |
| 398 observer.tabs()[1]->GetURL().spec()); | 393 observer.tabs()[1]->GetURL().spec()); |
| 394 browser()->window()->Close(); |
| 395 CloseShellWindowsAndWaitForAppToExit(); |
| 399 } | 396 } |
| 400 | 397 |
| 401 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Iframes) { | 398 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Iframes) { |
| 402 ASSERT_TRUE(StartTestServer()); | 399 ASSERT_TRUE(StartTestServer()); |
| 403 ASSERT_TRUE(RunPlatformAppTest("platform_apps/iframes")) << message_; | 400 ASSERT_TRUE(RunPlatformAppTest("platform_apps/iframes")) << message_; |
| 404 } | 401 } |
| 405 | 402 |
| 406 // Tests that localStorage and WebSQL are disabled for platform apps. | 403 // Tests that localStorage and WebSQL are disabled for platform apps. |
| 407 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowStorage) { | 404 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowStorage) { |
| 408 ASSERT_TRUE(RunPlatformAppTest("platform_apps/storage")) << message_; | 405 ASSERT_TRUE(RunPlatformAppTest("platform_apps/storage")) << message_; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 // Initially there should be just the one browser window visible to the | 455 // Initially there should be just the one browser window visible to the |
| 459 // extensions API. | 456 // extensions API. |
| 460 const Extension* extension = LoadExtension( | 457 const Extension* extension = LoadExtension( |
| 461 test_data_dir_.AppendASCII("common/background_page")); | 458 test_data_dir_.AppendASCII("common/background_page")); |
| 462 ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension)); | 459 ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension)); |
| 463 | 460 |
| 464 // And no shell windows. | 461 // And no shell windows. |
| 465 ASSERT_EQ(0U, GetShellWindowCount()); | 462 ASSERT_EQ(0U, GetShellWindowCount()); |
| 466 | 463 |
| 467 // Launch a platform app that shows a window. | 464 // Launch a platform app that shows a window. |
| 468 ExtensionTestMessageListener launched_listener("Launched", false); | |
| 469 LoadAndLaunchPlatformApp("minimal"); | 465 LoadAndLaunchPlatformApp("minimal"); |
| 470 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
| 471 ASSERT_EQ(1U, GetShellWindowCount()); | 466 ASSERT_EQ(1U, GetShellWindowCount()); |
| 472 ShellWindowRegistry::ShellWindowSet shell_windows = | 467 ShellWindowRegistry::ShellWindowSet shell_windows = |
| 473 ShellWindowRegistry::Get(browser()->profile())->shell_windows(); | 468 ShellWindowRegistry::Get(browser()->profile())->shell_windows(); |
| 474 int shell_window_id = (*shell_windows.begin())->session_id().id(); | 469 int shell_window_id = (*shell_windows.begin())->session_id().id(); |
| 475 | 470 |
| 476 // But it's not visible to the extensions API, it still thinks there's just | 471 // But it's not visible to the extensions API, it still thinks there's just |
| 477 // one browser window. | 472 // one browser window. |
| 478 ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension)); | 473 ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension)); |
| 479 // It can't look it up by ID either | 474 // It can't look it up by ID either |
| 480 ASSERT_FALSE(RunGetWindowFunctionForExtension(shell_window_id, extension)); | 475 ASSERT_FALSE(RunGetWindowFunctionForExtension(shell_window_id, extension)); |
| 481 | 476 |
| 482 // The app can also only see one window (its own). | 477 // The app can also only see one window (its own). |
| 483 // TODO(jeremya): add an extension function to get a shell window by ID, and | 478 // TODO(jeremya): add an extension function to get a shell window by ID, and |
| 484 // to get a list of all the shell windows, so we can test this. | 479 // to get a list of all the shell windows, so we can test this. |
| 485 | 480 |
| 486 // Launch another platform app that also shows a window. | 481 // Launch another platform app that also shows a window. |
| 487 ExtensionTestMessageListener launched_listener2("Launched", false); | |
| 488 LoadAndLaunchPlatformApp("context_menu"); | 482 LoadAndLaunchPlatformApp("context_menu"); |
| 489 ASSERT_TRUE(launched_listener2.WaitUntilSatisfied()); | |
| 490 | 483 |
| 491 // There are two total shell windows, but each app can only see its own. | 484 // There are two total shell windows, but each app can only see its own. |
| 492 ASSERT_EQ(2U, GetShellWindowCount()); | 485 ASSERT_EQ(2U, GetShellWindowCount()); |
| 493 // TODO(jeremya): as above, this requires more extension functions. | 486 // TODO(jeremya): as above, this requires more extension functions. |
| 487 CloseShellWindowsAndWaitForAppToExit(); |
| 494 } | 488 } |
| 495 | 489 |
| 496 // ChromeOS does not support passing arguments on the command line, so the tests | 490 // ChromeOS does not support passing arguments on the command line, so the tests |
| 497 // that rely on this functionality are disabled. | 491 // that rely on this functionality are disabled. |
| 498 #if !defined(OS_CHROMEOS) | 492 #if !defined(OS_CHROMEOS) |
| 499 // Tests that command line parameters get passed through to platform apps | 493 // Tests that command line parameters get passed through to platform apps |
| 500 // via launchData correctly when launching with a file. | 494 // via launchData correctly when launching with a file. |
| 501 // TODO(benwells/jeremya): tests need a way to specify a handler ID. | 495 // TODO(benwells/jeremya): tests need a way to specify a handler ID. |
| 502 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithFile) { | 496 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithFile) { |
| 503 SetCommandLineArg(kTestFilePath); | 497 SetCommandLineArg(kTestFilePath); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 528 extension_misc::LAUNCH_NONE, | 522 extension_misc::LAUNCH_NONE, |
| 529 NEW_WINDOW); | 523 NEW_WINDOW); |
| 530 params.command_line = CommandLine::ForCurrentProcess(); | 524 params.command_line = CommandLine::ForCurrentProcess(); |
| 531 params.current_directory = test_data_dir_; | 525 params.current_directory = test_data_dir_; |
| 532 application_launch::OpenApplication(params); | 526 application_launch::OpenApplication(params); |
| 533 | 527 |
| 534 if (!catcher.GetNextResult()) { | 528 if (!catcher.GetNextResult()) { |
| 535 message_ = catcher.message(); | 529 message_ = catcher.message(); |
| 536 ASSERT_TRUE(0); | 530 ASSERT_TRUE(0); |
| 537 } | 531 } |
| 532 CloseShellWindowsAndWaitForAppToExit(); |
| 538 } | 533 } |
| 539 | 534 |
| 540 // Tests that no launch data is sent through if the file is of the wrong MIME | 535 // Tests that no launch data is sent through if the file is of the wrong MIME |
| 541 // type. | 536 // type. |
| 542 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithWrongType) { | 537 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithWrongType) { |
| 543 SetCommandLineArg(kTestFilePath); | 538 SetCommandLineArg(kTestFilePath); |
| 544 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_type")) | 539 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_type")) |
| 545 << message_; | 540 << message_; |
| 546 } | 541 } |
| 547 | 542 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 #endif // defined(OS_CHROMEOS) | 589 #endif // defined(OS_CHROMEOS) |
| 595 | 590 |
| 596 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OpenLink) { | 591 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OpenLink) { |
| 597 ASSERT_TRUE(StartTestServer()); | 592 ASSERT_TRUE(StartTestServer()); |
| 598 content::WindowedNotificationObserver observer( | 593 content::WindowedNotificationObserver observer( |
| 599 chrome::NOTIFICATION_TAB_ADDED, | 594 chrome::NOTIFICATION_TAB_ADDED, |
| 600 content::Source<content::WebContentsDelegate>(browser())); | 595 content::Source<content::WebContentsDelegate>(browser())); |
| 601 LoadAndLaunchPlatformApp("open_link"); | 596 LoadAndLaunchPlatformApp("open_link"); |
| 602 observer.Wait(); | 597 observer.Wait(); |
| 603 ASSERT_EQ(2, browser()->tab_count()); | 598 ASSERT_EQ(2, browser()->tab_count()); |
| 599 browser()->window()->Close(); |
| 600 CloseShellWindowsAndWaitForAppToExit(); |
| 604 } | 601 } |
| 605 | 602 |
| 606 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MutationEventsDisabled) { | 603 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MutationEventsDisabled) { |
| 607 ASSERT_TRUE(RunPlatformAppTest("platform_apps/mutation_events")) << message_; | 604 ASSERT_TRUE(RunPlatformAppTest("platform_apps/mutation_events")) << message_; |
| 608 } | 605 } |
| 609 | 606 |
| 610 // Test that windows created with an id will remember and restore their | 607 // Test that windows created with an id will remember and restore their |
| 611 // geometry when opening new windows. | 608 // geometry when opening new windows. |
| 612 // Originally disabled due to flakiness (see http://crbug.com/155459) | 609 // Originally disabled due to flakiness (see http://crbug.com/155459) |
| 613 // but now because a regression breaks the test (http://crbug.com/160343). | 610 // but now because a regression breaks the test (http://crbug.com/160343). |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 | 662 |
| 666 // Make sure the window was properly moved&resized. | 663 // Make sure the window was properly moved&resized. |
| 667 ASSERT_EQ(bounds, window->GetBaseWindow()->GetBounds()); | 664 ASSERT_EQ(bounds, window->GetBaseWindow()->GetBounds()); |
| 668 | 665 |
| 669 // Tell javascript to open a second window. | 666 // Tell javascript to open a second window. |
| 670 page2_listener.Reply("continue"); | 667 page2_listener.Reply("continue"); |
| 671 | 668 |
| 672 // Wait for javascript to verify that the second window got the updated | 669 // Wait for javascript to verify that the second window got the updated |
| 673 // coordinates, ignoring the default coordinates passed to the create method. | 670 // coordinates, ignoring the default coordinates passed to the create method. |
| 674 ASSERT_TRUE(done2_listener.WaitUntilSatisfied()); | 671 ASSERT_TRUE(done2_listener.WaitUntilSatisfied()); |
| 672 |
| 673 CloseShellWindowsAndWaitForAppToExit(); |
| 675 } | 674 } |
| 676 | 675 |
| 677 // Tests that a running app is recorded in the preferences as such. | 676 // Tests that a running app is recorded in the preferences as such. |
| 678 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, RunningAppsAreRecorded) { | 677 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, RunningAppsAreRecorded) { |
| 679 content::WindowedNotificationObserver extension_suspended( | 678 content::WindowedNotificationObserver extension_suspended( |
| 680 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 679 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 681 content::NotificationService::AllSources()); | 680 content::NotificationService::AllSources()); |
| 682 | 681 |
| 683 const Extension* extension = LoadExtension( | 682 const Extension* extension = LoadExtension( |
| 684 test_data_dir_.AppendASCII("platform_apps/restart_test")); | 683 test_data_dir_.AppendASCII("platform_apps/restart_test")); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 696 // App isn't running because it got suspended. | 695 // App isn't running because it got suspended. |
| 697 ASSERT_FALSE(extension_prefs->IsExtensionRunning(extension->id())); | 696 ASSERT_FALSE(extension_prefs->IsExtensionRunning(extension->id())); |
| 698 | 697 |
| 699 // Pretend that the app is supposed to be running. | 698 // Pretend that the app is supposed to be running. |
| 700 extension_prefs->SetExtensionRunning(extension->id(), true); | 699 extension_prefs->SetExtensionRunning(extension->id(), true); |
| 701 | 700 |
| 702 ExtensionTestMessageListener restart_listener("onRestarted", false); | 701 ExtensionTestMessageListener restart_listener("onRestarted", false); |
| 703 AppRestoreServiceFactory::GetForProfile(browser()->profile())-> | 702 AppRestoreServiceFactory::GetForProfile(browser()->profile())-> |
| 704 HandleStartup(true); | 703 HandleStartup(true); |
| 705 restart_listener.WaitUntilSatisfied(); | 704 restart_listener.WaitUntilSatisfied(); |
| 705 CloseShellWindowsAndWaitForAppToExit(); |
| 706 } | 706 } |
| 707 | 707 |
| 708 namespace { | 708 namespace { |
| 709 | 709 |
| 710 class PlatformAppDevToolsBrowserTest : public PlatformAppBrowserTest { | 710 class PlatformAppDevToolsBrowserTest : public PlatformAppBrowserTest { |
| 711 protected: | 711 protected: |
| 712 enum TestFlags { | 712 enum TestFlags { |
| 713 RELAUNCH = 0x1, | 713 RELAUNCH = 0x1, |
| 714 HAS_ID = 0x2, | 714 HAS_ID = 0x2, |
| 715 }; | 715 }; |
| 716 // Runs a test inside a harness that opens DevTools on a shell window. | 716 // Runs a test inside a harness that opens DevTools on a shell window. |
| 717 void RunTestWithDevTools(const char* name, int test_flags); | 717 void RunTestWithDevTools(const char* name, int test_flags); |
| 718 }; | 718 }; |
| 719 | 719 |
| 720 void PlatformAppDevToolsBrowserTest::RunTestWithDevTools( | 720 void PlatformAppDevToolsBrowserTest::RunTestWithDevTools( |
| 721 const char* name, int test_flags) { | 721 const char* name, int test_flags) { |
| 722 using content::DevToolsAgentHostRegistry; | 722 using content::DevToolsAgentHostRegistry; |
| 723 ExtensionTestMessageListener launched_listener("Launched", false); | |
| 724 const Extension* extension = LoadAndLaunchPlatformApp(name); | 723 const Extension* extension = LoadAndLaunchPlatformApp(name); |
| 725 ASSERT_TRUE(extension); | 724 ASSERT_TRUE(extension); |
| 726 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
| 727 ShellWindow* window = GetFirstShellWindow(); | 725 ShellWindow* window = GetFirstShellWindow(); |
| 728 ASSERT_TRUE(window); | 726 ASSERT_TRUE(window); |
| 729 ASSERT_EQ(window->window_key().empty(), (test_flags & HAS_ID) == 0); | 727 ASSERT_EQ(window->window_key().empty(), (test_flags & HAS_ID) == 0); |
| 730 content::RenderViewHost* rvh = window->web_contents()->GetRenderViewHost(); | 728 content::RenderViewHost* rvh = window->web_contents()->GetRenderViewHost(); |
| 731 ASSERT_TRUE(rvh); | 729 ASSERT_TRUE(rvh); |
| 732 | 730 |
| 733 // Ensure no DevTools open for the ShellWindow, then open one. | 731 // Ensure no DevTools open for the ShellWindow, then open one. |
| 734 ASSERT_FALSE(DevToolsAgentHostRegistry::HasDevToolsAgentHost(rvh)); | 732 ASSERT_FALSE(DevToolsAgentHostRegistry::HasDevToolsAgentHost(rvh)); |
| 735 DevToolsWindow* devtools_window = DevToolsWindow::OpenDevToolsWindow(rvh); | 733 DevToolsWindow* devtools_window = DevToolsWindow::OpenDevToolsWindow(rvh); |
| 736 content::WindowedNotificationObserver loaded_observer( | 734 content::WindowedNotificationObserver loaded_observer( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 754 NEW_WINDOW)); | 752 NEW_WINDOW)); |
| 755 app_loaded_observer.Wait(); | 753 app_loaded_observer.Wait(); |
| 756 window = GetFirstShellWindow(); | 754 window = GetFirstShellWindow(); |
| 757 ASSERT_TRUE(window); | 755 ASSERT_TRUE(window); |
| 758 | 756 |
| 759 // DevTools should have reopened with the relaunch. | 757 // DevTools should have reopened with the relaunch. |
| 760 rvh = window->web_contents()->GetRenderViewHost(); | 758 rvh = window->web_contents()->GetRenderViewHost(); |
| 761 ASSERT_TRUE(rvh); | 759 ASSERT_TRUE(rvh); |
| 762 ASSERT_TRUE(DevToolsAgentHostRegistry::HasDevToolsAgentHost(rvh)); | 760 ASSERT_TRUE(DevToolsAgentHostRegistry::HasDevToolsAgentHost(rvh)); |
| 763 } | 761 } |
| 762 CloseShellWindowsAndWaitForAppToExit(); |
| 764 } | 763 } |
| 765 | 764 |
| 766 } // namespace | 765 } // namespace |
| 767 | 766 |
| 768 IN_PROC_BROWSER_TEST_F(PlatformAppDevToolsBrowserTest, ReOpenedWithID) { | 767 IN_PROC_BROWSER_TEST_F(PlatformAppDevToolsBrowserTest, ReOpenedWithID) { |
| 769 RunTestWithDevTools("minimal_id", RELAUNCH | HAS_ID); | 768 RunTestWithDevTools("minimal_id", RELAUNCH | HAS_ID); |
| 770 } | 769 } |
| 771 | 770 |
| 772 IN_PROC_BROWSER_TEST_F(PlatformAppDevToolsBrowserTest, ReOpenedWithURL) { | 771 IN_PROC_BROWSER_TEST_F(PlatformAppDevToolsBrowserTest, ReOpenedWithURL) { |
| 773 RunTestWithDevTools("minimal", RELAUNCH); | 772 RunTestWithDevTools("minimal", RELAUNCH); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 795 // Verify that the shell window has a constrained window attached. | 794 // Verify that the shell window has a constrained window attached. |
| 796 ConstrainedWindowTabHelper* constrained_window_tab_helper = | 795 ConstrainedWindowTabHelper* constrained_window_tab_helper = |
| 797 ConstrainedWindowTabHelper::FromWebContents(web_contents); | 796 ConstrainedWindowTabHelper::FromWebContents(web_contents); |
| 798 EXPECT_EQ(1u, constrained_window_tab_helper->constrained_window_count()); | 797 EXPECT_EQ(1u, constrained_window_tab_helper->constrained_window_count()); |
| 799 | 798 |
| 800 // Close the constrained window and wait for the reply to the permission | 799 // Close the constrained window and wait for the reply to the permission |
| 801 // request. | 800 // request. |
| 802 ExtensionTestMessageListener listener("PermissionRequestDone", false); | 801 ExtensionTestMessageListener listener("PermissionRequestDone", false); |
| 803 constrained_window_tab_helper->CloseConstrainedWindows(); | 802 constrained_window_tab_helper->CloseConstrainedWindows(); |
| 804 ASSERT_TRUE(listener.WaitUntilSatisfied()); | 803 ASSERT_TRUE(listener.WaitUntilSatisfied()); |
| 804 |
| 805 CloseShellWindowsAndWaitForAppToExit(); |
| 805 } | 806 } |
| 806 | 807 |
| 807 // Tests that an app calling chrome.runtime.reload will reload the app and | 808 // Tests that an app calling chrome.runtime.reload will reload the app and |
| 808 // relaunch it if it was running. | 809 // relaunch it if it was running. |
| 809 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ReloadRelaunches) { | 810 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ReloadRelaunches) { |
| 810 ExtensionTestMessageListener launched_listener("Launched", true); | 811 ExtensionTestMessageListener launched_listener("Launched", true); |
| 811 const Extension* extension = LoadAndLaunchPlatformApp("reload"); | 812 const Extension* extension = LoadPlatformApp("reload"); |
| 812 ASSERT_TRUE(extension); | 813 ASSERT_TRUE(extension); |
| 814 application_launch::OpenApplication(application_launch::LaunchParams( |
| 815 browser()->profile(), extension, extension_misc::LAUNCH_NONE, |
| 816 NEW_WINDOW)); |
| 813 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 817 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 814 ASSERT_TRUE(GetFirstShellWindow()); | 818 ASSERT_TRUE(GetFirstShellWindow()); |
| 815 | 819 |
| 816 // Now tell the app to reload itself | 820 // Now tell the app to reload itself |
| 817 ExtensionTestMessageListener launched_listener2("Launched", false); | 821 ExtensionTestMessageListener launched_listener2("Launched", false); |
| 818 launched_listener.Reply("reload"); | 822 launched_listener.Reply("reload"); |
| 819 ASSERT_TRUE(launched_listener2.WaitUntilSatisfied()); | 823 ASSERT_TRUE(launched_listener2.WaitUntilSatisfied()); |
| 820 ASSERT_TRUE(GetFirstShellWindow()); | 824 ASSERT_TRUE(GetFirstShellWindow()); |
| 825 CloseShellWindowsAndWaitForAppToExit(); |
| 821 } | 826 } |
| 822 | 827 |
| 823 namespace { | 828 namespace { |
| 824 | 829 |
| 825 // Simple observer to check for NOTIFICATION_EXTENSION_INSTALLED events to | 830 // Simple observer to check for NOTIFICATION_EXTENSION_INSTALLED events to |
| 826 // ensure installation does or does not occur in certain scenarios. | 831 // ensure installation does or does not occur in certain scenarios. |
| 827 class CheckExtensionInstalledObserver : public content::NotificationObserver { | 832 class CheckExtensionInstalledObserver : public content::NotificationObserver { |
| 828 public: | 833 public: |
| 829 CheckExtensionInstalledObserver() : seen_(false) { | 834 CheckExtensionInstalledObserver() : seen_(false) { |
| 830 registrar_.Add(this, | 835 registrar_.Add(this, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 | 877 |
| 873 app_loaded_observer.Wait(); | 878 app_loaded_observer.Wait(); |
| 874 ASSERT_TRUE(should_install.seen()); | 879 ASSERT_TRUE(should_install.seen()); |
| 875 | 880 |
| 876 ExtensionTestMessageListener launched_listener("Launched", false); | 881 ExtensionTestMessageListener launched_listener("Launched", false); |
| 877 application_launch::OpenApplication(application_launch::LaunchParams( | 882 application_launch::OpenApplication(application_launch::LaunchParams( |
| 878 browser()->profile(), extension, extension_misc::LAUNCH_NONE, | 883 browser()->profile(), extension, extension_misc::LAUNCH_NONE, |
| 879 NEW_WINDOW)); | 884 NEW_WINDOW)); |
| 880 | 885 |
| 881 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 886 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 887 |
| 888 CloseShellWindowsAndWaitForAppToExit(); |
| 882 } | 889 } |
| 883 | 890 |
| 884 // Component App Test 2 of 3: ensure an installed component app can be launched | 891 // Component App Test 2 of 3: ensure an installed component app can be launched |
| 885 // on a subsequent browser start, without requiring any install/upgrade logic | 892 // on a subsequent browser start, without requiring any install/upgrade logic |
| 886 // to be run, then perform setup for step 3. | 893 // to be run, then perform setup for step 3. |
| 887 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, | 894 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, |
| 888 PRE_ComponentAppBackgroundPage) { | 895 PRE_ComponentAppBackgroundPage) { |
| 889 | 896 |
| 890 // Since the component app is now installed, re-adding it in the same profile | 897 // Since the component app is now installed, re-adding it in the same profile |
| 891 // should not cause it to be re-installed. Instead, we wait for the OnLaunched | 898 // should not cause it to be re-installed. Instead, we wait for the OnLaunched |
| (...skipping 22 matching lines...) Expand all Loading... |
| 914 extension_prefs->SetRegisteredEvents(extension->id(), | 921 extension_prefs->SetRegisteredEvents(extension->id(), |
| 915 std::set<std::string>()); | 922 std::set<std::string>()); |
| 916 | 923 |
| 917 const base::StringValue old_version("1"); | 924 const base::StringValue old_version("1"); |
| 918 std::string pref_path("extensions.settings."); | 925 std::string pref_path("extensions.settings."); |
| 919 pref_path += extension->id(); | 926 pref_path += extension->id(); |
| 920 pref_path += ".manifest.version"; | 927 pref_path += ".manifest.version"; |
| 921 extension_prefs->pref_service()->RegisterStringPref( | 928 extension_prefs->pref_service()->RegisterStringPref( |
| 922 pref_path.c_str(), std::string(), PrefServiceBase::UNSYNCABLE_PREF); | 929 pref_path.c_str(), std::string(), PrefServiceBase::UNSYNCABLE_PREF); |
| 923 extension_prefs->pref_service()->Set(pref_path.c_str(), old_version); | 930 extension_prefs->pref_service()->Set(pref_path.c_str(), old_version); |
| 931 |
| 932 CloseShellWindowsAndWaitForAppToExit(); |
| 924 } | 933 } |
| 925 | 934 |
| 926 // Component App Test 3 of 3: simulate a component extension upgrade that | 935 // Component App Test 3 of 3: simulate a component extension upgrade that |
| 927 // re-adds the OnLaunched event, and allows the app to be launched. | 936 // re-adds the OnLaunched event, and allows the app to be launched. |
| 928 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ComponentAppBackgroundPage) { | 937 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ComponentAppBackgroundPage) { |
| 929 CheckExtensionInstalledObserver should_install; | 938 CheckExtensionInstalledObserver should_install; |
| 930 // Since we are forcing an upgrade, we need to wait for the load again. | 939 // Since we are forcing an upgrade, we need to wait for the load again. |
| 931 content::WindowedNotificationObserver app_loaded_observer( | 940 content::WindowedNotificationObserver app_loaded_observer( |
| 932 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 941 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 933 content::NotificationService::AllSources()); | 942 content::NotificationService::AllSources()); |
| 934 | 943 |
| 935 const Extension* extension = LoadExtensionAsComponent( | 944 const Extension* extension = LoadExtensionAsComponent( |
| 936 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component")); | 945 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component")); |
| 937 ASSERT_TRUE(extension); | 946 ASSERT_TRUE(extension); |
| 938 app_loaded_observer.Wait(); | 947 app_loaded_observer.Wait(); |
| 939 ASSERT_TRUE(should_install.seen()); | 948 ASSERT_TRUE(should_install.seen()); |
| 940 | 949 |
| 941 ExtensionTestMessageListener launched_listener("Launched", false); | 950 ExtensionTestMessageListener launched_listener("Launched", false); |
| 942 application_launch::OpenApplication(application_launch::LaunchParams( | 951 application_launch::OpenApplication(application_launch::LaunchParams( |
| 943 browser()->profile(), extension, extension_misc::LAUNCH_NONE, | 952 browser()->profile(), extension, extension_misc::LAUNCH_NONE, |
| 944 NEW_WINDOW)); | 953 NEW_WINDOW)); |
| 945 | 954 |
| 946 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 955 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 956 |
| 957 CloseShellWindowsAndWaitForAppToExit(); |
| 947 } | 958 } |
| 948 | 959 |
| 949 } // namespace extensions | 960 } // namespace extensions |
| OLD | NEW |