blob: fc95daec61bc75a6fdd0be387e65942f9d00ab93 [file] [log] [blame]
[email protected]9d02fa12013-02-19 05:12:571// 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.
4
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.
8
[email protected]2a69b942013-05-31 09:37:539#include "apps/switches.h"
[email protected]eb02ab62013-07-23 14:12:5510#include "base/process/launch.h"
[email protected]9d02fa12013-02-19 05:12:5711#include "base/test/test_timeouts.h"
[email protected]bb4bec02013-08-15 11:26:5812#include "chrome/browser/apps/app_browsertest_util.h"
[email protected]9d02fa12013-02-19 05:12:5713#include "chrome/browser/extensions/extension_browsertest.h"
[email protected]9d02fa12013-02-19 05:12:5714#include "chrome/browser/profiles/profile_manager.h"
15#include "chrome/common/chrome_switches.h"
benwellsfa165112015-01-20 04:12:5016#include "content/public/common/content_switches.h"
[email protected]9d02fa12013-02-19 05:12:5717#include "content/public/test/test_launcher.h"
lfg910f2f92014-09-19 05:31:0918#include "extensions/test/extension_test_message_listener.h"
[email protected]9d02fa12013-02-19 05:12:5719
[email protected]2a69b942013-05-31 09:37:5320using extensions::PlatformAppBrowserTest;
21
22namespace apps {
[email protected]9d02fa12013-02-19 05:12:5723
benwellsfa165112015-01-20 04:12:5024namespace {
25
26const char* kSwitchesToCopy[] = {
27 switches::kUserDataDir,
28 switches::kNoSandbox,
29};
30
31} // namespace
32
[email protected]9d02fa12013-02-19 05:12:5733// TODO(jackhou): Enable this test once it works on OSX. It currently does not
34// work for the same reason --app-id doesn't. See http://crbug.com/148465
35#if defined(OS_MACOSX)
36#define MAYBE_LoadAndLaunchAppChromeRunning \
37 DISABLED_LoadAndLaunchAppChromeRunning
38#else
39#define MAYBE_LoadAndLaunchAppChromeRunning LoadAndLaunchAppChromeRunning
40#endif
41
42// Case where Chrome is already running.
43IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
44 MAYBE_LoadAndLaunchAppChromeRunning) {
45 ExtensionTestMessageListener launched_listener("Launched", false);
46
pgal.u-szeged214274b2014-10-28 11:59:4847 const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess();
48 base::CommandLine new_cmdline(cmdline.GetProgram());
benwellsfa165112015-01-20 04:12:5049 new_cmdline.CopySwitchesFrom(cmdline, kSwitchesToCopy,
50 arraysize(kSwitchesToCopy));
[email protected]9d02fa12013-02-19 05:12:5751
52 base::FilePath app_path = test_data_dir_
53 .AppendASCII("platform_apps")
54 .AppendASCII("minimal");
55
[email protected]2a69b942013-05-31 09:37:5356 new_cmdline.AppendSwitchNative(apps::kLoadAndLaunchApp,
[email protected]9d02fa12013-02-19 05:12:5757 app_path.value());
58
59 new_cmdline.AppendSwitch(content::kLaunchAsBrowser);
rvargas6bfa2522014-12-10 02:09:5360 base::Process process =
61 base::LaunchProcess(new_cmdline, base::LaunchOptionsForTest());
62 ASSERT_TRUE(process.IsValid());
[email protected]9d02fa12013-02-19 05:12:5763
64 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
rvargas2f70a152015-02-24 00:28:1165 int exit_code;
66 ASSERT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_timeout(),
67 &exit_code));
68 ASSERT_EQ(0, exit_code);
[email protected]9d02fa12013-02-19 05:12:5769}
70
[email protected]7b9faeb72013-06-11 12:20:1771// TODO(jackhou): Enable this test once it works on OSX. It currently does not
72// work for the same reason --app-id doesn't. See http://crbug.com/148465
73#if defined(OS_MACOSX)
74#define MAYBE_LoadAndLaunchAppWithFile DISABLED_LoadAndLaunchAppWithFile
75#else
76#define MAYBE_LoadAndLaunchAppWithFile LoadAndLaunchAppWithFile
77#endif
78
79IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
80 MAYBE_LoadAndLaunchAppWithFile) {
81 ExtensionTestMessageListener launched_listener("Launched", false);
82
pgal.u-szeged214274b2014-10-28 11:59:4883 const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess();
84 base::CommandLine new_cmdline(cmdline.GetProgram());
benwellsfa165112015-01-20 04:12:5085 new_cmdline.CopySwitchesFrom(cmdline, kSwitchesToCopy,
86 arraysize(kSwitchesToCopy));
[email protected]7b9faeb72013-06-11 12:20:1787
88 base::FilePath app_path = test_data_dir_
89 .AppendASCII("platform_apps")
90 .AppendASCII("load_and_launch_file");
91
92 base::FilePath test_file_path = test_data_dir_
93 .AppendASCII("platform_apps")
94 .AppendASCII("launch_files")
95 .AppendASCII("test.txt");
96
97 new_cmdline.AppendSwitchNative(apps::kLoadAndLaunchApp,
98 app_path.value());
99 new_cmdline.AppendSwitch(content::kLaunchAsBrowser);
100 new_cmdline.AppendArgPath(test_file_path);
101
rvargas6bfa2522014-12-10 02:09:53102 base::Process process =
103 base::LaunchProcess(new_cmdline, base::LaunchOptionsForTest());
104 ASSERT_TRUE(process.IsValid());
[email protected]7b9faeb72013-06-11 12:20:17105
106 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
rvargas2f70a152015-02-24 00:28:11107 int exit_code;
108 ASSERT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_timeout(),
109 &exit_code));
110 ASSERT_EQ(0, exit_code);
[email protected]7b9faeb72013-06-11 12:20:17111}
112
[email protected]9d02fa12013-02-19 05:12:57113namespace {
114
115// TestFixture that appends --load-and-launch-app before calling BrowserMain.
116class PlatformAppLoadAndLaunchBrowserTest : public PlatformAppBrowserTest {
117 protected:
118 PlatformAppLoadAndLaunchBrowserTest() {}
119
pgal.u-szeged214274b2014-10-28 11:59:48120 void SetUpCommandLine(base::CommandLine* command_line) override {
[email protected]9d02fa12013-02-19 05:12:57121 PlatformAppBrowserTest::SetUpCommandLine(command_line);
122 app_path_ = test_data_dir_
123 .AppendASCII("platform_apps")
124 .AppendASCII("minimal");
[email protected]2a69b942013-05-31 09:37:53125 command_line->AppendSwitchNative(apps::kLoadAndLaunchApp,
[email protected]9d02fa12013-02-19 05:12:57126 app_path_.value());
127 }
128
129 void LoadAndLaunchApp() {
130 ExtensionTestMessageListener launched_listener("Launched", false);
131 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
132
133 // Start an actual browser because we can't shut down with just an app
134 // window.
[email protected]5d5bea82013-12-18 03:20:32135 CreateBrowser(ProfileManager::GetActiveUserProfile());
[email protected]9d02fa12013-02-19 05:12:57136 }
137
138 private:
139 base::FilePath app_path_;
140
141 DISALLOW_COPY_AND_ASSIGN(PlatformAppLoadAndLaunchBrowserTest);
142};
143
144} // namespace
145
[email protected]d99806e2013-02-19 10:21:30146
[email protected]d4d551e22013-11-21 14:41:13147// TODO(jackhou): Make this test not flaky on Vista or Linux Aura. See
148// http://crbug.com/176897
149#if defined(OS_WIN) || (defined(OS_LINUX) && defined(USE_AURA))
[email protected]d99806e2013-02-19 10:21:30150#define MAYBE_LoadAndLaunchAppChromeNotRunning \
151 DISABLED_LoadAndLaunchAppChromeNotRunning
152#else
153#define MAYBE_LoadAndLaunchAppChromeNotRunning \
154 LoadAndLaunchAppChromeNotRunning
155#endif
156
[email protected]9d02fa12013-02-19 05:12:57157// Case where Chrome is not running.
158IN_PROC_BROWSER_TEST_F(PlatformAppLoadAndLaunchBrowserTest,
[email protected]d99806e2013-02-19 10:21:30159 MAYBE_LoadAndLaunchAppChromeNotRunning) {
[email protected]9d02fa12013-02-19 05:12:57160 LoadAndLaunchApp();
161}
162
[email protected]2a69b942013-05-31 09:37:53163} // namespace apps