Index: chrome/browser/extensions/test_blacklist_fetcher.cc |
diff --git a/chrome/browser/extensions/test_blacklist_fetcher.cc b/chrome/browser/extensions/test_blacklist_fetcher.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8e696ef4038ee158c7a283608062177af3875000 |
--- /dev/null |
+++ b/chrome/browser/extensions/test_blacklist_fetcher.cc |
@@ -0,0 +1,70 @@ |
+// Copyright 2013 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/extensions/test_blacklist_fetcher.h" |
+ |
+namespace extensions { |
+namespace { |
+ |
+static const char kUrlPrefix[] = "https://prefix.com/foo"; |
+static const char kBackupConnectUrlPrefix[] = "https://alt1-prefix.com/foo"; |
+static const char kBackupHttpUrlPrefix[] = "https://alt2-prefix.com/foo"; |
+static const char kBackupNetworkUrlPrefix[] = "https://alt3-prefix.com/foo"; |
+static const char kClient[] = "unittest"; |
+static const char kAppVer[] = "1.0"; |
+ |
+SafeBrowsingProtocolConfig CreateSafeBrowsingProtocolConfig() { |
+ SafeBrowsingProtocolConfig config; |
+ config.client_name = kClient; |
+ config.url_prefix = kUrlPrefix; |
+ config.backup_connect_error_url_prefix = kBackupConnectUrlPrefix; |
+ config.backup_http_error_url_prefix = kBackupHttpUrlPrefix; |
+ config.backup_network_error_url_prefix = kBackupNetworkUrlPrefix; |
+ config.version = kAppVer; |
+ return config; |
+} |
+ |
+} // namespace |
+ |
+TestBlacklistFetcher::TestBlacklistFetcher(BlacklistFetcher* fetcher) |
+ : fetcher_(fetcher) { |
+ fetcher_->SetSafeBrowsingConfig(CreateSafeBrowsingProtocolConfig()); |
+} |
+ |
+void TestBlacklistFetcher::SetBlacklistVerdict( |
+ const std::string& id, ClientCRXListInfoResponse_Verdict state) { |
+ verdicts_[id] = state; |
+} |
+ |
+bool TestBlacklistFetcher::HandleFetcher(int fetcher_id) { |
+ net::TestURLFetcher* url_fetcher = url_fetcher_factory_.GetFetcherByID( |
+ fetcher_id); |
+ if (!url_fetcher) |
+ return false; |
+ |
+ const std::string& request_str = url_fetcher->upload_data(); |
+ ClientCRXListInfoRequest request; |
+ if (!request.ParseFromString(request_str)) |
+ return false; |
+ |
+ std::string id = request.id(); |
+ |
+ ClientCRXListInfoResponse response; |
+ if (verdicts_.find(id) != verdicts_.end()) |
+ response.set_verdict(verdicts_[id]); |
+ else |
+ response.set_verdict(ClientCRXListInfoResponse::UNKNOWN); |
+ |
+ std::string response_str; |
+ response.SerializeToString(&response_str); |
+ |
+ url_fetcher->set_status(net::URLRequestStatus()); |
+ url_fetcher->set_response_code(200); |
+ url_fetcher->SetResponseString(response_str); |
+ url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); |
+ |
+ return true; |
+} |
+ |
+} // namespace extensions |