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

Unified Diff: chrome/browser/privacy_blacklist/blacklist_manager_browsertest.cc

Issue 341050: Implement loading blacklists from extensions.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: use real extension Created 11 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/privacy_blacklist/blacklist_manager_browsertest.cc
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 0000000000000000000000000000000000000000..bbc30c452a757704a3d6ca0acf85a05694d24db4
--- /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<Profile>(browser()->profile()));
+ ui_test_utils::RunMessageLoop();
+ }
+
+ scoped_refptr<BlacklistManager> 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"));
+}
« no previous file with comments | « chrome/browser/privacy_blacklist/blacklist_manager.cc ('k') | chrome/browser/privacy_blacklist/blacklist_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698