From 24e7a9d2b4d7925ca25d2cdf75808d3ff88b5f6e Mon Sep 17 00:00:00 2001 From: "phajdan.jr@chromium.org" Date: Wed, 4 Nov 2009 11:11:34 +0000 Subject: Implement loading blacklists from extensions. It doesn't yet work in full-browser scenario, but allows me to write a simple test. TEST=Covered by browser_tests. BUG=21541 Review URL: http://codereview.chromium.org/341050 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30952 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/browser.cc | 5 +- .../extension_disabled_infobar_delegate.cc | 4 +- chrome/browser/extensions/extension_host.cc | 2 +- .../extensions/extension_process_manager.cc | 5 +- chrome/browser/extensions/extensions_service.cc | 60 +++++++++++--- chrome/browser/extensions/extensions_service.h | 8 ++ chrome/browser/extensions/user_script_listener.cc | 4 +- .../extensions/user_script_listener_unittest.cc | 62 ++++++++++----- chrome/browser/gtk/browser_actions_toolbar_gtk.cc | 7 +- .../browser/privacy_blacklist/blacklist_manager.cc | 34 +++++--- .../blacklist_manager_browsertest.cc | 92 ++++++++++++++++++++++ .../blacklist_manager_unittest.cc | 43 +++++----- chrome/browser/views/browser_actions_container.cc | 6 +- 13 files changed, 257 insertions(+), 75 deletions(-) create mode 100644 chrome/browser/privacy_blacklist/blacklist_manager_browsertest.cc (limited to 'chrome/browser') diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 48e46d7..6dd5f0e 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -2221,7 +2221,10 @@ void Browser::Observe(NotificationType type, case NotificationType::EXTENSION_UPDATE_DISABLED: { // Show the UI. - ExtensionsService* service = Source(source).ptr(); + Profile* profile = Source(source).ptr(); + DCHECK_EQ(profile_, profile); + ExtensionsService* service = profile->GetExtensionsService(); + DCHECK(service); Extension* extension = Details(details).ptr(); ShowExtensionDisabledUI(service, profile_, extension); break; diff --git a/chrome/browser/extensions/extension_disabled_infobar_delegate.cc b/chrome/browser/extensions/extension_disabled_infobar_delegate.cc index ea8de22..0d0d7b4 100644 --- a/chrome/browser/extensions/extension_disabled_infobar_delegate.cc +++ b/chrome/browser/extensions/extension_disabled_infobar_delegate.cc @@ -88,9 +88,9 @@ class ExtensionDisabledInfobarDelegate extension_(extension) { // The user might re-enable the extension in other ways, so watch for that. registrar_.Add(this, NotificationType::EXTENSION_LOADED, - Source(service)); + Source(service->profile())); registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED, - Source(service)); + Source(service->profile())); } virtual ~ExtensionDisabledInfobarDelegate() { } diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc index a468700..f9d6bd1 100644 --- a/chrome/browser/extensions/extension_host.cc +++ b/chrome/browser/extensions/extension_host.cc @@ -248,7 +248,7 @@ void ExtensionHost::RenderViewGone(RenderViewHost* render_view_host) { DCHECK_EQ(render_view_host_, render_view_host); NotificationService::current()->Notify( NotificationType::EXTENSION_PROCESS_CRASHED, - Source(profile_->GetExtensionsService()), + Source(profile_), Details(this)); } diff --git a/chrome/browser/extensions/extension_process_manager.cc b/chrome/browser/extensions/extension_process_manager.cc index e9bb7c49..6718691 100644 --- a/chrome/browser/extensions/extension_process_manager.cc +++ b/chrome/browser/extensions/extension_process_manager.cc @@ -175,11 +175,12 @@ void ExtensionProcessManager::Observe(NotificationType type, switch (type.value) { case NotificationType::EXTENSIONS_READY: CreateBackgroundHosts(this, - Source(source).ptr()->extensions()); + Source(source).ptr()->GetExtensionsService()->extensions()); break; case NotificationType::EXTENSION_LOADED: { - ExtensionsService* service = Source(source).ptr(); + ExtensionsService* service = + Source(source).ptr()->GetExtensionsService(); if (service->is_ready()) { Extension* extension = Details(details).ptr(); ::CreateBackgroundHost(this, extension); diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index 1692e3f..dcca59e 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -333,7 +333,7 @@ void ExtensionsService::NotifyExtensionLoaded(Extension* extension) { NotificationService::current()->Notify( NotificationType::EXTENSION_LOADED, - Source(this), + Source(profile_), Details(extension)); } @@ -342,7 +342,7 @@ void ExtensionsService::NotifyExtensionUnloaded(Extension* extension) { NotificationService::current()->Notify( NotificationType::EXTENSION_UNLOADED, - Source(this), + Source(profile_), Details(extension)); if (profile_ && !profile_->IsOffTheRecord()) { @@ -417,7 +417,7 @@ void ExtensionsService::UnloadExtension(const std::string& extension_id) { disabled_extensions_.erase(iter); NotificationService::current()->Notify( NotificationType::EXTENSION_UNLOADED_DISABLED, - Source(this), + Source(profile_), Details(extension.get())); return; } @@ -463,7 +463,7 @@ void ExtensionsService::OnLoadedInstalledExtensions() { } NotificationService::current()->Notify( NotificationType::EXTENSIONS_READY, - Source(this), + Source(profile_), NotificationService::NoDetails()); } @@ -494,7 +494,7 @@ void ExtensionsService::OnExtensionLoaded(Extension* extension, extension_prefs_->SetExtensionState(extension, Extension::DISABLED); NotificationService::current()->Notify( NotificationType::EXTENSION_UPDATE_DISABLED, - Source(this), + Source(profile_), Details(extension)); } } else { @@ -528,7 +528,7 @@ void ExtensionsService::OnExtensionLoaded(Extension* extension, if (extension->IsTheme() && extension->location() == Extension::LOAD) { NotificationService::current()->Notify( NotificationType::THEME_INSTALLED, - Source(this), + Source(profile_), Details(extension)); } else { ExtensionDOMUI::RegisterChromeURLOverrides(profile_, @@ -538,7 +538,7 @@ void ExtensionsService::OnExtensionLoaded(Extension* extension, case Extension::DISABLED: NotificationService::current()->Notify( NotificationType::EXTENSION_UPDATE_DISABLED, - Source(this), + Source(profile_), Details(extension)); disabled_extensions_.push_back(scoped_extension.release()); break; @@ -558,12 +558,12 @@ void ExtensionsService::OnExtensionInstalled(Extension* extension, if (extension->IsTheme()) { NotificationService::current()->Notify( NotificationType::THEME_INSTALLED, - Source(this), + Source(profile_), Details(extension)); } else { NotificationService::current()->Notify( NotificationType::EXTENSION_INSTALLED, - Source(this), + Source(profile_), Details(extension)); } @@ -576,12 +576,12 @@ void ExtensionsService::OnExtensionOverinstallAttempted(const std::string& id) { if (extension && extension->IsTheme()) { NotificationService::current()->Notify( NotificationType::THEME_INSTALLED, - Source(this), + Source(profile_), Details(extension)); } else { NotificationService::current()->Notify( NotificationType::NO_THEME_DETECTED, - Source(this), + Source(profile_), NotificationService::NoDetails()); } } @@ -666,7 +666,7 @@ void ExtensionsService::ReportExtensionLoadError( bool be_noisy) { NotificationService* service = NotificationService::current(); service->Notify(type, - Source(this), + Source(profile_), Details(&error)); // TODO(port): note that this isn't guaranteed to work properly on Linux. @@ -676,6 +676,42 @@ void ExtensionsService::ReportExtensionLoadError( ExtensionErrorReporter::GetInstance()->ReportError(message, be_noisy); } +std::vector ExtensionsService::GetPersistentBlacklistPaths() { + std::vector result; + for (ExtensionList::const_iterator extension_iter = extensions()->begin(); + extension_iter != extensions()->end(); ++extension_iter) { + if ((*extension_iter)->location() == Extension::LOAD) + continue; + + std::vector blacklists( + (*extension_iter)->privacy_blacklists()); + std::vector::const_iterator blacklist_iter; + for (blacklist_iter = blacklists.begin(); + blacklist_iter != blacklists.end(); ++blacklist_iter) { + result.push_back(blacklist_iter->path); + } + } + return result; +} + +std::vector ExtensionsService::GetTransientBlacklistPaths() { + std::vector result; + for (ExtensionList::const_iterator extension_iter = extensions()->begin(); + extension_iter != extensions()->end(); ++extension_iter) { + if ((*extension_iter)->location() != Extension::LOAD) + continue; + + std::vector blacklists( + (*extension_iter)->privacy_blacklists()); + std::vector::const_iterator blacklist_iter; + for (blacklist_iter = blacklists.begin(); + blacklist_iter != blacklists.end(); ++blacklist_iter) { + result.push_back(blacklist_iter->path); + } + } + return result; +} + // ExtensionsServicesBackend ExtensionsServiceBackend::ExtensionsServiceBackend( diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h index 6d525d7..55e336d 100644 --- a/chrome/browser/extensions/extensions_service.h +++ b/chrome/browser/extensions/extensions_service.h @@ -21,6 +21,7 @@ #include "chrome/browser/extensions/extension_process_manager.h" #include "chrome/browser/extensions/external_extension_provider.h" #include "chrome/browser/extensions/sandboxed_extension_unpacker.h" +#include "chrome/browser/privacy_blacklist/blacklist_manager.h" #include "chrome/common/extensions/extension.h" class Browser; @@ -51,6 +52,7 @@ class ExtensionUpdateService { // Manages installed and running Chromium extensions. class ExtensionsService : public ExtensionUpdateService, + public BlacklistPathProvider, public base::RefCountedThreadSafe { public: @@ -201,6 +203,8 @@ class ExtensionsService return show_extensions_prompts_; } + Profile* profile() { return profile_; } + // Profile calls this when it is destroyed so that we know not to call it. void ProfileDestroyed() { profile_ = NULL; } @@ -219,6 +223,10 @@ class ExtensionsService NotificationType type, bool be_noisy); + // BlacklistPathProvider: + virtual std::vector GetPersistentBlacklistPaths(); + virtual std::vector GetTransientBlacklistPaths(); + private: // Look up an extension by ID, optionally including either or both of enabled // and disabled extensions. diff --git a/chrome/browser/extensions/user_script_listener.cc b/chrome/browser/extensions/user_script_listener.cc index 31f0971..76a4ff5 100644 --- a/chrome/browser/extensions/user_script_listener.cc +++ b/chrome/browser/extensions/user_script_listener.cc @@ -6,6 +6,7 @@ #include "chrome/browser/chrome_thread.h" #include "chrome/browser/extensions/extensions_service.h" +#include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/notification_service.h" @@ -136,7 +137,8 @@ void UserScriptListener::Observe(NotificationType type, // Clear all our patterns and reregister all the still-loaded extensions. URLPatterns new_patterns; - ExtensionsService* service = Source(source).ptr(); + ExtensionsService* service = + Source(source).ptr()->GetExtensionsService(); for (ExtensionList::const_iterator it = service->extensions()->begin(); it != service->extensions()->end(); ++it) { if (*it != unloaded_extension) diff --git a/chrome/browser/extensions/user_script_listener_unittest.cc b/chrome/browser/extensions/user_script_listener_unittest.cc index 14a9d0e..2f87798 100644 --- a/chrome/browser/extensions/user_script_listener_unittest.cc +++ b/chrome/browser/extensions/user_script_listener_unittest.cc @@ -180,6 +180,38 @@ class ResourceDispatcherHostTester std::vector completed_requests_; }; +class ExtensionTestingProfile : public TestingProfile { + public: + ExtensionTestingProfile() { + } + + FilePath GetExtensionsInstallDir() { + return GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName); + } + + void InitializeExtensionsService() { + DCHECK(!GetExtensionsService()); + service_ = new ExtensionsService(this, + CommandLine::ForCurrentProcess(), + GetPrefs(), + GetExtensionsInstallDir(), + false); + service_->set_extensions_enabled(true); + service_->set_show_extensions_prompts(false); + service_->ClearProvidersForTesting(); + service_->Init(); + } + + virtual ExtensionsService* GetExtensionsService() { + return service_.get(); + } + + private: + scoped_refptr service_; + + DISALLOW_COPY_AND_ASSIGN(ExtensionTestingProfile); +}; + class UserScriptListenerTest : public testing::Test { public: virtual void SetUp() { @@ -196,17 +228,9 @@ class UserScriptListenerTest : public testing::Test { resource_tester_ = new ResourceDispatcherHostTester(); - master_ = new MockUserScriptMaster(install_dir); + master_ = new MockUserScriptMaster(profile_.GetExtensionsInstallDir()); - service_ = new ExtensionsService(&profile_, - CommandLine::ForCurrentProcess(), - profile_.GetPrefs(), - install_dir, - false); - service_->set_extensions_enabled(true); - service_->set_show_extensions_prompts(false); - service_->ClearProvidersForTesting(); - service_->Init(); + profile_.InitializeExtensionsService(); } virtual void TearDown() { @@ -217,14 +241,13 @@ class UserScriptListenerTest : public testing::Test { } protected: - TestingProfile profile_; + ExtensionTestingProfile profile_; MessageLoopForUI loop_; scoped_ptr ui_thread_; scoped_ptr file_thread_; scoped_ptr io_thread_; scoped_refptr resource_tester_; scoped_refptr master_; - scoped_refptr service_; }; // Loads a single extension and ensures that requests to URLs with content @@ -238,9 +261,9 @@ TEST_F(UserScriptListenerTest, SingleExtension) { .AppendASCII("Extensions") .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") .AppendASCII("1.0.0.0"); - service_->LoadExtension(ext1); + profile_.GetExtensionsService()->LoadExtension(ext1); loop_.RunAllPending(); - ASSERT_EQ(1u, service_->extensions()->size()); + ASSERT_EQ(1u, profile_.GetExtensionsService()->extensions()->size()); // Our extension has a content script on google.com. That request should be // delayed. @@ -271,18 +294,18 @@ TEST_F(UserScriptListenerTest, UnloadExtension) { .AppendASCII("Extensions") .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") .AppendASCII("1.0.0.0"); - service_->LoadExtension(ext1); + profile_.GetExtensionsService()->LoadExtension(ext1); loop_.RunAllPending(); - ASSERT_EQ(1u, service_->extensions()->size()); + ASSERT_EQ(1u, profile_.GetExtensionsService()->extensions()->size()); FilePath ext2 = extensions_path .AppendASCII("good") .AppendASCII("Extensions") .AppendASCII("bjafgdebaacbbbecmhlhpofkepfkgcpa") .AppendASCII("1.0"); - service_->LoadExtension(ext2); + profile_.GetExtensionsService()->LoadExtension(ext2); loop_.RunAllPending(); - ASSERT_EQ(2u, service_->extensions()->size()); + ASSERT_EQ(2u, profile_.GetExtensionsService()->extensions()->size()); // Our extension has a content script on google.com. That request should be // delayed. @@ -294,7 +317,8 @@ TEST_F(UserScriptListenerTest, UnloadExtension) { EXPECT_TRUE(resource_tester_->IsRequestComplete(1)); // Unload the first extension and run a scan. Request should complete. - service_->UnloadExtension("behllobkkfkfnphdnhnkndlbkcpglgmj"); + profile_.GetExtensionsService()->UnloadExtension( + "behllobkkfkfnphdnhnkndlbkcpglgmj"); resource_tester_->WaitForScan(master_.get()); EXPECT_TRUE(resource_tester_->IsRequestStarted(0)); diff --git a/chrome/browser/gtk/browser_actions_toolbar_gtk.cc b/chrome/browser/gtk/browser_actions_toolbar_gtk.cc index 86aec26..176b4ee 100644 --- a/chrome/browser/gtk/browser_actions_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_actions_toolbar_gtk.cc @@ -201,13 +201,12 @@ BrowserActionsToolbarGtk::BrowserActionsToolbarGtk(Browser* browser) : browser_(browser), profile_(browser->profile()), hbox_(gtk_hbox_new(FALSE, kBrowserActionButtonPadding)) { - ExtensionsService* extension_service = profile_->GetExtensionsService(); registrar_.Add(this, NotificationType::EXTENSION_LOADED, - Source(extension_service)); + Source(profile_)); registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, - Source(extension_service)); + Source(profile_)); registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED, - Source(extension_service)); + Source(profile_)); CreateAllButtons(); } diff --git a/chrome/browser/privacy_blacklist/blacklist_manager.cc b/chrome/browser/privacy_blacklist/blacklist_manager.cc index f7c9311..0629806 100644 --- a/chrome/browser/privacy_blacklist/blacklist_manager.cc +++ b/chrome/browser/privacy_blacklist/blacklist_manager.cc @@ -35,7 +35,7 @@ class BlacklistManagerTask : public Task { protected: BlacklistManager* blacklist_manager() const { return manager_; } - + MessageLoop* original_loop_; private: @@ -59,7 +59,7 @@ class BlacklistManager::CompileBlacklistTask : public BlacklistManagerTask { virtual void Run() { bool success = true; - + Blacklist blacklist; std::string error_string; @@ -107,7 +107,7 @@ class BlacklistManager::ReadBlacklistTask : public BlacklistManagerTask { ReportReadResult(NULL); return; } - + std::string error_string; std::vector::const_iterator i; for (i = transient_blacklists_.begin(); @@ -117,7 +117,7 @@ class BlacklistManager::ReadBlacklistTask : public BlacklistManagerTask { return; } } - + ReportReadResult(blacklist.release()); } @@ -128,7 +128,7 @@ class BlacklistManager::ReadBlacklistTask : public BlacklistManagerTask { &BlacklistManager::OnBlacklistReadFinished, blacklist)); } - + FilePath compiled_blacklist_; std::vector transient_blacklists_; @@ -145,7 +145,10 @@ BlacklistManager::BlacklistManager(Profile* profile, path_provider_(path_provider), backend_thread_(backend_thread) { registrar_.Add(this, - NotificationType::BLACKLIST_PATH_PROVIDER_UPDATED, + NotificationType::EXTENSION_LOADED, + Source(profile)); + registrar_.Add(this, + NotificationType::EXTENSION_UNLOADED, Source(profile)); ReadBlacklist(); } @@ -153,8 +156,15 @@ BlacklistManager::BlacklistManager(Profile* profile, void BlacklistManager::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { - DCHECK(type == NotificationType::BLACKLIST_PATH_PROVIDER_UPDATED); - CompileBlacklist(); + switch (type.value) { + case NotificationType::EXTENSION_LOADED: + case NotificationType::EXTENSION_UNLOADED: + CompileBlacklist(); + break; + default: + NOTREACHED(); + break; + } } void BlacklistManager::CompileBlacklist() { @@ -167,7 +177,7 @@ void BlacklistManager::CompileBlacklist() { void BlacklistManager::ReadBlacklist() { DCHECK(CalledOnValidThread()); - + RunTaskOnBackendThread(new ReadBlacklistTask( this, compiled_blacklist_path_, path_provider_->GetTransientBlacklistPaths())); @@ -175,7 +185,7 @@ void BlacklistManager::ReadBlacklist() { void BlacklistManager::OnBlacklistCompilationFinished(bool success) { DCHECK(CalledOnValidThread()); - + if (success) { ReadBlacklist(); } else { @@ -189,7 +199,7 @@ void BlacklistManager::OnBlacklistCompilationFinished(bool success) { void BlacklistManager::OnBlacklistReadFinished(Blacklist* blacklist) { DCHECK(CalledOnValidThread()); - + if (!blacklist) { if (!first_read_finished_) { // If we're loading for the first time, the compiled blacklist could @@ -207,7 +217,7 @@ void BlacklistManager::OnBlacklistReadFinished(Blacklist* blacklist) { } first_read_finished_ = true; compiled_blacklist_.reset(blacklist); - + NotificationService::current()->Notify( NotificationType::BLACKLIST_MANAGER_BLACKLIST_READ_FINISHED, Source(profile_), diff --git a/chrome/browser/privacy_blacklist/blacklist_manager_browsertest.cc b/chrome/browser/privacy_blacklist/blacklist_manager_browsertest.cc new file mode 100644 index 0000000..bbc30c4 --- /dev/null +++ b/chrome/browser/privacy_blacklist/blacklist_manager_browsertest.cc @@ -0,0 +1,92 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/privacy_blacklist/blacklist_manager.h" + +#include "chrome/browser/browser.h" +#include "chrome/browser/browser_process.h" +#include "chrome/browser/extensions/extension_browsertest.h" +#include "chrome/browser/profile.h" +#include "chrome/common/notification_registrar.h" +#include "chrome/common/notification_source.h" +#include "chrome/test/in_process_browser_test.h" +#include "chrome/test/ui_test_utils.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + +// Returns true if |blacklist| contains a match for |url|. +bool BlacklistHasMatch(const Blacklist* blacklist, const char* url) { + Blacklist::Match* match = blacklist->findMatch(GURL(url)); + + if (!match) + return false; + + delete match; + return true; +} + +} // namespace + +class BlacklistManagerBrowserTest : public ExtensionBrowserTest { + public: + void InitializeBlacklistManager() { + Profile* profile = browser()->profile(); + blacklist_manager_ = new BlacklistManager( + profile, profile->GetExtensionsService(), + g_browser_process->io_thread()); + WaitForBlacklistUpdate(); + } + + virtual void CleanUpOnMainThread() { + blacklist_manager_ = NULL; + ExtensionBrowserTest::CleanUpOnMainThread(); + } + + // NotificationObserver + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + if (type != NotificationType::BLACKLIST_MANAGER_ERROR && + type != NotificationType::BLACKLIST_MANAGER_BLACKLIST_READ_FINISHED) { + ExtensionBrowserTest::Observe(type, source, details); + return; + } + MessageLoop::current()->Quit(); + } + + protected: + void WaitForBlacklistUpdate() { + NotificationRegistrar registrar; + registrar.Add(this, + NotificationType::BLACKLIST_MANAGER_BLACKLIST_READ_FINISHED, + Source(browser()->profile())); + ui_test_utils::RunMessageLoop(); + } + + scoped_refptr blacklist_manager_; +}; + +IN_PROC_BROWSER_TEST_F(BlacklistManagerBrowserTest, Basic) { + InitializeBlacklistManager(); + ASSERT_TRUE(blacklist_manager_->GetCompiledBlacklist()); + EXPECT_FALSE(BlacklistHasMatch(blacklist_manager_->GetCompiledBlacklist(), + "http://host/annoying_ads/ad.jpg")); + + // Test loading an extension with blacklist. + ASSERT_TRUE(LoadExtension( + test_data_dir_.AppendASCII("common").AppendASCII("privacy_blacklist"))); + WaitForBlacklistUpdate(); + EXPECT_TRUE(BlacklistHasMatch(blacklist_manager_->GetCompiledBlacklist(), + "http://host/annoying_ads/ad.jpg")); + + // Make sure that after unloading the extension we update the blacklist. + ExtensionsService* extensions_service = + browser()->profile()->GetExtensionsService(); + ASSERT_EQ(1U, extensions_service->extensions()->size()); + UnloadExtension(extensions_service->extensions()->front()->id()); + WaitForBlacklistUpdate(); + EXPECT_FALSE(BlacklistHasMatch(blacklist_manager_->GetCompiledBlacklist(), + "http://host/annoying_ads/ad.jpg")); +} diff --git a/chrome/browser/privacy_blacklist/blacklist_manager_unittest.cc b/chrome/browser/privacy_blacklist/blacklist_manager_unittest.cc index b2e6996..e7d9f9d 100644 --- a/chrome/browser/privacy_blacklist/blacklist_manager_unittest.cc +++ b/chrome/browser/privacy_blacklist/blacklist_manager_unittest.cc @@ -10,6 +10,7 @@ #include "base/thread.h" #include "chrome/browser/privacy_blacklist/blacklist.h" #include "chrome/common/chrome_paths.h" +#include "chrome/common/extensions/extension.h" #include "chrome/common/notification_service.h" #include "chrome/test/testing_profile.h" #include "testing/gtest/include/gtest/gtest.h" @@ -37,7 +38,7 @@ class TestBlacklistPathProvider : public BlacklistPathProvider { virtual std::vector GetPersistentBlacklistPaths() { return persistent_paths_; } - + virtual std::vector GetTransientBlacklistPaths() { return transient_paths_; } @@ -46,12 +47,12 @@ class TestBlacklistPathProvider : public BlacklistPathProvider { persistent_paths_.push_back(path); SendUpdateNotification(); } - + void AddTransientPath(const FilePath& path) { transient_paths_.push_back(path); SendUpdateNotification(); } - + void clear() { persistent_paths_.clear(); transient_paths_.clear(); @@ -60,12 +61,18 @@ class TestBlacklistPathProvider : public BlacklistPathProvider { private: void SendUpdateNotification() { +#if defined(OS_WIN) + FilePath path(FILE_PATH_LITERAL("c:\\foo")); +#elif defined(OS_POSIX) + FilePath path(FILE_PATH_LITERAL("/foo")); +#endif + Extension extension(path); NotificationService::current()->Notify( - NotificationType::BLACKLIST_PATH_PROVIDER_UPDATED, + NotificationType::EXTENSION_LOADED, Source(profile_), - Details(this)); + Details(&extension)); } - + Profile* profile_; std::vector persistent_paths_; @@ -78,7 +85,7 @@ class BlacklistManagerTest : public testing::Test, public NotificationObserver { public: BlacklistManagerTest() : path_provider_(&profile_) { } - + virtual void SetUp() { ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_)); test_data_dir_ = test_data_dir_.AppendASCII("blacklist_samples"); @@ -103,7 +110,7 @@ class BlacklistManagerTest : public testing::Test, public NotificationObserver { Source(&profile_)); MessageLoop::current()->Run(); } - + void WaitForBlacklistUpdate() { NotificationRegistrar registrar; registrar.Add(this, @@ -111,11 +118,11 @@ class BlacklistManagerTest : public testing::Test, public NotificationObserver { Source(&profile_)); MessageLoop::current()->Run(); } - + FilePath test_data_dir_; MyTestingProfile profile_; - + TestBlacklistPathProvider path_provider_; private: @@ -157,24 +164,24 @@ TEST_F(BlacklistManagerTest, BlacklistPathProvider) { path_provider_.AddPersistentPath( test_data_dir_.AppendASCII("annoying_ads.pbl")); WaitForBlacklistUpdate(); - + const Blacklist* blacklist2 = manager->GetCompiledBlacklist(); // Added a real blacklist, the manager should recompile. EXPECT_NE(blacklist1, blacklist2); EXPECT_TRUE(BlacklistHasMatch(blacklist2, "http://host/annoying_ads/ad.jpg")); EXPECT_FALSE(BlacklistHasMatch(blacklist2, "http://host/other_ads/ad.jpg")); - + path_provider_.AddTransientPath(test_data_dir_.AppendASCII("other_ads.pbl")); WaitForBlacklistUpdate(); - + const Blacklist* blacklist3 = manager->GetCompiledBlacklist(); - + // In theory blacklist2 and blacklist3 could be the same object, so we're // not checking for inequality. EXPECT_TRUE(BlacklistHasMatch(blacklist3, "http://host/annoying_ads/ad.jpg")); EXPECT_TRUE(BlacklistHasMatch(blacklist3, "http://host/other_ads/ad.jpg")); - + // Now make sure that transient blacklists don't survive after re-creating // the BlacklistManager. manager = NULL; @@ -183,9 +190,9 @@ TEST_F(BlacklistManagerTest, BlacklistPathProvider) { test_data_dir_.AppendASCII("annoying_ads.pbl")); manager = new BlacklistManager(&profile_, &path_provider_, NULL); WaitForBlacklistUpdate(); - + const Blacklist* blacklist4 = manager->GetCompiledBlacklist(); - + EXPECT_TRUE(BlacklistHasMatch(blacklist4, "http://host/annoying_ads/ad.jpg")); EXPECT_FALSE(BlacklistHasMatch(blacklist4, "http://host/other_ads/ad.jpg")); } @@ -222,7 +229,7 @@ TEST_F(BlacklistManagerTest, BlacklistPathReadError) { ASSERT_FALSE(file_util::PathExists(bogus_path)); path_provider_.AddPersistentPath(bogus_path); WaitForBlacklistError(); - + const Blacklist* blacklist = manager->GetCompiledBlacklist(); EXPECT_TRUE(blacklist); } diff --git a/chrome/browser/views/browser_actions_container.cc b/chrome/browser/views/browser_actions_container.cc index 179677c..f6036dd 100644 --- a/chrome/browser/views/browser_actions_container.cc +++ b/chrome/browser/views/browser_actions_container.cc @@ -229,11 +229,11 @@ BrowserActionsContainer::BrowserActionsContainer( return; registrar_.Add(this, NotificationType::EXTENSION_LOADED, - Source(extension_service)); + Source(profile_)); registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, - Source(extension_service)); + Source(profile_)); registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED, - Source(extension_service)); + Source(profile_)); registrar_.Add(this, NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE, Source(profile_)); -- cgit v1.1