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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/privacy_blacklist/blacklist_manager.h"
6
7 #include "chrome/browser/browser.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/extensions/extension_browsertest.h"
10 #include "chrome/browser/profile.h"
11 #include "chrome/common/notification_registrar.h"
12 #include "chrome/common/notification_source.h"
13 #include "chrome/test/in_process_browser_test.h"
14 #include "chrome/test/ui_test_utils.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace {
18
19 // Returns true if |blacklist| contains a match for |url|.
20 bool BlacklistHasMatch(const Blacklist* blacklist, const char* url) {
21 Blacklist::Match* match = blacklist->findMatch(GURL(url));
22
23 if (!match)
24 return false;
25
26 delete match;
27 return true;
28 }
29
30 } // namespace
31
32 class BlacklistManagerBrowserTest : public ExtensionBrowserTest {
33 public:
34 void InitializeBlacklistManager() {
35 Profile* profile = browser()->profile();
36 blacklist_manager_ = new BlacklistManager(
37 profile, profile->GetExtensionsService(),
38 g_browser_process->io_thread());
39 WaitForBlacklistUpdate();
40 }
41
42 virtual void CleanUpOnMainThread() {
43 blacklist_manager_ = NULL;
44 ExtensionBrowserTest::CleanUpOnMainThread();
45 }
46
47 // NotificationObserver
48 virtual void Observe(NotificationType type,
49 const NotificationSource& source,
50 const NotificationDetails& details) {
51 if (type != NotificationType::BLACKLIST_MANAGER_ERROR &&
52 type != NotificationType::BLACKLIST_MANAGER_BLACKLIST_READ_FINISHED) {
53 ExtensionBrowserTest::Observe(type, source, details);
54 return;
55 }
56 MessageLoop::current()->Quit();
57 }
58
59 protected:
60 void WaitForBlacklistUpdate() {
61 NotificationRegistrar registrar;
62 registrar.Add(this,
63 NotificationType::BLACKLIST_MANAGER_BLACKLIST_READ_FINISHED,
64 Source<Profile>(browser()->profile()));
65 ui_test_utils::RunMessageLoop();
66 }
67
68 scoped_refptr<BlacklistManager> blacklist_manager_;
69 };
70
71 IN_PROC_BROWSER_TEST_F(BlacklistManagerBrowserTest, Basic) {
72 InitializeBlacklistManager();
73 ASSERT_TRUE(blacklist_manager_->GetCompiledBlacklist());
74 EXPECT_FALSE(BlacklistHasMatch(blacklist_manager_->GetCompiledBlacklist(),
75 "http://host/annoying_ads/ad.jpg"));
76
77 // Test loading an extension with blacklist.
78 ASSERT_TRUE(LoadExtension(
79 test_data_dir_.AppendASCII("common").AppendASCII("privacy_blacklist")));
80 WaitForBlacklistUpdate();
81 EXPECT_TRUE(BlacklistHasMatch(blacklist_manager_->GetCompiledBlacklist(),
82 "http://host/annoying_ads/ad.jpg"));
83
84 // Make sure that after unloading the extension we update the blacklist.
85 ExtensionsService* extensions_service =
86 browser()->profile()->GetExtensionsService();
87 ASSERT_EQ(1U, extensions_service->extensions()->size());
88 UnloadExtension(extensions_service->extensions()->front()->id());
89 WaitForBlacklistUpdate();
90 EXPECT_FALSE(BlacklistHasMatch(blacklist_manager_->GetCompiledBlacklist(),
91 "http://host/annoying_ads/ad.jpg"));
92 }
OLDNEW
« 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