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/lifetime/application_lifetime.h" |
12 #include "chrome/browser/extensions/app_restore_service_factory.h" | 13 #include "chrome/browser/extensions/app_restore_service_factory.h" |
13 #include "chrome/browser/extensions/app_restore_service.h" | 14 #include "chrome/browser/extensions/app_restore_service.h" |
14 #include "chrome/browser/extensions/extension_browsertest.h" | 15 #include "chrome/browser/extensions/extension_browsertest.h" |
15 #include "chrome/browser/extensions/extension_prefs.h" | 16 #include "chrome/browser/extensions/extension_prefs.h" |
16 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
17 #include "chrome/browser/extensions/extension_system.h" | 18 #include "chrome/browser/extensions/extension_system.h" |
18 #include "chrome/browser/extensions/extension_test_message_listener.h" | 19 #include "chrome/browser/extensions/extension_test_message_listener.h" |
19 #include "chrome/browser/extensions/platform_app_browsertest_util.h" | 20 #include "chrome/browser/extensions/platform_app_browsertest_util.h" |
20 #include "chrome/browser/extensions/platform_app_launcher.h" | 21 #include "chrome/browser/extensions/platform_app_launcher.h" |
21 #include "chrome/browser/extensions/shell_window_registry.h" | 22 #include "chrome/browser/extensions/shell_window_registry.h" |
22 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 23 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
23 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
| 25 #include "chrome/browser/ui/browser_window.h" |
24 #include "chrome/browser/ui/browser_tabstrip.h" | 26 #include "chrome/browser/ui/browser_tabstrip.h" |
25 #include "chrome/browser/ui/extensions/application_launch.h" | 27 #include "chrome/browser/ui/extensions/application_launch.h" |
26 #include "chrome/browser/ui/extensions/shell_window.h" | 28 #include "chrome/browser/ui/extensions/shell_window.h" |
27 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 29 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
28 #include "chrome/common/chrome_notification_types.h" | 30 #include "chrome/common/chrome_notification_types.h" |
29 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
30 #include "chrome/test/base/ui_test_utils.h" | 32 #include "chrome/test/base/ui_test_utils.h" |
31 #include "content/public/browser/devtools_agent_host_registry.h" | 33 #include "content/public/browser/devtools_agent_host_registry.h" |
32 #include "content/public/browser/render_process_host.h" | 34 #include "content/public/browser/render_process_host.h" |
33 #include "content/public/browser/web_intents_dispatcher.h" | 35 #include "content/public/browser/web_intents_dispatcher.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 size_t observations_; | 138 size_t observations_; |
137 std::vector<content::WebContents*> observed_tabs_; | 139 std::vector<content::WebContents*> observed_tabs_; |
138 | 140 |
139 DISALLOW_COPY_AND_ASSIGN(TabsAddedNotificationObserver); | 141 DISALLOW_COPY_AND_ASSIGN(TabsAddedNotificationObserver); |
140 }; | 142 }; |
141 | 143 |
142 const char kTestFilePath[] = "platform_apps/launch_files/test.txt"; | 144 const char kTestFilePath[] = "platform_apps/launch_files/test.txt"; |
143 | 145 |
144 } // namespace | 146 } // namespace |
145 | 147 |
| 148 // TODO(benwells): Break up this file into some sensible smaller files. |
| 149 |
146 // Tests that CreateShellWindow doesn't crash if you close it straight away. | 150 // Tests that CreateShellWindow doesn't crash if you close it straight away. |
147 // LauncherPlatformAppBrowserTest relies on this behaviour, but is only run for | 151 // LauncherPlatformAppBrowserTest relies on this behaviour, but is only run for |
148 // ash, so we test that it works here. | 152 // ash, so we test that it works here. |
149 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, CreateAndCloseShellWindow) { | 153 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, CreateAndCloseShellWindow) { |
150 const Extension* extension = LoadAndLaunchPlatformApp("minimal"); | 154 const Extension* extension = LoadAndLaunchPlatformApp("minimal"); |
151 ShellWindow* window = CreateShellWindow(extension); | 155 ShellWindow* window = CreateShellWindow(extension); |
152 CloseShellWindow(window); | 156 CloseShellWindow(window); |
| 157 CloseShellWindowsAndWaitForAppToExit(); |
153 } | 158 } |
154 | 159 |
155 // Tests that platform apps can be launched in incognito mode without crashing. | 160 // Tests that platform apps can be launched in incognito mode without crashing. |
156 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchAppIncognito) { | 161 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchAppIncognito) { |
157 Browser* browser_incognito = ui_test_utils::OpenURLOffTheRecord( | 162 Browser* browser_incognito = ui_test_utils::OpenURLOffTheRecord( |
158 browser()->profile(), GURL("about:blank")); | 163 browser()->profile(), GURL("about:blank")); |
159 | 164 |
160 ExtensionTestMessageListener launched_listener("Launched", false); | 165 ExtensionTestMessageListener launched_listener("Launched", false); |
161 | 166 |
162 const Extension* extension = LoadExtensionIncognito( | 167 const Extension* extension = LoadExtensionIncognito( |
163 test_data_dir_.AppendASCII("platform_apps").AppendASCII("minimal")); | 168 test_data_dir_.AppendASCII("platform_apps").AppendASCII("minimal")); |
164 EXPECT_TRUE(extension); | 169 EXPECT_TRUE(extension); |
165 | 170 |
166 application_launch::OpenApplication(application_launch::LaunchParams( | 171 application_launch::OpenApplication(application_launch::LaunchParams( |
167 browser_incognito->profile(), extension, extension_misc::LAUNCH_NONE, | 172 browser_incognito->profile(), extension, extension_misc::LAUNCH_NONE, |
168 NEW_WINDOW)); | 173 NEW_WINDOW)); |
169 | 174 |
170 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 175 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 176 CloseShellWindowsAndWaitForAppToExit(); |
| 177 } |
| 178 |
| 179 // Tests that the browser process is kept alive by the platform app's background |
| 180 // page. |
| 181 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppEventPageKeepsBrowserAlive) { |
| 182 LoadAndLaunchPlatformApp("minimal"); |
| 183 browser()->window()->Close(); |
| 184 ASSERT_TRUE(browser::WillKeepAlive()); |
| 185 CloseShellWindowsAndWaitForAppToExit(); |
171 } | 186 } |
172 | 187 |
173 // Tests that platform apps received the "launch" event when launched. | 188 // Tests that platform apps received the "launch" event when launched. |
174 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) { | 189 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) { |
175 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_; | 190 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_; |
176 } | 191 } |
177 | 192 |
178 // Tests that platform apps can reply to "launch" events that contain a Web | 193 // Tests that platform apps can reply to "launch" events that contain a Web |
179 // Intent. This test does not test the mechanics of invoking a Web Intent | 194 // Intent. This test does not test the mechanics of invoking a Web Intent |
180 // from a source page, and short-circuits to LaunchPlatformAppWithWebIntent. | 195 // from a source page, and short-circuits to LaunchPlatformAppWithWebIntent. |
(...skipping 14 matching lines...) Expand all Loading... |
195 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 210 WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
196 ASSERT_TRUE(web_contents); | 211 ASSERT_TRUE(web_contents); |
197 | 212 |
198 extensions::LaunchPlatformAppWithWebIntent( | 213 extensions::LaunchPlatformAppWithWebIntent( |
199 browser()->profile(), | 214 browser()->profile(), |
200 extension, | 215 extension, |
201 handler.intents_dispatcher(), | 216 handler.intents_dispatcher(), |
202 web_contents); | 217 web_contents); |
203 | 218 |
204 ASSERT_TRUE(handler.WaitUntilReply()); | 219 ASSERT_TRUE(handler.WaitUntilReply()); |
| 220 CloseShellWindowsAndWaitForAppToExit(); |
205 } | 221 } |
206 | 222 |
207 // Tests that platform apps cannot use certain disabled window properties, but | 223 // Tests that platform apps cannot use certain disabled window properties, but |
208 // can override them and then use them. | 224 // can override them and then use them. |
209 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisabledWindowProperties) { | 225 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisabledWindowProperties) { |
210 ASSERT_TRUE(RunPlatformAppTest("platform_apps/disabled_window_properties")) | 226 ASSERT_TRUE(RunPlatformAppTest("platform_apps/disabled_window_properties")) |
211 << message_; | 227 << message_; |
212 } | 228 } |
213 | 229 |
214 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) { | 230 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) { |
215 ExtensionTestMessageListener launched_listener("Launched", false); | |
216 LoadAndLaunchPlatformApp("minimal"); | 231 LoadAndLaunchPlatformApp("minimal"); |
217 | 232 |
218 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
219 | |
220 // The empty app doesn't add any context menu items, so its menu should | 233 // The empty app doesn't add any context menu items, so its menu should |
221 // only include the developer tools. | 234 // only include the developer tools. |
222 WebContents* web_contents = GetFirstShellWindowWebContents(); | 235 WebContents* web_contents = GetFirstShellWindowWebContents(); |
223 ASSERT_TRUE(web_contents); | 236 ASSERT_TRUE(web_contents); |
224 WebKit::WebContextMenuData data; | 237 WebKit::WebContextMenuData data; |
225 content::ContextMenuParams params(data); | 238 content::ContextMenuParams params(data); |
226 scoped_ptr<PlatformAppContextMenu> menu; | 239 scoped_ptr<PlatformAppContextMenu> menu; |
227 menu.reset(new PlatformAppContextMenu(web_contents, params)); | 240 menu.reset(new PlatformAppContextMenu(web_contents, params)); |
228 menu->Init(); | 241 menu->Init(); |
229 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); | 242 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
230 ASSERT_TRUE( | 243 ASSERT_TRUE( |
231 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); | 244 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
232 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); | 245 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); |
233 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); | 246 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
234 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); | 247 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
| 248 CloseShellWindowsAndWaitForAppToExit(); |
235 } | 249 } |
236 | 250 |
237 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) { | 251 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) { |
238 ExtensionTestMessageListener launched_listener("Launched", false); | |
239 LoadAndLaunchPlatformApp("context_menu"); | 252 LoadAndLaunchPlatformApp("context_menu"); |
240 | 253 |
241 // Wait for the extension to tell us it's initialized its context menus and | |
242 // launched a window. | |
243 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
244 | |
245 // The context_menu app has two context menu items. These, along with a | 254 // The context_menu app has two context menu items. These, along with a |
246 // separator and the developer tools, is all that should be in the menu. | 255 // separator and the developer tools, is all that should be in the menu. |
247 WebContents* web_contents = GetFirstShellWindowWebContents(); | 256 WebContents* web_contents = GetFirstShellWindowWebContents(); |
248 ASSERT_TRUE(web_contents); | 257 ASSERT_TRUE(web_contents); |
249 WebKit::WebContextMenuData data; | 258 WebKit::WebContextMenuData data; |
250 content::ContextMenuParams params(data); | 259 content::ContextMenuParams params(data); |
251 scoped_ptr<PlatformAppContextMenu> menu; | 260 scoped_ptr<PlatformAppContextMenu> menu; |
252 menu.reset(new PlatformAppContextMenu(web_contents, params)); | 261 menu.reset(new PlatformAppContextMenu(web_contents, params)); |
253 menu->Init(); | 262 menu->Init(); |
254 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); | 263 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
255 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1)); | 264 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1)); |
256 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); | 265 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
257 ASSERT_TRUE( | 266 ASSERT_TRUE( |
258 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); | 267 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
259 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); | 268 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); |
260 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); | 269 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
261 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); | 270 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
262 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); | 271 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
| 272 CloseShellWindowsAndWaitForAppToExit(); |
263 } | 273 } |
264 | 274 |
265 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, InstalledAppWithContextMenu) { | 275 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, InstalledAppWithContextMenu) { |
266 ExtensionTestMessageListener launched_listener("Launched", false); | |
267 InstallAndLaunchPlatformApp("context_menu"); | 276 InstallAndLaunchPlatformApp("context_menu"); |
268 | 277 |
269 // Wait for the extension to tell us it's initialized its context menus and | |
270 // launched a window. | |
271 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
272 | |
273 // The context_menu app has two context menu items. For an installed app | 278 // The context_menu app has two context menu items. For an installed app |
274 // these are all that should be in the menu. | 279 // these are all that should be in the menu. |
275 WebContents* web_contents = GetFirstShellWindowWebContents(); | 280 WebContents* web_contents = GetFirstShellWindowWebContents(); |
276 ASSERT_TRUE(web_contents); | 281 ASSERT_TRUE(web_contents); |
277 WebKit::WebContextMenuData data; | 282 WebKit::WebContextMenuData data; |
278 content::ContextMenuParams params(data); | 283 content::ContextMenuParams params(data); |
279 scoped_ptr<PlatformAppContextMenu> menu; | 284 scoped_ptr<PlatformAppContextMenu> menu; |
280 menu.reset(new PlatformAppContextMenu(web_contents, params)); | 285 menu.reset(new PlatformAppContextMenu(web_contents, params)); |
281 menu->Init(); | 286 menu->Init(); |
282 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); | 287 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
283 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1)); | 288 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1)); |
284 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); | 289 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
285 ASSERT_FALSE( | 290 ASSERT_FALSE( |
286 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); | 291 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
287 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); | 292 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); |
288 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); | 293 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
289 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); | 294 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
290 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); | 295 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
| 296 CloseShellWindowsAndWaitForAppToExit(); |
291 } | 297 } |
292 | 298 |
293 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuTextField) { | 299 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuTextField) { |
294 ExtensionTestMessageListener launched_listener("Launched", false); | |
295 LoadAndLaunchPlatformApp("context_menu"); | 300 LoadAndLaunchPlatformApp("context_menu"); |
296 | 301 |
297 // Wait for the extension to tell us it's initialized its context menus and | |
298 // launched a window. | |
299 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
300 | |
301 // The context_menu app has one context menu item. This, along with a | 302 // The context_menu app has one context menu item. This, along with a |
302 // separator and the developer tools, is all that should be in the menu. | 303 // separator and the developer tools, is all that should be in the menu. |
303 WebContents* web_contents = GetFirstShellWindowWebContents(); | 304 WebContents* web_contents = GetFirstShellWindowWebContents(); |
304 ASSERT_TRUE(web_contents); | 305 ASSERT_TRUE(web_contents); |
305 WebKit::WebContextMenuData data; | 306 WebKit::WebContextMenuData data; |
306 content::ContextMenuParams params(data); | 307 content::ContextMenuParams params(data); |
307 params.is_editable = true; | 308 params.is_editable = true; |
308 scoped_ptr<PlatformAppContextMenu> menu; | 309 scoped_ptr<PlatformAppContextMenu> menu; |
309 menu.reset(new PlatformAppContextMenu(web_contents, params)); | 310 menu.reset(new PlatformAppContextMenu(web_contents, params)); |
310 menu->Init(); | 311 menu->Init(); |
311 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); | 312 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
312 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); | 313 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
313 ASSERT_TRUE( | 314 ASSERT_TRUE( |
314 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); | 315 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
315 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); | 316 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); |
316 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); | 317 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
317 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); | 318 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); |
318 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); | 319 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
319 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); | 320 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
| 321 CloseShellWindowsAndWaitForAppToExit(); |
320 } | 322 } |
321 | 323 |
322 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuSelection) { | 324 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuSelection) { |
323 ExtensionTestMessageListener launched_listener("Launched", false); | |
324 LoadAndLaunchPlatformApp("context_menu"); | 325 LoadAndLaunchPlatformApp("context_menu"); |
325 | 326 |
326 // Wait for the extension to tell us it's initialized its context menus and | |
327 // launched a window. | |
328 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
329 | |
330 // The context_menu app has one context menu item. This, along with a | 327 // The context_menu app has one context menu item. This, along with a |
331 // separator and the developer tools, is all that should be in the menu. | 328 // separator and the developer tools, is all that should be in the menu. |
332 WebContents* web_contents = GetFirstShellWindowWebContents(); | 329 WebContents* web_contents = GetFirstShellWindowWebContents(); |
333 ASSERT_TRUE(web_contents); | 330 ASSERT_TRUE(web_contents); |
334 WebKit::WebContextMenuData data; | 331 WebKit::WebContextMenuData data; |
335 content::ContextMenuParams params(data); | 332 content::ContextMenuParams params(data); |
336 params.selection_text = ASCIIToUTF16("Hello World"); | 333 params.selection_text = ASCIIToUTF16("Hello World"); |
337 scoped_ptr<PlatformAppContextMenu> menu; | 334 scoped_ptr<PlatformAppContextMenu> menu; |
338 menu.reset(new PlatformAppContextMenu(web_contents, params)); | 335 menu.reset(new PlatformAppContextMenu(web_contents, params)); |
339 menu->Init(); | 336 menu->Init(); |
340 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); | 337 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
341 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); | 338 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
342 ASSERT_TRUE( | 339 ASSERT_TRUE( |
343 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); | 340 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
344 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); | 341 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); |
345 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); | 342 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
346 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); | 343 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); |
347 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); | 344 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
348 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); | 345 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
| 346 CloseShellWindowsAndWaitForAppToExit(); |
349 } | 347 } |
350 | 348 |
351 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuClicked) { | 349 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuClicked) { |
352 ExtensionTestMessageListener launched_listener("Launched", false); | |
353 LoadAndLaunchPlatformApp("context_menu_click"); | 350 LoadAndLaunchPlatformApp("context_menu_click"); |
354 | 351 |
355 // Wait for the extension to tell us it's initialized its context menus and | |
356 // launched a window. | |
357 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
358 | |
359 // Test that the menu item shows up | 352 // Test that the menu item shows up |
360 WebContents* web_contents = GetFirstShellWindowWebContents(); | 353 WebContents* web_contents = GetFirstShellWindowWebContents(); |
361 ASSERT_TRUE(web_contents); | 354 ASSERT_TRUE(web_contents); |
362 WebKit::WebContextMenuData data; | 355 WebKit::WebContextMenuData data; |
363 content::ContextMenuParams params(data); | 356 content::ContextMenuParams params(data); |
364 params.page_url = GURL("http://foo.bar"); | 357 params.page_url = GURL("http://foo.bar"); |
365 scoped_ptr<PlatformAppContextMenu> menu; | 358 scoped_ptr<PlatformAppContextMenu> menu; |
366 menu.reset(new PlatformAppContextMenu(web_contents, params)); | 359 menu.reset(new PlatformAppContextMenu(web_contents, params)); |
367 menu->Init(); | 360 menu->Init(); |
368 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); | 361 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
369 | 362 |
370 // Execute the menu item | 363 // Execute the menu item |
371 ExtensionTestMessageListener onclicked_listener("onClicked fired for id1", | 364 ExtensionTestMessageListener onclicked_listener("onClicked fired for id1", |
372 false); | 365 false); |
373 menu->ExecuteCommand(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST); | 366 menu->ExecuteCommand(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST); |
374 | 367 |
375 ASSERT_TRUE(onclicked_listener.WaitUntilSatisfied()); | 368 ASSERT_TRUE(onclicked_listener.WaitUntilSatisfied()); |
| 369 CloseShellWindowsAndWaitForAppToExit(); |
376 } | 370 } |
377 | 371 |
378 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowNavigation) { | 372 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowNavigation) { |
379 TabsAddedNotificationObserver observer(2); | 373 TabsAddedNotificationObserver observer(2); |
380 | 374 |
381 ASSERT_TRUE(StartTestServer()); | 375 ASSERT_TRUE(StartTestServer()); |
382 ASSERT_TRUE(RunPlatformAppTest("platform_apps/navigation")) << message_; | 376 ASSERT_TRUE(RunPlatformAppTestReturnImmediately("platform_apps/navigation")) |
| 377 << message_; |
383 | 378 |
384 observer.Wait(); | 379 observer.Wait(); |
385 ASSERT_EQ(2U, observer.tabs().size()); | 380 ASSERT_EQ(2U, observer.tabs().size()); |
386 EXPECT_EQ(std::string(chrome::kExtensionInvalidRequestURL), | 381 EXPECT_EQ(std::string(chrome::kExtensionInvalidRequestURL), |
387 observer.tabs()[0]->GetURL().spec()); | 382 observer.tabs()[0]->GetURL().spec()); |
388 EXPECT_EQ("http://chromium.org/", | 383 EXPECT_EQ("http://chromium.org/", |
389 observer.tabs()[1]->GetURL().spec()); | 384 observer.tabs()[1]->GetURL().spec()); |
| 385 browser()->window()->Close(); |
| 386 CloseShellWindowsAndWaitForAppToExit(); |
390 } | 387 } |
391 | 388 |
392 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Iframes) { | 389 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Iframes) { |
393 ASSERT_TRUE(StartTestServer()); | 390 ASSERT_TRUE(StartTestServer()); |
394 ASSERT_TRUE(RunPlatformAppTest("platform_apps/iframes")) << message_; | 391 ASSERT_TRUE(RunPlatformAppTest("platform_apps/iframes")) << message_; |
395 } | 392 } |
396 | 393 |
397 // Tests that localStorage and WebSQL are disabled for platform apps. | 394 // Tests that localStorage and WebSQL are disabled for platform apps. |
398 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowStorage) { | 395 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowStorage) { |
399 ASSERT_TRUE(RunPlatformAppTest("platform_apps/storage")) << message_; | 396 ASSERT_TRUE(RunPlatformAppTest("platform_apps/storage")) << message_; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 // Initially there should be just the one browser window visible to the | 446 // Initially there should be just the one browser window visible to the |
450 // extensions API. | 447 // extensions API. |
451 const Extension* extension = LoadExtension( | 448 const Extension* extension = LoadExtension( |
452 test_data_dir_.AppendASCII("common/background_page")); | 449 test_data_dir_.AppendASCII("common/background_page")); |
453 ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension)); | 450 ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension)); |
454 | 451 |
455 // And no shell windows. | 452 // And no shell windows. |
456 ASSERT_EQ(0U, GetShellWindowCount()); | 453 ASSERT_EQ(0U, GetShellWindowCount()); |
457 | 454 |
458 // Launch a platform app that shows a window. | 455 // Launch a platform app that shows a window. |
459 ExtensionTestMessageListener launched_listener("Launched", false); | |
460 LoadAndLaunchPlatformApp("minimal"); | 456 LoadAndLaunchPlatformApp("minimal"); |
461 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
462 ASSERT_EQ(1U, GetShellWindowCount()); | 457 ASSERT_EQ(1U, GetShellWindowCount()); |
463 ShellWindowRegistry::ShellWindowSet shell_windows = | 458 ShellWindowRegistry::ShellWindowSet shell_windows = |
464 ShellWindowRegistry::Get(browser()->profile())->shell_windows(); | 459 ShellWindowRegistry::Get(browser()->profile())->shell_windows(); |
465 int shell_window_id = (*shell_windows.begin())->session_id().id(); | 460 int shell_window_id = (*shell_windows.begin())->session_id().id(); |
466 | 461 |
467 // But it's not visible to the extensions API, it still thinks there's just | 462 // But it's not visible to the extensions API, it still thinks there's just |
468 // one browser window. | 463 // one browser window. |
469 ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension)); | 464 ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension)); |
470 // It can't look it up by ID either | 465 // It can't look it up by ID either |
471 ASSERT_FALSE(RunGetWindowFunctionForExtension(shell_window_id, extension)); | 466 ASSERT_FALSE(RunGetWindowFunctionForExtension(shell_window_id, extension)); |
472 | 467 |
473 // The app can also only see one window (its own). | 468 // The app can also only see one window (its own). |
474 // TODO(jeremya): add an extension function to get a shell window by ID, and | 469 // TODO(jeremya): add an extension function to get a shell window by ID, and |
475 // to get a list of all the shell windows, so we can test this. | 470 // to get a list of all the shell windows, so we can test this. |
476 | 471 |
477 // Launch another platform app that also shows a window. | 472 // Launch another platform app that also shows a window. |
478 ExtensionTestMessageListener launched_listener2("Launched", false); | |
479 LoadAndLaunchPlatformApp("context_menu"); | 473 LoadAndLaunchPlatformApp("context_menu"); |
480 ASSERT_TRUE(launched_listener2.WaitUntilSatisfied()); | |
481 | 474 |
482 // There are two total shell windows, but each app can only see its own. | 475 // There are two total shell windows, but each app can only see its own. |
483 ASSERT_EQ(2U, GetShellWindowCount()); | 476 ASSERT_EQ(2U, GetShellWindowCount()); |
484 // TODO(jeremya): as above, this requires more extension functions. | 477 // TODO(jeremya): as above, this requires more extension functions. |
| 478 CloseShellWindowsAndWaitForAppToExit(); |
485 } | 479 } |
486 | 480 |
487 // ChromeOS does not support passing arguments on the command line, so the tests | 481 // ChromeOS does not support passing arguments on the command line, so the tests |
488 // that rely on this functionality are disabled. | 482 // that rely on this functionality are disabled. |
489 #if !defined(OS_CHROMEOS) | 483 #if !defined(OS_CHROMEOS) |
490 // Tests that command line parameters get passed through to platform apps | 484 // Tests that command line parameters get passed through to platform apps |
491 // via launchData correctly when launching with a file. | 485 // via launchData correctly when launching with a file. |
492 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithFile) { | 486 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithFile) { |
493 SetCommandLineArg(kTestFilePath); | 487 SetCommandLineArg(kTestFilePath); |
494 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_file")) | 488 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_file")) |
(...skipping 23 matching lines...) Expand all Loading... |
518 extension_misc::LAUNCH_NONE, | 512 extension_misc::LAUNCH_NONE, |
519 NEW_WINDOW); | 513 NEW_WINDOW); |
520 params.command_line = CommandLine::ForCurrentProcess(); | 514 params.command_line = CommandLine::ForCurrentProcess(); |
521 params.current_directory = test_data_dir_; | 515 params.current_directory = test_data_dir_; |
522 application_launch::OpenApplication(params); | 516 application_launch::OpenApplication(params); |
523 | 517 |
524 if (!catcher.GetNextResult()) { | 518 if (!catcher.GetNextResult()) { |
525 message_ = catcher.message(); | 519 message_ = catcher.message(); |
526 ASSERT_TRUE(0); | 520 ASSERT_TRUE(0); |
527 } | 521 } |
| 522 CloseShellWindowsAndWaitForAppToExit(); |
528 } | 523 } |
529 | 524 |
530 // Tests that no launch data is sent through if the platform app provides | 525 // Tests that no launch data is sent through if the platform app provides |
531 // an intent with the wrong action. | 526 // an intent with the wrong action. |
532 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithWrongIntent) { | 527 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithWrongIntent) { |
533 SetCommandLineArg(kTestFilePath); | 528 SetCommandLineArg(kTestFilePath); |
534 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_intent")) | 529 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_intent")) |
535 << message_; | 530 << message_; |
536 } | 531 } |
537 | 532 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 #endif // defined(OS_CHROMEOS) | 587 #endif // defined(OS_CHROMEOS) |
593 | 588 |
594 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OpenLink) { | 589 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OpenLink) { |
595 ASSERT_TRUE(StartTestServer()); | 590 ASSERT_TRUE(StartTestServer()); |
596 content::WindowedNotificationObserver observer( | 591 content::WindowedNotificationObserver observer( |
597 chrome::NOTIFICATION_TAB_ADDED, | 592 chrome::NOTIFICATION_TAB_ADDED, |
598 content::Source<content::WebContentsDelegate>(browser())); | 593 content::Source<content::WebContentsDelegate>(browser())); |
599 LoadAndLaunchPlatformApp("open_link"); | 594 LoadAndLaunchPlatformApp("open_link"); |
600 observer.Wait(); | 595 observer.Wait(); |
601 ASSERT_EQ(2, browser()->tab_count()); | 596 ASSERT_EQ(2, browser()->tab_count()); |
| 597 browser()->window()->Close(); |
| 598 CloseShellWindowsAndWaitForAppToExit(); |
602 } | 599 } |
603 | 600 |
604 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MutationEventsDisabled) { | 601 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MutationEventsDisabled) { |
605 ASSERT_TRUE(RunPlatformAppTest("platform_apps/mutation_events")) << message_; | 602 ASSERT_TRUE(RunPlatformAppTest("platform_apps/mutation_events")) << message_; |
606 } | 603 } |
607 | 604 |
608 // Test that windows created with an id will remember and restore their | 605 // Test that windows created with an id will remember and restore their |
609 // geometry when opening new windows. | 606 // geometry when opening new windows. |
610 // Flaky, see http://crbug.com/155459. | 607 // Flaky, see http://crbug.com/155459. |
611 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, | 608 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 // Wait for javascript to verify that the second window got the updated | 663 // Wait for javascript to verify that the second window got the updated |
667 // coordinates, ignoring the default coordinates passed to the create method. | 664 // coordinates, ignoring the default coordinates passed to the create method. |
668 ASSERT_TRUE(done2_listener.WaitUntilSatisfied()); | 665 ASSERT_TRUE(done2_listener.WaitUntilSatisfied()); |
669 | 666 |
670 // Tell javascript to open a third window. | 667 // Tell javascript to open a third window. |
671 page3_listener.Reply("continue"); | 668 page3_listener.Reply("continue"); |
672 | 669 |
673 // Wait for javascript to verify that the third window got the restored size | 670 // Wait for javascript to verify that the third window got the restored size |
674 // and explicitly specified coordinates. | 671 // and explicitly specified coordinates. |
675 ASSERT_TRUE(done3_listener.WaitUntilSatisfied()); | 672 ASSERT_TRUE(done3_listener.WaitUntilSatisfied()); |
| 673 CloseShellWindowsAndWaitForAppToExit(); |
676 } | 674 } |
677 | 675 |
678 // 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. |
679 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, RunningAppsAreRecorded) { | 677 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, RunningAppsAreRecorded) { |
680 content::WindowedNotificationObserver extension_suspended( | 678 content::WindowedNotificationObserver extension_suspended( |
681 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 679 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
682 content::NotificationService::AllSources()); | 680 content::NotificationService::AllSources()); |
683 | 681 |
684 const Extension* extension = LoadExtension( | 682 const Extension* extension = LoadExtension( |
685 test_data_dir_.AppendASCII("platform_apps/restart_test")); | 683 test_data_dir_.AppendASCII("platform_apps/restart_test")); |
(...skipping 11 matching lines...) Expand all Loading... |
697 // App isn't running because it got suspended. | 695 // App isn't running because it got suspended. |
698 ASSERT_FALSE(extension_prefs->IsExtensionRunning(extension->id())); | 696 ASSERT_FALSE(extension_prefs->IsExtensionRunning(extension->id())); |
699 | 697 |
700 // Pretend that the app is supposed to be running. | 698 // Pretend that the app is supposed to be running. |
701 extension_prefs->SetExtensionRunning(extension->id(), true); | 699 extension_prefs->SetExtensionRunning(extension->id(), true); |
702 | 700 |
703 ExtensionTestMessageListener restart_listener("onRestarted", false); | 701 ExtensionTestMessageListener restart_listener("onRestarted", false); |
704 AppRestoreServiceFactory::GetForProfile(browser()->profile())-> | 702 AppRestoreServiceFactory::GetForProfile(browser()->profile())-> |
705 HandleStartup(true); | 703 HandleStartup(true); |
706 restart_listener.WaitUntilSatisfied(); | 704 restart_listener.WaitUntilSatisfied(); |
| 705 CloseShellWindowsAndWaitForAppToExit(); |
707 } | 706 } |
708 | 707 |
709 // Tests that relaunching an app with devtools open reopens devtools. | 708 // Tests that relaunching an app with devtools open reopens devtools. |
710 #ifdef NDEBUG | 709 #ifdef NDEBUG |
711 #define MAYBE_DevToolsOpenedWithReload DevToolsOpenedWithReload | 710 #define MAYBE_DevToolsOpenedWithReload DevToolsOpenedWithReload |
712 #else | 711 #else |
713 // This is currently expected to fail in debug builds due to a segfault in | 712 // This is currently expected to fail in debug builds due to a segfault in |
714 // WebKit triggered by a dereference between #ifndef NDEBUG guards see | 713 // WebKit triggered by a dereference between #ifndef NDEBUG guards see |
715 // http://crbug.com/157097 . | 714 // http://crbug.com/157097 . |
716 // The test is disabled because of timeouts, see http://crbug.com/158283. | 715 // The test is disabled because of timeouts, see http://crbug.com/158283. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 browser()->profile(), extension, extension_misc::LAUNCH_NONE, | 750 browser()->profile(), extension, extension_misc::LAUNCH_NONE, |
752 NEW_WINDOW)); | 751 NEW_WINDOW)); |
753 app_loaded_observer.Wait(); | 752 app_loaded_observer.Wait(); |
754 window = GetFirstShellWindow(); | 753 window = GetFirstShellWindow(); |
755 ASSERT_TRUE(window); | 754 ASSERT_TRUE(window); |
756 | 755 |
757 // DevTools should have reopened with the relaunch. | 756 // DevTools should have reopened with the relaunch. |
758 rvh = window->web_contents()->GetRenderViewHost(); | 757 rvh = window->web_contents()->GetRenderViewHost(); |
759 ASSERT_TRUE(rvh); | 758 ASSERT_TRUE(rvh); |
760 ASSERT_TRUE(DevToolsAgentHostRegistry::HasDevToolsAgentHost(rvh)); | 759 ASSERT_TRUE(DevToolsAgentHostRegistry::HasDevToolsAgentHost(rvh)); |
| 760 CloseShellWindowsAndWaitForAppToExit(); |
761 } | 761 } |
762 | 762 |
763 } // namespace extensions | 763 } // namespace extensions |
OLD | NEW |