Chromium side plumbing for enabling fixed root background compositing.
[chromium-blink-merge.git] / apps / load_and_launch_browsertest.cc
blobfd0f2ddc3f23a07a338736487963578daaa4a75e
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/test/test_timeouts.h"
11 #include "chrome/browser/extensions/extension_browsertest.h"
12 #include "chrome/browser/extensions/extension_test_message_listener.h"
13 #include "chrome/browser/extensions/platform_app_browsertest_util.h"
14 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "content/public/test/test_launcher.h"
18 using extensions::PlatformAppBrowserTest;
20 namespace apps {
22 // TODO(jackhou): Enable this test once it works on OSX. It currently does not
23 // work for the same reason --app-id doesn't. See http://crbug.com/148465
24 #if defined(OS_MACOSX)
25 #define MAYBE_LoadAndLaunchAppChromeRunning \
26 DISABLED_LoadAndLaunchAppChromeRunning
27 #else
28 #define MAYBE_LoadAndLaunchAppChromeRunning LoadAndLaunchAppChromeRunning
29 #endif
31 // Case where Chrome is already running.
32 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
33 MAYBE_LoadAndLaunchAppChromeRunning) {
34 ExtensionTestMessageListener launched_listener("Launched", false);
36 const CommandLine& cmdline = *CommandLine::ForCurrentProcess();
37 CommandLine new_cmdline(cmdline.GetProgram());
39 const char* kSwitchNames[] = {
40 switches::kUserDataDir,
42 new_cmdline.CopySwitchesFrom(cmdline, kSwitchNames, arraysize(kSwitchNames));
44 base::FilePath app_path = test_data_dir_
45 .AppendASCII("platform_apps")
46 .AppendASCII("minimal");
48 new_cmdline.AppendSwitchNative(apps::kLoadAndLaunchApp,
49 app_path.value());
51 new_cmdline.AppendSwitch(content::kLaunchAsBrowser);
52 base::ProcessHandle process;
53 base::LaunchProcess(new_cmdline, base::LaunchOptions(), &process);
54 ASSERT_NE(base::kNullProcessHandle, process);
56 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
57 ASSERT_TRUE(base::WaitForSingleProcess(
58 process, TestTimeouts::action_timeout()));
61 // TODO(jackhou): Enable this test once it works on OSX. It currently does not
62 // work for the same reason --app-id doesn't. See http://crbug.com/148465
63 #if defined(OS_MACOSX)
64 #define MAYBE_LoadAndLaunchAppWithFile DISABLED_LoadAndLaunchAppWithFile
65 #else
66 #define MAYBE_LoadAndLaunchAppWithFile LoadAndLaunchAppWithFile
67 #endif
69 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
70 MAYBE_LoadAndLaunchAppWithFile) {
71 ExtensionTestMessageListener launched_listener("Launched", false);
73 const CommandLine& cmdline = *CommandLine::ForCurrentProcess();
74 CommandLine new_cmdline(cmdline.GetProgram());
76 const char* kSwitchNames[] = {
77 switches::kUserDataDir,
79 new_cmdline.CopySwitchesFrom(cmdline, kSwitchNames, arraysize(kSwitchNames));
81 base::FilePath app_path = test_data_dir_
82 .AppendASCII("platform_apps")
83 .AppendASCII("load_and_launch_file");
85 base::FilePath test_file_path = test_data_dir_
86 .AppendASCII("platform_apps")
87 .AppendASCII("launch_files")
88 .AppendASCII("test.txt");
90 new_cmdline.AppendSwitchNative(apps::kLoadAndLaunchApp,
91 app_path.value());
92 new_cmdline.AppendSwitch(content::kLaunchAsBrowser);
93 new_cmdline.AppendArgPath(test_file_path);
95 base::ProcessHandle process;
96 base::LaunchProcess(new_cmdline, base::LaunchOptions(), &process);
97 ASSERT_NE(base::kNullProcessHandle, process);
99 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
100 ASSERT_TRUE(base::WaitForSingleProcess(
101 process, TestTimeouts::action_timeout()));
104 namespace {
106 // TestFixture that appends --load-and-launch-app before calling BrowserMain.
107 class PlatformAppLoadAndLaunchBrowserTest : public PlatformAppBrowserTest {
108 protected:
109 PlatformAppLoadAndLaunchBrowserTest() {}
111 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
112 PlatformAppBrowserTest::SetUpCommandLine(command_line);
113 app_path_ = test_data_dir_
114 .AppendASCII("platform_apps")
115 .AppendASCII("minimal");
116 command_line->AppendSwitchNative(apps::kLoadAndLaunchApp,
117 app_path_.value());
120 void LoadAndLaunchApp() {
121 ExtensionTestMessageListener launched_listener("Launched", false);
122 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
124 // Start an actual browser because we can't shut down with just an app
125 // window.
126 CreateBrowser(ProfileManager::GetDefaultProfile());
129 private:
130 base::FilePath app_path_;
132 DISALLOW_COPY_AND_ASSIGN(PlatformAppLoadAndLaunchBrowserTest);
135 } // namespace
138 // TODO(jackhou): Make this test not flaky on Vista. See http://crbug.com/176897
139 #if defined(OS_WIN)
140 #define MAYBE_LoadAndLaunchAppChromeNotRunning \
141 DISABLED_LoadAndLaunchAppChromeNotRunning
142 #else
143 #define MAYBE_LoadAndLaunchAppChromeNotRunning \
144 LoadAndLaunchAppChromeNotRunning
145 #endif
147 // Case where Chrome is not running.
148 IN_PROC_BROWSER_TEST_F(PlatformAppLoadAndLaunchBrowserTest,
149 MAYBE_LoadAndLaunchAppChromeNotRunning) {
150 LoadAndLaunchApp();
153 } // namespace apps