Chromium Code Reviews| Index: components/data_reduction_proxy/content/browser/data_reduction_proxy_resource_throttle_unittest.cc |
| diff --git a/components/data_reduction_proxy/content/browser/data_reduction_proxy_resource_throttle_unittest.cc b/components/data_reduction_proxy/content/browser/data_reduction_proxy_resource_throttle_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d7f4c0ce9328d4e97be0ed7dc0fadb71d2d06805 |
| --- /dev/null |
| +++ b/components/data_reduction_proxy/content/browser/data_reduction_proxy_resource_throttle_unittest.cc |
| @@ -0,0 +1,153 @@ |
| +// Copyright 2014 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 "components/data_reduction_proxy/content/browser/data_reduction_proxy_resource_throttle.h" |
| + |
| +#include "base/macros.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "components/data_reduction_proxy/content/browser/data_reduction_proxy_ui_service.h" |
| +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h" |
| +#include "net/base/load_flags.h" |
| +#include "net/proxy/proxy_config.h" |
| +#include "net/url_request/url_request.h" |
| +#include "net/url_request/url_request_job_factory_impl.h" |
| +#include "net/url_request/url_request_status.h" |
|
bengr
2014/12/29 18:45:41
Is this needed?
megjablon
2014/12/30 23:40:00
Removed.
|
| +#include "net/url_request/url_request_test_job.h" |
|
bengr
2014/12/29 18:45:42
Is this needed?
megjablon
2014/12/30 23:40:00
Removed.
|
| +#include "net/url_request/url_request_test_util.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace data_reduction_proxy { |
| + |
| +namespace { |
| + |
| +class TestDataReductionProxyResourceThrottle |
| + : public DataReductionProxyResourceThrottle { |
| + public: |
| + TestDataReductionProxyResourceThrottle( |
| + net::URLRequest* request, |
| + content::ResourceType resource_type, |
|
bengr
2014/12/29 18:45:41
#include "src/content/public/common/resource_type.
megjablon
2014/12/30 23:40:00
Done.
|
| + DataReductionProxyUIService* ui_service, |
| + const DataReductionProxyParams* params) |
| + : DataReductionProxyResourceThrottle( |
| + request, resource_type, ui_service, params) { |
| + } |
| + |
| + ~TestDataReductionProxyResourceThrottle() override { |
| + } |
| + |
| + private: |
| + void DisplayBlockingPage(bool* defer) override { |
| + *defer = true; |
| + } |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TestDataReductionProxyResourceThrottle); |
| +}; |
| + |
| +class TestDataReductionProxyUIService : public DataReductionProxyUIService { |
| + public: |
| + TestDataReductionProxyUIService() { |
| + } |
| + |
| + ~TestDataReductionProxyUIService() override { |
| + } |
| + |
| + const net::ProxyConfig& data_reduction_proxy_config() const override { |
| + return proxy_config_; |
| + } |
| + |
| + private: |
| + net::ProxyConfig proxy_config_; |
| + DISALLOW_COPY_AND_ASSIGN(TestDataReductionProxyUIService); |
| +}; |
| + |
| +class DataReductionProxyParamsMock : public DataReductionProxyParams { |
|
bengr
2014/12/29 18:45:41
Can you use https://code.google.com/p/chromium/cod
megjablon
2014/12/30 23:40:00
Done.
|
| + public: |
| + DataReductionProxyParamsMock() : DataReductionProxyParams(0) { |
| + } |
| + |
| + ~DataReductionProxyParamsMock() override { |
| + } |
| + |
| + MOCK_CONST_METHOD2( |
|
bengr
2014/12/29 18:45:41
When possible, I'd like to move away from mocks.
megjablon
2014/12/30 23:40:00
Done.
|
| + IsDataReductionProxy, |
| + bool(const net::HostPortPair& host_port_pair, |
| + data_reduction_proxy::DataReductionProxyTypeInfo* proxy_info)); |
| + MOCK_CONST_METHOD2( |
| + IsBypassedByDataReductionProxyLocalRules, |
| + bool(const net::URLRequest& request, |
| + const net::ProxyConfig& data_reduction_proxy_config)); |
| + MOCK_CONST_METHOD2( |
| + AreDataReductionProxiesBypassed, |
| + bool(const net::URLRequest& request, base::TimeDelta* min_retry_delay)); |
|
bengr
2014/12/29 18:45:42
Forward declare base::TimeDelta.
megjablon
2014/12/30 23:40:00
Done.
|
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(DataReductionProxyParamsMock); |
| +}; |
| + |
| +} // namespace |
| + |
| +class DataReductionProxyResourceThrottleTest : public testing::Test { |
| + public: |
| + DataReductionProxyResourceThrottleTest() : context_(true) { |
| + context_.Init(); |
| + |
| + // The |test_job_factory_| takes ownership of the interceptor. |
| + test_job_interceptor_ = new net::TestJobInterceptor(); |
| + EXPECT_TRUE(test_job_factory_.SetProtocolHandler(url::kHttpScheme, |
| + test_job_interceptor_)); |
| + |
| + context_.set_job_factory(&test_job_factory_); |
| + |
| + request_ = context_.CreateRequest(GURL("http://www.google.com/"), net::IDLE, |
| + &delegate_, NULL); |
| + ui_service_.reset(new TestDataReductionProxyUIService()); |
| + resource_throttle_.reset(new TestDataReductionProxyResourceThrottle( |
| + request_.get(), content::RESOURCE_TYPE_MAIN_FRAME, |
| + ui_service_.get(), ¶ms_)); |
| + } |
| + |
| + protected: |
| + // Required for base::MessageLoopProxy::current(). |
| + base::MessageLoopForIO loop_; |
|
bengr
2014/12/29 18:45:42
#include "base/message_loop/message_loop.h"
megjablon
2014/12/30 23:40:00
Done.
|
| + |
| + net::TestURLRequestContext context_; |
| + net::TestDelegate delegate_; |
| + // |test_job_interceptor_| is owned by |test_job_factory_|. |
| + net::TestJobInterceptor* test_job_interceptor_; |
| + net::URLRequestJobFactoryImpl test_job_factory_; |
| + |
| + scoped_ptr<net::URLRequest> request_; |
| + scoped_ptr<TestDataReductionProxyUIService> ui_service_; |
| + DataReductionProxyParamsMock params_; |
| + scoped_ptr<TestDataReductionProxyResourceThrottle> resource_throttle_; |
| +}; |
| + |
| +TEST_F(DataReductionProxyResourceThrottleTest, WillStartUsingNetwork) { |
| + EXPECT_CALL(params_, AreDataReductionProxiesBypassed(testing::_, testing::_)) |
| + .WillOnce(testing::Return(true)); |
| + EXPECT_CALL(params_, |
| + IsBypassedByDataReductionProxyLocalRules(testing::_, testing::_)) |
| + .WillOnce(testing::Return(false)); |
| + bool defer = false; |
| + resource_throttle_->WillStartUsingNetwork(&defer); |
| + EXPECT_TRUE(defer); |
| +} |
| + |
| +TEST_F(DataReductionProxyResourceThrottleTest, WillRedirectRequest) { |
| + request_->SetLoadFlags(net::LOAD_BYPASS_PROXY); |
| + bool defer = false; |
| + resource_throttle_->WillRedirectRequest(GURL(), &defer); |
|
bengr
2014/12/29 18:45:41
#include "url/gurl.h"
megjablon
2014/12/30 23:40:00
Done.
|
| + EXPECT_TRUE(defer); |
| +} |
| + |
| +TEST_F(DataReductionProxyResourceThrottleTest, WillProcessResponse) { |
|
bengr
2014/12/29 18:45:41
I know we don't do a great job of this, but would
megjablon
2014/12/30 23:40:00
Done.
|
| + EXPECT_CALL(params_, IsDataReductionProxy(testing::_, testing::_)) |
| + .WillOnce(testing::Return(false)); |
| + bool defer = false; |
| + resource_throttle_->WillProcessResponse(&defer); |
| + EXPECT_TRUE(defer); |
| +} |
| + |
| +} // namespace data_reduction_proxy |