diff options
author | cmasone@google.com <cmasone@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-18 21:05:24 +0000 |
---|---|---|
committer | cmasone@google.com <cmasone@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-18 21:05:24 +0000 |
commit | e50013c3d749c3de25eba0ec414416ed05ab7907 (patch) | |
tree | 7db51de713712c9d7262482cd350113f9f25e17c /chrome/browser | |
parent | e57d57b67290c8dfd701ac5021264a9ae1588b81 (diff) | |
download | chromium_src-e50013c3d749c3de25eba0ec414416ed05ab7907.zip chromium_src-e50013c3d749c3de25eba0ec414416ed05ab7907.tar.gz chromium_src-e50013c3d749c3de25eba0ec414416ed05ab7907.tar.bz2 |
Re-land r56529, and add fixes for the browser tests on chromium os.
Add fixes for browser tests broken by r56529
Revert "Revert 56529 - [Chrome OS] Block the installation of extensions with NPAPI plugins"
BUG=chromium-os:5454
TEST=browser tests, unit tests
This reverts commit 8e3ffd2dab317dd7fb2d501353153d3e4dcc1c90.
Review URL: http://codereview.chromium.org/3164026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56601 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
4 files changed, 74 insertions, 14 deletions
diff --git a/chrome/browser/extensions/extension_startup_browsertest.cc b/chrome/browser/extensions/extension_startup_browsertest.cc index 165054d..9ca4d081 100644 --- a/chrome/browser/extensions/extension_startup_browsertest.cc +++ b/chrome/browser/extensions/extension_startup_browsertest.cc @@ -31,6 +31,11 @@ class ExtensionStartupTestBase : public InProcessBrowserTest { public: ExtensionStartupTestBase() : enable_extensions_(false) { +#if defined(OS_CHROMEOS) + num_expected_extensions_ = 3; +#else + num_expected_extensions_ = 4; +#endif } protected: @@ -124,6 +129,8 @@ class ExtensionStartupTestBase : public InProcessBrowserTest { FilePath user_scripts_dir_; bool enable_extensions_; FilePath load_extension_; + + int num_expected_extensions_; }; @@ -139,7 +146,8 @@ class ExtensionsStartupTest : public ExtensionStartupTestBase { }; IN_PROC_BROWSER_TEST_F(ExtensionsStartupTest, Test) { - WaitForServicesToStart(4, true); // 1 component extension and 3 others. + // 1 component extension and 2 or 3 others, depending on the platform. + WaitForServicesToStart(num_expected_extensions_, true); TestInjection(true, true); } @@ -152,7 +160,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionsStartupTest, Test) { // Tests that disallowing file access on an extension prevents it from injecting // script into a page with a file URL. IN_PROC_BROWSER_TEST_F(ExtensionsStartupTest, MAYBE_NoFileAccess) { - WaitForServicesToStart(4, true); // 1 component extension and 3 others. + // 1 component extension and 2 or 3 others, depending on the platform. + WaitForServicesToStart(num_expected_extensions_, true); ExtensionsService* service = browser()->profile()->GetExtensionsService(); for (size_t i = 0; i < service->extensions()->size(); ++i) { 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<std::string> 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<std::string> errors = GetErrors(); + for (std::vector<std::string>::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) { diff --git a/chrome/browser/sync/glue/extension_util_unittest.cc b/chrome/browser/sync/glue/extension_util_unittest.cc index ba87b8d..6a3aacc 100644 --- a/chrome/browser/sync/glue/extension_util_unittest.cc +++ b/chrome/browser/sync/glue/extension_util_unittest.cc @@ -66,7 +66,14 @@ void MakeExtension(bool is_theme, const GURL& update_url, } source.Set(extension_manifest_keys::kPlugins, plugins); } + std::string error; +#if defined(OS_CHROMEOS) + if (num_plugins > 0) { // plugins are illegal in extensions on chrome os. + EXPECT_FALSE(extension->InitFromValue(source, false, &error)); + return; + } +#endif EXPECT_TRUE(extension->InitFromValue(source, false, &error)); EXPECT_EQ("", error); extension->set_location(location); |