Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(579)

Side by Side Diff: chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc

Issue 15732016: Remove tests for webstore bundle install feature (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include <vector> 5 #include <vector>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h" 11 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h"
12 #include "chrome/browser/extensions/bundle_installer.h"
13 #include "chrome/browser/extensions/extension_apitest.h" 12 #include "chrome/browser/extensions/extension_apitest.h"
14 #include "chrome/browser/extensions/extension_function_test_utils.h" 13 #include "chrome/browser/extensions/extension_function_test_utils.h"
15 #include "chrome/browser/extensions/extension_install_prompt.h" 14 #include "chrome/browser/extensions/extension_install_prompt.h"
16 #include "chrome/browser/extensions/extension_install_ui.h" 15 #include "chrome/browser/extensions/extension_install_ui.h"
17 #include "chrome/browser/extensions/extension_service.h" 16 #include "chrome/browser/extensions/extension_service.h"
18 #include "chrome/browser/extensions/webstore_installer.h" 17 #include "chrome/browser/extensions/webstore_installer.h"
19 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" 20 #include "chrome/browser/ui/tabs/tab_strip_model.h"
22 #include "chrome/common/chrome_notification_types.h" 21 #include "chrome/common/chrome_notification_types.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 return RunPageTest(page_url.spec()); 146 return RunPageTest(page_url.spec());
148 } 147 }
149 148
150 ExtensionService* service() { 149 ExtensionService* service() {
151 return browser()->profile()->GetExtensionService(); 150 return browser()->profile()->GetExtensionService();
152 } 151 }
153 152
154 base::ScopedTempDir tmp_; 153 base::ScopedTempDir tmp_;
155 }; 154 };
156 155
157 class ExtensionWebstorePrivateBundleTest
158 : public ExtensionWebstorePrivateApiTest {
159 public:
160 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
161 ExtensionWebstorePrivateApiTest::SetUpInProcessBrowserTestFixture();
162
163 // The test server needs to have already started, so setup the switch here
164 // rather than in SetUpCommandLine.
165 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
166 switches::kAppsGalleryDownloadURL,
167 GetTestServerURL("bundle/%s.crx").spec());
168 }
169
170 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE {
171 ExtensionWebstorePrivateApiTest::TearDownInProcessBrowserTestFixture();
172 for (size_t i = 0; i < test_crx_.size(); ++i)
173 ASSERT_TRUE(file_util::Delete(test_crx_[i], false));
174 }
175
176 protected:
177 // Packs the |manifest| file into a CRX using |id|'s PEM key.
178 void PackCRX(const std::string& id, const std::string& manifest) {
179 // Move the extension to a temporary directory.
180 base::ScopedTempDir tmp;
181 ASSERT_TRUE(tmp.CreateUniqueTempDir());
182 ASSERT_TRUE(file_util::CreateDirectory(tmp.path()));
183
184 base::FilePath tmp_manifest = tmp.path().AppendASCII("manifest.json");
185 base::FilePath data_path =
186 test_data_dir_.AppendASCII("webstore_private/bundle");
187 base::FilePath manifest_path = data_path.AppendASCII(manifest);
188
189 ASSERT_TRUE(file_util::PathExists(manifest_path));
190 ASSERT_TRUE(file_util::CopyFile(manifest_path, tmp_manifest));
191
192 PackCRX(id, tmp.path());
193 }
194
195 // Packs the extension at |ext_path| using |id|'s PEM key.
196 void PackCRX(const std::string& id, const base::FilePath& ext_path) {
197 base::FilePath data_path =
198 tmp_.path().AppendASCII("webstore_private/bundle");
199 base::FilePath pem_path = data_path.AppendASCII(id + ".pem");
200 base::FilePath crx_path = data_path.AppendASCII(id + ".crx");
201 base::FilePath destination = PackExtensionWithOptions(
202 ext_path, crx_path, pem_path, base::FilePath());
203
204 ASSERT_FALSE(destination.empty());
205 ASSERT_EQ(destination, crx_path);
206
207 test_crx_.push_back(destination);
208 }
209
210 // Creates an invalid CRX.
211 void PackInvalidCRX(const std::string& id) {
212 base::FilePath contents = test_data_dir_
213 .AppendASCII("webstore_private")
214 .AppendASCII("install_bundle_invalid.html");
215 base::FilePath crx_path = test_data_dir_
216 .AppendASCII("webstore_private/bundle")
217 .AppendASCII(id + ".crx");
218
219 ASSERT_TRUE(file_util::CopyFile(contents, crx_path));
220
221 test_crx_.push_back(crx_path);
222 }
223
224 private:
225 std::vector<base::FilePath> test_crx_;
226 };
227
228 class ExtensionWebstoreGetWebGLStatusTest : public InProcessBrowserTest {
229 public:
230 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
231 // We need to launch GPU process to decide if WebGL is allowed.
232 // Run it on top of osmesa to avoid bot driver issues.
233 #if !defined(OS_MACOSX)
234 CHECK(test_launcher_utils::OverrideGLImplementation(
235 command_line, gfx::kGLImplementationOSMesaName)) <<
236 "kUseGL must not be set multiple times!";
237 #endif
238 }
239
240 protected:
241 void RunTest(bool webgl_allowed) {
242 static const char kEmptyArgs[] = "[]";
243 static const char kWebGLStatusAllowed[] = "webgl_allowed";
244 static const char kWebGLStatusBlocked[] = "webgl_blocked";
245 scoped_refptr<GetWebGLStatusFunction> function =
246 new GetWebGLStatusFunction();
247 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
248 function.get(), kEmptyArgs, browser()));
249 ASSERT_TRUE(result);
250 EXPECT_EQ(base::Value::TYPE_STRING, result->GetType());
251 std::string webgl_status;
252 EXPECT_TRUE(result->GetAsString(&webgl_status));
253 EXPECT_STREQ(webgl_allowed ? kWebGLStatusAllowed : kWebGLStatusBlocked,
254 webgl_status.c_str());
255 }
256 };
257
258 // Test cases for webstore origin frame blocking. 156 // Test cases for webstore origin frame blocking.
259 // TODO(mkwst): Disabled until new X-Frame-Options behavior rolls into 157 // TODO(mkwst): Disabled until new X-Frame-Options behavior rolls into
260 // Chromium, see crbug.com/226018. 158 // Chromium, see crbug.com/226018.
261 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, 159 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
262 DISABLED_FrameWebstorePageBlocked) { 160 DISABLED_FrameWebstorePageBlocked) {
263 content::WebContents* contents = 161 content::WebContents* contents =
264 browser()->tab_strip_model()->GetActiveWebContents(); 162 browser()->tab_strip_model()->GetActiveWebContents();
265 string16 expected_title = UTF8ToUTF16("PASS: about:blank"); 163 string16 expected_title = UTF8ToUTF16("PASS: about:blank");
266 string16 failure_title = UTF8ToUTF16("FAIL"); 164 string16 failure_title = UTF8ToUTF16("FAIL");
267 content::TitleWatcher watcher(contents, expected_title); 165 content::TitleWatcher watcher(contents, expected_title);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 listener.Wait(); 289 listener.Wait();
392 ASSERT_TRUE(listener.received_success()); 290 ASSERT_TRUE(listener.received_success());
393 ASSERT_EQ("iamefpfkojoapidjnbafmgkgncegbkad", listener.id()); 291 ASSERT_EQ("iamefpfkojoapidjnbafmgkgncegbkad", listener.id());
394 } 292 }
395 293
396 // Tests that an error is properly reported when an empty crx is returned. 294 // Tests that an error is properly reported when an empty crx is returned.
397 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, EmptyCrx) { 295 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, EmptyCrx) {
398 ASSERT_TRUE(RunInstallTest("empty.html", "empty.crx")); 296 ASSERT_TRUE(RunInstallTest("empty.html", "empty.crx"));
399 } 297 }
400 298
401 // Tests successfully installing a bundle of 2 apps and 2 extensions. 299 class ExtensionWebstoreGetWebGLStatusTest : public InProcessBrowserTest {
402 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateBundleTest, InstallBundle) { 300 public:
403 extensions::BundleInstaller::SetAutoApproveForTesting(true); 301 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
302 // We need to launch GPU process to decide if WebGL is allowed.
303 // Run it on top of osmesa to avoid bot driver issues.
304 #if !defined(OS_MACOSX)
305 CHECK(test_launcher_utils::OverrideGLImplementation(
306 command_line, gfx::kGLImplementationOSMesaName)) <<
307 "kUseGL must not be set multiple times!";
308 #endif
309 }
404 310
405 PackCRX("bmfoocgfinpmkmlbjhcbofejhkhlbchk", "extension1.json"); 311 protected:
406 PackCRX("pkapffpjmiilhlhbibjhamlmdhfneidj", "extension2.json"); 312 void RunTest(bool webgl_allowed) {
407 PackCRX("begfmnajjkbjdgmffnjaojchoncnmngg", "app1.json"); 313 static const char kEmptyArgs[] = "[]";
408 PackCRX("mpneghmdnmaolkljkipbhaienajcflfe", "app2.json"); 314 static const char kWebGLStatusAllowed[] = "webgl_allowed";
409 315 static const char kWebGLStatusBlocked[] = "webgl_blocked";
410 ASSERT_TRUE(RunPageTest(GetTestServerURL("install_bundle.html").spec())); 316 scoped_refptr<GetWebGLStatusFunction> function =
411 } 317 new GetWebGLStatusFunction();
412 318 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
413 #if defined(OS_WIN) 319 function.get(), kEmptyArgs, browser()));
414 // Acting flakey in Windows. http://crbug.com/160219 320 ASSERT_TRUE(result);
415 #define MAYBE_InstallBundleIncognito DISABLED_InstallBundleIncognito 321 EXPECT_EQ(base::Value::TYPE_STRING, result->GetType());
416 #else 322 std::string webgl_status;
417 #define MAYBE_InstallBundleIncognito InstallBundleIncognito 323 EXPECT_TRUE(result->GetAsString(&webgl_status));
418 #endif 324 EXPECT_STREQ(webgl_allowed ? kWebGLStatusAllowed : kWebGLStatusBlocked,
419 325 webgl_status.c_str());
420 // Tests that bundles can be installed from incognito windows. 326 }
421 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateBundleTest, 327 };
422 MAYBE_InstallBundleIncognito) {
423 extensions::BundleInstaller::SetAutoApproveForTesting(true);
424
425 PackCRX("bmfoocgfinpmkmlbjhcbofejhkhlbchk", "extension1.json");
426 PackCRX("pkapffpjmiilhlhbibjhamlmdhfneidj", "extension2.json");
427 PackCRX("begfmnajjkbjdgmffnjaojchoncnmngg", "app1.json");
428 PackCRX("mpneghmdnmaolkljkipbhaienajcflfe", "app2.json");
429
430 ASSERT_TRUE(RunPageTest(GetTestServerURL("install_bundle.html").spec(),
431 ExtensionApiTest::kFlagUseIncognito));
432 }
433
434 // Tests the user canceling the bundle install prompt.
435 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateBundleTest,
436 InstallBundleCancel) {
437 // We don't need to create the CRX files since we are aborting the install.
438 extensions::BundleInstaller::SetAutoApproveForTesting(false);
439 ASSERT_TRUE(RunPageTest(GetTestServerURL(
440 "install_bundle_cancel.html").spec()));
441 }
442
443 // Tests partially installing a bundle (2 succeed, 1 fails due to an invalid
444 // CRX, and 1 fails due to the manifests not matching).
445 #if defined(OS_WIN)
446 // Times out on Windows. http://crbug.com/238805
447 #define MAYBE_InstallBundleInvalid DISABLED_InstallBundleInvalid
448 #else
449 #define MAYBE_InstallBundleInvalid InstallBundleInvalid
450 #endif
451 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateBundleTest,
452 MAYBE_InstallBundleInvalid) {
453 extensions::BundleInstaller::SetAutoApproveForTesting(true);
454
455 PackInvalidCRX("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
456 PackCRX("bmfoocgfinpmkmlbjhcbofejhkhlbchk", "extension1.json");
457 PackCRX("begfmnajjkbjdgmffnjaojchoncnmngg", "app1.json");
458
459 ASSERT_TRUE(RunPageTest(GetTestServerURL(
460 "install_bundle_invalid.html").spec()));
461
462 ASSERT_TRUE(service()->GetExtensionById(
463 "begfmnajjkbjdgmffnjaojchoncnmngg", false));
464 ASSERT_FALSE(service()->GetExtensionById(
465 "pkapffpjmiilhlhbibjhamlmdhfneidj", true));
466 ASSERT_FALSE(service()->GetExtensionById(
467 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", true));
468 ASSERT_FALSE(service()->GetExtensionById(
469 "bmfoocgfinpmkmlbjhcbofejhkhlbchk", true));
470 }
471 328
472 // Tests getWebGLStatus function when WebGL is allowed. 329 // Tests getWebGLStatus function when WebGL is allowed.
473 IN_PROC_BROWSER_TEST_F(ExtensionWebstoreGetWebGLStatusTest, Allowed) { 330 IN_PROC_BROWSER_TEST_F(ExtensionWebstoreGetWebGLStatusTest, Allowed) {
474 bool webgl_allowed = true; 331 bool webgl_allowed = true;
475 RunTest(webgl_allowed); 332 RunTest(webgl_allowed);
476 } 333 }
477 334
478 // Tests getWebGLStatus function when WebGL is blacklisted. 335 // Tests getWebGLStatus function when WebGL is blacklisted.
479 IN_PROC_BROWSER_TEST_F(ExtensionWebstoreGetWebGLStatusTest, Blocked) { 336 IN_PROC_BROWSER_TEST_F(ExtensionWebstoreGetWebGLStatusTest, Blocked) {
480 static const std::string json_blacklist = 337 static const std::string json_blacklist =
(...skipping 13 matching lines...) Expand all
494 content::GpuDataManager::GetInstance()->InitializeForTesting( 351 content::GpuDataManager::GetInstance()->InitializeForTesting(
495 json_blacklist, gpu_info); 352 json_blacklist, gpu_info);
496 EXPECT_TRUE(content::GpuDataManager::GetInstance()->IsFeatureBlacklisted( 353 EXPECT_TRUE(content::GpuDataManager::GetInstance()->IsFeatureBlacklisted(
497 gpu::GPU_FEATURE_TYPE_WEBGL)); 354 gpu::GPU_FEATURE_TYPE_WEBGL));
498 355
499 bool webgl_allowed = false; 356 bool webgl_allowed = false;
500 RunTest(webgl_allowed); 357 RunTest(webgl_allowed);
501 } 358 }
502 359
503 } // namespace extensions 360 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698