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