Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Unified Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor_unittest.cc

Issue 749793002: Data reduction proxy bypass with test server (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor_unittest.cc
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor_unittest.cc
index 0c7559d7f5c2202eb1144ab73eeb0b728e9f7568..09ae8048bc34c203463f3b10ef7272ec88090432 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor_unittest.cc
@@ -4,11 +4,19 @@
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor.h"
+#include "base/files/file_path.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.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_switches.h"
#include "net/base/capturing_net_log.h"
+#include "net/base/request_priority.h"
#include "net/http/http_response_headers.h"
+#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_intercepting_job_factory.h"
#include "net/url_request/url_request_interceptor.h"
@@ -143,4 +151,117 @@ TEST_F(DataReductionProxyInterceptorTest, TestJobFactoryChaining) {
EXPECT_EQ(0, interceptor2->redirect_count());
EXPECT_EQ(1, interceptor2->response_count());
}
+
+class DataReductionProxyInterceptorWithServerTest : public testing::Test {
+ public:
+ DataReductionProxyInterceptorWithServerTest()
+ : context_(true) {
+ context_.set_network_delegate(&network_delegate_);
+ context_.set_net_log(&net_log_);
+ }
+
+ ~DataReductionProxyInterceptorWithServerTest() override {
+ // URLRequestJobs may post clean-up tasks on destruction.
+ base::RunLoop().RunUntilIdle();
+ }
+
+ void SetUp() override {
+ base::FilePath root_path, proxy_file_path, direct_file_path;
+ PathService::Get(base::DIR_SOURCE_ROOT, &root_path);
+ proxy_file_path = root_path.AppendASCII(
+ "components/test/data/data_reduction_proxy/proxy");
+ direct_file_path = root_path.AppendASCII(
+ "components/test/data/data_reduction_proxy/direct");
+ proxy_.ServeFilesFromDirectory(proxy_file_path);
+ direct_.ServeFilesFromDirectory(direct_file_path);
+ ASSERT_TRUE(proxy_.InitializeAndWaitUntilReady());
+ ASSERT_TRUE(direct_.InitializeAndWaitUntilReady());
+
+ params_.reset(
+ new TestDataReductionProxyParams(
+ DataReductionProxyParams::kAllowed,
+ TestDataReductionProxyParams::HAS_EVERYTHING &
+ ~TestDataReductionProxyParams::HAS_DEV_ORIGIN &
+ ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN));
+ params_->set_origin(proxy_.GetURL("/"));
+ std::string proxy_name =
+ net::HostPortPair::FromURL(GURL(params_->origin())).ToString();
+ proxy_service_.reset(
+ net::ProxyService::CreateFixedFromPacResult(
+ "PROXY " + proxy_name + "; DIRECT"));
+
+ context_.set_proxy_service(proxy_service_.get());
+
+ event_store_.reset(
+ new DataReductionProxyEventStore(loop_.message_loop_proxy()));
+
+ DataReductionProxyInterceptor* interceptor =
+ new DataReductionProxyInterceptor(params_.get(), NULL,
+ event_store_.get());
+
+ scoped_ptr<net::URLRequestJobFactoryImpl> job_factory_impl(
+ new net::URLRequestJobFactoryImpl());
+ job_factory_.reset(
+ new net::URLRequestInterceptingJobFactory(
+ job_factory_impl.Pass(),
+ make_scoped_ptr(interceptor)));
+ context_.set_job_factory(job_factory_.get());
+ context_.Init();
+ }
+
+
+ const net::TestURLRequestContext& context() {
+ return context_;
+ }
+
+ const net::test_server::EmbeddedTestServer& direct() {
+ return direct_;
+ }
+
+ private:
+ net::CapturingNetLog net_log_;
+ net::TestNetworkDelegate network_delegate_;
+
+ net::TestURLRequestContext context_;
+ net::test_server::EmbeddedTestServer proxy_;
+ net::test_server::EmbeddedTestServer direct_;
+ scoped_ptr<TestDataReductionProxyParams> params_;
+ scoped_ptr<net::ProxyService> proxy_service_;
+ scoped_ptr<DataReductionProxyEventStore> event_store_;
+ scoped_ptr<net::URLRequestJobFactory> job_factory_;
+
+ base::MessageLoopForIO loop_;
+};
+
+TEST_F(DataReductionProxyInterceptorWithServerTest, TestBypass) {
+ // Tests the mechanics of proxy bypass work with a "real" server. For tests
+ // that cover every imaginable response that could trigger a bypass, see:
+ // DataReductionProxyProtocolTest.
+ net::TestDelegate delegate;
+ scoped_ptr<net::URLRequest> request(
+ context().CreateRequest(direct().GetURL("/block10.html"),
+ net::DEFAULT_PRIORITY, &delegate, NULL));
+ request->Start();
+ EXPECT_TRUE(request->is_pending());
+ base::RunLoop().Run();
+
+ EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status());
+ EXPECT_EQ(net::OK, request->status().error());
+ EXPECT_EQ("hello", delegate.data_received());
+}
+
+TEST_F(DataReductionProxyInterceptorWithServerTest, TestNoBypass) {
+ net::TestDelegate delegate;
+ scoped_ptr<net::URLRequest> request(
+ context().CreateRequest(direct().GetURL("/noblock.html"),
+ net::DEFAULT_PRIORITY, &delegate, NULL));
+ request->Start();
+ EXPECT_TRUE(request->is_pending());
+ base::RunLoop().Run();
+
+ EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status());
+ EXPECT_EQ(net::OK, request->status().error());
+ EXPECT_EQ("hello", delegate.data_received());
+}
+
} // namespace data_reduction_proxy
« no previous file with comments | « components/components_unittests.isolate ('k') | components/data_reduction_proxy/core/common/data_reduction_proxy_params.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698