<webview> Reclaim compositor resources released in the parent.
[chromium-blink-merge.git] / apps / load_and_launch_browsertest.cc
blob40f748c41fecb3190c91564881137b1b5c1788b9
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 // Tests for the --load-and-launch-app switch.
6 // The two cases are when chrome is running and another process uses the switch
7 // and when chrome is started from scratch.
9 #include "apps/switches.h"
10 #include "base/process/launch.h"
11 #include "base/test/test_timeouts.h"
12 #include "chrome/browser/apps/app_browsertest_util.h"
13 #include "chrome/browser/extensions/extension_browsertest.h"
14 #include "chrome/browser/extensions/extension_test_message_listener.h"
15 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/common/chrome_switches.h"
17 #include "content/public/test/test_launcher.h"
19 using extensions::PlatformAppBrowserTest;
21 namespace apps {
23 // TODO(jackhou): Enable this test once it works on OSX. It currently does not
24 // work for the same reason --app-id doesn't. See http://crbug.com/148465
25 #if defined(OS_MACOSX)
26 #define MAYBE_LoadAndLaunchAppChromeRunning \
27 DISABLED_LoadAndLaunchAppChromeRunning
28 #else
29 #define MAYBE_LoadAndLaunchAppChromeRunning LoadAndLaunchAppChromeRunning
30 #endif
32 // Case where Chrome is already running.
33 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
34 MAYBE_LoadAndLaunchAppChromeRunning) {
35 ExtensionTestMessageListener launched_listener("Launched", false);
37 const CommandLine& cmdline = *CommandLine::ForCurrentProcess();
38 CommandLine new_cmdline(cmdline.GetProgram());
40 const char* kSwitchNames[] = {
41 switches::kUserDataDir,
43 new_cmdline.CopySwitchesFrom(cmdline, kSwitchNames, arraysize(kSwitchNames));
45 base::FilePath app_path = test_data_dir_
46 .AppendASCII("platform_apps")
47 .AppendASCII("minimal");
49 new_cmdline.AppendSwitchNative(apps::kLoadAndLaunchApp,
50 app_path.value());
52 new_cmdline.AppendSwitch(content::kLaunchAsBrowser);
53 base::ProcessHandle process;
54 base::LaunchProcess(new_cmdline, base::LaunchOptions(), &process);
55 ASSERT_NE(base::kNullProcessHandle, process);
57 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
58 ASSERT_TRUE(base::WaitForSingleProcess(
59 process, TestTimeouts::action_timeout()));
62 // TODO(jackhou): Enable this test once it works on OSX. It currently does not
63 // work for the same reason --app-id doesn't. See http://crbug.com/148465
64 #if defined(OS_MACOSX)
65 #define MAYBE_LoadAndLaunchAppWithFile DISABLED_LoadAndLaunchAppWithFile
66 #else
67 #define MAYBE_LoadAndLaunchAppWithFile LoadAndLaunchAppWithFile
68 #endif
70 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
71 MAYBE_LoadAndLaunchAppWithFile) {
72 ExtensionTestMessageListener launched_listener("Launched", false);
74 const CommandLine& cmdline = *CommandLine::ForCurrentProcess();
75 CommandLine new_cmdline(cmdline.GetProgram());
77 const char* kSwitchNames[] = {
78 switches::kUserDataDir,
80 new_cmdline.CopySwitchesFrom(cmdline, kSwitchNames, arraysize(kSwitchNames));
82 base::FilePath app_path = test_data_dir_
83 .AppendASCII("platform_apps")
84 .AppendASCII("load_and_launch_file");
86 base::FilePath test_file_path = test_data_dir_
87 .AppendASCII("platform_apps")
88 .AppendASCII("launch_files")
89 .AppendASCII("test.txt");
91 new_cmdline.AppendSwitchNative(apps::kLoadAndLaunchApp,
92 app_path.value());
93 new_cmdline.AppendSwitch(content::kLaunchAsBrowser);
94 new_cmdline.AppendArgPath(test_file_path);
96 base::ProcessHandle process;
97 base::LaunchProcess(new_cmdline, base::LaunchOptions(), &process);
98 ASSERT_NE(base::kNullProcessHandle, process);
100 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
101 ASSERT_TRUE(base::WaitForSingleProcess(
102 process, TestTimeouts::action_timeout()));
105 namespace {
107 // TestFixture that appends --load-and-launch-app before calling BrowserMain.
108 class PlatformAppLoadAndLaunchBrowserTest : public PlatformAppBrowserTest {
109 protected:
110 PlatformAppLoadAndLaunchBrowserTest() {}
112 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
113 PlatformAppBrowserTest::SetUpCommandLine(command_line);
114 app_path_ = test_data_dir_
115 .AppendASCII("platform_apps")
116 .AppendASCII("minimal");
117 command_line->AppendSwitchNative(apps::kLoadAndLaunchApp,
118 app_path_.value());
121 void LoadAndLaunchApp() {
122 ExtensionTestMessageListener launched_listener("Launched", false);
123 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
125 // Start an actual browser because we can't shut down with just an app
126 // window.
127 CreateBrowser(ProfileManager::GetDefaultProfile());
130 private:
131 base::FilePath app_path_;
133 DISALLOW_COPY_AND_ASSIGN(PlatformAppLoadAndLaunchBrowserTest);
136 } // namespace
139 // TODO(jackhou): Make this test not flaky on Vista. See http://crbug.com/176897
140 #if defined(OS_WIN)
141 #define MAYBE_LoadAndLaunchAppChromeNotRunning \
142 DISABLED_LoadAndLaunchAppChromeNotRunning
143 #else
144 #define MAYBE_LoadAndLaunchAppChromeNotRunning \
145 LoadAndLaunchAppChromeNotRunning
146 #endif
148 // Case where Chrome is not running.
149 IN_PROC_BROWSER_TEST_F(PlatformAppLoadAndLaunchBrowserTest,
150 MAYBE_LoadAndLaunchAppChromeNotRunning) {
151 LoadAndLaunchApp();
154 } // namespace apps