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

Side by Side Diff: chrome/browser/extensions/test_blacklist.cc

Issue 119963004: Manage all the testing classes for Blacklist in TestBlacklist. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/test_blacklist.h" 5 #include "chrome/browser/extensions/test_blacklist.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/stl_util.h"
12 #include "chrome/browser/extensions/blacklist.h" 13 #include "chrome/browser/extensions/blacklist.h"
14 #include "chrome/browser/extensions/blacklist_state_fetcher.h"
15 #include "chrome/browser/extensions/fake_safe_browsing_database_manager.h"
13 16
14 namespace extensions { 17 namespace extensions {
15 18
16 TestBlacklist::TestBlacklist(Blacklist* blacklist)
17 : blacklist_(blacklist) {
18 }
19
20 namespace { 19 namespace {
21 20
22 void Assign(BlacklistState *out, BlacklistState in) { 21 void Assign(BlacklistState *out, BlacklistState in) {
23 *out = in; 22 *out = in;
24 } 23 }
25 24
26 } // namespace 25 } // namespace
27 26
27 BlacklistStateFetcherMock::BlacklistStateFetcherMock() : request_count_(0) {}
28
29 void BlacklistStateFetcherMock::Request(const std::string& id,
30 const RequestCallback& callback) {
31 request_count_++;
not at google - send to devlin 2013/12/21 00:34:24 ++request_count_ for consistency.
Oleg Eterevsky 2014/01/09 13:54:01 Done.
32
33 BlacklistState result = NOT_BLACKLISTED;
34 if (ContainsKey(states_, id))
35 result = states_[id];
36
37 base::MessageLoopProxy::current()->PostTask(FROM_HERE,
38 base::Bind(callback, result));
39 }
40
41 void BlacklistStateFetcherMock::SetState(const std::string& id,
42 BlacklistState state) {
43 states_[id] = state;
44 }
45
46 void BlacklistStateFetcherMock::Clear() {
47 states_.clear();
48 }
49
50
51 TestBlacklist::TestBlacklist()
52 : blacklist_(NULL),
53 blacklist_db_(new FakeSafeBrowsingDatabaseManager(true)),
54 scoped_blacklist_db_(blacklist_db_) {
55 }
56
57 TestBlacklist::TestBlacklist(Blacklist* blacklist)
58 : blacklist_(NULL),
59 blacklist_db_(new FakeSafeBrowsingDatabaseManager(true)),
60 scoped_blacklist_db_(blacklist_db_) {
61 Attach(blacklist);
62 }
63
64 TestBlacklist::~TestBlacklist() {
65 Detach();
66 }
67
68 void TestBlacklist::Attach(Blacklist* blacklist) {
69 if (blacklist_)
70 Detach();
71
72 blacklist_ = blacklist;
73 blacklist_->SetBlacklistStateFetcherForTest(&state_fetcher_mock_);
74 }
75
76 void TestBlacklist::Detach() {
77 blacklist_->ResetBlacklistStateFetcherForTest();
not at google - send to devlin 2013/12/21 00:34:24 this will leak but making ResetBlacklistStateFetch
Oleg Eterevsky 2014/01/09 13:54:01 Done.
78 }
79
80 void TestBlacklist::SetBlacklistState(const std::string& extension_id,
81 BlacklistState state,
82 bool notify) {
83 state_fetcher_mock_.SetState(extension_id, state);
84
85 switch (state) {
86 case NOT_BLACKLISTED:
87 blacklist_db_->RemoveUnsafe(extension_id);
88 break;
89
90 case BLACKLISTED_MALWARE:
91 case BLACKLISTED_SECURITY_VULNERABILITY:
92 case BLACKLISTED_CWS_POLICY_VIOLATION:
93 case BLACKLISTED_POTENTIALLY_UNWANTED:
94 blacklist_db_->AddUnsafe(extension_id);
95 break;
96
97 default:
98 break;
99 }
100
101 if (notify)
102 blacklist_db_->NotifyUpdate();
103 }
104
105 void TestBlacklist::Clear(bool notify) {
106 state_fetcher_mock_.Clear();
107 blacklist_db_->ClearUnsafe();
108 if (notify)
109 blacklist_db_->NotifyUpdate();
110 }
111
28 BlacklistState TestBlacklist::GetBlacklistState( 112 BlacklistState TestBlacklist::GetBlacklistState(
29 const std::string& extension_id) { 113 const std::string& extension_id) {
30 BlacklistState blacklist_state; 114 BlacklistState blacklist_state;
31 blacklist_->IsBlacklisted(extension_id, 115 blacklist_->IsBlacklisted(extension_id,
32 base::Bind(&Assign, &blacklist_state)); 116 base::Bind(&Assign, &blacklist_state));
33 base::RunLoop().RunUntilIdle(); 117 base::RunLoop().RunUntilIdle();
34 return blacklist_state; 118 return blacklist_state;
35 } 119 }
36 120
121 void TestBlacklist::DisableSafeBrowsing() {
122 blacklist_db_->Disable();
123 }
124
125 void TestBlacklist::EnableSafeBrowsing() {
126 blacklist_db_->Enable();
127 }
128
129 void TestBlacklist::NotifyUpdate() {
130 blacklist_db_->NotifyUpdate();
131 }
132
37 } // namespace extensions 133 } // namespace extensions
OLDNEW
« chrome/browser/extensions/test_blacklist.h ('K') | « chrome/browser/extensions/test_blacklist.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698