media-internals: Simplify the code path for creating a media log entry
[chromium-blink-merge.git] / apps / load_and_launch_browsertest.cc
blobfc95daec61bc75a6fdd0be387e65942f9d00ab93
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/profiles/profile_manager.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "content/public/common/content_switches.h"
17 #include "content/public/test/test_launcher.h"
18 #include "extensions/test/extension_test_message_listener.h"
20 using extensions::PlatformAppBrowserTest;
22 namespace apps {
24 namespace {
26 const char* kSwitchesToCopy[] = {
27 switches::kUserDataDir,
28 switches::kNoSandbox,
31 } // namespace
33 // 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
42 // Case where Chrome is already running.
43 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
44 MAYBE_LoadAndLaunchAppChromeRunning) {
45 ExtensionTestMessageListener launched_listener("Launched", false);
47 const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess();
48 base::CommandLine new_cmdline(cmdline.GetProgram());
49 new_cmdline.CopySwitchesFrom(cmdline, kSwitchesToCopy,
50 arraysize(kSwitchesToCopy));
52 base::FilePath app_path = test_data_dir_
53 .AppendASCII("platform_apps")
54 .AppendASCII("minimal");
56 new_cmdline.AppendSwitchNative(apps::kLoadAndLaunchApp,
57 app_path.value());
59 new_cmdline.AppendSwitch(content::kLaunchAsBrowser);
60 base::Process process =
61 base::LaunchProcess(new_cmdline, base::LaunchOptionsForTest());
62 ASSERT_TRUE(process.IsValid());
64 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
65 int exit_code;
66 ASSERT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_timeout(),
67 &exit_code));
68 ASSERT_EQ(0, exit_code);
71 // 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
79 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
80 MAYBE_LoadAndLaunchAppWithFile) {
81 ExtensionTestMessageListener launched_listener("Launched", false);
83 const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess();
84 base::CommandLine new_cmdline(cmdline.GetProgram());
85 new_cmdline.CopySwitchesFrom(cmdline, kSwitchesToCopy,
86 arraysize(kSwitchesToCopy));
88 base::FilePath app_path = test_data_dir_
89 .AppendASCII("platform_apps")
90 .AppendASCII("load_and_launch_file");
92 base::FilePath test_file_path = test_data_dir_
93 .AppendASCII("platform_apps")
94 .AppendASCII("launch_files")
95 .AppendASCII("test.txt");
97 new_cmdline.AppendSwitchNative(apps::kLoadAndLaunchApp,
98 app_path.value());
99 new_cmdline.AppendSwitch(content::kLaunchAsBrowser);
100 new_cmdline.AppendArgPath(test_file_path);
102 base::Process process =
103 base::LaunchProcess(new_cmdline, base::LaunchOptionsForTest());
104 ASSERT_TRUE(process.IsValid());
106 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
107 int exit_code;
108 ASSERT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_timeout(),
109 &exit_code));
110 ASSERT_EQ(0, exit_code);
113 namespace {
115 // TestFixture that appends --load-and-launch-app before calling BrowserMain.
116 class PlatformAppLoadAndLaunchBrowserTest : public PlatformAppBrowserTest {
117 protected:
118 PlatformAppLoadAndLaunchBrowserTest() {}
120 void SetUpCommandLine(base::CommandLine* command_line) override {
121 PlatformAppBrowserTest::SetUpCommandLine(command_line);
122 app_path_ = test_data_dir_
123 .AppendASCII("platform_apps")
124 .AppendASCII("minimal");
125 command_line->AppendSwitchNative(apps::kLoadAndLaunchApp,
126 app_path_.value());
129 void LoadAndLaunchApp() {
130 ExtensionTestMessageListener launched_listener("Launched", false);
131 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
133 // Start an actual browser because we can't shut down with just an app
134 // window.
135 CreateBrowser(ProfileManager::GetActiveUserProfile());
138 private:
139 base::FilePath app_path_;
141 DISALLOW_COPY_AND_ASSIGN(PlatformAppLoadAndLaunchBrowserTest);
144 } // namespace
147 // 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))
150 #define MAYBE_LoadAndLaunchAppChromeNotRunning \
151 DISABLED_LoadAndLaunchAppChromeNotRunning
152 #else
153 #define MAYBE_LoadAndLaunchAppChromeNotRunning \
154 LoadAndLaunchAppChromeNotRunning
155 #endif
157 // Case where Chrome is not running.
158 IN_PROC_BROWSER_TEST_F(PlatformAppLoadAndLaunchBrowserTest,
159 MAYBE_LoadAndLaunchAppChromeNotRunning) {
160 LoadAndLaunchApp();
163 } // namespace apps