Commit 15574a68 authored by rajendrant's avatar rajendrant Committed by Commit Bot

Remove unneeded URL redirect cycle unittests

Redirect cycle tests are in browser test with NetworkService.

Bug: 968214
Change-Id: I27f6d659789fceaf3dc37ffe13204a5925573212
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1644322Reviewed-by: default avatarRobert Ogden <robertogden@chromium.org>
Reviewed-by: default avatarTarun Bansal <tbansal@chromium.org>
Commit-Queue: rajendrant <rajendrant@chromium.org>
Cr-Commit-Position: refs/heads/master@{#666173}
parent 2aef1e3c
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/scoped_task_environment.h" #include "base/test/scoped_task_environment.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h"
...@@ -27,7 +26,6 @@ ...@@ -27,7 +26,6 @@
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_bypass_protocol.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_bypass_protocol.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers_test_utils.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers_test_utils.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h"
...@@ -148,10 +146,6 @@ class DataReductionProxyBypassStatsEndToEndTest : public testing::Test { ...@@ -148,10 +146,6 @@ class DataReductionProxyBypassStatsEndToEndTest : public testing::Test {
} }
void SetUp() override { void SetUp() override {
// TODO(crbug.com/968214): Modify these tests to work correctly with the
// network service (and DRP) enabled by default.
scoped_feature_list_.InitWithFeatures(
{}, {features::kDataReductionProxyEnabledWithNetworkService});
drp_test_context_ = DataReductionProxyTestContext::Builder() drp_test_context_ = DataReductionProxyTestContext::Builder()
.WithURLRequestContext(&context_) .WithURLRequestContext(&context_)
.WithMockClientSocketFactory(&mock_socket_factory_) .WithMockClientSocketFactory(&mock_socket_factory_)
...@@ -388,7 +382,6 @@ class DataReductionProxyBypassStatsEndToEndTest : public testing::Test { ...@@ -388,7 +382,6 @@ class DataReductionProxyBypassStatsEndToEndTest : public testing::Test {
net::TestDelegate* delegate() { return &delegate_; } net::TestDelegate* delegate() { return &delegate_; }
private: private:
base::test::ScopedFeatureList scoped_feature_list_;
base::test::ScopedTaskEnvironment task_environment_{ base::test::ScopedTaskEnvironment task_environment_{
base::test::ScopedTaskEnvironment::MainThreadType::IO}; base::test::ScopedTaskEnvironment::MainThreadType::IO};
net::TestDelegate delegate_; net::TestDelegate delegate_;
...@@ -436,31 +429,6 @@ TEST_F(DataReductionProxyBypassStatsEndToEndTest, BypassedBytesNoRetry) { ...@@ -436,31 +429,6 @@ TEST_F(DataReductionProxyBypassStatsEndToEndTest, BypassedBytesNoRetry) {
} }
} }
// Verify that when there is a URL redirect cycle, data reduction proxy is
// bypassed for a single request.
TEST_F(DataReductionProxyBypassStatsEndToEndTest, URLRedirectCycle) {
InitializeContext();
ClearBadProxies();
base::HistogramTester histogram_tester_1;
CreateAndExecuteURLRedirectCycleRequest();
histogram_tester_1.ExpectUniqueSample(
"DataReductionProxy.BypassedBytes.URLRedirectCycle", kBody.size(), 1);
ExpectOtherBypassedBytesHistogramsEmpty(
histogram_tester_1, "DataReductionProxy.BypassedBytes.URLRedirectCycle");
// The second request should be sent via the proxy.
base::HistogramTester histogram_tester_2;
CreateAndExecuteRequest(GURL("http://bar.com"), net::LOAD_NORMAL, net::OK,
"HTTP/1.1 200 OK\r\n"
"Via: 1.1 Chrome-Compression-Proxy\r\n\r\n",
kNextBody.c_str(), nullptr, nullptr);
histogram_tester_2.ExpectUniqueSample(
"DataReductionProxy.BypassedBytes.NotBypassed", kNextBody.size(), 1);
ExpectOtherBypassedBytesHistogramsEmpty(
histogram_tester_2, "DataReductionProxy.BypassedBytes.NotBypassed");
}
TEST_F(DataReductionProxyBypassStatsEndToEndTest, TEST_F(DataReductionProxyBypassStatsEndToEndTest,
BypassedBytesProxyOverridden) { BypassedBytesProxyOverridden) {
std::unique_ptr<net::ProxyResolutionService> proxy_resolution_service( std::unique_ptr<net::ProxyResolutionService> proxy_resolution_service(
......
...@@ -420,66 +420,6 @@ TEST_F(DataReductionProxyInterceptorEndToEndTest, RedirectWithoutRetry) { ...@@ -420,66 +420,6 @@ TEST_F(DataReductionProxyInterceptorEndToEndTest, RedirectWithoutRetry) {
EXPECT_EQ(1, delegate().received_redirect_count()); EXPECT_EQ(1, delegate().received_redirect_count());
} }
// Test that data reduction proxy is byppassed if there is a URL redirect cycle.
// TODO(crbug.com/968214): Modify this test to work correctly with the
// network service (and DRP) enabled by default.
TEST_F(DataReductionProxyInterceptorEndToEndTest, DISABLED_URLRedirectCycle) {
base::HistogramTester histogram_tester;
MockRead redirect_mock_reads_1[] = {
MockRead("HTTP/1.1 302 Found\r\n"
"Via: 1.1 Chrome-Compression-Proxy\r\n"
"Location: http://bar.com/\r\n\r\n"),
MockRead(""), MockRead(net::SYNCHRONOUS, net::OK),
};
net::StaticSocketDataProvider redirect_socket_data_provider_1(
redirect_mock_reads_1, base::span<net::MockWrite>());
mock_socket_factory()->AddSocketDataProvider(
&redirect_socket_data_provider_1);
MockRead redirect_mock_reads_2[] = {
MockRead("HTTP/1.1 302 Found\r\n"
"Via: 1.1 Chrome-Compression-Proxy\r\n"
"Location: http://foo.com/\r\n\r\n"),
MockRead(""), MockRead(net::SYNCHRONOUS, net::OK),
};
net::StaticSocketDataProvider redirect_socket_data_provider_2(
redirect_mock_reads_2, base::span<net::MockWrite>());
mock_socket_factory()->AddSocketDataProvider(
&redirect_socket_data_provider_2);
// Redirect cycle.
MockRead redirect_mock_reads_3[] = {
MockRead("HTTP/1.1 302 Found\r\n"
"Via: 1.1 Chrome-Compression-Proxy\r\n"
"Location: http://bar.com/\r\n\r\n"),
MockRead(""), MockRead(net::SYNCHRONOUS, net::OK),
};
net::StaticSocketDataProvider redirect_socket_data_provider_3(
redirect_mock_reads_3, base::span<net::MockWrite>());
mock_socket_factory()->AddSocketDataProvider(
&redirect_socket_data_provider_3);
// Data reduction proxy should be bypassed.
MockRead redirect_mock_reads_4[] = {
MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead(kBody.c_str()),
MockRead(net::SYNCHRONOUS, net::OK),
};
net::StaticSocketDataProvider redirect_socket_data_provider_4(
redirect_mock_reads_4, base::span<net::MockWrite>());
mock_socket_factory()->AddSocketDataProvider(
&redirect_socket_data_provider_4);
std::unique_ptr<net::URLRequest> request =
CreateAndExecuteRequest(GURL("http://foo.com"));
EXPECT_EQ(net::OK, delegate().request_status());
EXPECT_EQ(200, request->GetResponseCode());
EXPECT_EQ(kBody, delegate().data_received());
EXPECT_TRUE(request->proxy_server().is_direct());
histogram_tester.ExpectTotalCount(
"DataReductionProxy.BypassedBytes.URLRedirectCycle", 1);
}
TEST_F(DataReductionProxyInterceptorEndToEndTest, ResponseWithBypassAndRetry) { TEST_F(DataReductionProxyInterceptorEndToEndTest, ResponseWithBypassAndRetry) {
// The first try gives a bypass. // The first try gives a bypass.
MockRead initial_mock_reads[] = { MockRead initial_mock_reads[] = {
......
...@@ -24,21 +24,7 @@ ...@@ -24,21 +24,7 @@
namespace data_reduction_proxy { namespace data_reduction_proxy {
class DataReductionProxyHeadersTest : public testing::Test { TEST(DataReductionProxyHeadersTest, IsEmptyImagePreview) {
public:
void SetUp() override {
// TODO(crbug.com/968214): Modify these tests to work correctly with the
// network service (and DRP) enabled by default. This class can be deleted
// and TEST_F => TEST with that change.
scoped_feature_list_.InitWithFeatures(
{}, {features::kDataReductionProxyEnabledWithNetworkService});
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
TEST_F(DataReductionProxyHeadersTest, IsEmptyImagePreview) {
const struct { const struct {
const char* headers; const char* headers;
bool expected_result; bool expected_result;
...@@ -86,7 +72,7 @@ TEST_F(DataReductionProxyHeadersTest, IsEmptyImagePreview) { ...@@ -86,7 +72,7 @@ TEST_F(DataReductionProxyHeadersTest, IsEmptyImagePreview) {
} }
} }
TEST_F(DataReductionProxyHeadersTest, IsEmptyImagePreviewValue) { TEST(DataReductionProxyHeadersTest, IsEmptyImagePreviewValue) {
const struct { const struct {
const char* chrome_proxy_content_transform_header; const char* chrome_proxy_content_transform_header;
const char* chrome_proxy_header; const char* chrome_proxy_header;
...@@ -107,7 +93,7 @@ TEST_F(DataReductionProxyHeadersTest, IsEmptyImagePreviewValue) { ...@@ -107,7 +93,7 @@ TEST_F(DataReductionProxyHeadersTest, IsEmptyImagePreviewValue) {
} }
} }
TEST_F(DataReductionProxyHeadersTest, IsLitePagePreview) { TEST(DataReductionProxyHeadersTest, IsLitePagePreview) {
const struct { const struct {
const char* headers; const char* headers;
bool expected_result; bool expected_result;
...@@ -155,7 +141,7 @@ TEST_F(DataReductionProxyHeadersTest, IsLitePagePreview) { ...@@ -155,7 +141,7 @@ TEST_F(DataReductionProxyHeadersTest, IsLitePagePreview) {
} }
} }
TEST_F(DataReductionProxyHeadersTest, GetDataReductionProxyActionValue) { TEST(DataReductionProxyHeadersTest, GetDataReductionProxyActionValue) {
const struct { const struct {
const char* headers; const char* headers;
std::string action_key; std::string action_key;
...@@ -249,7 +235,7 @@ TEST_F(DataReductionProxyHeadersTest, GetDataReductionProxyActionValue) { ...@@ -249,7 +235,7 @@ TEST_F(DataReductionProxyHeadersTest, GetDataReductionProxyActionValue) {
} }
} }
TEST_F(DataReductionProxyHeadersTest, GetProxyBypassInfo) { TEST(DataReductionProxyHeadersTest, GetProxyBypassInfo) {
const struct { const struct {
const char* headers; const char* headers;
bool expected_result; bool expected_result;
...@@ -501,7 +487,7 @@ TEST_F(DataReductionProxyHeadersTest, GetProxyBypassInfo) { ...@@ -501,7 +487,7 @@ TEST_F(DataReductionProxyHeadersTest, GetProxyBypassInfo) {
} }
} }
TEST_F(DataReductionProxyHeadersTest, ParseHeadersAndSetProxyInfo) { TEST(DataReductionProxyHeadersTest, ParseHeadersAndSetProxyInfo) {
std::string headers = std::string headers =
"HTTP/1.1 200 OK\n" "HTTP/1.1 200 OK\n"
"connection: keep-alive\n" "connection: keep-alive\n"
...@@ -518,7 +504,7 @@ TEST_F(DataReductionProxyHeadersTest, ParseHeadersAndSetProxyInfo) { ...@@ -518,7 +504,7 @@ TEST_F(DataReductionProxyHeadersTest, ParseHeadersAndSetProxyInfo) {
EXPECT_FALSE(data_reduction_proxy_info.bypass_all); EXPECT_FALSE(data_reduction_proxy_info.bypass_all);
} }
TEST_F(DataReductionProxyHeadersTest, HasDataReductionProxyViaHeader) { TEST(DataReductionProxyHeadersTest, HasDataReductionProxyViaHeader) {
const struct { const struct {
const char* headers; const char* headers;
bool expected_result; bool expected_result;
...@@ -616,7 +602,7 @@ TEST_F(DataReductionProxyHeadersTest, HasDataReductionProxyViaHeader) { ...@@ -616,7 +602,7 @@ TEST_F(DataReductionProxyHeadersTest, HasDataReductionProxyViaHeader) {
} }
} }
TEST_F(DataReductionProxyHeadersTest, GetDataReductionProxyBypassEventType) { TEST(DataReductionProxyHeadersTest, GetDataReductionProxyBypassEventType) {
const struct { const struct {
const char* headers; const char* headers;
DataReductionProxyBypassType expected_result; DataReductionProxyBypassType expected_result;
...@@ -748,82 +734,4 @@ TEST_F(DataReductionProxyHeadersTest, GetDataReductionProxyBypassEventType) { ...@@ -748,82 +734,4 @@ TEST_F(DataReductionProxyHeadersTest, GetDataReductionProxyBypassEventType) {
} }
} }
TEST_F(DataReductionProxyHeadersTest,
GetDataReductionProxyBypassEventTypeURLRedirectCycle) {
const struct {
const char* headers;
std::vector<GURL> url_chain;
DataReductionProxyBypassType expected_result;
} tests[] = {
{
"HTTP/1.1 200 OK\n"
"Via: 1.1 Chrome-Compression-Proxy\n",
std::vector<GURL>{GURL("http://google.com/1"),
GURL("http://google.com/2"),
GURL("http://google.com/1")},
BYPASS_EVENT_TYPE_URL_REDIRECT_CYCLE,
},
{
"HTTP/1.1 200 OK\n"
"Via: 1.1 Chrome-Compression-Proxy\n",
std::vector<GURL>{
GURL("http://google.com/1"), GURL("http://google.com/2"),
GURL("http://google.com/1"), GURL("http://google.com/2")},
BYPASS_EVENT_TYPE_URL_REDIRECT_CYCLE,
},
{
"HTTP/1.1 200 OK\n"
"Via: 1.1 Chrome-Compression-Proxy\n",
std::vector<GURL>{GURL("http://google.com/1")}, BYPASS_EVENT_TYPE_MAX,
},
{
"HTTP/1.1 200 OK\n"
"Via: 1.1 Chrome-Compression-Proxy\n",
std::vector<GURL>{GURL("http://google.com/1"),
GURL("http://google.com/2")},
BYPASS_EVENT_TYPE_MAX,
},
{
"HTTP/1.1 200 OK\n"
"Via: 1.1 Chrome-Compression-Proxy\n",
std::vector<GURL>{GURL("http://google.com/1"),
GURL("http://google.com/2"),
GURL("http://google.com/3")},
BYPASS_EVENT_TYPE_MAX,
},
{
"HTTP/1.1 200 OK\n"
"Via: 1.1 Chrome-Compression-Proxy\n",
std::vector<GURL>{
GURL("http://google.com/1"), GURL("http://google.com/2"),
GURL("http://google.com/3"), GURL("http://google.com/1")},
BYPASS_EVENT_TYPE_URL_REDIRECT_CYCLE,
},
{
"HTTP/1.1 200 OK\n"
"Via: 1.1 Chrome-Compression-Proxy\n",
std::vector<GURL>{
GURL("http://google.com/1"), GURL("http://google.com/2"),
GURL("http://google.com/1"), GURL("http://google.com/3")},
BYPASS_EVENT_TYPE_MAX,
},
{
"HTTP/1.1 200 OK\n"
"Via: 1.1 Chrome-Compression-Proxy\n",
std::vector<GURL>(), BYPASS_EVENT_TYPE_MAX,
}};
for (const auto& test : tests) {
std::string headers(test.headers);
HeadersToRaw(&headers);
scoped_refptr<net::HttpResponseHeaders> parsed(
new net::HttpResponseHeaders(headers));
DataReductionProxyInfo chrome_proxy_info;
EXPECT_EQ(test.expected_result,
GetDataReductionProxyBypassType(test.url_chain, *parsed,
&chrome_proxy_info));
}
}
} // namespace data_reduction_proxy } // namespace data_reduction_proxy
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment