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

Unified Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc

Issue 1017853003: Add ClientConfig proto, and JSON generation/parsing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tweak test values Created 5 years, 9 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
Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc
index 422cd424f34a846ebee419190125aef311fe5054..e9ea65ee061dfa2742900b986caceec3b973f8ae 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc
@@ -22,8 +22,55 @@
#include "net/url_request/url_request_job_factory_impl.h"
#include "net/url_request/url_request_test_util.h"
+namespace {
+
+const char kTestKey[] = "test-key";
+
+} // namespace
+
namespace data_reduction_proxy {
+TestDataReductionProxyRequestOptions::TestDataReductionProxyRequestOptions(
+ Client client,
+ const std::string& version,
+ DataReductionProxyConfig* config,
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner)
+ : DataReductionProxyRequestOptions(client, version, config, task_runner) {
+}
+
+std::string TestDataReductionProxyRequestOptions::GetDefaultKey() const {
+ return kTestKey;
+}
+
+base::Time TestDataReductionProxyRequestOptions::Now() const {
+ return base::Time::UnixEpoch() + now_offset_;
+}
+
+void TestDataReductionProxyRequestOptions::RandBytes(void* output,
+ size_t length) const {
+ char* c = static_cast<char*>(output);
+ for (size_t i = 0; i < length; ++i) {
+ c[i] = 'a';
+ }
+}
+
+// Time after the unix epoch that Now() reports.
+void TestDataReductionProxyRequestOptions::set_offset(
+ const base::TimeDelta& now_offset) {
+ now_offset_ = now_offset;
+}
+
+MockDataReductionProxyRequestOptions::MockDataReductionProxyRequestOptions(
+ Client client,
+ const std::string& version,
+ DataReductionProxyConfig* config,
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner)
+ : DataReductionProxyRequestOptions(client, version, config, task_runner) {
+}
+
+MockDataReductionProxyRequestOptions::~MockDataReductionProxyRequestOptions() {
+}
+
MockDataReductionProxyService::MockDataReductionProxyService(
scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs,
DataReductionProxySettings* settings,
@@ -65,6 +112,7 @@ DataReductionProxyTestContext::Builder::Builder()
use_mock_config_(false),
use_test_configurator_(false),
use_mock_service_(false),
+ use_mock_request_options_(false),
skip_settings_initialization_(false) {
}
@@ -120,6 +168,12 @@ DataReductionProxyTestContext::Builder::WithMockDataReductionProxyService() {
}
DataReductionProxyTestContext::Builder&
+DataReductionProxyTestContext::Builder::WithMockRequestOptions() {
+ use_mock_request_options_ = true;
+ return *this;
+}
+
+DataReductionProxyTestContext::Builder&
DataReductionProxyTestContext::Builder::SkipSettingsInitialization() {
skip_settings_initialization_ = true;
return *this;
@@ -173,8 +227,15 @@ DataReductionProxyTestContext::Builder::Build() {
configurator.get(), event_store.get()));
}
- scoped_ptr<DataReductionProxyRequestOptions> request_options(
- new DataReductionProxyRequestOptions(client_, config.get(), task_runner));
+ scoped_ptr<DataReductionProxyRequestOptions> request_options;
+ if (use_mock_request_options_) {
+ test_context_flags |= USE_MOCK_REQUEST_OPTIONS;
+ request_options.reset(new MockDataReductionProxyRequestOptions(
+ client_, std::string(), config.get(), task_runner));
+ } else {
+ request_options.reset(new DataReductionProxyRequestOptions(
+ client_, config.get(), task_runner));
+ }
scoped_ptr<DataReductionProxySettings> settings(
new DataReductionProxySettings());
@@ -344,6 +405,14 @@ DataReductionProxyTestContext::mock_data_reduction_proxy_service()
data_reduction_proxy_service());
}
+MockDataReductionProxyRequestOptions*
+DataReductionProxyTestContext::mock_request_options() const {
+ DCHECK(test_context_flags_ &
+ DataReductionProxyTestContext::USE_MOCK_REQUEST_OPTIONS);
+ return reinterpret_cast<MockDataReductionProxyRequestOptions*>(
+ io_data_->request_options());
+}
+
DataReductionProxyUsageStats::UnreachableCallback
DataReductionProxyTestContext::unreachable_callback() const {
return base::Bind(&DataReductionProxySettings::SetUnreachable,

Powered by Google App Engine
This is Rietveld 408576698