Rename isSystemLocationEnabled to isLocationEnabled, as per internal review (185995).
[chromium-blink-merge.git] / apps / load_and_launch_browsertest.cc
blob6624de9bb76f44aff6aab7ba90d28e693938310f
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/test/test_launcher.h"
17 #include "extensions/test/extension_test_message_listener.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 base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess();
38 base::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::Process process =
54 base::LaunchProcess(new_cmdline, base::LaunchOptionsForTest());
55 ASSERT_TRUE(process.IsValid());
57 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
58 ASSERT_TRUE(base::WaitForSingleProcess(process.Handle(),
59 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 base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess();
75 base::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::Process process =
97 base::LaunchProcess(new_cmdline, base::LaunchOptionsForTest());
98 ASSERT_TRUE(process.IsValid());
100 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
101 ASSERT_TRUE(base::WaitForSingleProcess(process.Handle(),
102 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 void SetUpCommandLine(base::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::GetActiveUserProfile());
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 or Linux Aura. See
140 // http://crbug.com/176897
141 #if defined(OS_WIN) || (defined(OS_LINUX) && defined(USE_AURA))
142 #define MAYBE_LoadAndLaunchAppChromeNotRunning \
143 DISABLED_LoadAndLaunchAppChromeNotRunning
144 #else
145 #define MAYBE_LoadAndLaunchAppChromeNotRunning \
146 LoadAndLaunchAppChromeNotRunning
147 #endif
149 // Case where Chrome is not running.
150 IN_PROC_BROWSER_TEST_F(PlatformAppLoadAndLaunchBrowserTest,
151 MAYBE_LoadAndLaunchAppChromeNotRunning) {
152 LoadAndLaunchApp();
155 } // namespace apps