| Index: chrome/browser/chromeos/gview_request_interceptor_unittest.cc
|
| diff --git a/chrome/browser/chromeos/gview_request_interceptor_unittest.cc b/chrome/browser/chromeos/gview_request_interceptor_unittest.cc
|
| index 0723a967170e928b6b5d3ce8ce905462e370955a..f841bf5d9b0cda20a2c715c707a92eb83def3f70 100644
|
| --- a/chrome/browser/chromeos/gview_request_interceptor_unittest.cc
|
| +++ b/chrome/browser/chromeos/gview_request_interceptor_unittest.cc
|
| @@ -11,6 +11,7 @@
|
| #include "net/base/load_flags.h"
|
| #include "net/url_request/url_request.h"
|
| #include "net/url_request/url_request_job.h"
|
| +#include "net/url_request/url_request_job_factory.h"
|
| #include "net/url_request/url_request_test_job.h"
|
| #include "net/url_request/url_request_test_util.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| @@ -18,6 +19,8 @@
|
|
|
| namespace chromeos {
|
|
|
| +namespace {
|
| +
|
| class GViewURLRequestTestJob : public net::URLRequestTestJob {
|
| public:
|
| explicit GViewURLRequestTestJob(net::URLRequest* request)
|
| @@ -47,23 +50,25 @@ class GViewURLRequestTestJob : public net::URLRequestTestJob {
|
| ~GViewURLRequestTestJob() {}
|
| };
|
|
|
| -class GViewRequestInterceptorTest : public testing::Test {
|
| +class GViewRequestProtocolFactory
|
| + : public net::URLRequestJobFactory::ProtocolHandler {
|
| public:
|
| - virtual void SetUp() {
|
| - net::URLRequest::RegisterProtocolFactory("http",
|
| - &GViewRequestInterceptorTest::Factory);
|
| - interceptor_ = GViewRequestInterceptor::GetInstance();
|
| - ASSERT_TRUE(PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path_));
|
| - }
|
| + GViewRequestProtocolFactory() {}
|
| + virtual ~GViewRequestProtocolFactory() {}
|
|
|
| - virtual void TearDown() {
|
| - net::URLRequest::RegisterProtocolFactory("http", NULL);
|
| - message_loop_.RunAllPending();
|
| + virtual net::URLRequestJob* MaybeCreateJob(net::URLRequest* request) const {
|
| + return new GViewURLRequestTestJob(request);
|
| }
|
| +};
|
|
|
| - static net::URLRequestJob* Factory(net::URLRequest* request,
|
| - const std::string& scheme) {
|
| - return new GViewURLRequestTestJob(request);
|
| +class GViewRequestInterceptorTest : public testing::Test {
|
| + public:
|
| + virtual void SetUp() {
|
| + job_factory_.SetProtocolHandler("http", new GViewRequestProtocolFactory);
|
| + job_factory_.AddInterceptor(new GViewRequestInterceptor);
|
| + request_context_ = new TestURLRequestContext;
|
| + request_context_->set_job_factory(&job_factory_);
|
| + ASSERT_TRUE(PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path_));
|
| }
|
|
|
| void RegisterPDFPlugin() {
|
| @@ -102,13 +107,15 @@ class GViewRequestInterceptorTest : public testing::Test {
|
|
|
| protected:
|
| MessageLoopForIO message_loop_;
|
| + net::URLRequestJobFactory job_factory_;
|
| + scoped_refptr<TestURLRequestContext> request_context_;
|
| TestDelegate test_delegate_;
|
| - net::URLRequest::Interceptor* interceptor_;
|
| FilePath pdf_path_;
|
| };
|
|
|
| TEST_F(GViewRequestInterceptorTest, DoNotInterceptHtml) {
|
| net::URLRequest request(GURL("http://foo.com/index.html"), &test_delegate_);
|
| + request.set_context(request_context_);
|
| request.Start();
|
| MessageLoop::current()->Run();
|
| EXPECT_EQ(0, test_delegate_.received_redirect_count());
|
| @@ -117,6 +124,7 @@ TEST_F(GViewRequestInterceptorTest, DoNotInterceptHtml) {
|
|
|
| TEST_F(GViewRequestInterceptorTest, DoNotInterceptDownload) {
|
| net::URLRequest request(GURL("http://foo.com/file.pdf"), &test_delegate_);
|
| + request.set_context(request_context_);
|
| request.set_load_flags(net::LOAD_IS_DOWNLOAD);
|
| request.Start();
|
| MessageLoop::current()->Run();
|
| @@ -135,6 +143,7 @@ TEST_F(GViewRequestInterceptorTest, DoNotInterceptPdfWhenEnabled) {
|
| }
|
|
|
| net::URLRequest request(GURL("http://foo.com/file.pdf"), &test_delegate_);
|
| + request.set_context(request_context_);
|
| request.Start();
|
| MessageLoop::current()->Run();
|
| EXPECT_EQ(0, test_delegate_.received_redirect_count());
|
| @@ -152,6 +161,7 @@ TEST_F(GViewRequestInterceptorTest, InterceptPdfWhenDisabled) {
|
| }
|
|
|
| net::URLRequest request(GURL("http://foo.com/file.pdf"), &test_delegate_);
|
| + request.set_context(request_context_);
|
| request.Start();
|
| MessageLoop::current()->Run();
|
| EXPECT_EQ(1, test_delegate_.received_redirect_count());
|
| @@ -165,6 +175,7 @@ TEST_F(GViewRequestInterceptorTest, InterceptPdfWithNoPlugin) {
|
| SetPDFPluginLoadedState(false, &enabled);
|
|
|
| net::URLRequest request(GURL("http://foo.com/file.pdf"), &test_delegate_);
|
| + request.set_context(request_context_);
|
| request.Start();
|
| MessageLoop::current()->Run();
|
| EXPECT_EQ(1, test_delegate_.received_redirect_count());
|
| @@ -174,6 +185,7 @@ TEST_F(GViewRequestInterceptorTest, InterceptPdfWithNoPlugin) {
|
|
|
| TEST_F(GViewRequestInterceptorTest, InterceptPowerpoint) {
|
| net::URLRequest request(GURL("http://foo.com/file.ppt"), &test_delegate_);
|
| + request.set_context(request_context_);
|
| request.Start();
|
| MessageLoop::current()->Run();
|
| EXPECT_EQ(1, test_delegate_.received_redirect_count());
|
| @@ -181,4 +193,6 @@ TEST_F(GViewRequestInterceptorTest, InterceptPowerpoint) {
|
| request.url());
|
| }
|
|
|
| +} // namespace
|
| +
|
| } // namespace chromeos
|
|
|