Index: components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats_unittest.cc |
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats_unittest.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats_unittest.cc |
index e522a95f40892f89b50f81391f6a18320a066225..7e0c16cc4c0b97d046fc9f92f902a8ec4ea2177d 100644 |
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats_unittest.cc |
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats_unittest.cc |
@@ -6,6 +6,7 @@ |
#include "base/bind.h" |
#include "base/memory/scoped_ptr.h" |
+#include "net/base/host_port_pair.h" |
#include "net/base/request_priority.h" |
#include "net/url_request/url_request.h" |
#include "net/url_request/url_request_status.h" |
@@ -13,27 +14,25 @@ |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
-using base::MessageLoop; |
-using base::MessageLoopProxy; |
-using data_reduction_proxy::DataReductionProxyParams; |
-using net::TestDelegate; |
-using net::TestURLRequestContext; |
-using net::URLRequest; |
-using net::URLRequestStatus; |
using testing::Return; |
namespace { |
-class DataReductionProxyParamsMock : public DataReductionProxyParams { |
+class DataReductionProxyParamsMock : |
+ public data_reduction_proxy::DataReductionProxyParams { |
public: |
- DataReductionProxyParamsMock() : DataReductionProxyParams(0) {} |
+ DataReductionProxyParamsMock() : |
+ data_reduction_proxy::DataReductionProxyParams(0) {} |
virtual ~DataReductionProxyParamsMock() {} |
- MOCK_METHOD1(IsDataReductionProxyEligible, bool(const net::URLRequest*)); |
+ MOCK_CONST_METHOD2( |
+ IsDataReductionProxy, |
+ bool(const net::HostPortPair& host_port_pair, |
+ data_reduction_proxy::DataReductionProxyTypeInfo* proxy_info)); |
MOCK_CONST_METHOD2( |
WasDataReductionProxyUsed, |
bool(const net::URLRequest*, |
- data_reduction_proxy::DataReductionProxyTypeInfo* proxy_servers)); |
+ data_reduction_proxy::DataReductionProxyTypeInfo* proxy_info)); |
private: |
DISALLOW_COPY_AND_ASSIGN(DataReductionProxyParamsMock); |
@@ -43,10 +42,11 @@ class DataReductionProxyParamsMock : public DataReductionProxyParams { |
namespace data_reduction_proxy { |
+ |
class DataReductionProxyUsageStatsTest : public testing::Test { |
public: |
DataReductionProxyUsageStatsTest() |
- : loop_proxy_(MessageLoopProxy::current().get()), |
+ : loop_proxy_(base::MessageLoopProxy::current().get()), |
context_(true), |
unavailable_(false) { |
context_.Init(); |
@@ -58,21 +58,24 @@ class DataReductionProxyUsageStatsTest : public testing::Test { |
unavailable_ = unavailable; |
} |
- // Required for MessageLoopProxy::current(). |
+ // Required for base::MessageLoopProxy::current(). |
base::MessageLoopForUI loop_; |
- MessageLoopProxy* loop_proxy_; |
+ base::MessageLoopProxy* loop_proxy_; |
protected: |
- TestURLRequestContext context_; |
- TestDelegate delegate_; |
+ net::TestURLRequestContext context_; |
+ net::TestDelegate delegate_; |
DataReductionProxyParamsMock mock_params_; |
- scoped_ptr<URLRequest> mock_url_request_; |
+ scoped_ptr<net::URLRequest> mock_url_request_; |
bool unavailable_; |
}; |
TEST_F(DataReductionProxyUsageStatsTest, IsDataReductionProxyUnreachable) { |
+ net::ProxyServer fallback_proxy_server = |
+ net::ProxyServer::FromURI("foo.com", net::ProxyServer::SCHEME_HTTP); |
+ data_reduction_proxy::DataReductionProxyTypeInfo proxy_info; |
struct TestCase { |
- bool is_proxy_eligible; |
+ bool fallback_proxy_server_is_data_reduction_proxy; |
bool was_proxy_used; |
bool is_unreachable; |
}; |
@@ -83,6 +86,11 @@ TEST_F(DataReductionProxyUsageStatsTest, IsDataReductionProxyUnreachable) { |
false |
}, |
{ |
+ false, |
+ true, |
+ false |
+ }, |
+ { |
true, |
true, |
false |
@@ -96,12 +104,12 @@ TEST_F(DataReductionProxyUsageStatsTest, IsDataReductionProxyUnreachable) { |
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
TestCase test_case = test_cases[i]; |
- EXPECT_CALL(mock_params_, |
- IsDataReductionProxyEligible(mock_url_request_.get())) |
- .WillRepeatedly(Return(test_case.is_proxy_eligible)); |
+ EXPECT_CALL(mock_params_, IsDataReductionProxy(testing::_, testing::_)) |
+ .WillRepeatedly(testing::Return( |
+ test_case.fallback_proxy_server_is_data_reduction_proxy)); |
EXPECT_CALL(mock_params_, |
WasDataReductionProxyUsed(mock_url_request_.get(), NULL)) |
- .WillRepeatedly(Return(test_case.was_proxy_used)); |
+ .WillRepeatedly(testing::Return(test_case.was_proxy_used)); |
scoped_ptr<DataReductionProxyUsageStats> usage_stats( |
new DataReductionProxyUsageStats( |
@@ -110,8 +118,10 @@ TEST_F(DataReductionProxyUsageStatsTest, IsDataReductionProxyUnreachable) { |
base::Bind(&DataReductionProxyUsageStatsTest::NotifyUnavailable, |
base::Unretained(this))); |
+ usage_stats->OnProxyFallback(fallback_proxy_server, |
+ net::ERR_PROXY_CONNECTION_FAILED); |
usage_stats->OnUrlRequestCompleted(mock_url_request_.get(), false); |
- MessageLoop::current()->RunUntilIdle(); |
+ base::MessageLoop::current()->RunUntilIdle(); |
EXPECT_EQ(test_case.is_unreachable, unavailable_); |
} |