OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Tests for the --load-and-launch-app switch. | 5 // Tests for the --load-and-launch-app switch. |
6 // The two cases are when chrome is running and another process uses the switch | 6 // The two cases are when chrome is running and another process uses the switch |
7 // and when chrome is started from scratch. | 7 // and when chrome is started from scratch. |
8 | 8 |
9 #include "apps/switches.h" | 9 #include "apps/switches.h" |
10 #include "base/process/launch.h" | 10 #include "base/process/launch.h" |
| 11 #include "base/strings/utf_string_conversions.h" |
11 #include "base/test/test_timeouts.h" | 12 #include "base/test/test_timeouts.h" |
12 #include "chrome/browser/apps/app_browsertest_util.h" | 13 #include "chrome/browser/apps/app_browsertest_util.h" |
13 #include "chrome/browser/extensions/extension_browsertest.h" | 14 #include "chrome/browser/extensions/extension_browsertest.h" |
| 15 #include "chrome/browser/extensions/extension_error_reporter.h" |
14 #include "chrome/browser/profiles/profile_manager.h" | 16 #include "chrome/browser/profiles/profile_manager.h" |
| 17 #include "chrome/browser/ui/simple_message_box_internal.h" |
15 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
16 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
17 #include "content/public/test/test_launcher.h" | 20 #include "content/public/test/test_launcher.h" |
| 21 #include "extensions/browser/extension_registry.h" |
18 #include "extensions/test/extension_test_message_listener.h" | 22 #include "extensions/test/extension_test_message_listener.h" |
19 | 23 |
20 using extensions::PlatformAppBrowserTest; | 24 using extensions::PlatformAppBrowserTest; |
21 | 25 |
22 namespace apps { | 26 namespace apps { |
23 | 27 |
24 namespace { | 28 namespace { |
25 | 29 |
26 const char* kSwitchesToCopy[] = { | 30 const char* kSwitchesToCopy[] = { |
27 switches::kUserDataDir, | 31 switches::kUserDataDir, |
28 switches::kNoSandbox, | 32 switches::kNoSandbox, |
29 }; | 33 }; |
30 | 34 |
| 35 static const std::string kTestExtensionId("behllobkkfkfnphdnhnkndlbkcpglgmj"); |
| 36 |
31 } // namespace | 37 } // namespace |
32 | 38 |
33 // TODO(jackhou): Enable this test once it works on OSX. It currently does not | 39 // 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 | 40 // work for the same reason --app-id doesn't. See http://crbug.com/148465 |
35 #if defined(OS_MACOSX) | 41 #if defined(OS_MACOSX) |
36 #define MAYBE_LoadAndLaunchAppChromeRunning \ | 42 #define MAYBE_LoadAndLaunchAppChromeRunning \ |
37 DISABLED_LoadAndLaunchAppChromeRunning | 43 DISABLED_LoadAndLaunchAppChromeRunning |
38 #else | 44 #else |
39 #define MAYBE_LoadAndLaunchAppChromeRunning LoadAndLaunchAppChromeRunning | 45 #define MAYBE_LoadAndLaunchAppChromeRunning LoadAndLaunchAppChromeRunning |
40 #endif | 46 #endif |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 111 |
106 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 112 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
107 int exit_code; | 113 int exit_code; |
108 ASSERT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_timeout(), | 114 ASSERT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_timeout(), |
109 &exit_code)); | 115 &exit_code)); |
110 ASSERT_EQ(0, exit_code); | 116 ASSERT_EQ(0, exit_code); |
111 } | 117 } |
112 | 118 |
113 namespace { | 119 namespace { |
114 | 120 |
115 // TestFixture that appends --load-and-launch-app before calling BrowserMain. | 121 // TestFixture that appends --load-and-launch-app with an app before calling |
116 class PlatformAppLoadAndLaunchBrowserTest : public PlatformAppBrowserTest { | 122 // BrowserMain. |
| 123 class LoadAndLaunchPlatformAppBrowserTest : public PlatformAppBrowserTest { |
117 protected: | 124 protected: |
118 PlatformAppLoadAndLaunchBrowserTest() {} | 125 LoadAndLaunchPlatformAppBrowserTest() {} |
119 | 126 |
120 void SetUpCommandLine(base::CommandLine* command_line) override { | 127 void SetUpCommandLine(base::CommandLine* command_line) override { |
121 PlatformAppBrowserTest::SetUpCommandLine(command_line); | 128 PlatformAppBrowserTest::SetUpCommandLine(command_line); |
122 app_path_ = test_data_dir_ | 129 base::FilePath app_path = |
123 .AppendASCII("platform_apps") | 130 test_data_dir_.AppendASCII("platform_apps").AppendASCII("minimal"); |
124 .AppendASCII("minimal"); | 131 command_line->AppendSwitchNative(apps::kLoadAndLaunchApp, app_path.value()); |
125 command_line->AppendSwitchNative(apps::kLoadAndLaunchApp, | |
126 app_path_.value()); | |
127 } | 132 } |
128 | 133 |
129 void LoadAndLaunchApp() { | 134 void LoadAndLaunchApp() { |
130 ExtensionTestMessageListener launched_listener("Launched", false); | 135 ExtensionTestMessageListener launched_listener("Launched", false); |
131 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 136 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
132 | 137 |
133 // Start an actual browser because we can't shut down with just an app | 138 // Start an actual browser because we can't shut down with just an app |
134 // window. | 139 // window. |
135 CreateBrowser(ProfileManager::GetActiveUserProfile()); | 140 CreateBrowser(ProfileManager::GetActiveUserProfile()); |
136 } | 141 } |
137 | 142 |
138 private: | 143 private: |
139 base::FilePath app_path_; | 144 DISALLOW_COPY_AND_ASSIGN(LoadAndLaunchPlatformAppBrowserTest); |
| 145 }; |
140 | 146 |
141 DISALLOW_COPY_AND_ASSIGN(PlatformAppLoadAndLaunchBrowserTest); | 147 // TestFixture that appends --load-and-launch-app with an extension before |
| 148 // calling BrowserMain. |
| 149 class LoadAndLaunchExtensionBrowserTest : public PlatformAppBrowserTest { |
| 150 protected: |
| 151 LoadAndLaunchExtensionBrowserTest() {} |
| 152 |
| 153 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 154 PlatformAppBrowserTest::SetUpCommandLine(command_line); |
| 155 base::FilePath app_path = test_data_dir_.AppendASCII("good") |
| 156 .AppendASCII("Extensions") |
| 157 .AppendASCII(kTestExtensionId) |
| 158 .AppendASCII("1.0.0.0"); |
| 159 command_line->AppendSwitchNative(apps::kLoadAndLaunchApp, app_path.value()); |
| 160 } |
| 161 |
| 162 void SetUpInProcessBrowserTestFixture() override { |
| 163 PlatformAppBrowserTest::SetUpInProcessBrowserTestFixture(); |
| 164 |
| 165 // Skip showing the error message box to avoid freezing the main thread. |
| 166 chrome::internal::g_should_skip_message_box_for_test = true; |
| 167 } |
| 168 |
| 169 DISALLOW_COPY_AND_ASSIGN(LoadAndLaunchExtensionBrowserTest); |
142 }; | 170 }; |
143 | 171 |
144 } // namespace | 172 } // namespace |
145 | 173 |
146 | 174 |
147 // TODO(jackhou): Make this test not flaky on Vista or Linux Aura. See | 175 // TODO(jackhou): Make this test not flaky on Vista or Linux Aura. See |
148 // http://crbug.com/176897 | 176 // http://crbug.com/176897 |
149 #if defined(OS_WIN) || (defined(OS_LINUX) && defined(USE_AURA)) | 177 #if defined(OS_WIN) || (defined(OS_LINUX) && defined(USE_AURA)) |
150 #define MAYBE_LoadAndLaunchAppChromeNotRunning \ | 178 #define MAYBE_LoadAndLaunchAppChromeNotRunning \ |
151 DISABLED_LoadAndLaunchAppChromeNotRunning | 179 DISABLED_LoadAndLaunchAppChromeNotRunning |
152 #else | 180 #else |
153 #define MAYBE_LoadAndLaunchAppChromeNotRunning \ | 181 #define MAYBE_LoadAndLaunchAppChromeNotRunning \ |
154 LoadAndLaunchAppChromeNotRunning | 182 LoadAndLaunchAppChromeNotRunning |
155 #endif | 183 #endif |
156 | 184 |
157 // Case where Chrome is not running. | 185 // Case where Chrome is not running. |
158 IN_PROC_BROWSER_TEST_F(PlatformAppLoadAndLaunchBrowserTest, | 186 IN_PROC_BROWSER_TEST_F(LoadAndLaunchPlatformAppBrowserTest, |
159 MAYBE_LoadAndLaunchAppChromeNotRunning) { | 187 MAYBE_LoadAndLaunchAppChromeNotRunning) { |
160 LoadAndLaunchApp(); | 188 LoadAndLaunchApp(); |
161 } | 189 } |
162 | 190 |
| 191 IN_PROC_BROWSER_TEST_F(LoadAndLaunchExtensionBrowserTest, |
| 192 LoadAndLaunchExtension) { |
| 193 const std::vector<base::string16>* errors = |
| 194 ExtensionErrorReporter::GetInstance()->GetErrors(); |
| 195 |
| 196 #if defined(GOOGLE_CHROME_BUILD) |
| 197 // The error is skipped on official builds. |
| 198 EXPECT_TRUE(errors->empty()); |
| 199 #else |
| 200 // Expect kUnpackedExtensionInsteadOfAppError. |
| 201 EXPECT_EQ(1u, errors->size()); |
| 202 EXPECT_NE(base::string16::npos, |
| 203 errors->at(0).find(base::ASCIIToUTF16( |
| 204 "App loading flags cannot be used to load extensions"))); |
| 205 #endif |
| 206 |
| 207 extensions::ExtensionRegistry* registry = |
| 208 extensions::ExtensionRegistry::Get(profile()); |
| 209 EXPECT_EQ(nullptr, |
| 210 registry->GetExtensionById( |
| 211 kTestExtensionId, extensions::ExtensionRegistry::EVERYTHING)); |
| 212 } |
| 213 |
163 } // namespace apps | 214 } // namespace apps |
OLD | NEW |