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

Unified Diff: net/url_request/url_request_http_job_unittest.cc

Issue 1563633002: Make URLRequestJob::SetStatus private. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Response to comments Created 4 years, 11 months 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: 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 713ae608e40a4247fe371c6903a28b595dd29784..5958487c9e3403e6f00c0427b92020e5d994f4f6 100644
--- a/net/url_request/url_request_http_job_unittest.cc
+++ b/net/url_request/url_request_http_job_unittest.cc
@@ -22,12 +22,14 @@
#include "net/socket/socket_test_util.h"
#include "net/test/cert_test_util.h"
#include "net/url_request/url_request.h"
+#include "net/url_request/url_request_job_factory_impl.h"
#include "net/url_request/url_request_status.h"
#include "net/url_request/url_request_test_util.h"
#include "net/websockets/websocket_handshake_stream_base.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
+#include "url/url_constants.h"
namespace net {
@@ -52,11 +54,19 @@ class TestURLRequestHttpJob : public URLRequestHttpJob {
class URLRequestHttpJobTest : public ::testing::Test {
protected:
- URLRequestHttpJobTest()
- : req_(context_.CreateRequest(GURL("http://www.example.com"),
- DEFAULT_PRIORITY,
- &delegate_)) {
+ URLRequestHttpJobTest() : context_(true) {
context_.set_http_transaction_factory(&network_layer_);
+
+ // The |test_job_factory_| takes ownership of the interceptor.
+ test_job_interceptor_ = new TestJobInterceptor();
+ EXPECT_TRUE(test_job_factory_.SetProtocolHandler(
+ url::kHttpScheme, make_scoped_ptr(test_job_interceptor_)));
+ context_.set_job_factory(&test_job_factory_);
+
+ context_.Init();
+
+ req_ = context_.CreateRequest(GURL("http://www.example.com"),
+ DEFAULT_PRIORITY, &delegate_);
}
bool TransactionAcceptsSdchEncoding() {
@@ -91,6 +101,11 @@ class URLRequestHttpJobTest : public ::testing::Test {
}
MockNetworkLayer network_layer_;
+
+ // |test_job_interceptor_| is owned by |test_job_factory_|.
+ TestJobInterceptor* test_job_interceptor_;
+ URLRequestJobFactoryImpl test_job_factory_;
+
TestURLRequestContext context_;
TestDelegate delegate_;
scoped_ptr<URLRequest> req_;
@@ -543,7 +558,7 @@ TEST_F(URLRequestHttpJobTest, TestCancelWhileReadingCookies) {
}
// Make sure that SetPriority actually sets the URLRequestHttpJob's
-// priority, both before and after start.
+// priority, before start. Other tests handle the after start case.
TEST_F(URLRequestHttpJobTest, SetPriorityBasic) {
scoped_ptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(req_.get()));
EXPECT_EQ(DEFAULT_PRIORITY, job->priority());
@@ -553,23 +568,18 @@ TEST_F(URLRequestHttpJobTest, SetPriorityBasic) {
job->SetPriority(LOW);
EXPECT_EQ(LOW, job->priority());
-
- job->Start();
- EXPECT_EQ(LOW, job->priority());
-
- job->SetPriority(MEDIUM);
- EXPECT_EQ(MEDIUM, job->priority());
}
// Make sure that URLRequestHttpJob passes on its priority to its
// transaction on start.
TEST_F(URLRequestHttpJobTest, SetTransactionPriorityOnStart) {
- scoped_ptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(req_.get()));
- job->SetPriority(LOW);
+ test_job_interceptor_->set_main_intercept_job(
+ make_scoped_ptr(new TestURLRequestHttpJob(req_.get())));
+ req_->SetPriority(LOW);
EXPECT_FALSE(network_layer_.last_transaction());
- job->Start();
+ req_->Start();
ASSERT_TRUE(network_layer_.last_transaction());
EXPECT_EQ(LOW, network_layer_.last_transaction()->priority());
@@ -578,13 +588,14 @@ TEST_F(URLRequestHttpJobTest, SetTransactionPriorityOnStart) {
// Make sure that URLRequestHttpJob passes on its priority updates to
// its transaction.
TEST_F(URLRequestHttpJobTest, SetTransactionPriority) {
- scoped_ptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(req_.get()));
- job->SetPriority(LOW);
- job->Start();
+ test_job_interceptor_->set_main_intercept_job(
+ make_scoped_ptr(new TestURLRequestHttpJob(req_.get())));
+ req_->SetPriority(LOW);
+ req_->Start();
ASSERT_TRUE(network_layer_.last_transaction());
EXPECT_EQ(LOW, network_layer_.last_transaction()->priority());
- job->SetPriority(HIGHEST);
+ req_->SetPriority(HIGHEST);
EXPECT_EQ(HIGHEST, network_layer_.last_transaction()->priority());
}
@@ -592,8 +603,9 @@ TEST_F(URLRequestHttpJobTest, SetTransactionPriority) {
TEST_F(URLRequestHttpJobTest, SdchAdvertisementGet) {
EnableSdch();
req_->set_method("GET"); // Redundant with default.
- scoped_ptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(req_.get()));
- job->Start();
+ test_job_interceptor_->set_main_intercept_job(
+ make_scoped_ptr(new TestURLRequestHttpJob(req_.get())));
+ req_->Start();
EXPECT_TRUE(TransactionAcceptsSdchEncoding());
}
@@ -601,8 +613,9 @@ TEST_F(URLRequestHttpJobTest, SdchAdvertisementGet) {
TEST_F(URLRequestHttpJobTest, SdchAdvertisementPost) {
EnableSdch();
req_->set_method("POST");
- scoped_ptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(req_.get()));
- job->Start();
+ test_job_interceptor_->set_main_intercept_job(
+ make_scoped_ptr(new TestURLRequestHttpJob(req_.get())));
+ req_->Start();
EXPECT_FALSE(TransactionAcceptsSdchEncoding());
}
@@ -710,12 +723,6 @@ class URLRequestHttpJobWebSocketTest
: req_(context_.CreateRequest(GURL("ws://www.example.com"),
DEFAULT_PRIORITY,
&delegate_)) {
- // The TestNetworkDelegate expects a call to NotifyBeforeURLRequest before
- // anything else happens.
- GURL url("ws://localhost/");
- TestCompletionCallback dummy;
- network_delegate_.NotifyBeforeURLRequest(
- req_.get(), dummy.callback(), &url);
}
TestDelegate delegate_;
@@ -741,6 +748,12 @@ class MockCreateHelper : public WebSocketHandshakeStreamBase::CreateHelper {
bool));
};
+// iOS doesn't support WebSockets, so these tests fail with ERR_UNKOWN_SCHEME on
+// iOS.
+// TODO(mmenke): Hard coding features based on OS is regression prone and ugly.
+// Seems like this should use a build flag instead.
+#if !defined(OS_IOS)
+
class FakeWebSocketHandshakeStream : public WebSocketHandshakeStreamBase {
public:
FakeWebSocketHandshakeStream() : initialize_stream_was_called_(false) {}
@@ -818,15 +831,13 @@ class FakeWebSocketHandshakeStream : public WebSocketHandshakeStreamBase {
};
TEST_F(URLRequestHttpJobWebSocketTest, RejectedWithoutCreateHelper) {
- scoped_ptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(req_.get()));
- job->Start();
+ req_->Start();
base::RunLoop().RunUntilIdle();
EXPECT_EQ(URLRequestStatus::FAILED, req_->status().status());
EXPECT_EQ(ERR_DISALLOWED_URL_SCHEME, req_->status().error());
}
TEST_F(URLRequestHttpJobWebSocketTest, CreateHelperPassedThrough) {
- scoped_ptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(req_.get()));
scoped_ptr<MockCreateHelper> create_helper(
new ::testing::StrictMock<MockCreateHelper>());
FakeWebSocketHandshakeStream* fake_handshake_stream(
@@ -838,12 +849,14 @@ TEST_F(URLRequestHttpJobWebSocketTest, CreateHelperPassedThrough) {
req_->SetUserData(WebSocketHandshakeStreamBase::CreateHelper::DataKey(),
create_helper.release());
req_->SetLoadFlags(LOAD_DISABLE_CACHE);
- job->Start();
+ req_->Start();
base::RunLoop().RunUntilIdle();
EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status());
EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called());
}
+#endif // !defined(OS_IOS)
+
} // namespace
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698