Chromium Code Reviews| Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc |
| diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc |
| index 440053c95a2abaaf7a074460fac442df038b4f8c..35cd87c2e7ae272acab6152d535045ace1bb8760 100644 |
| --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc |
| +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc |
| @@ -111,6 +111,22 @@ class TestLoFiDecider : public LoFiDecider { |
| bool should_request_lofi_resource_; |
| }; |
| +class TestLoFiUIService : public LoFiUIService { |
| + public: |
| + TestLoFiUIService() : notified_lofi_response_(false) {} |
| + ~TestLoFiUIService() override {} |
| + |
| + bool DidNotifyLoFiResponse() { return notified_lofi_response_; } |
|
tbansal1
2016/01/05 03:10:59
Add const?
megjablon
2016/01/05 20:13:03
Done.
|
| + |
| + void NotifyLoFiReponseReceived( |
| + const net::URLRequest& request) const override { |
| + notified_lofi_response_ = true; |
| + } |
| + |
| + private: |
| + mutable bool notified_lofi_response_; |
| +}; |
| + |
| } // namespace |
| class DataReductionProxyNetworkDelegateTest : public testing::Test { |
| @@ -142,6 +158,10 @@ class DataReductionProxyNetworkDelegateTest : public testing::Test { |
| scoped_ptr<TestLoFiDecider> lofi_decider(new TestLoFiDecider()); |
| lofi_decider_ = lofi_decider.get(); |
| io_data()->set_lofi_decider(std::move(lofi_decider)); |
| + |
| + scoped_ptr<TestLoFiUIService> lofi_ui_service(new TestLoFiUIService()); |
| + lofi_ui_service_ = lofi_ui_service.get(); |
| + io_data()->set_lofi_ui_service(std::move(lofi_ui_service)); |
| } |
| const net::ProxyConfig& GetProxyConfig() const { return config_; } |
| @@ -165,6 +185,10 @@ class DataReductionProxyNetworkDelegateTest : public testing::Test { |
| test_context_->settings()->WasLoFiModeActiveOnMainFrame()); |
| } |
| + void VerifyDidNotifyLoFiResponse(bool lofi_response) { |
| + EXPECT_EQ(lofi_response, lofi_ui_service_->DidNotifyLoFiResponse()); |
| + } |
| + |
| int64_t total_received_bytes() { |
| return data_reduction_proxy_network_delegate_->total_received_bytes_; |
| } |
| @@ -238,6 +262,7 @@ class DataReductionProxyNetworkDelegateTest : public testing::Test { |
| net::ProxyConfig config_; |
| net::NetworkDelegate* network_delegate_; |
| TestLoFiDecider* lofi_decider_; |
| + TestLoFiUIService* lofi_ui_service_; |
| scoped_ptr<DataReductionProxyTestContext> test_context_; |
| scoped_ptr<DataReductionProxyBypassStats> bypass_stats_; |
| }; |
| @@ -680,4 +705,41 @@ TEST_F(DataReductionProxyNetworkDelegateTest, OnCompletedInternal) { |
| total_original_received_bytes()); |
| } |
| +TEST_F(DataReductionProxyNetworkDelegateTest, OnCompletedInternalLoFi) { |
| + const int64_t kResponseContentLength = 140; |
| + const int64_t kOriginalContentLength = 200; |
| + |
| + set_network_delegate(data_reduction_proxy_network_delegate_.get()); |
| + |
| + // Enable Lo-Fi. |
| + const struct { |
| + bool lofi_response; |
| + } tests[] = { |
| + {false}, {true}, |
| + }; |
| + |
| + for (size_t i = 0; i < arraysize(tests); ++i) { |
| + std::string raw_headers = |
| + "HTTP/1.1 200 OK\n" |
| + "Date: Wed, 28 Nov 2007 09:40:09 GMT\n" |
| + "Expires: Mon, 24 Nov 2014 12:45:26 GMT\n" |
| + "Via: 1.1 Chrome-Compression-Proxy\n" |
| + "x-original-content-length: " + |
| + base::Int64ToString(kOriginalContentLength) + "\n"; |
| + |
| + if (tests[i].lofi_response) { |
| + raw_headers += "Chrome-Proxy: q=low\n"; |
|
tbansal1
2016/01/05 03:10:59
Braces not needed.
megjablon
2016/01/05 20:13:03
Done.
|
| + } |
| + |
| + HeadersToRaw(&raw_headers); |
| + std::string response_headers = |
| + net::HttpUtil::ConvertHeadersBackToHTTPResponse(raw_headers); |
| + |
| + FetchURLRequest(GURL("http://www.google.com/"), response_headers, |
| + kResponseContentLength); |
| + |
| + VerifyDidNotifyLoFiResponse(tests[i].lofi_response); |
| + } |
| +} |
| + |
| } // namespace data_reduction_proxy |