Index: chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc |
diff --git a/chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc b/chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc |
index fe9b64466c3eb3d49bb041a9638ccd8157d787cc..19bdfed8c2364ad4706b7e3f6ebcf1c5f96b467f 100644 |
--- a/chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc |
+++ b/chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc |
@@ -10,6 +10,7 @@ |
#include "base/strings/utf_string_conversions.h" |
#include "chrome/browser/chrome_notification_types.h" |
#include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h" |
+#include "chrome/browser/extensions/bundle_installer.h" |
#include "chrome/browser/extensions/extension_apitest.h" |
#include "chrome/browser/extensions/extension_function_test_utils.h" |
#include "chrome/browser/extensions/extension_install_prompt.h" |
@@ -434,4 +435,123 @@ IN_PROC_BROWSER_TEST_F(EphemeralAppWebstorePrivateApiTest, LaunchEphemeralApp) { |
ASSERT_TRUE(RunInstallTest("webstore_launch_app.html", "app.crx")); |
} |
+class BundleWebstorePrivateApiTest |
+ : public ExtensionWebstorePrivateApiTest { |
+ public: |
+ void SetUpInProcessBrowserTestFixture() override { |
+ ExtensionWebstorePrivateApiTest::SetUpInProcessBrowserTestFixture(); |
+ |
+ // The test server needs to have already started, so setup the switch here |
+ // rather than in SetUpCommandLine. |
+ base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
+ switches::kAppsGalleryDownloadURL, |
+ GetTestServerURL("bundle/%s.crx").spec()); |
+ } |
+ |
+ void TearDownInProcessBrowserTestFixture() override { |
+ ExtensionWebstorePrivateApiTest::TearDownInProcessBrowserTestFixture(); |
+ for (size_t i = 0; i < test_crx_.size(); ++i) |
+ ASSERT_TRUE(base::DeleteFile(test_crx_[i], false)); |
asargent_no_longer_on_chrome
2015/03/26 18:12:50
nit: instead of creating the |test_crx_| files in
Marc Treib
2015/03/27 11:52:12
I've switched to using a ScopedTempDir, so now I d
asargent_no_longer_on_chrome
2015/03/27 23:38:27
Hmm, stepping back for a moment, do you really nee
Marc Treib
2015/03/30 08:52:17
Yep, done!
|
+ } |
+ |
+ protected: |
+ // Packs the |manifest| file into a CRX using |id|'s PEM key. |
+ void PackCRX(const std::string& id, const std::string& manifest) { |
+ // Move the extension to a temporary directory. |
+ base::ScopedTempDir tmp; |
+ ASSERT_TRUE(tmp.CreateUniqueTempDir()); |
+ |
+ base::FilePath tmp_manifest = tmp.path().AppendASCII("manifest.json"); |
+ base::FilePath data_path = |
+ test_data_dir_.AppendASCII("webstore_private/bundle"); |
+ base::FilePath manifest_path = data_path.AppendASCII(manifest); |
+ |
+ ASSERT_TRUE(base::PathExists(manifest_path)); |
+ ASSERT_TRUE(base::CopyFile(manifest_path, tmp_manifest)); |
+ |
+ PackCRX(id, tmp.path()); |
+ } |
+ |
+ // Packs the extension at |ext_path| using |id|'s PEM key. |
+ void PackCRX(const std::string& id, const base::FilePath& ext_path) { |
+ base::FilePath data_path = |
+ test_data_dir_.AppendASCII("webstore_private/bundle"); |
+ base::FilePath pem_path = data_path.AppendASCII(id + ".pem"); |
+ base::FilePath crx_path = data_path.AppendASCII(id + ".crx"); |
+ base::FilePath destination = PackExtensionWithOptions( |
+ ext_path, crx_path, pem_path, base::FilePath()); |
+ |
+ ASSERT_FALSE(destination.empty()); |
+ ASSERT_EQ(destination, crx_path); |
+ |
+ test_crx_.push_back(destination); |
+ } |
+ |
+ // Creates an invalid CRX. |
+ void PackInvalidCRX(const std::string& id) { |
+ base::FilePath contents = test_data_dir_ |
+ .AppendASCII("webstore_private") |
+ .AppendASCII("install_bundle_invalid.html"); |
+ base::FilePath crx_path = test_data_dir_ |
+ .AppendASCII("webstore_private/bundle") |
+ .AppendASCII(id + ".crx"); |
+ |
+ ASSERT_TRUE(base::CopyFile(contents, crx_path)); |
+ |
+ test_crx_.push_back(crx_path); |
+ } |
+ |
+ private: |
+ std::vector<base::FilePath> test_crx_; |
+}; |
+ |
+// Tests successfully installing a bundle of 2 apps and 2 extensions. |
+IN_PROC_BROWSER_TEST_F(BundleWebstorePrivateApiTest, InstallBundle) { |
+ extensions::BundleInstaller::SetAutoApproveForTesting(true); |
+ |
+ PackCRX("begfmnajjkbjdgmffnjaojchoncnmngg", "app1.json"); |
+ PackCRX("mpneghmdnmaolkljkipbhaienajcflfe", "app2.json"); |
+ PackCRX("bmfoocgfinpmkmlbjhcbofejhkhlbchk", "extension1.json"); |
+ PackCRX("pkapffpjmiilhlhbibjhamlmdhfneidj", "extension2.json"); |
+ |
+ ASSERT_TRUE(RunPageTest(GetTestServerURL("install_bundle.html").spec())); |
+} |
+ |
+// Tests that bundles can be installed from incognito windows. |
+IN_PROC_BROWSER_TEST_F(BundleWebstorePrivateApiTest, InstallBundleIncognito) { |
+ extensions::BundleInstaller::SetAutoApproveForTesting(true); |
+ |
+ PackCRX("begfmnajjkbjdgmffnjaojchoncnmngg", "app1.json"); |
+ PackCRX("mpneghmdnmaolkljkipbhaienajcflfe", "app2.json"); |
+ PackCRX("bmfoocgfinpmkmlbjhcbofejhkhlbchk", "extension1.json"); |
+ PackCRX("pkapffpjmiilhlhbibjhamlmdhfneidj", "extension2.json"); |
+ |
+ ASSERT_TRUE(RunPageTest(GetTestServerURL("install_bundle.html").spec(), |
+ ExtensionApiTest::kFlagUseIncognito)); |
+} |
+ |
+// Tests the user canceling the bundle install prompt. |
+IN_PROC_BROWSER_TEST_F(BundleWebstorePrivateApiTest, InstallBundleCancel) { |
+ // We don't need to create the CRX files since we are aborting the install. |
+ extensions::BundleInstaller::SetAutoApproveForTesting(false); |
+ |
+ ASSERT_TRUE( |
+ RunPageTest(GetTestServerURL("install_bundle_cancel.html").spec())); |
+} |
+ |
+// Tests partially installing a bundle (1 succeeds, 1 fails due to an invalid |
+// CRX, 1 fails due to the manifests not matching, and 1 fails due to a missing |
+// crx file). |
+IN_PROC_BROWSER_TEST_F(BundleWebstorePrivateApiTest, InstallBundleInvalid) { |
+ extensions::BundleInstaller::SetAutoApproveForTesting(true); |
+ |
+ PackCRX("begfmnajjkbjdgmffnjaojchoncnmngg", "app1.json"); |
+ PackInvalidCRX("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); |
+ PackCRX("bmfoocgfinpmkmlbjhcbofejhkhlbchk", "extension1.json"); |
+ // Extension2 is missing the crx file. |
+ |
+ ASSERT_TRUE( |
+ RunPageTest(GetTestServerURL("install_bundle_invalid.html").spec())); |
+} |
+ |
} // namespace extensions |