1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "apps/app_window.h"
6 #include "apps/app_window_registry.h"
7 #include "apps/common/api/app_runtime.h"
8 #include "apps/launcher.h"
9 #include "apps/ui/native_app_window.h"
10 #include "base/bind.h"
11 #include "base/command_line.h"
12 #include "base/file_util.h"
13 #include "base/files/scoped_temp_dir.h"
14 #include "base/prefs/pref_service.h"
15 #include "base/stl_util.h"
16 #include "base/strings/utf_string_conversions.h"
17 #include "chrome/app/chrome_command_ids.h"
18 #include "chrome/browser/apps/app_browsertest_util.h"
19 #include "chrome/browser/chrome_notification_types.h"
20 #include "chrome/browser/devtools/devtools_window.h"
21 #include "chrome/browser/extensions/api/permissions/permissions_api.h"
22 #include "chrome/browser/extensions/component_loader.h"
23 #include "chrome/browser/extensions/extension_browsertest.h"
24 #include "chrome/browser/extensions/extension_service.h"
25 #include "chrome/browser/extensions/extension_test_message_listener.h"
26 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
27 #include "chrome/browser/ui/browser.h"
28 #include "chrome/browser/ui/extensions/application_launch.h"
29 #include "chrome/browser/ui/tabs/tab_strip_model.h"
30 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
31 #include "chrome/common/chrome_switches.h"
32 #include "chrome/common/pref_names.h"
33 #include "chrome/common/url_constants.h"
34 #include "chrome/test/base/test_switches.h"
35 #include "chrome/test/base/ui_test_utils.h"
36 #include "components/user_prefs/pref_registry_syncable.h"
37 #include "components/web_modal/web_contents_modal_dialog_manager.h"
38 #include "content/public/browser/devtools_agent_host.h"
39 #include "content/public/browser/render_process_host.h"
40 #include "content/public/browser/render_widget_host_view.h"
41 #include "content/public/browser/web_contents_view.h"
42 #include "content/public/test/test_utils.h"
43 #include "extensions/browser/event_router.h"
44 #include "extensions/browser/extension_system.h"
45 #include "extensions/browser/pref_names.h"
46 #include "net/test/embedded_test_server/embedded_test_server.h"
49 #if defined(OS_CHROMEOS)
50 #include "base/memory/scoped_ptr.h"
51 #include "chrome/browser/chromeos/login/mock_user_manager.h"
52 #include "chrome/browser/chromeos/login/user_manager.h"
53 #include "chromeos/dbus/dbus_thread_manager.h"
54 #include "chromeos/dbus/fake_dbus_thread_manager.h"
55 #include "chromeos/dbus/fake_power_manager_client.h"
58 using apps::AppWindow
;
59 using apps::AppWindowRegistry
;
60 using content::WebContents
;
61 using web_modal::WebContentsModalDialogManager
;
63 namespace app_runtime
= apps::api::app_runtime
;
65 namespace extensions
{
69 // Non-abstract RenderViewContextMenu class.
70 class PlatformAppContextMenu
: public RenderViewContextMenu
{
72 PlatformAppContextMenu(content::RenderFrameHost
* render_frame_host
,
73 const content::ContextMenuParams
& params
)
74 : RenderViewContextMenu(render_frame_host
, params
) {}
76 bool HasCommandWithId(int command_id
) {
77 return menu_model_
.GetIndexOfCommandId(command_id
) != -1;
81 // RenderViewContextMenu implementation.
82 virtual bool GetAcceleratorForCommandId(
84 ui::Accelerator
* accelerator
) OVERRIDE
{
87 virtual void PlatformInit() OVERRIDE
{}
88 virtual void PlatformCancel() OVERRIDE
{}
91 // This class keeps track of tabs as they are added to the browser. It will be
92 // "done" (i.e. won't block on Wait()) once |observations| tabs have been added.
93 class TabsAddedNotificationObserver
94 : public content::WindowedNotificationObserver
{
96 explicit TabsAddedNotificationObserver(size_t observations
)
97 : content::WindowedNotificationObserver(
98 chrome::NOTIFICATION_TAB_ADDED
,
99 content::NotificationService::AllSources()),
100 observations_(observations
) {
103 virtual void Observe(int type
,
104 const content::NotificationSource
& source
,
105 const content::NotificationDetails
& details
) OVERRIDE
{
106 observed_tabs_
.push_back(
107 content::Details
<WebContents
>(details
).ptr());
108 if (observed_tabs_
.size() == observations_
)
109 content::WindowedNotificationObserver::Observe(type
, source
, details
);
112 const std::vector
<content::WebContents
*>& tabs() { return observed_tabs_
; }
115 size_t observations_
;
116 std::vector
<content::WebContents
*> observed_tabs_
;
118 DISALLOW_COPY_AND_ASSIGN(TabsAddedNotificationObserver
);
121 class ScopedPreviewTestingDelegate
: PrintPreviewUI::TestingDelegate
{
123 explicit ScopedPreviewTestingDelegate(bool auto_cancel
)
124 : auto_cancel_(auto_cancel
),
125 total_page_count_(1),
126 rendered_page_count_(0) {
127 PrintPreviewUI::SetDelegateForTesting(this);
130 ~ScopedPreviewTestingDelegate() {
131 PrintPreviewUI::SetDelegateForTesting(NULL
);
134 // PrintPreviewUI::TestingDelegate implementation.
135 virtual bool IsAutoCancelEnabled() OVERRIDE
{
139 // PrintPreviewUI::TestingDelegate implementation.
140 virtual void DidGetPreviewPageCount(int page_count
) OVERRIDE
{
141 total_page_count_
= page_count
;
144 // PrintPreviewUI::TestingDelegate implementation.
145 virtual void DidRenderPreviewPage(const content::WebContents
& preview_dialog
)
147 dialog_size_
= preview_dialog
.GetView()->GetContainerSize();
148 ++rendered_page_count_
;
149 CHECK(rendered_page_count_
<= total_page_count_
);
150 if (waiting_runner_
&& rendered_page_count_
== total_page_count_
) {
151 waiting_runner_
->Quit();
155 void WaitUntilPreviewIsReady() {
156 CHECK(!waiting_runner_
);
157 if (rendered_page_count_
< total_page_count_
) {
158 waiting_runner_
= new content::MessageLoopRunner
;
159 waiting_runner_
->Run();
160 waiting_runner_
= NULL
;
164 gfx::Size
dialog_size() {
170 int total_page_count_
;
171 int rendered_page_count_
;
172 scoped_refptr
<content::MessageLoopRunner
> waiting_runner_
;
173 gfx::Size dialog_size_
;
176 #if !defined(OS_CHROMEOS) && !defined(OS_WIN)
177 bool CopyTestDataAndSetCommandLineArg(
178 const base::FilePath
& test_data_file
,
179 const base::FilePath
& temp_dir
,
180 const char* filename
) {
181 base::FilePath path
= temp_dir
.AppendASCII(
182 filename
).NormalizePathSeparators();
183 if (!(base::CopyFile(test_data_file
, path
)))
186 CommandLine
* command_line
= CommandLine::ForCurrentProcess();
187 command_line
->AppendArgPath(path
);
190 #endif // !defined(OS_CHROMEOS) && !defined(OS_WIN)
192 #if !defined(OS_CHROMEOS)
193 const char kTestFilePath
[] = "platform_apps/launch_files/test.txt";
198 // Tests that CreateAppWindow doesn't crash if you close it straight away.
199 // LauncherPlatformAppBrowserTest relies on this behaviour, but is only run for
200 // ash, so we test that it works here.
201 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, CreateAndCloseAppWindow
) {
202 const Extension
* extension
= LoadAndLaunchPlatformApp("minimal");
203 AppWindow
* window
= CreateAppWindow(extension
);
204 CloseAppWindow(window
);
207 // Tests that platform apps received the "launch" event when launched.
208 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, OnLaunchedEvent
) {
209 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_
;
212 // Tests that platform apps cannot use certain disabled window properties, but
213 // can override them and then use them.
214 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, DisabledWindowProperties
) {
215 ASSERT_TRUE(RunPlatformAppTest("platform_apps/disabled_window_properties"))
219 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, EmptyContextMenu
) {
220 ExtensionTestMessageListener
launched_listener("Launched", false);
221 LoadAndLaunchPlatformApp("minimal");
223 ASSERT_TRUE(launched_listener
.WaitUntilSatisfied());
225 // The empty app doesn't add any context menu items, so its menu should
226 // only include the developer tools.
227 WebContents
* web_contents
= GetFirstAppWindowWebContents();
228 ASSERT_TRUE(web_contents
);
229 content::ContextMenuParams params
;
230 scoped_ptr
<PlatformAppContextMenu
> menu
;
231 menu
.reset(new PlatformAppContextMenu(web_contents
->GetMainFrame(), params
));
233 ASSERT_TRUE(menu
->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT
));
235 menu
->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE
));
236 ASSERT_TRUE(menu
->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP
));
237 ASSERT_FALSE(menu
->HasCommandWithId(IDC_BACK
));
238 ASSERT_FALSE(menu
->HasCommandWithId(IDC_SAVE_PAGE
));
241 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, AppWithContextMenu
) {
242 ExtensionTestMessageListener
launched_listener("Launched", false);
243 LoadAndLaunchPlatformApp("context_menu");
245 // Wait for the extension to tell us it's initialized its context menus and
246 // launched a window.
247 ASSERT_TRUE(launched_listener
.WaitUntilSatisfied());
249 // The context_menu app has two context menu items. These, along with a
250 // separator and the developer tools, is all that should be in the menu.
251 WebContents
* web_contents
= GetFirstAppWindowWebContents();
252 ASSERT_TRUE(web_contents
);
253 content::ContextMenuParams params
;
254 scoped_ptr
<PlatformAppContextMenu
> menu
;
255 menu
.reset(new PlatformAppContextMenu(web_contents
->GetMainFrame(), params
));
257 ASSERT_TRUE(menu
->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST
));
258 ASSERT_TRUE(menu
->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST
+ 1));
259 ASSERT_TRUE(menu
->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT
));
261 menu
->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE
));
262 ASSERT_TRUE(menu
->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP
));
263 ASSERT_FALSE(menu
->HasCommandWithId(IDC_BACK
));
264 ASSERT_FALSE(menu
->HasCommandWithId(IDC_SAVE_PAGE
));
265 ASSERT_FALSE(menu
->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO
));
268 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, InstalledAppWithContextMenu
) {
269 ExtensionTestMessageListener
launched_listener("Launched", false);
270 InstallAndLaunchPlatformApp("context_menu");
272 // Wait for the extension to tell us it's initialized its context menus and
273 // launched a window.
274 ASSERT_TRUE(launched_listener
.WaitUntilSatisfied());
276 // The context_menu app has two context menu items. For an installed app
277 // these are all that should be in the menu.
278 WebContents
* web_contents
= GetFirstAppWindowWebContents();
279 ASSERT_TRUE(web_contents
);
280 content::ContextMenuParams params
;
281 scoped_ptr
<PlatformAppContextMenu
> menu
;
282 menu
.reset(new PlatformAppContextMenu(web_contents
->GetMainFrame(), params
));
284 ASSERT_TRUE(menu
->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST
));
285 ASSERT_TRUE(menu
->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST
+ 1));
286 ASSERT_FALSE(menu
->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT
));
288 menu
->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE
));
289 ASSERT_FALSE(menu
->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP
));
290 ASSERT_FALSE(menu
->HasCommandWithId(IDC_BACK
));
291 ASSERT_FALSE(menu
->HasCommandWithId(IDC_SAVE_PAGE
));
292 ASSERT_FALSE(menu
->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO
));
295 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, AppWithContextMenuTextField
) {
296 ExtensionTestMessageListener
launched_listener("Launched", false);
297 LoadAndLaunchPlatformApp("context_menu");
299 // Wait for the extension to tell us it's initialized its context menus and
300 // launched a window.
301 ASSERT_TRUE(launched_listener
.WaitUntilSatisfied());
303 // The context_menu app has one context menu item. This, along with a
304 // separator and the developer tools, is all that should be in the menu.
305 WebContents
* web_contents
= GetFirstAppWindowWebContents();
306 ASSERT_TRUE(web_contents
);
307 content::ContextMenuParams params
;
308 params
.is_editable
= true;
309 scoped_ptr
<PlatformAppContextMenu
> menu
;
310 menu
.reset(new PlatformAppContextMenu(web_contents
->GetMainFrame(), params
));
312 ASSERT_TRUE(menu
->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST
));
313 ASSERT_TRUE(menu
->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT
));
315 menu
->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE
));
316 ASSERT_TRUE(menu
->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP
));
317 ASSERT_TRUE(menu
->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO
));
318 ASSERT_TRUE(menu
->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY
));
319 ASSERT_FALSE(menu
->HasCommandWithId(IDC_BACK
));
320 ASSERT_FALSE(menu
->HasCommandWithId(IDC_SAVE_PAGE
));
323 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, AppWithContextMenuSelection
) {
324 ExtensionTestMessageListener
launched_listener("Launched", false);
325 LoadAndLaunchPlatformApp("context_menu");
327 // Wait for the extension to tell us it's initialized its context menus and
328 // launched a window.
329 ASSERT_TRUE(launched_listener
.WaitUntilSatisfied());
331 // The context_menu app has one context menu item. This, along with a
332 // separator and the developer tools, is all that should be in the menu.
333 WebContents
* web_contents
= GetFirstAppWindowWebContents();
334 ASSERT_TRUE(web_contents
);
335 content::ContextMenuParams params
;
336 params
.selection_text
= base::ASCIIToUTF16("Hello World");
337 scoped_ptr
<PlatformAppContextMenu
> menu
;
338 menu
.reset(new PlatformAppContextMenu(web_contents
->GetMainFrame(), params
));
340 ASSERT_TRUE(menu
->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST
));
341 ASSERT_TRUE(menu
->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT
));
343 menu
->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE
));
344 ASSERT_TRUE(menu
->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP
));
345 ASSERT_FALSE(menu
->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO
));
346 ASSERT_TRUE(menu
->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY
));
347 ASSERT_FALSE(menu
->HasCommandWithId(IDC_BACK
));
348 ASSERT_FALSE(menu
->HasCommandWithId(IDC_SAVE_PAGE
));
351 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, AppWithContextMenuClicked
) {
352 ExtensionTestMessageListener
launched_listener("Launched", false);
353 LoadAndLaunchPlatformApp("context_menu_click");
355 // Wait for the extension to tell us it's initialized its context menus and
356 // launched a window.
357 ASSERT_TRUE(launched_listener
.WaitUntilSatisfied());
359 // Test that the menu item shows up
360 WebContents
* web_contents
= GetFirstAppWindowWebContents();
361 ASSERT_TRUE(web_contents
);
362 content::ContextMenuParams params
;
363 params
.page_url
= GURL("http://foo.bar");
364 scoped_ptr
<PlatformAppContextMenu
> menu
;
365 menu
.reset(new PlatformAppContextMenu(web_contents
->GetMainFrame(), params
));
367 ASSERT_TRUE(menu
->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST
));
369 // Execute the menu item
370 ExtensionTestMessageListener
onclicked_listener("onClicked fired for id1",
372 menu
->ExecuteCommand(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST
, 0);
374 ASSERT_TRUE(onclicked_listener
.WaitUntilSatisfied());
377 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
378 // TODO(erg): linux_aura bringup: http://crbug.com/163931
379 #define MAYBE_DisallowNavigation DISABLED_DisallowNavigation
381 #define MAYBE_DisallowNavigation DisallowNavigation
384 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, MAYBE_DisallowNavigation
) {
385 TabsAddedNotificationObserver
observer(2);
387 ASSERT_TRUE(StartEmbeddedTestServer());
388 ASSERT_TRUE(RunPlatformAppTest("platform_apps/navigation")) << message_
;
391 ASSERT_EQ(2U, observer
.tabs().size());
392 EXPECT_EQ(std::string(chrome::kExtensionInvalidRequestURL
),
393 observer
.tabs()[0]->GetURL().spec());
394 EXPECT_EQ("http://chromium.org/",
395 observer
.tabs()[1]->GetURL().spec());
398 // Failing on some Win and Linux buildbots. See crbug.com/354425.
399 #if (defined(OS_WIN) || defined(OS_LINUX)) && defined(ARCH_CPU_X86)
400 #define MAYBE_Iframes DISABLED_Iframes
402 #define MAYBE_Iframes Iframes
404 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, MAYBE_Iframes
) {
405 ASSERT_TRUE(StartEmbeddedTestServer());
406 ASSERT_TRUE(RunPlatformAppTest("platform_apps/iframes")) << message_
;
409 // Tests that localStorage and WebSQL are disabled for platform apps.
410 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, DisallowStorage
) {
411 ASSERT_TRUE(RunPlatformAppTest("platform_apps/storage")) << message_
;
414 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, Restrictions
) {
415 ASSERT_TRUE(RunPlatformAppTest("platform_apps/restrictions")) << message_
;
418 // Tests that extensions can't use platform-app-only APIs.
419 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, PlatformAppsOnly
) {
420 ASSERT_TRUE(RunExtensionTestIgnoreManifestWarnings(
421 "platform_apps/apps_only")) << message_
;
424 // Tests that platform apps have isolated storage by default.
425 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, Isolation
) {
426 ASSERT_TRUE(StartEmbeddedTestServer());
428 // Load a (non-app) page under the "localhost" origin that sets a cookie.
429 GURL set_cookie_url
= embedded_test_server()->GetURL(
430 "/extensions/platform_apps/isolation/set_cookie.html");
431 GURL::Replacements replace_host
;
432 std::string
host_str("localhost"); // Must stay in scope with replace_host.
433 replace_host
.SetHostStr(host_str
);
434 set_cookie_url
= set_cookie_url
.ReplaceComponents(replace_host
);
436 ui_test_utils::NavigateToURLWithDisposition(
437 browser(), set_cookie_url
,
438 CURRENT_TAB
, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION
);
440 // Make sure the cookie is set.
442 std::string cookie_value
;
443 ui_test_utils::GetCookies(
445 browser()->tab_strip_model()->GetWebContentsAt(0),
448 ASSERT_EQ("testCookie=1", cookie_value
);
450 // Let the platform app request the same URL, and make sure that it doesn't
452 ASSERT_TRUE(RunPlatformAppTest("platform_apps/isolation")) << message_
;
455 // See crbug.com/248441
457 #define MAYBE_ExtensionWindowingApis DISABLED_ExtensionWindowingApis
459 #define MAYBE_ExtensionWindowingApis ExtensionWindowingApis
462 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, MAYBE_ExtensionWindowingApis
) {
463 // Initially there should be just the one browser window visible to the
465 const Extension
* extension
= LoadExtension(
466 test_data_dir_
.AppendASCII("common/background_page"));
467 ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension
));
469 // And no app windows.
470 ASSERT_EQ(0U, GetAppWindowCount());
472 // Launch a platform app that shows a window.
473 ExtensionTestMessageListener
launched_listener("Launched", false);
474 LoadAndLaunchPlatformApp("minimal");
475 ASSERT_TRUE(launched_listener
.WaitUntilSatisfied());
476 ASSERT_EQ(1U, GetAppWindowCount());
477 int app_window_id
= GetFirstAppWindow()->session_id().id();
479 // But it's not visible to the extensions API, it still thinks there's just
480 // one browser window.
481 ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension
));
482 // It can't look it up by ID either
483 ASSERT_FALSE(RunGetWindowFunctionForExtension(app_window_id
, extension
));
485 // The app can also only see one window (its own).
486 // TODO(jeremya): add an extension function to get an app window by ID, and
487 // to get a list of all the app windows, so we can test this.
489 // Launch another platform app that also shows a window.
490 ExtensionTestMessageListener
launched_listener2("Launched", false);
491 LoadAndLaunchPlatformApp("context_menu");
492 ASSERT_TRUE(launched_listener2
.WaitUntilSatisfied());
494 // There are two total app windows, but each app can only see its own.
495 ASSERT_EQ(2U, GetAppWindowCount());
496 // TODO(jeremya): as above, this requires more extension functions.
499 // ChromeOS does not support passing arguments on the command line, so the tests
500 // that rely on this functionality are disabled.
501 #if !defined(OS_CHROMEOS)
502 // Tests that command line parameters get passed through to platform apps
503 // via launchData correctly when launching with a file.
504 // TODO(benwells/jeremya): tests need a way to specify a handler ID.
505 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, LaunchWithFile
) {
506 SetCommandLineArg(kTestFilePath
);
507 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_file"))
511 // Tests that relative paths can be passed through to the platform app.
512 // This test doesn't use the normal test infrastructure as it needs to open
513 // the application differently to all other platform app tests, by setting
514 // the AppLaunchParams.current_directory field.
515 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, LaunchWithRelativeFile
) {
516 // Setup the command line
517 ClearCommandLineArgs();
518 CommandLine
* command_line
= CommandLine::ForCurrentProcess();
519 base::FilePath relative_test_doc
=
520 base::FilePath::FromUTF8Unsafe(kTestFilePath
);
521 relative_test_doc
= relative_test_doc
.NormalizePathSeparators();
522 command_line
->AppendArgPath(relative_test_doc
);
524 // Load the extension
525 ResultCatcher catcher
;
526 const Extension
* extension
= LoadExtension(
527 test_data_dir_
.AppendASCII("platform_apps/launch_file"));
528 ASSERT_TRUE(extension
);
531 AppLaunchParams
params(
532 browser()->profile(), extension
, LAUNCH_CONTAINER_NONE
, NEW_WINDOW
);
533 params
.command_line
= *CommandLine::ForCurrentProcess();
534 params
.current_directory
= test_data_dir_
;
535 OpenApplication(params
);
537 if (!catcher
.GetNextResult()) {
538 message_
= catcher
.message();
543 // Tests that launch data is sent through if the file extension matches.
544 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, LaunchWithFileExtension
) {
545 SetCommandLineArg(kTestFilePath
);
546 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_file_by_extension"))
550 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
551 // TODO(erg): linux_aura bringup: http://crbug.com/163931
552 #define MAYBE_LaunchWithFileExtensionAndMimeType DISABLED_LaunchWithFileExtensionAndMimeType
554 #define MAYBE_LaunchWithFileExtensionAndMimeType LaunchWithFileExtensionAndMimeType
557 // Tests that launch data is sent through if the file extension and MIME type
559 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
,
560 MAYBE_LaunchWithFileExtensionAndMimeType
) {
561 SetCommandLineArg(kTestFilePath
);
562 ASSERT_TRUE(RunPlatformAppTest(
563 "platform_apps/launch_file_by_extension_and_type")) << message_
;
566 // Tests that launch data is sent through for a file with no extension if a
567 // handler accepts "".
568 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, LaunchWithFileWithoutExtension
) {
569 SetCommandLineArg("platform_apps/launch_files/test");
570 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_file_with_no_extension"))
575 // Tests that launch data is sent through for a file with an empty extension if
576 // a handler accepts "".
577 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, LaunchWithFileEmptyExtension
) {
578 base::ScopedTempDir temp_dir
;
579 ASSERT_TRUE(temp_dir
.CreateUniqueTempDir());
580 ClearCommandLineArgs();
581 ASSERT_TRUE(CopyTestDataAndSetCommandLineArg(
582 test_data_dir_
.AppendASCII(kTestFilePath
),
585 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_file_with_no_extension"))
589 // Tests that launch data is sent through for a file with an empty extension if
590 // a handler accepts *.
591 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
,
592 LaunchWithFileEmptyExtensionAcceptAny
) {
593 base::ScopedTempDir temp_dir
;
594 ASSERT_TRUE(temp_dir
.CreateUniqueTempDir());
595 ClearCommandLineArgs();
596 ASSERT_TRUE(CopyTestDataAndSetCommandLineArg(
597 test_data_dir_
.AppendASCII(kTestFilePath
),
600 ASSERT_TRUE(RunPlatformAppTest(
601 "platform_apps/launch_file_with_any_extension")) << message_
;
605 // Tests that launch data is sent through for a file with no extension if a
606 // handler accepts *.
607 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
,
608 LaunchWithFileWithoutExtensionAcceptAny
) {
609 SetCommandLineArg("platform_apps/launch_files/test");
610 ASSERT_TRUE(RunPlatformAppTest(
611 "platform_apps/launch_file_with_any_extension")) << message_
;
614 // Tests that launch data is sent through for a file with an extension if a
615 // handler accepts *.
616 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
,
617 LaunchWithFileAcceptAnyExtension
) {
618 SetCommandLineArg(kTestFilePath
);
619 ASSERT_TRUE(RunPlatformAppTest(
620 "platform_apps/launch_file_with_any_extension")) << message_
;
623 // Tests that no launch data is sent through if the file has the wrong
625 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, LaunchWithWrongExtension
) {
626 SetCommandLineArg(kTestFilePath
);
627 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_extension"))
631 // Tests that no launch data is sent through if the file has no extension but
632 // the handler requires a specific extension.
633 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, LaunchWithWrongEmptyExtension
) {
634 SetCommandLineArg("platform_apps/launch_files/test");
635 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_extension"))
639 // Tests that no launch data is sent through if the file is of the wrong MIME
641 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, LaunchWithWrongType
) {
642 SetCommandLineArg(kTestFilePath
);
643 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_type"))
647 // Tests that no launch data is sent through if the platform app does not
648 // provide an intent.
649 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, LaunchWithNoIntent
) {
650 SetCommandLineArg(kTestFilePath
);
651 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_no_intent"))
655 // Tests that launch data is sent through when the file has unknown extension
656 // but the MIME type can be sniffed and the sniffed type matches.
657 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, LaunchWithSniffableType
) {
658 SetCommandLineArg("platform_apps/launch_files/test.unknownextension");
659 ASSERT_TRUE(RunPlatformAppTest(
660 "platform_apps/launch_file_by_extension_and_type")) << message_
;
663 // Tests that launch data is sent through with the MIME type set to
664 // application/octet-stream if the file MIME type cannot be read.
665 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, LaunchNoType
) {
666 SetCommandLineArg("platform_apps/launch_files/test_binary.unknownextension");
667 ASSERT_TRUE(RunPlatformAppTest(
668 "platform_apps/launch_application_octet_stream")) << message_
;
671 // Tests that no launch data is sent through if the file does not exist.
672 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, LaunchNoFile
) {
673 SetCommandLineArg("platform_apps/launch_files/doesnotexist.txt");
674 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid"))
678 // Tests that no launch data is sent through if the argument is a directory.
679 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, LaunchWithDirectory
) {
680 SetCommandLineArg("platform_apps/launch_files");
681 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid"))
685 // Tests that no launch data is sent through if there are no arguments passed
686 // on the command line
687 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, LaunchWithNothing
) {
688 ClearCommandLineArgs();
689 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_nothing"))
693 // Test that platform apps can use the chrome.fileSystem.getDisplayPath
694 // function to get the native file system path of a file they are launched with.
695 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, GetDisplayPath
) {
696 SetCommandLineArg(kTestFilePath
);
697 ASSERT_TRUE(RunPlatformAppTest("platform_apps/get_display_path"))
701 // Tests that the file is created if the file does not exist and the app has the
702 // fileSystem.write permission.
703 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, LaunchNewFile
) {
704 base::ScopedTempDir temp_dir
;
705 ASSERT_TRUE(temp_dir
.CreateUniqueTempDir());
706 ClearCommandLineArgs();
707 CommandLine
* command_line
= CommandLine::ForCurrentProcess();
708 command_line
->AppendArgPath(temp_dir
.path().AppendASCII("new_file.txt"));
709 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_new_file")) << message_
;
712 #endif // !defined(OS_CHROMEOS)
714 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, OpenLink
) {
715 ASSERT_TRUE(StartEmbeddedTestServer());
716 content::WindowedNotificationObserver
observer(
717 chrome::NOTIFICATION_TAB_ADDED
,
718 content::Source
<content::WebContentsDelegate
>(browser()));
719 LoadAndLaunchPlatformApp("open_link");
721 ASSERT_EQ(2, browser()->tab_strip_model()->count());
724 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, MutationEventsDisabled
) {
725 ASSERT_TRUE(RunPlatformAppTest("platform_apps/mutation_events")) << message_
;
728 // This appears to be unreliable on linux.
729 // TODO(stevenjb): Investigate and enable
730 #if defined(OS_LINUX) && !defined(USE_ASH)
731 #define MAYBE_AppWindowRestoreState DISABLED_AppWindowRestoreState
733 #define MAYBE_AppWindowRestoreState AppWindowRestoreState
735 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, MAYBE_AppWindowRestoreState
) {
736 ASSERT_TRUE(RunPlatformAppTest("platform_apps/restore_state"));
739 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
,
740 AppWindowAdjustBoundsToBeVisibleOnScreen
) {
741 const Extension
* extension
= LoadAndLaunchPlatformApp("minimal");
742 AppWindow
* window
= CreateAppWindow(extension
);
744 // The screen bounds didn't change, the cached bounds didn't need to adjust.
745 gfx::Rect
cached_bounds(80, 100, 400, 400);
746 gfx::Rect
cached_screen_bounds(0, 0, 1600, 900);
747 gfx::Rect
current_screen_bounds(0, 0, 1600, 900);
748 gfx::Size
minimum_size(200, 200);
750 CallAdjustBoundsToBeVisibleOnScreenForAppWindow(window
,
752 cached_screen_bounds
,
753 current_screen_bounds
,
756 EXPECT_EQ(bounds
, cached_bounds
);
758 // We have an empty screen bounds, the cached bounds didn't need to adjust.
759 gfx::Rect empty_screen_bounds
;
760 CallAdjustBoundsToBeVisibleOnScreenForAppWindow(window
,
763 current_screen_bounds
,
766 EXPECT_EQ(bounds
, cached_bounds
);
768 // Cached bounds is completely off the new screen bounds in horizontal
769 // locations. Expect to reposition the bounds.
770 gfx::Rect
horizontal_out_of_screen_bounds(-800, 100, 400, 400);
771 CallAdjustBoundsToBeVisibleOnScreenForAppWindow(
773 horizontal_out_of_screen_bounds
,
774 gfx::Rect(-1366, 0, 1600, 900),
775 current_screen_bounds
,
778 EXPECT_EQ(bounds
, gfx::Rect(0, 100, 400, 400));
780 // Cached bounds is completely off the new screen bounds in vertical
781 // locations. Expect to reposition the bounds.
782 gfx::Rect
vertical_out_of_screen_bounds(10, 1000, 400, 400);
783 CallAdjustBoundsToBeVisibleOnScreenForAppWindow(
785 vertical_out_of_screen_bounds
,
786 gfx::Rect(-1366, 0, 1600, 900),
787 current_screen_bounds
,
790 EXPECT_EQ(bounds
, gfx::Rect(10, 500, 400, 400));
792 // From a large screen resulotion to a small one. Expect it fit on screen.
793 gfx::Rect
big_cache_bounds(10, 10, 1000, 1000);
794 CallAdjustBoundsToBeVisibleOnScreenForAppWindow(window
,
796 gfx::Rect(0, 0, 1600, 1000),
797 gfx::Rect(0, 0, 800, 600),
800 EXPECT_EQ(bounds
, gfx::Rect(0, 0, 800, 600));
802 // Don't resize the bounds smaller than minimum size, when the minimum size is
803 // larger than the screen.
804 CallAdjustBoundsToBeVisibleOnScreenForAppWindow(window
,
806 gfx::Rect(0, 0, 1600, 1000),
807 gfx::Rect(0, 0, 800, 600),
810 EXPECT_EQ(bounds
, gfx::Rect(0, 0, 900, 900));
815 class PlatformAppDevToolsBrowserTest
: public PlatformAppBrowserTest
{
821 // Runs a test inside a harness that opens DevTools on an app window.
822 void RunTestWithDevTools(const char* name
, int test_flags
);
825 void PlatformAppDevToolsBrowserTest::RunTestWithDevTools(
826 const char* name
, int test_flags
) {
827 using content::DevToolsAgentHost
;
828 ExtensionTestMessageListener
launched_listener("Launched", false);
829 const Extension
* extension
= LoadAndLaunchPlatformApp(name
);
830 ASSERT_TRUE(extension
);
831 ASSERT_TRUE(launched_listener
.WaitUntilSatisfied());
832 AppWindow
* window
= GetFirstAppWindow();
834 ASSERT_EQ(window
->window_key().empty(), (test_flags
& HAS_ID
) == 0);
835 content::RenderViewHost
* rvh
= window
->web_contents()->GetRenderViewHost();
838 // Ensure no DevTools open for the AppWindow, then open one.
839 ASSERT_FALSE(DevToolsAgentHost::HasFor(rvh
));
840 DevToolsWindow::OpenDevToolsWindow(rvh
);
841 ASSERT_TRUE(DevToolsAgentHost::HasFor(rvh
));
843 if (test_flags
& RELAUNCH
) {
844 // Close the AppWindow, and ensure it is gone.
845 CloseAppWindow(window
);
846 ASSERT_FALSE(GetFirstAppWindow());
848 // Relaunch the app and get a new AppWindow.
849 content::WindowedNotificationObserver
app_loaded_observer(
850 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME
,
851 content::NotificationService::AllSources());
852 OpenApplication(AppLaunchParams(
853 browser()->profile(), extension
, LAUNCH_CONTAINER_NONE
, NEW_WINDOW
));
854 app_loaded_observer
.Wait();
855 window
= GetFirstAppWindow();
858 // DevTools should have reopened with the relaunch.
859 rvh
= window
->web_contents()->GetRenderViewHost();
861 ASSERT_TRUE(DevToolsAgentHost::HasFor(rvh
));
867 // http://crbug.com/246634
868 #if defined(OS_CHROMEOS)
869 #define MAYBE_ReOpenedWithID DISABLED_ReOpenedWithID
871 #define MAYBE_ReOpenedWithID ReOpenedWithID
873 IN_PROC_BROWSER_TEST_F(PlatformAppDevToolsBrowserTest
, MAYBE_ReOpenedWithID
) {
874 #if defined(OS_WIN) && defined(USE_ASH)
875 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
876 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests
))
879 RunTestWithDevTools("minimal_id", RELAUNCH
| HAS_ID
);
882 // http://crbug.com/246999
883 #if defined(OS_CHROMEOS) || defined(OS_WIN)
884 #define MAYBE_ReOpenedWithURL DISABLED_ReOpenedWithURL
886 #define MAYBE_ReOpenedWithURL ReOpenedWithURL
888 IN_PROC_BROWSER_TEST_F(PlatformAppDevToolsBrowserTest
, MAYBE_ReOpenedWithURL
) {
889 RunTestWithDevTools("minimal", RELAUNCH
);
892 // Test that showing a permission request as a constrained window works and is
893 // correctly parented.
894 #if defined(OS_MACOSX)
895 #define MAYBE_ConstrainedWindowRequest DISABLED_ConstrainedWindowRequest
897 // TODO(sail): Enable this on other platforms once http://crbug.com/95455 is
899 #define MAYBE_ConstrainedWindowRequest DISABLED_ConstrainedWindowRequest
902 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, MAYBE_ConstrainedWindowRequest
) {
903 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true);
904 const Extension
* extension
=
905 LoadAndLaunchPlatformApp("optional_permission_request");
906 ASSERT_TRUE(extension
) << "Failed to load extension.";
908 WebContents
* web_contents
= GetFirstAppWindowWebContents();
909 ASSERT_TRUE(web_contents
);
911 // Verify that the app window has a dialog attached.
912 WebContentsModalDialogManager
* web_contents_modal_dialog_manager
=
913 WebContentsModalDialogManager::FromWebContents(web_contents
);
914 EXPECT_TRUE(web_contents_modal_dialog_manager
->IsDialogActive());
916 // Close the constrained window and wait for the reply to the permission
918 ExtensionTestMessageListener
listener("PermissionRequestDone", false);
919 WebContentsModalDialogManager::TestApi
test_api(
920 web_contents_modal_dialog_manager
);
921 test_api
.CloseAllDialogs();
922 ASSERT_TRUE(listener
.WaitUntilSatisfied());
925 // Tests that an app calling chrome.runtime.reload will reload the app and
926 // relaunch it if it was running.
927 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, ReloadRelaunches
) {
928 ExtensionTestMessageListener
launched_listener("Launched", true);
929 const Extension
* extension
= LoadAndLaunchPlatformApp("reload");
930 ASSERT_TRUE(extension
);
931 ASSERT_TRUE(launched_listener
.WaitUntilSatisfied());
932 ASSERT_TRUE(GetFirstAppWindow());
934 // Now tell the app to reload itself
935 ExtensionTestMessageListener
launched_listener2("Launched", false);
936 launched_listener
.Reply("reload");
937 ASSERT_TRUE(launched_listener2
.WaitUntilSatisfied());
938 ASSERT_TRUE(GetFirstAppWindow());
943 // Simple observer to check for NOTIFICATION_EXTENSION_INSTALLED events to
944 // ensure installation does or does not occur in certain scenarios.
945 class CheckExtensionInstalledObserver
: public content::NotificationObserver
{
947 CheckExtensionInstalledObserver() : seen_(false) {
949 chrome::NOTIFICATION_EXTENSION_INSTALLED
,
950 content::NotificationService::AllSources());
957 // NotificationObserver:
958 virtual void Observe(int type
,
959 const content::NotificationSource
& source
,
960 const content::NotificationDetails
& details
) OVERRIDE
{
967 content::NotificationRegistrar registrar_
;
972 // Component App Test 1 of 3: ensure that the initial load of a component
973 // extension utilizing a background page (e.g. a v2 platform app) has its
974 // background page run and is launchable. Waits for the Launched response from
975 // the script resource in the opened app window.
976 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
,
977 PRE_PRE_ComponentAppBackgroundPage
) {
978 CheckExtensionInstalledObserver should_install
;
980 // Ensure that we wait until the background page is run (to register the
981 // OnLaunched listener) before trying to open the application. This is similar
982 // to LoadAndLaunchPlatformApp, but we want to load as a component extension.
983 content::WindowedNotificationObserver
app_loaded_observer(
984 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME
,
985 content::NotificationService::AllSources());
987 const Extension
* extension
= LoadExtensionAsComponent(
988 test_data_dir_
.AppendASCII("platform_apps").AppendASCII("component"));
989 ASSERT_TRUE(extension
);
991 app_loaded_observer
.Wait();
992 ASSERT_TRUE(should_install
.seen());
994 ExtensionTestMessageListener
launched_listener("Launched", false);
995 OpenApplication(AppLaunchParams(
996 browser()->profile(), extension
, LAUNCH_CONTAINER_NONE
, NEW_WINDOW
));
998 ASSERT_TRUE(launched_listener
.WaitUntilSatisfied());
1001 // Component App Test 2 of 3: ensure an installed component app can be launched
1002 // on a subsequent browser start, without requiring any install/upgrade logic
1003 // to be run, then perform setup for step 3.
1004 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
,
1005 PRE_ComponentAppBackgroundPage
) {
1007 // Since the component app is now installed, re-adding it in the same profile
1008 // should not cause it to be re-installed. Instead, we wait for the OnLaunched
1009 // in a different observer (which would timeout if not the app was not
1010 // previously installed properly) and then check this observer to make sure it
1011 // never saw the NOTIFICATION_EXTENSION_INSTALLED event.
1012 CheckExtensionInstalledObserver should_not_install
;
1013 const Extension
* extension
= LoadExtensionAsComponent(
1014 test_data_dir_
.AppendASCII("platform_apps").AppendASCII("component"));
1015 ASSERT_TRUE(extension
);
1017 ExtensionTestMessageListener
launched_listener("Launched", false);
1018 OpenApplication(AppLaunchParams(
1019 browser()->profile(), extension
, LAUNCH_CONTAINER_NONE
, NEW_WINDOW
));
1021 ASSERT_TRUE(launched_listener
.WaitUntilSatisfied());
1022 ASSERT_FALSE(should_not_install
.seen());
1024 // Simulate a "downgrade" from version 2 in the test manifest.json to 1.
1025 ExtensionPrefs
* extension_prefs
= ExtensionPrefs::Get(browser()->profile());
1027 // Clear the registered events to ensure they are updated.
1028 extensions::EventRouter::Get(browser()->profile())
1029 ->SetRegisteredEvents(extension
->id(), std::set
<std::string
>());
1031 DictionaryPrefUpdate
update(extension_prefs
->pref_service(),
1032 extensions::pref_names::kExtensions
);
1033 base::DictionaryValue
* dict
= update
.Get();
1034 std::string
key(extension
->id());
1035 key
+= ".manifest.version";
1036 dict
->SetString(key
, "1");
1039 // Component App Test 3 of 3: simulate a component extension upgrade that
1040 // re-adds the OnLaunched event, and allows the app to be launched.
1041 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, ComponentAppBackgroundPage
) {
1042 CheckExtensionInstalledObserver should_install
;
1043 // Since we are forcing an upgrade, we need to wait for the load again.
1044 content::WindowedNotificationObserver
app_loaded_observer(
1045 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME
,
1046 content::NotificationService::AllSources());
1048 const Extension
* extension
= LoadExtensionAsComponent(
1049 test_data_dir_
.AppendASCII("platform_apps").AppendASCII("component"));
1050 ASSERT_TRUE(extension
);
1051 app_loaded_observer
.Wait();
1052 ASSERT_TRUE(should_install
.seen());
1054 ExtensionTestMessageListener
launched_listener("Launched", false);
1055 OpenApplication(AppLaunchParams(
1056 browser()->profile(), extension
, LAUNCH_CONTAINER_NONE
, NEW_WINDOW
));
1058 ASSERT_TRUE(launched_listener
.WaitUntilSatisfied());
1061 // Flakes on Windows: http://crbug.com/171450
1063 #define MAYBE_Messaging DISABLED_Messaging
1065 #define MAYBE_Messaging Messaging
1067 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, MAYBE_Messaging
) {
1068 ExtensionApiTest::ResultCatcher result_catcher
;
1069 LoadAndLaunchPlatformApp("messaging/app2");
1070 LoadAndLaunchPlatformApp("messaging/app1");
1071 EXPECT_TRUE(result_catcher
.GetNextResult());
1074 // TODO(linux_aura) http://crbug.com/163931
1075 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
1076 #define MAYBE_WebContentsHasFocus DISABLED_WebContentsHasFocus
1078 // This test depends on focus and so needs to be in interactive_ui_tests.
1079 // http://crbug.com/227041
1080 #define MAYBE_WebContentsHasFocus DISABLED_WebContentsHasFocus
1082 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, MAYBE_WebContentsHasFocus
) {
1083 ExtensionTestMessageListener
launched_listener("Launched", true);
1084 LoadAndLaunchPlatformApp("minimal");
1085 ASSERT_TRUE(launched_listener
.WaitUntilSatisfied());
1087 EXPECT_EQ(1LU, GetAppWindowCount());
1088 EXPECT_TRUE(GetFirstAppWindow()
1090 ->GetRenderWidgetHostView()
1094 // The next three tests will only run automatically with Chrome branded builds
1095 // because they require the PDF preview plug-in. To run these tests manually for
1096 // Chromium (non-Chrome branded) builds in a development environment:
1098 // 1) Remove "MAYBE_" in the first line of each test definition
1099 // 2) Build Chromium browser_tests
1100 // 3) Make a copy of the PDF plug-in from a recent version of Chrome (Canary
1101 // or a recent development build) to your Chromium build:
1102 // - On Linux and Chrome OS, copy /opt/google/chrome/libpdf.so to
1103 // <path-to-your-src>/out/Debug
1104 // - On OS X, copy PDF.plugin from
1105 // <recent-chrome-app-folder>/*/*/*/*/"Internet Plug-Ins" to
1106 // <path-to-your-src>/out/Debug/Chromium.app/*/*/*/*/"Internet Plug-Ins"
1107 // 4) Run browser_tests with the --enable-print-preview flag
1109 #if !defined(GOOGLE_CHROME_BUILD) || \
1110 (defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX)))
1111 #define MAYBE_WindowDotPrintShouldBringUpPrintPreview \
1112 DISABLED_WindowDotPrintShouldBringUpPrintPreview
1114 #define MAYBE_WindowDotPrintShouldBringUpPrintPreview \
1115 WindowDotPrintShouldBringUpPrintPreview
1118 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
,
1119 MAYBE_WindowDotPrintShouldBringUpPrintPreview
) {
1120 ScopedPreviewTestingDelegate
preview_delegate(true);
1121 ASSERT_TRUE(RunPlatformAppTest("platform_apps/print_api")) << message_
;
1122 preview_delegate
.WaitUntilPreviewIsReady();
1125 #if !defined(GOOGLE_CHROME_BUILD)
1126 #define MAYBE_ClosingWindowWhilePrintingShouldNotCrash \
1127 DISABLED_ClosingWindowWhilePrintingShouldNotCrash
1129 #define MAYBE_ClosingWindowWhilePrintingShouldNotCrash \
1130 ClosingWindowWhilePrintingShouldNotCrash
1133 // This test verifies that http://crbug.com/297179 is fixed.
1134 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
,
1135 MAYBE_ClosingWindowWhilePrintingShouldNotCrash
) {
1136 ScopedPreviewTestingDelegate
preview_delegate(false);
1137 ASSERT_TRUE(RunPlatformAppTest("platform_apps/print_api")) << message_
;
1138 preview_delegate
.WaitUntilPreviewIsReady();
1139 GetFirstAppWindow()->GetBaseWindow()->Close();
1142 // This test currently only passes on OS X (on other platforms the print preview
1143 // dialog's size is limited by the size of the window being printed).
1144 #if !defined(GOOGLE_CHROME_BUILD) || !defined(OS_MACOSX)
1145 #define MAYBE_PrintPreviewShouldNotBeTooSmall \
1146 DISABLED_PrintPreviewShouldNotBeTooSmall
1148 #define MAYBE_PrintPreviewShouldNotBeTooSmall \
1149 PrintPreviewShouldNotBeTooSmall
1152 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
,
1153 MAYBE_PrintPreviewShouldNotBeTooSmall
) {
1154 // Print preview dialogs with widths less than 410 pixels will have preview
1155 // areas that are too small, and ones with heights less than 191 pixels will
1156 // have vertical scrollers for their controls that are too small.
1157 gfx::Size
minimum_dialog_size(410, 191);
1158 ScopedPreviewTestingDelegate
preview_delegate(false);
1159 ASSERT_TRUE(RunPlatformAppTest("platform_apps/print_api")) << message_
;
1160 preview_delegate
.WaitUntilPreviewIsReady();
1161 EXPECT_GE(preview_delegate
.dialog_size().width(),
1162 minimum_dialog_size
.width());
1163 EXPECT_GE(preview_delegate
.dialog_size().height(),
1164 minimum_dialog_size
.height());
1165 GetFirstAppWindow()->GetBaseWindow()->Close();
1169 #if defined(OS_CHROMEOS)
1171 class PlatformAppIncognitoBrowserTest
: public PlatformAppBrowserTest
,
1172 public AppWindowRegistry::Observer
{
1174 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
1175 // Tell chromeos to launch in Guest mode, aka incognito.
1176 command_line
->AppendSwitch(switches::kIncognito
);
1177 PlatformAppBrowserTest::SetUpCommandLine(command_line
);
1179 virtual void SetUp() OVERRIDE
{
1180 // Make sure the file manager actually gets loaded.
1181 ComponentLoader::EnableBackgroundExtensionsForTesting();
1182 PlatformAppBrowserTest::SetUp();
1185 // AppWindowRegistry::Observer implementation.
1186 virtual void OnAppWindowAdded(AppWindow
* app_window
) OVERRIDE
{
1187 opener_app_ids_
.insert(app_window
->extension_id());
1189 virtual void OnAppWindowIconChanged(AppWindow
* app_window
) OVERRIDE
{}
1190 virtual void OnAppWindowRemoved(AppWindow
* app_window
) OVERRIDE
{}
1193 // A set of ids of apps we've seen open a app window.
1194 std::set
<std::string
> opener_app_ids_
;
1197 IN_PROC_BROWSER_TEST_F(PlatformAppIncognitoBrowserTest
, IncognitoComponentApp
) {
1198 // Get the file manager app.
1199 const Extension
* file_manager
= extension_service()->GetExtensionById(
1200 "hhaomjibdihmijegdhdafkllkbggdgoj", false);
1201 ASSERT_TRUE(file_manager
!= NULL
);
1202 Profile
* incognito_profile
= profile()->GetOffTheRecordProfile();
1203 ASSERT_TRUE(incognito_profile
!= NULL
);
1205 // Wait until the file manager has had a chance to register its listener
1206 // for the launch event.
1207 EventRouter
* router
= EventRouter::Get(incognito_profile
);
1208 ASSERT_TRUE(router
!= NULL
);
1209 while (!router
->ExtensionHasEventListener(
1210 file_manager
->id(), app_runtime::OnLaunched::kEventName
)) {
1211 content::RunAllPendingInMessageLoop();
1214 // Listen for new app windows so we see the file manager app launch itself.
1215 AppWindowRegistry
* registry
= AppWindowRegistry::Get(incognito_profile
);
1216 ASSERT_TRUE(registry
!= NULL
);
1217 registry
->AddObserver(this);
1219 OpenApplication(AppLaunchParams(
1220 incognito_profile
, file_manager
, 0, chrome::HOST_DESKTOP_TYPE_NATIVE
));
1222 while (!ContainsKey(opener_app_ids_
, file_manager
->id())) {
1223 content::RunAllPendingInMessageLoop();
1227 class RestartDeviceTest
: public PlatformAppBrowserTest
{
1230 : power_manager_client_(NULL
),
1231 mock_user_manager_(NULL
) {}
1232 virtual ~RestartDeviceTest() {}
1234 // PlatformAppBrowserTest overrides
1235 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE
{
1236 PlatformAppBrowserTest::SetUpInProcessBrowserTestFixture();
1238 chromeos::FakeDBusThreadManager
* dbus_manager
=
1239 new chromeos::FakeDBusThreadManager
;
1240 dbus_manager
->SetFakeClients();
1241 power_manager_client_
= new chromeos::FakePowerManagerClient
;
1242 dbus_manager
->SetPowerManagerClient(
1243 scoped_ptr
<chromeos::PowerManagerClient
>(power_manager_client_
));
1244 chromeos::DBusThreadManager::SetInstanceForTesting(dbus_manager
);
1247 virtual void SetUpOnMainThread() OVERRIDE
{
1248 PlatformAppBrowserTest::SetUpOnMainThread();
1250 mock_user_manager_
= new chromeos::MockUserManager
;
1251 user_manager_enabler_
.reset(
1252 new chromeos::ScopedUserManagerEnabler(mock_user_manager_
));
1254 EXPECT_CALL(*mock_user_manager_
, IsUserLoggedIn())
1255 .WillRepeatedly(testing::Return(true));
1256 EXPECT_CALL(*mock_user_manager_
, IsLoggedInAsKioskApp())
1257 .WillRepeatedly(testing::Return(true));
1260 virtual void CleanUpOnMainThread() OVERRIDE
{
1261 user_manager_enabler_
.reset();
1262 PlatformAppBrowserTest::CleanUpOnMainThread();
1265 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE
{
1266 PlatformAppBrowserTest::TearDownInProcessBrowserTestFixture();
1269 int num_request_restart_calls() const {
1270 return power_manager_client_
->num_request_restart_calls();
1274 chromeos::FakePowerManagerClient
* power_manager_client_
;
1275 chromeos::MockUserManager
* mock_user_manager_
;
1276 scoped_ptr
<chromeos::ScopedUserManagerEnabler
> user_manager_enabler_
;
1278 DISALLOW_COPY_AND_ASSIGN(RestartDeviceTest
);
1281 // Tests that chrome.runtime.restart would request device restart in
1282 // ChromeOS kiosk mode.
1283 IN_PROC_BROWSER_TEST_F(RestartDeviceTest
, Restart
) {
1284 ASSERT_EQ(0, num_request_restart_calls());
1286 ExtensionTestMessageListener
launched_listener("Launched", true);
1287 const Extension
* extension
= LoadAndLaunchPlatformApp("restart_device");
1288 ASSERT_TRUE(extension
);
1289 ASSERT_TRUE(launched_listener
.WaitUntilSatisfied());
1291 launched_listener
.Reply("restart");
1292 ExtensionTestMessageListener
restart_requested_listener("restartRequested",
1294 ASSERT_TRUE(restart_requested_listener
.WaitUntilSatisfied());
1296 EXPECT_EQ(1, num_request_restart_calls());
1299 #endif // defined(OS_CHROMEOS)
1301 // Test that when an application is uninstalled and re-install it does not have
1302 // access to the previously set data.
1303 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest
, ReinstallDataCleanup
) {
1304 // The application is installed and launched. After the 'Launched' message is
1305 // acknowledged by the browser process, the application will test that some
1306 // data are not installed and then install them. The application will then be
1307 // uninstalled and the same process will be repeated.
1308 std::string extension_id
;
1311 ExtensionTestMessageListener
launched_listener("Launched", false);
1312 const Extension
* extension
=
1313 LoadAndLaunchPlatformApp("reinstall_data_cleanup");
1314 ASSERT_TRUE(extension
);
1315 extension_id
= extension
->id();
1317 ExtensionApiTest::ResultCatcher result_catcher
;
1318 ASSERT_TRUE(launched_listener
.WaitUntilSatisfied());
1320 EXPECT_TRUE(result_catcher
.GetNextResult());
1323 UninstallExtension(extension_id
);
1324 content::RunAllPendingInMessageLoop();
1327 ExtensionTestMessageListener
launched_listener("Launched", false);
1328 const Extension
* extension
=
1329 LoadAndLaunchPlatformApp("reinstall_data_cleanup");
1330 ASSERT_TRUE(extension
);
1331 ASSERT_EQ(extension_id
, extension
->id());
1333 ExtensionApiTest::ResultCatcher result_catcher
;
1335 ASSERT_TRUE(launched_listener
.WaitUntilSatisfied());
1337 EXPECT_TRUE(result_catcher
.GetNextResult());
1341 } // namespace extensions