OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/url_request/url_request_http_job.h" | 5 #include "net/url_request/url_request_http_job.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 class URLRequestHttpJobTest : public ::testing::Test { | 47 class URLRequestHttpJobTest : public ::testing::Test { |
48 protected: | 48 protected: |
49 URLRequestHttpJobTest() | 49 URLRequestHttpJobTest() |
50 : req_(GURL("http://www.example.com"), | 50 : req_(GURL("http://www.example.com"), |
51 DEFAULT_PRIORITY, | 51 DEFAULT_PRIORITY, |
52 &delegate_, | 52 &delegate_, |
53 &context_) { | 53 &context_) { |
54 context_.set_http_transaction_factory(&network_layer_); | 54 context_.set_http_transaction_factory(&network_layer_); |
55 } | 55 } |
56 | 56 |
| 57 bool TransactionAcceptsSdchEncoding() { |
| 58 base::WeakPtr<MockNetworkTransaction> transaction( |
| 59 network_layer_.last_transaction()); |
| 60 EXPECT_TRUE(transaction); |
| 61 if (!transaction) return false; |
| 62 |
| 63 const HttpRequestInfo* request_info = transaction->request(); |
| 64 EXPECT_TRUE(request_info); |
| 65 if (!request_info) return false; |
| 66 |
| 67 std::string encoding_headers; |
| 68 bool get_success = request_info->extra_headers.GetHeader( |
| 69 "Accept-Encoding", &encoding_headers); |
| 70 EXPECT_TRUE(get_success); |
| 71 if (!get_success) return false; |
| 72 |
| 73 // This check isn't wrapped with EXPECT* macros because different |
| 74 // results from this function may be expected in different tests. |
| 75 std::vector<std::string> tokens; |
| 76 size_t num_tokens = Tokenize(encoding_headers, ",", &tokens); |
| 77 for (size_t i = 0; i < num_tokens; i++) { |
| 78 if (!base::strncasecmp(tokens[i].data(), "sdch", tokens[i].length())) |
| 79 return true; |
| 80 } |
| 81 return false; |
| 82 } |
| 83 |
| 84 void EnableSdch() { |
| 85 context_.SetSdchManager(scoped_ptr<SdchManager>(new SdchManager).Pass()); |
| 86 } |
| 87 |
57 MockNetworkLayer network_layer_; | 88 MockNetworkLayer network_layer_; |
58 TestURLRequestContext context_; | 89 TestURLRequestContext context_; |
59 TestDelegate delegate_; | 90 TestDelegate delegate_; |
60 TestURLRequest req_; | 91 TestURLRequest req_; |
61 }; | 92 }; |
62 | 93 |
63 // Make sure that SetPriority actually sets the URLRequestHttpJob's | 94 // Make sure that SetPriority actually sets the URLRequestHttpJob's |
64 // priority, both before and after start. | 95 // priority, both before and after start. |
65 TEST_F(URLRequestHttpJobTest, SetPriorityBasic) { | 96 TEST_F(URLRequestHttpJobTest, SetPriorityBasic) { |
66 scoped_refptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(&req_)); | 97 scoped_refptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(&req_)); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 | 149 |
119 job->Kill(); | 150 job->Kill(); |
120 network_layer_.ClearLastTransaction(); | 151 network_layer_.ClearLastTransaction(); |
121 | 152 |
122 // Creates a second transaction. | 153 // Creates a second transaction. |
123 job->Start(); | 154 job->Start(); |
124 ASSERT_TRUE(network_layer_.last_transaction()); | 155 ASSERT_TRUE(network_layer_.last_transaction()); |
125 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); | 156 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); |
126 } | 157 } |
127 | 158 |
| 159 // Confirm we do advertise SDCH encoding in the case of a GET. |
| 160 TEST_F(URLRequestHttpJobTest, SdchAdvertisementGet) { |
| 161 EnableSdch(); |
| 162 req_.set_method("GET"); // Redundant with default. |
| 163 scoped_refptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(&req_)); |
| 164 job->Start(); |
| 165 EXPECT_TRUE(TransactionAcceptsSdchEncoding()); |
| 166 } |
| 167 |
| 168 // Confirm we don't advertise SDCH encoding in the case of a POST. |
| 169 TEST_F(URLRequestHttpJobTest, SdchAdvertisementPost) { |
| 170 EnableSdch(); |
| 171 req_.set_method("POST"); |
| 172 scoped_refptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(&req_)); |
| 173 job->Start(); |
| 174 EXPECT_FALSE(TransactionAcceptsSdchEncoding()); |
| 175 } |
| 176 |
128 // This base class just serves to set up some things before the TestURLRequest | 177 // This base class just serves to set up some things before the TestURLRequest |
129 // constructor is called. | 178 // constructor is called. |
130 class URLRequestHttpJobWebSocketTestBase : public ::testing::Test { | 179 class URLRequestHttpJobWebSocketTestBase : public ::testing::Test { |
131 protected: | 180 protected: |
132 URLRequestHttpJobWebSocketTestBase() : socket_data_(NULL, 0, NULL, 0), | 181 URLRequestHttpJobWebSocketTestBase() : socket_data_(NULL, 0, NULL, 0), |
133 context_(true) { | 182 context_(true) { |
134 // A Network Delegate is required for the WebSocketHandshakeStreamBase | 183 // A Network Delegate is required for the WebSocketHandshakeStreamBase |
135 // object to be passed on to the HttpNetworkTransaction. | 184 // object to be passed on to the HttpNetworkTransaction. |
136 context_.set_network_delegate(&network_delegate_); | 185 context_.set_network_delegate(&network_delegate_); |
137 | 186 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 req_.SetLoadFlags(LOAD_DISABLE_CACHE); | 329 req_.SetLoadFlags(LOAD_DISABLE_CACHE); |
281 job->Start(); | 330 job->Start(); |
282 base::RunLoop().RunUntilIdle(); | 331 base::RunLoop().RunUntilIdle(); |
283 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_.status().status()); | 332 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_.status().status()); |
284 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); | 333 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); |
285 } | 334 } |
286 | 335 |
287 } // namespace | 336 } // namespace |
288 | 337 |
289 } // namespace net | 338 } // namespace net |
OLD | NEW |