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