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

Unified 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: Rebase Created 6 years, 11 months 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
« no previous file with comments | « chrome/browser/extensions/test_blacklist.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/test_blacklist.cc
diff --git a/chrome/browser/extensions/test_blacklist.cc b/chrome/browser/extensions/test_blacklist.cc
index c14cee1339ae23574c872d29f72ef0a396583f06..f4941bdd6a8e1edc2b9e779e616360a0b6ea733c 100644
--- a/chrome/browser/extensions/test_blacklist.cc
+++ b/chrome/browser/extensions/test_blacklist.cc
@@ -9,14 +9,13 @@
#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
+#include "base/stl_util.h"
#include "chrome/browser/extensions/blacklist.h"
+#include "chrome/browser/extensions/blacklist_state_fetcher.h"
+#include "chrome/browser/extensions/fake_safe_browsing_database_manager.h"
namespace extensions {
-TestBlacklist::TestBlacklist(Blacklist* blacklist)
- : blacklist_(blacklist) {
-}
-
namespace {
void Assign(BlacklistState *out, BlacklistState in) {
@@ -25,6 +24,93 @@ void Assign(BlacklistState *out, BlacklistState in) {
} // namespace
+BlacklistStateFetcherMock::BlacklistStateFetcherMock() : request_count_(0) {}
+
+BlacklistStateFetcherMock::~BlacklistStateFetcherMock() {}
+
+void BlacklistStateFetcherMock::Request(const std::string& id,
+ const RequestCallback& callback) {
+ ++request_count_;
+
+ BlacklistState result = NOT_BLACKLISTED;
+ if (ContainsKey(states_, id))
+ result = states_[id];
+
+ base::MessageLoopProxy::current()->PostTask(FROM_HERE,
+ base::Bind(callback, result));
+}
+
+void BlacklistStateFetcherMock::SetState(const std::string& id,
+ BlacklistState state) {
+ states_[id] = state;
+}
+
+void BlacklistStateFetcherMock::Clear() {
+ states_.clear();
+}
+
+
+TestBlacklist::TestBlacklist()
+ : blacklist_(NULL),
+ blacklist_db_(new FakeSafeBrowsingDatabaseManager(true)),
+ scoped_blacklist_db_(blacklist_db_) {
+}
+
+TestBlacklist::TestBlacklist(Blacklist* blacklist)
+ : blacklist_(NULL),
+ blacklist_db_(new FakeSafeBrowsingDatabaseManager(true)),
+ scoped_blacklist_db_(blacklist_db_) {
+ Attach(blacklist);
+}
+
+TestBlacklist::~TestBlacklist() {
+ Detach();
+}
+
+void TestBlacklist::Attach(Blacklist* blacklist) {
+ if (blacklist_)
+ Detach();
+
+ blacklist_ = blacklist;
+ blacklist_->SetBlacklistStateFetcherForTest(&state_fetcher_mock_);
+}
+
+void TestBlacklist::Detach() {
+ blacklist_->ResetBlacklistStateFetcherForTest();
+}
+
+void TestBlacklist::SetBlacklistState(const std::string& extension_id,
+ BlacklistState state,
+ bool notify) {
+ state_fetcher_mock_.SetState(extension_id, state);
+
+ switch (state) {
+ case NOT_BLACKLISTED:
+ blacklist_db_->RemoveUnsafe(extension_id);
+ break;
+
+ case BLACKLISTED_MALWARE:
+ case BLACKLISTED_SECURITY_VULNERABILITY:
+ case BLACKLISTED_CWS_POLICY_VIOLATION:
+ case BLACKLISTED_POTENTIALLY_UNWANTED:
+ blacklist_db_->AddUnsafe(extension_id);
+ break;
+
+ default:
+ break;
+ }
+
+ if (notify)
+ blacklist_db_->NotifyUpdate();
+}
+
+void TestBlacklist::Clear(bool notify) {
+ state_fetcher_mock_.Clear();
+ blacklist_db_->ClearUnsafe();
+ if (notify)
+ blacklist_db_->NotifyUpdate();
+}
+
BlacklistState TestBlacklist::GetBlacklistState(
const std::string& extension_id) {
BlacklistState blacklist_state;
@@ -34,4 +120,16 @@ BlacklistState TestBlacklist::GetBlacklistState(
return blacklist_state;
}
+void TestBlacklist::DisableSafeBrowsing() {
+ blacklist_db_->Disable();
+}
+
+void TestBlacklist::EnableSafeBrowsing() {
+ blacklist_db_->Enable();
+}
+
+void TestBlacklist::NotifyUpdate() {
+ blacklist_db_->NotifyUpdate();
+}
+
} // namespace extensions
« no previous file with comments | « chrome/browser/extensions/test_blacklist.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698