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..fa5d9fe4530b35606050eb0c60ba4236fdc775fd |
--- /dev/null |
+++ b/components/data_reduction_proxy/content/browser/data_reduction_proxy_resource_throttle_unittest.cc |
@@ -0,0 +1,161 @@ |
+// 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 "base/message_loop/message_loop.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_test_utils.h" |
+#include "content/public/common/resource_type.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_test_util.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "url/gurl.h" |
+ |
+namespace base { |
+class TimeDelta; |
+} |
+ |
+namespace data_reduction_proxy { |
+ |
+namespace { |
+ |
+class TestDataReductionProxyResourceThrottle |
+ : public DataReductionProxyResourceThrottle { |
+ public: |
+ TestDataReductionProxyResourceThrottle( |
+ net::URLRequest* request, |
+ content::ResourceType resource_type, |
+ 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); |
+}; |
+ |
+} // 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()); |
+ params_.reset(new TestDataReductionProxyParams(0, 0)); |
bengr
2014/12/31 01:10:21
#include
megjablon
2014/12/31 02:12:28
Done.
|
+ resource_throttle_.reset(new TestDataReductionProxyResourceThrottle( |
+ request_.get(), content::RESOURCE_TYPE_MAIN_FRAME, |
+ ui_service_.get(), params_.get())); |
+ } |
+ |
+ protected: |
+ // Required for base::MessageLoopProxy::current(). |
+ base::MessageLoopForIO loop_; |
+ |
+ 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_; |
+ scoped_ptr<TestDataReductionProxyParams> params_; |
+ scoped_ptr<TestDataReductionProxyResourceThrottle> resource_throttle_; |
+}; |
+ |
+// Tests that WillStartUsingNetwork calls DisplayBlockingPage when |
bengr
2014/12/31 01:10:21
I like adding parentheses when referring to functi
megjablon
2014/12/31 02:12:28
Done.
|
+// AreDataReductionProxiesBypassed returns true and |
+// IsBypassedByDataReductionProxyLocalRules returns false. Also tests that |
+// DisplayBlockingPage is not called for other values of |
+// AreDataReductionProxiesBypassed and IsBypassedByDataReductionProxyLocalRules. |
+TEST_F(DataReductionProxyResourceThrottleTest, WillStartUsingNetwork) { |
+ bool defer = false; |
+ params_->MockAreDataReductionProxiesBypassed(false); |
+ resource_throttle_->WillStartUsingNetwork(&defer); |
+ EXPECT_FALSE(defer); |
+ |
+ params_->MockAreDataReductionProxiesBypassed(true); |
+ params_->MockIsBypassedByDataReductionProxyLocalRules(false); |
+ resource_throttle_->WillStartUsingNetwork(&defer); |
+ EXPECT_TRUE(defer); |
+ |
+ // Must be tested last because this sets |state_| of |resource_throttle_| |
+ // to LOCAL_BYPASS. |
+ defer = false; |
+ params_->MockAreDataReductionProxiesBypassed(true); |
+ params_->MockIsBypassedByDataReductionProxyLocalRules(true); |
+ resource_throttle_->WillStartUsingNetwork(&defer); |
+ EXPECT_FALSE(defer); |
+} |
+ |
+// Tests that WillRedirectRequest does not call DisplayBlockingPage when the |
+// LOAD_BYPASS_PROXY flag is not set and does call DisplayBlockingPage when the |
+// flag is set. |
+TEST_F(DataReductionProxyResourceThrottleTest, WillRedirectRequest) { |
+ bool defer = false; |
+ resource_throttle_->WillRedirectRequest(GURL(), &defer); |
+ EXPECT_FALSE(defer); |
+ |
+ request_->SetLoadFlags(net::LOAD_BYPASS_PROXY); |
+ resource_throttle_->WillRedirectRequest(GURL(), &defer); |
+ EXPECT_TRUE(defer); |
+} |
+ |
+// Tests that WillProcessResponse dose not call DisplayBlockingPage when |
bengr
2014/12/31 01:10:21
Rewrite this too. (From the test code I have no id
megjablon
2014/12/31 02:12:28
Done.
|
+// IsDataReductionProxy returns true. Also tests that it does call |
+// DisplayBlockingPage when IsDataReductionProxy returns false. |
+TEST_F(DataReductionProxyResourceThrottleTest, WillProcessResponse) { |
+ bool defer = false; |
+ params_->MockIsDataReductionProxy(true); |
+ resource_throttle_->WillProcessResponse(&defer); |
+ EXPECT_FALSE(defer); |
+ |
+ params_->MockIsDataReductionProxy(false); |
+ resource_throttle_->WillProcessResponse(&defer); |
+ EXPECT_TRUE(defer); |
+} |
+ |
+} // namespace data_reduction_proxy |