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

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

Issue 855513002: Add/resurrect support for bundles of WebStore items. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@testext_bundle
Patch Set: cleanup;rebase Created 5 years, 9 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
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/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h" 12 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h"
13 #include "chrome/browser/extensions/bundle_installer.h"
13 #include "chrome/browser/extensions/extension_apitest.h" 14 #include "chrome/browser/extensions/extension_apitest.h"
14 #include "chrome/browser/extensions/extension_function_test_utils.h" 15 #include "chrome/browser/extensions/extension_function_test_utils.h"
15 #include "chrome/browser/extensions/extension_install_prompt.h" 16 #include "chrome/browser/extensions/extension_install_prompt.h"
16 #include "chrome/browser/extensions/extension_service.h" 17 #include "chrome/browser/extensions/extension_service.h"
17 #include "chrome/browser/extensions/webstore_installer.h" 18 #include "chrome/browser/extensions/webstore_installer.h"
18 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/tabs/tab_strip_model.h" 21 #include "chrome/browser/ui/tabs/tab_strip_model.h"
21 #include "chrome/common/chrome_switches.h" 22 #include "chrome/common/chrome_switches.h"
22 #include "chrome/test/base/ui_test_utils.h" 23 #include "chrome/test/base/ui_test_utils.h"
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 428
428 // Run tests when the --enable-ephemeral-apps switch is enabled. 429 // Run tests when the --enable-ephemeral-apps switch is enabled.
429 IN_PROC_BROWSER_TEST_F(EphemeralAppWebstorePrivateApiTest, LaunchEphemeralApp) { 430 IN_PROC_BROWSER_TEST_F(EphemeralAppWebstorePrivateApiTest, LaunchEphemeralApp) {
430 base::CommandLine::ForCurrentProcess()->AppendSwitch( 431 base::CommandLine::ForCurrentProcess()->AppendSwitch(
431 switches::kEnableEphemeralAppsInWebstore); 432 switches::kEnableEphemeralAppsInWebstore);
432 base::CommandLine::ForCurrentProcess()->AppendSwitch( 433 base::CommandLine::ForCurrentProcess()->AppendSwitch(
433 app_list::switches::kEnableExperimentalAppList); 434 app_list::switches::kEnableExperimentalAppList);
434 ASSERT_TRUE(RunInstallTest("webstore_launch_app.html", "app.crx")); 435 ASSERT_TRUE(RunInstallTest("webstore_launch_app.html", "app.crx"));
435 } 436 }
436 437
438 class BundleWebstorePrivateApiTest
439 : public ExtensionWebstorePrivateApiTest {
440 public:
441 void SetUpInProcessBrowserTestFixture() override {
442 ExtensionWebstorePrivateApiTest::SetUpInProcessBrowserTestFixture();
443
444 // The test server needs to have already started, so setup the switch here
445 // rather than in SetUpCommandLine.
446 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
447 switches::kAppsGalleryDownloadURL,
448 GetTestServerURL("bundle/%s.crx").spec());
449 }
450
451 void TearDownInProcessBrowserTestFixture() override {
452 ExtensionWebstorePrivateApiTest::TearDownInProcessBrowserTestFixture();
453 for (size_t i = 0; i < test_crx_.size(); ++i)
454 ASSERT_TRUE(base::DeleteFile(test_crx_[i], false));
455 }
456
457 protected:
458 // Packs the |manifest| file into a CRX using |id|'s PEM key.
459 void PackCRX(const std::string& id, const std::string& manifest) {
460 // Move the extension to a temporary directory.
461 base::ScopedTempDir tmp;
462 ASSERT_TRUE(tmp.CreateUniqueTempDir());
463
464 base::FilePath tmp_manifest = tmp.path().AppendASCII("manifest.json");
465 base::FilePath data_path =
466 test_data_dir_.AppendASCII("webstore_private/bundle");
467 base::FilePath manifest_path = data_path.AppendASCII(manifest);
468
469 ASSERT_TRUE(base::PathExists(manifest_path));
470 ASSERT_TRUE(base::CopyFile(manifest_path, tmp_manifest));
471
472 PackCRX(id, tmp.path());
473 }
474
475 // Packs the extension at |ext_path| using |id|'s PEM key.
476 void PackCRX(const std::string& id, const base::FilePath& ext_path) {
477 base::FilePath data_path =
478 test_data_dir_.AppendASCII("webstore_private/bundle");
479 base::FilePath pem_path = data_path.AppendASCII(id + ".pem");
480 base::FilePath crx_path = data_path.AppendASCII(id + ".crx");
481 base::FilePath destination = PackExtensionWithOptions(
482 ext_path, crx_path, pem_path, base::FilePath());
483
484 ASSERT_FALSE(destination.empty());
485 ASSERT_EQ(destination, crx_path);
486
487 test_crx_.push_back(destination);
488 }
489
490 // Creates an invalid CRX.
491 void PackInvalidCRX(const std::string& id) {
492 base::FilePath contents = test_data_dir_
493 .AppendASCII("webstore_private")
494 .AppendASCII("install_bundle_invalid.html");
495 base::FilePath crx_path = test_data_dir_
496 .AppendASCII("webstore_private/bundle")
497 .AppendASCII(id + ".crx");
498
499 ASSERT_TRUE(base::CopyFile(contents, crx_path));
500
501 test_crx_.push_back(crx_path);
502 }
503
504 private:
505 std::vector<base::FilePath> test_crx_;
506 };
507
508 // Tests successfully installing a bundle of 2 apps and 2 extensions.
509 IN_PROC_BROWSER_TEST_F(BundleWebstorePrivateApiTest, InstallBundle) {
510 extensions::BundleInstaller::SetAutoApproveForTesting(true);
511
512 PackCRX("begfmnajjkbjdgmffnjaojchoncnmngg", "app1.json");
513 PackCRX("mpneghmdnmaolkljkipbhaienajcflfe", "app2.json");
514 PackCRX("bmfoocgfinpmkmlbjhcbofejhkhlbchk", "extension1.json");
515 PackCRX("pkapffpjmiilhlhbibjhamlmdhfneidj", "extension2.json");
516
517 ASSERT_TRUE(RunPageTest(GetTestServerURL("install_bundle.html").spec()));
518 }
519
520 // Tests that bundles can be installed from incognito windows.
521 IN_PROC_BROWSER_TEST_F(BundleWebstorePrivateApiTest, InstallBundleIncognito) {
522 extensions::BundleInstaller::SetAutoApproveForTesting(true);
523
524 PackCRX("begfmnajjkbjdgmffnjaojchoncnmngg", "app1.json");
525 PackCRX("mpneghmdnmaolkljkipbhaienajcflfe", "app2.json");
526 PackCRX("bmfoocgfinpmkmlbjhcbofejhkhlbchk", "extension1.json");
527 PackCRX("pkapffpjmiilhlhbibjhamlmdhfneidj", "extension2.json");
528
529 ASSERT_TRUE(RunPageTest(GetTestServerURL("install_bundle.html").spec(),
530 ExtensionApiTest::kFlagUseIncognito));
531 }
532
533 // Tests the user canceling the bundle install prompt.
534 IN_PROC_BROWSER_TEST_F(BundleWebstorePrivateApiTest, InstallBundleCancel) {
535 // We don't need to create the CRX files since we are aborting the install.
536 extensions::BundleInstaller::SetAutoApproveForTesting(false);
537
538 ASSERT_TRUE(
539 RunPageTest(GetTestServerURL("install_bundle_cancel.html").spec()));
540 }
541
542 // Tests partially installing a bundle (1 succeeds, 1 fails due to an invalid
543 // CRX, 1 fails due to the manifests not matching, and 1 fails due to a missing
544 // crx file).
545 IN_PROC_BROWSER_TEST_F(BundleWebstorePrivateApiTest, InstallBundleInvalid) {
546 extensions::BundleInstaller::SetAutoApproveForTesting(true);
547
548 PackCRX("begfmnajjkbjdgmffnjaojchoncnmngg", "app1.json");
549 PackInvalidCRX("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
550 PackCRX("bmfoocgfinpmkmlbjhcbofejhkhlbchk", "extension1.json");
551 // Extension2 is missing the crx file.
552
553 ASSERT_TRUE(
554 RunPageTest(GetTestServerURL("install_bundle_invalid.html").spec()));
555 }
556
437 } // namespace extensions 557 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698