blob: fecfe844f1465afcf4d45a653e069875495da995 [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"
14#include "chrome/browser/extensions/extension_test_message_listener.h"
[email protected]9d02fa12013-02-19 05:12:5715#include "chrome/browser/profiles/profile_manager.h"
16#include "chrome/common/chrome_switches.h"
17#include "content/public/test/test_launcher.h"
18
[email protected]2a69b942013-05-31 09:37:5319using extensions::PlatformAppBrowserTest;
20
21namespace apps {
[email protected]9d02fa12013-02-19 05:12:5722
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
31
32// Case where Chrome is already running.
33IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
34 MAYBE_LoadAndLaunchAppChromeRunning) {
35 ExtensionTestMessageListener launched_listener("Launched", false);
36
37 const CommandLine& cmdline = *CommandLine::ForCurrentProcess();
38 CommandLine new_cmdline(cmdline.GetProgram());
39
40 const char* kSwitchNames[] = {
41 switches::kUserDataDir,
42 };
43 new_cmdline.CopySwitchesFrom(cmdline, kSwitchNames, arraysize(kSwitchNames));
44
45 base::FilePath app_path = test_data_dir_
46 .AppendASCII("platform_apps")
47 .AppendASCII("minimal");
48
[email protected]2a69b942013-05-31 09:37:5349 new_cmdline.AppendSwitchNative(apps::kLoadAndLaunchApp,
[email protected]9d02fa12013-02-19 05:12:5750 app_path.value());
51
52 new_cmdline.AppendSwitch(content::kLaunchAsBrowser);
53 base::ProcessHandle process;
54 base::LaunchProcess(new_cmdline, base::LaunchOptions(), &process);
55 ASSERT_NE(base::kNullProcessHandle, process);
56
57 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
58 ASSERT_TRUE(base::WaitForSingleProcess(
59 process, TestTimeouts::action_timeout()));
60}
61
[email protected]7b9faeb72013-06-11 12:20:1762// 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
69
70IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
71 MAYBE_LoadAndLaunchAppWithFile) {
72 ExtensionTestMessageListener launched_listener("Launched", false);
73
74 const CommandLine& cmdline = *CommandLine::ForCurrentProcess();
75 CommandLine new_cmdline(cmdline.GetProgram());
76
77 const char* kSwitchNames[] = {
78 switches::kUserDataDir,
79 };
80 new_cmdline.CopySwitchesFrom(cmdline, kSwitchNames, arraysize(kSwitchNames));
81
82 base::FilePath app_path = test_data_dir_
83 .AppendASCII("platform_apps")
84 .AppendASCII("load_and_launch_file");
85
86 base::FilePath test_file_path = test_data_dir_
87 .AppendASCII("platform_apps")
88 .AppendASCII("launch_files")
89 .AppendASCII("test.txt");
90
91 new_cmdline.AppendSwitchNative(apps::kLoadAndLaunchApp,
92 app_path.value());
93 new_cmdline.AppendSwitch(content::kLaunchAsBrowser);
94 new_cmdline.AppendArgPath(test_file_path);
95
96 base::ProcessHandle process;
97 base::LaunchProcess(new_cmdline, base::LaunchOptions(), &process);
98 ASSERT_NE(base::kNullProcessHandle, process);
99
100 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
101 ASSERT_TRUE(base::WaitForSingleProcess(
102 process, TestTimeouts::action_timeout()));
103}
104
[email protected]9d02fa12013-02-19 05:12:57105namespace {
106
107// TestFixture that appends --load-and-launch-app before calling BrowserMain.
108class PlatformAppLoadAndLaunchBrowserTest : public PlatformAppBrowserTest {
109 protected:
110 PlatformAppLoadAndLaunchBrowserTest() {}
111
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");
[email protected]2a69b942013-05-31 09:37:53117 command_line->AppendSwitchNative(apps::kLoadAndLaunchApp,
[email protected]9d02fa12013-02-19 05:12:57118 app_path_.value());
119 }
120
121 void LoadAndLaunchApp() {
122 ExtensionTestMessageListener launched_listener("Launched", false);
123 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
124
125 // Start an actual browser because we can't shut down with just an app
126 // window.
[email protected]5d5bea82013-12-18 03:20:32127 CreateBrowser(ProfileManager::GetActiveUserProfile());
[email protected]9d02fa12013-02-19 05:12:57128 }
129
130 private:
131 base::FilePath app_path_;
132
133 DISALLOW_COPY_AND_ASSIGN(PlatformAppLoadAndLaunchBrowserTest);
134};
135
136} // namespace
137
[email protected]d99806e2013-02-19 10:21:30138
[email protected]d4d551e22013-11-21 14:41:13139// TODO(jackhou): Make this test not flaky on Vista or Linux Aura. See
140// http://crbug.com/176897
141#if defined(OS_WIN) || (defined(OS_LINUX) && defined(USE_AURA))
[email protected]d99806e2013-02-19 10:21:30142#define MAYBE_LoadAndLaunchAppChromeNotRunning \
143 DISABLED_LoadAndLaunchAppChromeNotRunning
144#else
145#define MAYBE_LoadAndLaunchAppChromeNotRunning \
146 LoadAndLaunchAppChromeNotRunning
147#endif
148
[email protected]9d02fa12013-02-19 05:12:57149// Case where Chrome is not running.
150IN_PROC_BROWSER_TEST_F(PlatformAppLoadAndLaunchBrowserTest,
[email protected]d99806e2013-02-19 10:21:30151 MAYBE_LoadAndLaunchAppChromeNotRunning) {
[email protected]9d02fa12013-02-19 05:12:57152 LoadAndLaunchApp();
153}
154
[email protected]2a69b942013-05-31 09:37:53155} // namespace apps