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" | |
12 #include "base/test/test_timeouts.h" | 11 #include "base/test/test_timeouts.h" |
13 #include "chrome/browser/apps/app_browsertest_util.h" | 12 #include "chrome/browser/apps/app_browsertest_util.h" |
14 #include "chrome/browser/extensions/extension_browsertest.h" | 13 #include "chrome/browser/extensions/extension_browsertest.h" |
15 #include "chrome/browser/extensions/extension_error_reporter.h" | |
16 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
17 #include "chrome/browser/ui/simple_message_box_internal.h" | |
18 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
19 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
20 #include "content/public/test/test_launcher.h" | 17 #include "content/public/test/test_launcher.h" |
21 #include "extensions/browser/extension_registry.h" | |
22 #include "extensions/test/extension_test_message_listener.h" | 18 #include "extensions/test/extension_test_message_listener.h" |
23 | 19 |
24 using extensions::PlatformAppBrowserTest; | 20 using extensions::PlatformAppBrowserTest; |
25 | 21 |
26 namespace apps { | 22 namespace apps { |
27 | 23 |
28 namespace { | 24 namespace { |
29 | 25 |
30 const char* kSwitchesToCopy[] = { | 26 const char* kSwitchesToCopy[] = { |
31 switches::kUserDataDir, | 27 switches::kUserDataDir, |
32 switches::kNoSandbox, | 28 switches::kNoSandbox, |
33 }; | 29 }; |
34 | 30 |
35 static const std::string kTestExtensionId("behllobkkfkfnphdnhnkndlbkcpglgmj"); | |
36 | |
37 } // namespace | 31 } // namespace |
38 | 32 |
39 // TODO(jackhou): Enable this test once it works on OSX. It currently does not | 33 // TODO(jackhou): Enable this test once it works on OSX. It currently does not |
40 // work for the same reason --app-id doesn't. See http://crbug.com/148465 | 34 // work for the same reason --app-id doesn't. See http://crbug.com/148465 |
41 #if defined(OS_MACOSX) | 35 #if defined(OS_MACOSX) |
42 #define MAYBE_LoadAndLaunchAppChromeRunning \ | 36 #define MAYBE_LoadAndLaunchAppChromeRunning \ |
43 DISABLED_LoadAndLaunchAppChromeRunning | 37 DISABLED_LoadAndLaunchAppChromeRunning |
44 #else | 38 #else |
45 #define MAYBE_LoadAndLaunchAppChromeRunning LoadAndLaunchAppChromeRunning | 39 #define MAYBE_LoadAndLaunchAppChromeRunning LoadAndLaunchAppChromeRunning |
46 #endif | 40 #endif |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 105 |
112 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 106 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
113 int exit_code; | 107 int exit_code; |
114 ASSERT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_timeout(), | 108 ASSERT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_timeout(), |
115 &exit_code)); | 109 &exit_code)); |
116 ASSERT_EQ(0, exit_code); | 110 ASSERT_EQ(0, exit_code); |
117 } | 111 } |
118 | 112 |
119 namespace { | 113 namespace { |
120 | 114 |
121 // TestFixture that appends --load-and-launch-app with an app before calling | 115 // TestFixture that appends --load-and-launch-app before calling BrowserMain. |
122 // BrowserMain. | 116 class PlatformAppLoadAndLaunchBrowserTest : public PlatformAppBrowserTest { |
123 class LoadAndLaunchPlatformAppBrowserTest : public PlatformAppBrowserTest { | |
124 protected: | 117 protected: |
125 LoadAndLaunchPlatformAppBrowserTest() {} | 118 PlatformAppLoadAndLaunchBrowserTest() {} |
126 | 119 |
127 void SetUpCommandLine(base::CommandLine* command_line) override { | 120 void SetUpCommandLine(base::CommandLine* command_line) override { |
128 PlatformAppBrowserTest::SetUpCommandLine(command_line); | 121 PlatformAppBrowserTest::SetUpCommandLine(command_line); |
129 base::FilePath app_path = | 122 app_path_ = test_data_dir_ |
130 test_data_dir_.AppendASCII("platform_apps").AppendASCII("minimal"); | 123 .AppendASCII("platform_apps") |
131 command_line->AppendSwitchNative(apps::kLoadAndLaunchApp, app_path.value()); | 124 .AppendASCII("minimal"); |
| 125 command_line->AppendSwitchNative(apps::kLoadAndLaunchApp, |
| 126 app_path_.value()); |
132 } | 127 } |
133 | 128 |
134 void LoadAndLaunchApp() { | 129 void LoadAndLaunchApp() { |
135 ExtensionTestMessageListener launched_listener("Launched", false); | 130 ExtensionTestMessageListener launched_listener("Launched", false); |
136 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 131 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
137 | 132 |
138 // Start an actual browser because we can't shut down with just an app | 133 // Start an actual browser because we can't shut down with just an app |
139 // window. | 134 // window. |
140 CreateBrowser(ProfileManager::GetActiveUserProfile()); | 135 CreateBrowser(ProfileManager::GetActiveUserProfile()); |
141 } | 136 } |
142 | 137 |
143 private: | 138 private: |
144 DISALLOW_COPY_AND_ASSIGN(LoadAndLaunchPlatformAppBrowserTest); | 139 base::FilePath app_path_; |
145 }; | |
146 | 140 |
147 // TestFixture that appends --load-and-launch-app with an extension before | 141 DISALLOW_COPY_AND_ASSIGN(PlatformAppLoadAndLaunchBrowserTest); |
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); | |
170 }; | 142 }; |
171 | 143 |
172 } // namespace | 144 } // namespace |
173 | 145 |
174 | 146 |
175 // TODO(jackhou): Make this test not flaky on Vista or Linux Aura. See | 147 // TODO(jackhou): Make this test not flaky on Vista or Linux Aura. See |
176 // http://crbug.com/176897 | 148 // http://crbug.com/176897 |
177 #if defined(OS_WIN) || (defined(OS_LINUX) && defined(USE_AURA)) | 149 #if defined(OS_WIN) || (defined(OS_LINUX) && defined(USE_AURA)) |
178 #define MAYBE_LoadAndLaunchAppChromeNotRunning \ | 150 #define MAYBE_LoadAndLaunchAppChromeNotRunning \ |
179 DISABLED_LoadAndLaunchAppChromeNotRunning | 151 DISABLED_LoadAndLaunchAppChromeNotRunning |
180 #else | 152 #else |
181 #define MAYBE_LoadAndLaunchAppChromeNotRunning \ | 153 #define MAYBE_LoadAndLaunchAppChromeNotRunning \ |
182 LoadAndLaunchAppChromeNotRunning | 154 LoadAndLaunchAppChromeNotRunning |
183 #endif | 155 #endif |
184 | 156 |
185 // Case where Chrome is not running. | 157 // Case where Chrome is not running. |
186 IN_PROC_BROWSER_TEST_F(LoadAndLaunchPlatformAppBrowserTest, | 158 IN_PROC_BROWSER_TEST_F(PlatformAppLoadAndLaunchBrowserTest, |
187 MAYBE_LoadAndLaunchAppChromeNotRunning) { | 159 MAYBE_LoadAndLaunchAppChromeNotRunning) { |
188 LoadAndLaunchApp(); | 160 LoadAndLaunchApp(); |
189 } | 161 } |
190 | 162 |
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 | |
214 } // namespace apps | 163 } // namespace apps |
OLD | NEW |