| Index: net/url_request/url_request_http_job_unittest.cc
|
| diff --git a/net/url_request/url_request_http_job_unittest.cc b/net/url_request/url_request_http_job_unittest.cc
|
| index aa1599aa6cce1b56b906753b84491447423c7fff..41ee02c9c7e789c93eff34f38214af55c65c867f 100644
|
| --- a/net/url_request/url_request_http_job_unittest.cc
|
| +++ b/net/url_request/url_request_http_job_unittest.cc
|
| @@ -46,21 +46,91 @@ namespace {
|
|
|
| using ::testing::Return;
|
|
|
| +const char kSimpleGetMockWrite[] =
|
| + "GET / HTTP/1.1\r\n"
|
| + "Host: www.example.com\r\n"
|
| + "Connection: keep-alive\r\n"
|
| + "User-Agent:\r\n"
|
| + "Accept-Encoding: gzip, deflate\r\n"
|
| + "Accept-Language: en-us,fr\r\n\r\n";
|
| +
|
| // Inherit from URLRequestHttpJob to expose the priority and some
|
| // other hidden functions.
|
| class TestURLRequestHttpJob : public URLRequestHttpJob {
|
| public:
|
| explicit TestURLRequestHttpJob(URLRequest* request)
|
| - : URLRequestHttpJob(request, request->context()->network_delegate(),
|
| - request->context()->http_user_agent_settings()) {}
|
| + : URLRequestHttpJob(request,
|
| + request->context()->network_delegate(),
|
| + request->context()->http_user_agent_settings()),
|
| + use_null_source_stream_(false) {}
|
| +
|
| ~TestURLRequestHttpJob() override {}
|
|
|
| + // URLRequestJob implementation:
|
| + std::unique_ptr<SourceStream> SetUpSourceStream() override {
|
| + if (use_null_source_stream_)
|
| + return nullptr;
|
| + return URLRequestHttpJob::SetUpSourceStream();
|
| + }
|
| +
|
| + void set_use_null_source_stream(bool use_null_source_stream) {
|
| + use_null_source_stream_ = use_null_source_stream;
|
| + }
|
| +
|
| using URLRequestHttpJob::SetPriority;
|
| using URLRequestHttpJob::Start;
|
| using URLRequestHttpJob::Kill;
|
| using URLRequestHttpJob::priority;
|
| +
|
| + private:
|
| + bool use_null_source_stream_;
|
| +};
|
| +
|
| +class URLRequestHttpJobSetUpSourceTest : public ::testing::Test {
|
| + protected:
|
| + URLRequestHttpJobSetUpSourceTest() : context_(true) {
|
| + test_job_interceptor_ = new TestJobInterceptor();
|
| + EXPECT_TRUE(test_job_factory_.SetProtocolHandler(
|
| + url::kHttpScheme, base::WrapUnique(test_job_interceptor_)));
|
| + context_.set_job_factory(&test_job_factory_);
|
| + context_.set_client_socket_factory(&socket_factory_);
|
| + context_.Init();
|
| + }
|
| +
|
| + MockClientSocketFactory socket_factory_;
|
| + // |test_job_interceptor_| is owned by |test_job_factory_|.
|
| + TestJobInterceptor* test_job_interceptor_;
|
| + URLRequestJobFactoryImpl test_job_factory_;
|
| +
|
| + TestURLRequestContext context_;
|
| + TestDelegate delegate_;
|
| };
|
|
|
| +// Tests that if SetUpSourceStream() returns nullptr, the request fails.
|
| +TEST_F(URLRequestHttpJobSetUpSourceTest, SetUpSourceFails) {
|
| + MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)};
|
| + MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n"
|
| + "Content-Length: 12\r\n\r\n"),
|
| + MockRead("Test Content")};
|
| +
|
| + StaticSocketDataProvider socket_data(reads, arraysize(reads), writes,
|
| + arraysize(writes));
|
| + socket_factory_.AddSocketDataProvider(&socket_data);
|
| +
|
| + std::unique_ptr<URLRequest> request = context_.CreateRequest(
|
| + GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate_);
|
| + std::unique_ptr<TestURLRequestHttpJob> job(
|
| + new TestURLRequestHttpJob(request.get()));
|
| + job->set_use_null_source_stream(true);
|
| + test_job_interceptor_->set_main_intercept_job(std::move(job));
|
| + request->SetPriority(LOW);
|
| + request->Start();
|
| +
|
| + base::RunLoop().Run();
|
| + EXPECT_FALSE(request->status().is_success());
|
| + EXPECT_EQ(ERR_CONTENT_DECODING_INIT_FAILED, request->status().error());
|
| +}
|
| +
|
| class URLRequestHttpJobTest : public ::testing::Test {
|
| protected:
|
| URLRequestHttpJobTest() : context_(true) {
|
| @@ -135,14 +205,6 @@ class URLRequestHttpJobWithMockSocketsTest : public ::testing::Test {
|
| std::unique_ptr<TestURLRequestContext> context_;
|
| };
|
|
|
| -const char kSimpleGetMockWrite[] =
|
| - "GET / HTTP/1.1\r\n"
|
| - "Host: www.example.com\r\n"
|
| - "Connection: keep-alive\r\n"
|
| - "User-Agent:\r\n"
|
| - "Accept-Encoding: gzip, deflate\r\n"
|
| - "Accept-Language: en-us,fr\r\n\r\n";
|
| -
|
| TEST_F(URLRequestHttpJobWithMockSocketsTest,
|
| TestContentLengthSuccessfulRequest) {
|
| MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)};
|
| @@ -695,7 +757,7 @@ class URLRequestHttpJobWebSocketTest
|
| class MockCreateHelper : public WebSocketHandshakeStreamBase::CreateHelper {
|
| public:
|
| // GoogleMock does not appear to play nicely with move-only types like
|
| - // scoped_ptr, so this forwarding method acts as a workaround.
|
| + // std::unique_ptr, so this forwarding method acts as a workaround.
|
| WebSocketHandshakeStreamBase* CreateBasicStream(
|
| std::unique_ptr<ClientSocketHandle> connection,
|
| bool using_proxy) override {
|
|
|