[email protected] | 9d02fa1 | 2013-02-19 05:12:57 | [diff] [blame] | 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. |
| 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] | 2a69b94 | 2013-05-31 09:37:53 | [diff] [blame] | 9 | #include "apps/switches.h" |
[email protected] | eb02ab6 | 2013-07-23 14:12:55 | [diff] [blame] | 10 | #include "base/process/launch.h" |
[email protected] | 9d02fa1 | 2013-02-19 05:12:57 | [diff] [blame] | 11 | #include "base/test/test_timeouts.h" |
[email protected] | bb4bec0 | 2013-08-15 11:26:58 | [diff] [blame] | 12 | #include "chrome/browser/apps/app_browsertest_util.h" |
[email protected] | 9d02fa1 | 2013-02-19 05:12:57 | [diff] [blame] | 13 | #include "chrome/browser/extensions/extension_browsertest.h" |
[email protected] | 9d02fa1 | 2013-02-19 05:12:57 | [diff] [blame] | 14 | #include "chrome/browser/profiles/profile_manager.h" |
| 15 | #include "chrome/common/chrome_switches.h" |
benwells | fa16511 | 2015-01-20 04:12:50 | [diff] [blame] | 16 | #include "content/public/common/content_switches.h" |
[email protected] | 9d02fa1 | 2013-02-19 05:12:57 | [diff] [blame] | 17 | #include "content/public/test/test_launcher.h" |
lfg | 910f2f9 | 2014-09-19 05:31:09 | [diff] [blame] | 18 | #include "extensions/test/extension_test_message_listener.h" |
[email protected] | 9d02fa1 | 2013-02-19 05:12:57 | [diff] [blame] | 19 | |
[email protected] | 2a69b94 | 2013-05-31 09:37:53 | [diff] [blame] | 20 | using extensions::PlatformAppBrowserTest; |
| 21 | |
| 22 | namespace apps { |
[email protected] | 9d02fa1 | 2013-02-19 05:12:57 | [diff] [blame] | 23 | |
benwells | fa16511 | 2015-01-20 04:12:50 | [diff] [blame] | 24 | namespace { |
| 25 | |
| 26 | const char* kSwitchesToCopy[] = { |
| 27 | switches::kUserDataDir, |
| 28 | switches::kNoSandbox, |
| 29 | }; |
| 30 | |
| 31 | } // namespace |
| 32 | |
[email protected] | 9d02fa1 | 2013-02-19 05:12:57 | [diff] [blame] | 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 |
| 41 | |
| 42 | // Case where Chrome is already running. |
| 43 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, |
| 44 | MAYBE_LoadAndLaunchAppChromeRunning) { |
| 45 | ExtensionTestMessageListener launched_listener("Launched", false); |
| 46 | |
pgal.u-szeged | 214274b | 2014-10-28 11:59:48 | [diff] [blame] | 47 | const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess(); |
| 48 | base::CommandLine new_cmdline(cmdline.GetProgram()); |
benwells | fa16511 | 2015-01-20 04:12:50 | [diff] [blame] | 49 | new_cmdline.CopySwitchesFrom(cmdline, kSwitchesToCopy, |
| 50 | arraysize(kSwitchesToCopy)); |
[email protected] | 9d02fa1 | 2013-02-19 05:12:57 | [diff] [blame] | 51 | |
| 52 | base::FilePath app_path = test_data_dir_ |
| 53 | .AppendASCII("platform_apps") |
| 54 | .AppendASCII("minimal"); |
| 55 | |
[email protected] | 2a69b94 | 2013-05-31 09:37:53 | [diff] [blame] | 56 | new_cmdline.AppendSwitchNative(apps::kLoadAndLaunchApp, |
[email protected] | 9d02fa1 | 2013-02-19 05:12:57 | [diff] [blame] | 57 | app_path.value()); |
| 58 | |
| 59 | new_cmdline.AppendSwitch(content::kLaunchAsBrowser); |
rvargas | 6bfa252 | 2014-12-10 02:09:53 | [diff] [blame] | 60 | base::Process process = |
| 61 | base::LaunchProcess(new_cmdline, base::LaunchOptionsForTest()); |
| 62 | ASSERT_TRUE(process.IsValid()); |
[email protected] | 9d02fa1 | 2013-02-19 05:12:57 | [diff] [blame] | 63 | |
| 64 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
rvargas | 2f70a15 | 2015-02-24 00:28:11 | [diff] [blame] | 65 | int exit_code; |
| 66 | ASSERT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_timeout(), |
| 67 | &exit_code)); |
| 68 | ASSERT_EQ(0, exit_code); |
[email protected] | 9d02fa1 | 2013-02-19 05:12:57 | [diff] [blame] | 69 | } |
| 70 | |
[email protected] | 7b9faeb7 | 2013-06-11 12:20:17 | [diff] [blame] | 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 |
| 78 | |
| 79 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, |
| 80 | MAYBE_LoadAndLaunchAppWithFile) { |
| 81 | ExtensionTestMessageListener launched_listener("Launched", false); |
| 82 | |
pgal.u-szeged | 214274b | 2014-10-28 11:59:48 | [diff] [blame] | 83 | const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess(); |
| 84 | base::CommandLine new_cmdline(cmdline.GetProgram()); |
benwells | fa16511 | 2015-01-20 04:12:50 | [diff] [blame] | 85 | new_cmdline.CopySwitchesFrom(cmdline, kSwitchesToCopy, |
| 86 | arraysize(kSwitchesToCopy)); |
[email protected] | 7b9faeb7 | 2013-06-11 12:20:17 | [diff] [blame] | 87 | |
| 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 | |
rvargas | 6bfa252 | 2014-12-10 02:09:53 | [diff] [blame] | 102 | base::Process process = |
| 103 | base::LaunchProcess(new_cmdline, base::LaunchOptionsForTest()); |
| 104 | ASSERT_TRUE(process.IsValid()); |
[email protected] | 7b9faeb7 | 2013-06-11 12:20:17 | [diff] [blame] | 105 | |
| 106 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
rvargas | 2f70a15 | 2015-02-24 00:28:11 | [diff] [blame] | 107 | int exit_code; |
| 108 | ASSERT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_timeout(), |
| 109 | &exit_code)); |
| 110 | ASSERT_EQ(0, exit_code); |
[email protected] | 7b9faeb7 | 2013-06-11 12:20:17 | [diff] [blame] | 111 | } |
| 112 | |
[email protected] | 9d02fa1 | 2013-02-19 05:12:57 | [diff] [blame] | 113 | namespace { |
| 114 | |
| 115 | // TestFixture that appends --load-and-launch-app before calling BrowserMain. |
| 116 | class PlatformAppLoadAndLaunchBrowserTest : public PlatformAppBrowserTest { |
| 117 | protected: |
| 118 | PlatformAppLoadAndLaunchBrowserTest() {} |
| 119 | |
pgal.u-szeged | 214274b | 2014-10-28 11:59:48 | [diff] [blame] | 120 | void SetUpCommandLine(base::CommandLine* command_line) override { |
[email protected] | 9d02fa1 | 2013-02-19 05:12:57 | [diff] [blame] | 121 | PlatformAppBrowserTest::SetUpCommandLine(command_line); |
| 122 | app_path_ = test_data_dir_ |
| 123 | .AppendASCII("platform_apps") |
| 124 | .AppendASCII("minimal"); |
[email protected] | 2a69b94 | 2013-05-31 09:37:53 | [diff] [blame] | 125 | command_line->AppendSwitchNative(apps::kLoadAndLaunchApp, |
[email protected] | 9d02fa1 | 2013-02-19 05:12:57 | [diff] [blame] | 126 | 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] | 5d5bea8 | 2013-12-18 03:20:32 | [diff] [blame] | 135 | CreateBrowser(ProfileManager::GetActiveUserProfile()); |
[email protected] | 9d02fa1 | 2013-02-19 05:12:57 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | private: |
| 139 | base::FilePath app_path_; |
| 140 | |
| 141 | DISALLOW_COPY_AND_ASSIGN(PlatformAppLoadAndLaunchBrowserTest); |
| 142 | }; |
| 143 | |
| 144 | } // namespace |
| 145 | |
[email protected] | d99806e | 2013-02-19 10:21:30 | [diff] [blame] | 146 | |
[email protected] | d4d551e2 | 2013-11-21 14:41:13 | [diff] [blame] | 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)) |
[email protected] | d99806e | 2013-02-19 10:21:30 | [diff] [blame] | 150 | #define MAYBE_LoadAndLaunchAppChromeNotRunning \ |
| 151 | DISABLED_LoadAndLaunchAppChromeNotRunning |
| 152 | #else |
| 153 | #define MAYBE_LoadAndLaunchAppChromeNotRunning \ |
| 154 | LoadAndLaunchAppChromeNotRunning |
| 155 | #endif |
| 156 | |
[email protected] | 9d02fa1 | 2013-02-19 05:12:57 | [diff] [blame] | 157 | // Case where Chrome is not running. |
| 158 | IN_PROC_BROWSER_TEST_F(PlatformAppLoadAndLaunchBrowserTest, |
[email protected] | d99806e | 2013-02-19 10:21:30 | [diff] [blame] | 159 | MAYBE_LoadAndLaunchAppChromeNotRunning) { |
[email protected] | 9d02fa1 | 2013-02-19 05:12:57 | [diff] [blame] | 160 | LoadAndLaunchApp(); |
| 161 | } |
| 162 | |
[email protected] | 2a69b94 | 2013-05-31 09:37:53 | [diff] [blame] | 163 | } // namespace apps |