From 270eb8f84ec765617bab57c3af4c86763c3fc5a0 Mon Sep 17 00:00:00 2001 From: "cmasone@google.com" Date: Wed, 18 Aug 2010 15:47:50 +0000 Subject: [Chrome OS] Block the installation of extensions with NPAPI plugins BUG=chromium-os:5454 TEST=try to install http://www.3djam.com/roozz/roozz-plugin.crx, see that it is rejected. Try to install https://chrome.google.com/extensions/detail/gofhjkjmkpinhpoiabjplobcaignabnl, see that it works. And...unit tests Review URL: http://codereview.chromium.org/3163013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56529 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/extensions/extension_ui_unittest.cc | 2 + .../extensions/extensions_service_unittest.cc | 66 ++++++++++++++++++---- 2 files changed, 56 insertions(+), 12 deletions(-) (limited to 'chrome/browser/extensions') diff --git a/chrome/browser/extensions/extension_ui_unittest.cc b/chrome/browser/extensions/extension_ui_unittest.cc index 96af1c8..f4075b6 100644 --- a/chrome/browser/extensions/extension_ui_unittest.cc +++ b/chrome/browser/extensions/extension_ui_unittest.cc @@ -85,6 +85,7 @@ TEST(ExtensionUITest, GenerateExtensionsJSONData) { EXPECT_TRUE(CompareExpectedAndActualOutput(extension_path, pages, expected_output_path)) << extension_path.value(); +#if !defined(OS_CHROMEOS) // Test Extension2 extension_path = data_test_dir_path.AppendASCII("extensions") .AppendASCII("good") @@ -102,6 +103,7 @@ TEST(ExtensionUITest, GenerateExtensionsJSONData) { EXPECT_TRUE(CompareExpectedAndActualOutput(extension_path, pages, expected_output_path)) << extension_path.value(); +#endif // Test Extension3 extension_path = data_test_dir_path.AppendASCII("extensions") diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc index 1319da9..b8c176b 100644 --- a/chrome/browser/extensions/extensions_service_unittest.cc +++ b/chrome/browser/extensions/extensions_service_unittest.cc @@ -681,7 +681,13 @@ TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectorySuccess) { service_->Init(); loop_.RunAllPending(); - ASSERT_EQ(3u, loaded_.size()); + // On Chrome OS, we disallow extensions with plugins. "good1" has plugins, + // so we need to edit it out here. + uint32 expected_num_extensions = 3u; +#if defined(OS_CHROMEOS) + --expected_num_extensions; +#endif + ASSERT_EQ(expected_num_extensions, loaded_.size()); EXPECT_EQ(std::string(good0), loaded_[0]->id()); EXPECT_EQ(std::string("My extension 1"), @@ -690,7 +696,7 @@ TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectorySuccess) { loaded_[0]->description()); EXPECT_EQ(Extension::INTERNAL, loaded_[0]->location()); EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)); - EXPECT_EQ(3u, service_->extensions()->size()); + EXPECT_EQ(expected_num_extensions, service_->extensions()->size()); ValidatePrefKeyCount(3); ValidateIntegerPref(good0, "state", Extension::ENABLED); @@ -738,6 +744,7 @@ TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectorySuccess) { EXPECT_EQ("http://*.google.com/*", permissions[0].GetAsString()); EXPECT_EQ("https://*.google.com/*", permissions[1].GetAsString()); +#if !defined(OS_CHROMEOS) EXPECT_EQ(std::string(good1), loaded_[1]->id()); EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name()); EXPECT_EQ(std::string(""), loaded_[1]->description()); @@ -752,12 +759,14 @@ TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectorySuccess) { loaded_[1]->plugins()[1].path.value()); EXPECT_FALSE(loaded_[1]->plugins()[1].is_public); EXPECT_EQ(Extension::INTERNAL, loaded_[1]->location()); +#endif - EXPECT_EQ(std::string(good2), loaded_[2]->id()); - EXPECT_EQ(std::string("My extension 3"), loaded_[2]->name()); - EXPECT_EQ(std::string(""), loaded_[2]->description()); - EXPECT_EQ(0u, loaded_[2]->content_scripts().size()); - EXPECT_EQ(Extension::INTERNAL, loaded_[2]->location()); + int index = expected_num_extensions - 1; + EXPECT_EQ(std::string(good2), loaded_[index]->id()); + EXPECT_EQ(std::string("My extension 3"), loaded_[index]->name()); + EXPECT_EQ(std::string(""), loaded_[index]->description()); + EXPECT_EQ(0u, loaded_[index]->content_scripts().size()); + EXPECT_EQ(Extension::INTERNAL, loaded_[index]->location()); }; // Test loading bad extensions from the profile directory. @@ -1677,15 +1686,47 @@ TEST_F(ExtensionsServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) { .AppendASCII("Preferences"); InitializeInstalledExtensionsService(pref_path, source_install_dir); - // Blacklist good0. + // Blacklist good1. std::vector blacklist; - blacklist.push_back(good0); + blacklist.push_back(good1); service_->UpdateExtensionBlacklist(blacklist); // Make sure pref is updated loop_.RunAllPending(); - ValidateBooleanPref(good0, "blacklist", true); + ValidateBooleanPref(good1, "blacklist", true); + + // Load extensions. + service_->Init(); + loop_.RunAllPending(); + + std::vector errors = GetErrors(); + for (std::vector::iterator err = errors.begin(); + err != errors.end(); ++err) { + LOG(ERROR) << *err; + } + ASSERT_EQ(2u, loaded_.size()); + + EXPECT_NE(std::string(good1), loaded_[0]->id()); + EXPECT_NE(std::string(good1), loaded_[1]->id()); +} +#if defined(OS_CHROMEOS) +// Test loading extensions from the profile directory, except +// ones with a plugin. +TEST_F(ExtensionsServiceTest, WillNotLoadPluginExtensionsFromDirectory) { + // Initialize the test dir with a good Preferences/extensions. + FilePath source_install_dir; + ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_install_dir)); + source_install_dir = source_install_dir + .AppendASCII("extensions") + .AppendASCII("good") + .AppendASCII("Extensions"); + FilePath pref_path = source_install_dir + .DirName() + .AppendASCII("Preferences"); + InitializeInstalledExtensionsService(pref_path, source_install_dir); + + // good1 contains a plugin. // Load extensions. service_->Init(); loop_.RunAllPending(); @@ -1697,9 +1738,10 @@ TEST_F(ExtensionsServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) { } ASSERT_EQ(2u, loaded_.size()); - EXPECT_NE(std::string(good0), loaded_[0]->id()); - EXPECT_NE(std::string(good0), loaded_[1]->id()); + EXPECT_NE(std::string(good1), loaded_[0]->id()); + EXPECT_NE(std::string(good1), loaded_[1]->id()); } +#endif // Will not install extension blacklisted by policy. TEST_F(ExtensionsServiceTest, BlacklistedByPolicyWillNotInstall) { -- cgit v1.1