[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] | 9d02fa1 | 2013-02-19 05:12:57 | [diff] [blame] | 10 | #include "base/test/test_timeouts.h" |
| 11 | #include "chrome/browser/extensions/extension_browsertest.h" |
| 12 | #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 13 | #include "chrome/browser/extensions/platform_app_browsertest_util.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 | |
[email protected] | 2a69b94 | 2013-05-31 09:37:53 | [diff] [blame^] | 18 | using extensions::PlatformAppBrowserTest; |
| 19 | |
| 20 | namespace apps { |
[email protected] | 9d02fa1 | 2013-02-19 05:12:57 | [diff] [blame] | 21 | |
| 22 | // TODO(jackhou): Enable this test once it works on OSX. It currently does not |
| 23 | // work for the same reason --app-id doesn't. See http://crbug.com/148465 |
| 24 | #if defined(OS_MACOSX) |
| 25 | #define MAYBE_LoadAndLaunchAppChromeRunning \ |
| 26 | DISABLED_LoadAndLaunchAppChromeRunning |
| 27 | #else |
| 28 | #define MAYBE_LoadAndLaunchAppChromeRunning LoadAndLaunchAppChromeRunning |
| 29 | #endif |
| 30 | |
| 31 | // Case where Chrome is already running. |
| 32 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, |
| 33 | MAYBE_LoadAndLaunchAppChromeRunning) { |
| 34 | ExtensionTestMessageListener launched_listener("Launched", false); |
| 35 | |
| 36 | const CommandLine& cmdline = *CommandLine::ForCurrentProcess(); |
| 37 | CommandLine new_cmdline(cmdline.GetProgram()); |
| 38 | |
| 39 | const char* kSwitchNames[] = { |
| 40 | switches::kUserDataDir, |
| 41 | }; |
| 42 | new_cmdline.CopySwitchesFrom(cmdline, kSwitchNames, arraysize(kSwitchNames)); |
| 43 | |
| 44 | base::FilePath app_path = test_data_dir_ |
| 45 | .AppendASCII("platform_apps") |
| 46 | .AppendASCII("minimal"); |
| 47 | |
[email protected] | 2a69b94 | 2013-05-31 09:37:53 | [diff] [blame^] | 48 | new_cmdline.AppendSwitchNative(apps::kLoadAndLaunchApp, |
[email protected] | 9d02fa1 | 2013-02-19 05:12:57 | [diff] [blame] | 49 | app_path.value()); |
| 50 | |
| 51 | new_cmdline.AppendSwitch(content::kLaunchAsBrowser); |
| 52 | base::ProcessHandle process; |
| 53 | base::LaunchProcess(new_cmdline, base::LaunchOptions(), &process); |
| 54 | ASSERT_NE(base::kNullProcessHandle, process); |
| 55 | |
| 56 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 57 | ASSERT_TRUE(base::WaitForSingleProcess( |
| 58 | process, TestTimeouts::action_timeout())); |
| 59 | } |
| 60 | |
| 61 | namespace { |
| 62 | |
| 63 | // TestFixture that appends --load-and-launch-app before calling BrowserMain. |
| 64 | class PlatformAppLoadAndLaunchBrowserTest : public PlatformAppBrowserTest { |
| 65 | protected: |
| 66 | PlatformAppLoadAndLaunchBrowserTest() {} |
| 67 | |
| 68 | virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 69 | PlatformAppBrowserTest::SetUpCommandLine(command_line); |
| 70 | app_path_ = test_data_dir_ |
| 71 | .AppendASCII("platform_apps") |
| 72 | .AppendASCII("minimal"); |
[email protected] | 2a69b94 | 2013-05-31 09:37:53 | [diff] [blame^] | 73 | command_line->AppendSwitchNative(apps::kLoadAndLaunchApp, |
[email protected] | 9d02fa1 | 2013-02-19 05:12:57 | [diff] [blame] | 74 | app_path_.value()); |
| 75 | } |
| 76 | |
| 77 | void LoadAndLaunchApp() { |
| 78 | ExtensionTestMessageListener launched_listener("Launched", false); |
| 79 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 80 | |
| 81 | // Start an actual browser because we can't shut down with just an app |
| 82 | // window. |
| 83 | CreateBrowser(ProfileManager::GetDefaultProfile()); |
| 84 | } |
| 85 | |
| 86 | private: |
| 87 | base::FilePath app_path_; |
| 88 | |
| 89 | DISALLOW_COPY_AND_ASSIGN(PlatformAppLoadAndLaunchBrowserTest); |
| 90 | }; |
| 91 | |
| 92 | } // namespace |
| 93 | |
[email protected] | d99806e | 2013-02-19 10:21:30 | [diff] [blame] | 94 | |
| 95 | // TODO(jackhou): Make this test not flaky on Vista. See http://crbug.com/176897 |
| 96 | #if defined(OS_WIN) |
| 97 | #define MAYBE_LoadAndLaunchAppChromeNotRunning \ |
| 98 | DISABLED_LoadAndLaunchAppChromeNotRunning |
| 99 | #else |
| 100 | #define MAYBE_LoadAndLaunchAppChromeNotRunning \ |
| 101 | LoadAndLaunchAppChromeNotRunning |
| 102 | #endif |
| 103 | |
[email protected] | 9d02fa1 | 2013-02-19 05:12:57 | [diff] [blame] | 104 | // Case where Chrome is not running. |
| 105 | IN_PROC_BROWSER_TEST_F(PlatformAppLoadAndLaunchBrowserTest, |
[email protected] | d99806e | 2013-02-19 10:21:30 | [diff] [blame] | 106 | MAYBE_LoadAndLaunchAppChromeNotRunning) { |
[email protected] | 9d02fa1 | 2013-02-19 05:12:57 | [diff] [blame] | 107 | LoadAndLaunchApp(); |
| 108 | } |
| 109 | |
[email protected] | 2a69b94 | 2013-05-31 09:37:53 | [diff] [blame^] | 110 | } // namespace apps |