OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "base/metrics/field_trial.h" | 5 #include "base/metrics/field_trial.h" |
6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
7 #include "base/synchronization/waitable_event.h" | 7 #include "base/synchronization/waitable_event.h" |
8 #include "base/test/mock_entropy_provider.h" | 8 #include "base/test/mock_entropy_provider.h" |
9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
10 #include "net/http/http_response_headers.h" | 10 #include "net/http/http_response_headers.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 output->swap(uncompressed_output); | 99 output->swap(uncompressed_output); |
100 return true; | 100 return true; |
101 } | 101 } |
102 return false; | 102 return false; |
103 } | 103 } |
104 | 104 |
105 } // namespace | 105 } // namespace |
106 | 106 |
107 const char kUserAgent[] = "user-agent"; | 107 const char kUserAgent[] = "user-agent"; |
108 | 108 |
109 class SyncHttpBridgeTest : public testing::Test { | 109 #if defined(OS_ANDROID) |
| 110 #define MAYBE_SyncHttpBridgeTest DISABLED_SyncHttpBridgeTest |
| 111 #else |
| 112 #define MAYBE_SyncHttpBridgeTest SyncHttpBridgeTest |
| 113 #endif // defined(OS_ANDROID) |
| 114 class MAYBE_SyncHttpBridgeTest : public testing::Test { |
110 public: | 115 public: |
111 SyncHttpBridgeTest() | 116 MAYBE_SyncHttpBridgeTest() |
112 : test_server_(net::SpawnedTestServer::TYPE_HTTP, | 117 : test_server_(net::SpawnedTestServer::TYPE_HTTP, |
113 net::SpawnedTestServer::kLocalhost, | 118 net::SpawnedTestServer::kLocalhost, |
114 base::FilePath(kDocRoot)), | 119 base::FilePath(kDocRoot)), |
115 fake_default_request_context_getter_(NULL), | 120 fake_default_request_context_getter_(NULL), |
116 bridge_for_race_test_(NULL), | 121 bridge_for_race_test_(NULL), |
117 io_thread_("IO thread") { | 122 io_thread_("IO thread") { |
118 } | 123 } |
119 | 124 |
120 void SetUp() override { | 125 void SetUp() override { |
121 base::Thread::Options options; | 126 base::Thread::Options options; |
(...skipping 26 matching lines...) Expand all Loading... |
148 static void Abort(HttpBridge* bridge) { | 153 static void Abort(HttpBridge* bridge) { |
149 bridge->Abort(); | 154 bridge->Abort(); |
150 } | 155 } |
151 | 156 |
152 // Used by AbortAndReleaseBeforeFetchCompletes to test an interesting race | 157 // Used by AbortAndReleaseBeforeFetchCompletes to test an interesting race |
153 // condition. | 158 // condition. |
154 void RunSyncThreadBridgeUseTest(base::WaitableEvent* signal_when_created, | 159 void RunSyncThreadBridgeUseTest(base::WaitableEvent* signal_when_created, |
155 base::WaitableEvent* signal_when_released); | 160 base::WaitableEvent* signal_when_released); |
156 | 161 |
157 static void TestSameHttpNetworkSession(base::MessageLoop* main_message_loop, | 162 static void TestSameHttpNetworkSession(base::MessageLoop* main_message_loop, |
158 SyncHttpBridgeTest* test) { | 163 MAYBE_SyncHttpBridgeTest* test) { |
159 scoped_refptr<HttpBridge> http_bridge(test->BuildBridge()); | 164 scoped_refptr<HttpBridge> http_bridge(test->BuildBridge()); |
160 EXPECT_TRUE(test->GetTestRequestContextGetter()); | 165 EXPECT_TRUE(test->GetTestRequestContextGetter()); |
161 net::HttpNetworkSession* test_session = | 166 net::HttpNetworkSession* test_session = |
162 test->GetTestRequestContextGetter()->GetURLRequestContext()-> | 167 test->GetTestRequestContextGetter()->GetURLRequestContext()-> |
163 http_transaction_factory()->GetSession(); | 168 http_transaction_factory()->GetSession(); |
164 EXPECT_EQ(test_session, | 169 EXPECT_EQ(test_session, |
165 http_bridge->GetRequestContextGetterForTest()-> | 170 http_bridge->GetRequestContextGetterForTest()-> |
166 GetURLRequestContext()-> | 171 GetURLRequestContext()-> |
167 http_transaction_factory()->GetSession()); | 172 http_transaction_factory()->GetSession()); |
168 main_message_loop->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); | 173 main_message_loop->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); |
(...skipping 26 matching lines...) Expand all Loading... |
195 | 200 |
196 // An HttpBridge that doesn't actually make network requests and just calls | 201 // An HttpBridge that doesn't actually make network requests and just calls |
197 // back with dummy response info. | 202 // back with dummy response info. |
198 // TODO(tim): Instead of inheriting here we should inject a component | 203 // TODO(tim): Instead of inheriting here we should inject a component |
199 // responsible for the MakeAsynchronousPost bit. | 204 // responsible for the MakeAsynchronousPost bit. |
200 class ShuntedHttpBridge : public HttpBridge { | 205 class ShuntedHttpBridge : public HttpBridge { |
201 public: | 206 public: |
202 // If |never_finishes| is true, the simulated request never actually | 207 // If |never_finishes| is true, the simulated request never actually |
203 // returns. | 208 // returns. |
204 ShuntedHttpBridge(net::URLRequestContextGetter* baseline_context_getter, | 209 ShuntedHttpBridge(net::URLRequestContextGetter* baseline_context_getter, |
205 SyncHttpBridgeTest* test, bool never_finishes) | 210 MAYBE_SyncHttpBridgeTest* test, bool never_finishes) |
206 : HttpBridge(kUserAgent, | 211 : HttpBridge(kUserAgent, |
207 baseline_context_getter, | 212 baseline_context_getter, |
208 NetworkTimeUpdateCallback()), | 213 NetworkTimeUpdateCallback()), |
209 test_(test), never_finishes_(never_finishes) { } | 214 test_(test), never_finishes_(never_finishes) { } |
210 protected: | 215 protected: |
211 void MakeAsynchronousPost() override { | 216 void MakeAsynchronousPost() override { |
212 ASSERT_TRUE(base::MessageLoop::current() == test_->GetIOThreadLoop()); | 217 ASSERT_TRUE(base::MessageLoop::current() == test_->GetIOThreadLoop()); |
213 if (never_finishes_) | 218 if (never_finishes_) |
214 return; | 219 return; |
215 | 220 |
(...skipping 13 matching lines...) Expand all Loading... |
229 std::string response_content = "success!"; | 234 std::string response_content = "success!"; |
230 net::TestURLFetcher fetcher(0, GURL("http://www.google.com"), NULL); | 235 net::TestURLFetcher fetcher(0, GURL("http://www.google.com"), NULL); |
231 scoped_refptr<net::HttpResponseHeaders> response_headers( | 236 scoped_refptr<net::HttpResponseHeaders> response_headers( |
232 new net::HttpResponseHeaders("")); | 237 new net::HttpResponseHeaders("")); |
233 fetcher.set_response_code(200); | 238 fetcher.set_response_code(200); |
234 fetcher.set_cookies(cookies); | 239 fetcher.set_cookies(cookies); |
235 fetcher.SetResponseString(response_content); | 240 fetcher.SetResponseString(response_content); |
236 fetcher.set_response_headers(response_headers); | 241 fetcher.set_response_headers(response_headers); |
237 OnURLFetchComplete(&fetcher); | 242 OnURLFetchComplete(&fetcher); |
238 } | 243 } |
239 SyncHttpBridgeTest* test_; | 244 MAYBE_SyncHttpBridgeTest* test_; |
240 bool never_finishes_; | 245 bool never_finishes_; |
241 }; | 246 }; |
242 | 247 |
243 void SyncHttpBridgeTest::RunSyncThreadBridgeUseTest( | 248 void MAYBE_SyncHttpBridgeTest::RunSyncThreadBridgeUseTest( |
244 base::WaitableEvent* signal_when_created, | 249 base::WaitableEvent* signal_when_created, |
245 base::WaitableEvent* signal_when_released) { | 250 base::WaitableEvent* signal_when_released) { |
246 scoped_refptr<net::URLRequestContextGetter> ctx_getter( | 251 scoped_refptr<net::URLRequestContextGetter> ctx_getter( |
247 new net::TestURLRequestContextGetter(io_thread_.task_runner())); | 252 new net::TestURLRequestContextGetter(io_thread_.task_runner())); |
248 { | 253 { |
249 scoped_refptr<ShuntedHttpBridge> bridge( | 254 scoped_refptr<ShuntedHttpBridge> bridge( |
250 new ShuntedHttpBridge(ctx_getter.get(), this, true)); | 255 new ShuntedHttpBridge(ctx_getter.get(), this, true)); |
251 bridge->SetURL("http://www.google.com", 9999); | 256 bridge->SetURL("http://www.google.com", 9999); |
252 bridge->SetPostPayload("text/plain", 2, " "); | 257 bridge->SetPostPayload("text/plain", 2, " "); |
253 bridge_for_race_test_ = bridge.get(); | 258 bridge_for_race_test_ = bridge.get(); |
254 signal_when_created->Signal(); | 259 signal_when_created->Signal(); |
255 | 260 |
256 int os_error = 0; | 261 int os_error = 0; |
257 int response_code = 0; | 262 int response_code = 0; |
258 bridge->MakeSynchronousPost(&os_error, &response_code); | 263 bridge->MakeSynchronousPost(&os_error, &response_code); |
259 bridge_for_race_test_ = NULL; | 264 bridge_for_race_test_ = NULL; |
260 } | 265 } |
261 signal_when_released->Signal(); | 266 signal_when_released->Signal(); |
262 } | 267 } |
263 | 268 |
264 TEST_F(SyncHttpBridgeTest, TestUsesSameHttpNetworkSession) { | 269 TEST_F(MAYBE_SyncHttpBridgeTest, TestUsesSameHttpNetworkSession) { |
265 // Run this test on the IO thread because we can only call | 270 // Run this test on the IO thread because we can only call |
266 // URLRequestContextGetter::GetURLRequestContext on the IO thread. | 271 // URLRequestContextGetter::GetURLRequestContext on the IO thread. |
267 io_thread()->message_loop() | 272 io_thread()->message_loop()->PostTask( |
268 ->PostTask(FROM_HERE, | 273 FROM_HERE, |
269 base::Bind(&SyncHttpBridgeTest::TestSameHttpNetworkSession, | 274 base::Bind(&MAYBE_SyncHttpBridgeTest::TestSameHttpNetworkSession, |
270 base::MessageLoop::current(), | 275 base::MessageLoop::current(), this)); |
271 this)); | |
272 base::MessageLoop::current()->Run(); | 276 base::MessageLoop::current()->Run(); |
273 } | 277 } |
274 | 278 |
275 // Test the HttpBridge without actually making any network requests. | 279 // Test the HttpBridge without actually making any network requests. |
276 TEST_F(SyncHttpBridgeTest, TestMakeSynchronousPostShunted) { | 280 TEST_F(MAYBE_SyncHttpBridgeTest, TestMakeSynchronousPostShunted) { |
277 scoped_refptr<net::URLRequestContextGetter> ctx_getter( | 281 scoped_refptr<net::URLRequestContextGetter> ctx_getter( |
278 new net::TestURLRequestContextGetter(io_thread()->task_runner())); | 282 new net::TestURLRequestContextGetter(io_thread()->task_runner())); |
279 scoped_refptr<HttpBridge> http_bridge( | 283 scoped_refptr<HttpBridge> http_bridge( |
280 new ShuntedHttpBridge(ctx_getter.get(), this, false)); | 284 new ShuntedHttpBridge(ctx_getter.get(), this, false)); |
281 http_bridge->SetURL("http://www.google.com", 9999); | 285 http_bridge->SetURL("http://www.google.com", 9999); |
282 http_bridge->SetPostPayload("text/plain", 2, " "); | 286 http_bridge->SetPostPayload("text/plain", 2, " "); |
283 | 287 |
284 int os_error = 0; | 288 int os_error = 0; |
285 int response_code = 0; | 289 int response_code = 0; |
286 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); | 290 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); |
287 EXPECT_TRUE(success); | 291 EXPECT_TRUE(success); |
288 EXPECT_EQ(200, response_code); | 292 EXPECT_EQ(200, response_code); |
289 EXPECT_EQ(0, os_error); | 293 EXPECT_EQ(0, os_error); |
290 | 294 |
291 EXPECT_EQ(8, http_bridge->GetResponseContentLength()); | 295 EXPECT_EQ(8, http_bridge->GetResponseContentLength()); |
292 EXPECT_EQ(std::string("success!"), | 296 EXPECT_EQ(std::string("success!"), |
293 std::string(http_bridge->GetResponseContent())); | 297 std::string(http_bridge->GetResponseContent())); |
294 } | 298 } |
295 | 299 |
296 // Full round-trip test of the HttpBridge, using default UA string and | 300 // Full round-trip test of the HttpBridge, using default UA string and |
297 // no request cookies. | 301 // no request cookies. |
298 TEST_F(SyncHttpBridgeTest, TestMakeSynchronousPostLiveWithPayload) { | 302 TEST_F(MAYBE_SyncHttpBridgeTest, TestMakeSynchronousPostLiveWithPayload) { |
299 ASSERT_TRUE(test_server_.Start()); | 303 ASSERT_TRUE(test_server_.Start()); |
300 | 304 |
301 scoped_refptr<HttpBridge> http_bridge(BuildBridge()); | 305 scoped_refptr<HttpBridge> http_bridge(BuildBridge()); |
302 | 306 |
303 std::string payload = "this should be echoed back"; | 307 std::string payload = "this should be echoed back"; |
304 GURL echo = test_server_.GetURL("echo"); | 308 GURL echo = test_server_.GetURL("echo"); |
305 http_bridge->SetURL(echo.spec().c_str(), echo.IntPort()); | 309 http_bridge->SetURL(echo.spec().c_str(), echo.IntPort()); |
306 http_bridge->SetPostPayload("application/x-www-form-urlencoded", | 310 http_bridge->SetPostPayload("application/x-www-form-urlencoded", |
307 payload.length() + 1, payload.c_str()); | 311 payload.length() + 1, payload.c_str()); |
308 int os_error = 0; | 312 int os_error = 0; |
309 int response_code = 0; | 313 int response_code = 0; |
310 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); | 314 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); |
311 EXPECT_TRUE(success); | 315 EXPECT_TRUE(success); |
312 EXPECT_EQ(200, response_code); | 316 EXPECT_EQ(200, response_code); |
313 EXPECT_EQ(0, os_error); | 317 EXPECT_EQ(0, os_error); |
314 | 318 |
315 EXPECT_EQ(payload.length() + 1, | 319 EXPECT_EQ(payload.length() + 1, |
316 static_cast<size_t>(http_bridge->GetResponseContentLength())); | 320 static_cast<size_t>(http_bridge->GetResponseContentLength())); |
317 EXPECT_EQ(payload, std::string(http_bridge->GetResponseContent())); | 321 EXPECT_EQ(payload, std::string(http_bridge->GetResponseContent())); |
318 } | 322 } |
319 | 323 |
320 // Full round-trip test of the HttpBridge with compressed data, check if the | 324 // Full round-trip test of the HttpBridge with compressed data, check if the |
321 // data is correctly compressed. | 325 // data is correctly compressed. |
322 TEST_F(SyncHttpBridgeTest, CompressedRequestPayloadCheck) { | 326 TEST_F(MAYBE_SyncHttpBridgeTest, CompressedRequestPayloadCheck) { |
323 ASSERT_TRUE(test_server_.Start()); | 327 ASSERT_TRUE(test_server_.Start()); |
324 | 328 |
325 scoped_refptr<HttpBridge> http_bridge(BuildBridge()); | 329 scoped_refptr<HttpBridge> http_bridge(BuildBridge()); |
326 | 330 |
327 std::string payload = "this should be echoed back"; | 331 std::string payload = "this should be echoed back"; |
328 GURL echo = test_server_.GetURL("echo"); | 332 GURL echo = test_server_.GetURL("echo"); |
329 http_bridge->SetURL(echo.spec().c_str(), echo.IntPort()); | 333 http_bridge->SetURL(echo.spec().c_str(), echo.IntPort()); |
330 http_bridge->SetPostPayload("application/x-www-form-urlencoded", | 334 http_bridge->SetPostPayload("application/x-www-form-urlencoded", |
331 payload.length(), payload.c_str()); | 335 payload.length(), payload.c_str()); |
332 int os_error = 0; | 336 int os_error = 0; |
(...skipping 11 matching lines...) Expand all Loading... |
344 std::string compressed_payload(http_bridge->GetResponseContent(), | 348 std::string compressed_payload(http_bridge->GetResponseContent(), |
345 http_bridge->GetResponseContentLength()); | 349 http_bridge->GetResponseContentLength()); |
346 std::string uncompressed_payload; | 350 std::string uncompressed_payload; |
347 GzipUncompress(compressed_payload, &uncompressed_payload); | 351 GzipUncompress(compressed_payload, &uncompressed_payload); |
348 EXPECT_EQ(payload, uncompressed_payload); | 352 EXPECT_EQ(payload, uncompressed_payload); |
349 } | 353 } |
350 | 354 |
351 // Full round-trip test of the HttpBridge with compression, check if header | 355 // Full round-trip test of the HttpBridge with compression, check if header |
352 // fields("Content-Encoding" ,"Accept-Encoding" and user agent) are set | 356 // fields("Content-Encoding" ,"Accept-Encoding" and user agent) are set |
353 // correctly. | 357 // correctly. |
354 TEST_F(SyncHttpBridgeTest, CompressedRequestHeaderCheck) { | 358 TEST_F(MAYBE_SyncHttpBridgeTest, CompressedRequestHeaderCheck) { |
355 ASSERT_TRUE(test_server_.Start()); | 359 ASSERT_TRUE(test_server_.Start()); |
356 | 360 |
357 scoped_refptr<HttpBridge> http_bridge(BuildBridge()); | 361 scoped_refptr<HttpBridge> http_bridge(BuildBridge()); |
358 | 362 |
359 GURL echo_header = test_server_.GetURL("echoall"); | 363 GURL echo_header = test_server_.GetURL("echoall"); |
360 http_bridge->SetURL(echo_header.spec().c_str(), echo_header.IntPort()); | 364 http_bridge->SetURL(echo_header.spec().c_str(), echo_header.IntPort()); |
361 | 365 |
362 std::string test_payload = "###TEST PAYLOAD###"; | 366 std::string test_payload = "###TEST PAYLOAD###"; |
363 http_bridge->SetPostPayload("text/html", test_payload.length() + 1, | 367 http_bridge->SetPostPayload("text/html", test_payload.length() + 1, |
364 test_payload.c_str()); | 368 test_payload.c_str()); |
(...skipping 14 matching lines...) Expand all Loading... |
379 EXPECT_NE(std::string::npos, | 383 EXPECT_NE(std::string::npos, |
380 response.find(base::StringPrintf( | 384 response.find(base::StringPrintf( |
381 "%s: %s", net::HttpRequestHeaders::kAcceptEncoding, | 385 "%s: %s", net::HttpRequestHeaders::kAcceptEncoding, |
382 "gzip, deflate"))); | 386 "gzip, deflate"))); |
383 EXPECT_NE(std::string::npos, | 387 EXPECT_NE(std::string::npos, |
384 response.find(base::StringPrintf( | 388 response.find(base::StringPrintf( |
385 "%s: %s", net::HttpRequestHeaders::kUserAgent, kUserAgent))); | 389 "%s: %s", net::HttpRequestHeaders::kUserAgent, kUserAgent))); |
386 } | 390 } |
387 | 391 |
388 // Full round-trip test of the HttpBridge. | 392 // Full round-trip test of the HttpBridge. |
389 TEST_F(SyncHttpBridgeTest, TestMakeSynchronousPostLiveComprehensive) { | 393 TEST_F(MAYBE_SyncHttpBridgeTest, TestMakeSynchronousPostLiveComprehensive) { |
390 ASSERT_TRUE(test_server_.Start()); | 394 ASSERT_TRUE(test_server_.Start()); |
391 | 395 |
392 scoped_refptr<HttpBridge> http_bridge(BuildBridge()); | 396 scoped_refptr<HttpBridge> http_bridge(BuildBridge()); |
393 | 397 |
394 GURL echo_header = test_server_.GetURL("echoall"); | 398 GURL echo_header = test_server_.GetURL("echoall"); |
395 http_bridge->SetURL(echo_header.spec().c_str(), echo_header.IntPort()); | 399 http_bridge->SetURL(echo_header.spec().c_str(), echo_header.IntPort()); |
396 | 400 |
397 std::string test_payload = "###TEST PAYLOAD###"; | 401 std::string test_payload = "###TEST PAYLOAD###"; |
398 http_bridge->SetPostPayload("text/html", test_payload.length() + 1, | 402 http_bridge->SetPostPayload("text/html", test_payload.length() + 1, |
399 test_payload.c_str()); | 403 test_payload.c_str()); |
(...skipping 11 matching lines...) Expand all Loading... |
411 EXPECT_NE(std::string::npos, | 415 EXPECT_NE(std::string::npos, |
412 response.find(base::StringPrintf( | 416 response.find(base::StringPrintf( |
413 "%s: %s", net::HttpRequestHeaders::kAcceptEncoding, | 417 "%s: %s", net::HttpRequestHeaders::kAcceptEncoding, |
414 "deflate"))); | 418 "deflate"))); |
415 EXPECT_NE(std::string::npos, | 419 EXPECT_NE(std::string::npos, |
416 response.find(base::StringPrintf("%s: %s", | 420 response.find(base::StringPrintf("%s: %s", |
417 net::HttpRequestHeaders::kUserAgent, kUserAgent))); | 421 net::HttpRequestHeaders::kUserAgent, kUserAgent))); |
418 EXPECT_NE(std::string::npos, response.find(test_payload.c_str())); | 422 EXPECT_NE(std::string::npos, response.find(test_payload.c_str())); |
419 } | 423 } |
420 | 424 |
421 TEST_F(SyncHttpBridgeTest, TestExtraRequestHeaders) { | 425 TEST_F(MAYBE_SyncHttpBridgeTest, TestExtraRequestHeaders) { |
422 ASSERT_TRUE(test_server_.Start()); | 426 ASSERT_TRUE(test_server_.Start()); |
423 | 427 |
424 scoped_refptr<HttpBridge> http_bridge(BuildBridge()); | 428 scoped_refptr<HttpBridge> http_bridge(BuildBridge()); |
425 | 429 |
426 GURL echo_header = test_server_.GetURL("echoall"); | 430 GURL echo_header = test_server_.GetURL("echoall"); |
427 | 431 |
428 http_bridge->SetURL(echo_header.spec().c_str(), echo_header.IntPort()); | 432 http_bridge->SetURL(echo_header.spec().c_str(), echo_header.IntPort()); |
429 http_bridge->SetExtraRequestHeaders("test:fnord"); | 433 http_bridge->SetExtraRequestHeaders("test:fnord"); |
430 | 434 |
431 std::string test_payload = "###TEST PAYLOAD###"; | 435 std::string test_payload = "###TEST PAYLOAD###"; |
432 http_bridge->SetPostPayload("text/html", test_payload.length() + 1, | 436 http_bridge->SetPostPayload("text/html", test_payload.length() + 1, |
433 test_payload.c_str()); | 437 test_payload.c_str()); |
434 | 438 |
435 int os_error = 0; | 439 int os_error = 0; |
436 int response_code = 0; | 440 int response_code = 0; |
437 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); | 441 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); |
438 EXPECT_TRUE(success); | 442 EXPECT_TRUE(success); |
439 EXPECT_EQ(200, response_code); | 443 EXPECT_EQ(200, response_code); |
440 EXPECT_EQ(0, os_error); | 444 EXPECT_EQ(0, os_error); |
441 | 445 |
442 std::string response(http_bridge->GetResponseContent(), | 446 std::string response(http_bridge->GetResponseContent(), |
443 http_bridge->GetResponseContentLength()); | 447 http_bridge->GetResponseContentLength()); |
444 | 448 |
445 EXPECT_NE(std::string::npos, response.find("fnord")); | 449 EXPECT_NE(std::string::npos, response.find("fnord")); |
446 EXPECT_NE(std::string::npos, response.find(test_payload.c_str())); | 450 EXPECT_NE(std::string::npos, response.find(test_payload.c_str())); |
447 } | 451 } |
448 | 452 |
449 TEST_F(SyncHttpBridgeTest, TestResponseHeader) { | 453 TEST_F(MAYBE_SyncHttpBridgeTest, TestResponseHeader) { |
450 ASSERT_TRUE(test_server_.Start()); | 454 ASSERT_TRUE(test_server_.Start()); |
451 | 455 |
452 scoped_refptr<HttpBridge> http_bridge(BuildBridge()); | 456 scoped_refptr<HttpBridge> http_bridge(BuildBridge()); |
453 | 457 |
454 GURL echo_header = test_server_.GetURL("echoall"); | 458 GURL echo_header = test_server_.GetURL("echoall"); |
455 http_bridge->SetURL(echo_header.spec().c_str(), echo_header.IntPort()); | 459 http_bridge->SetURL(echo_header.spec().c_str(), echo_header.IntPort()); |
456 | 460 |
457 std::string test_payload = "###TEST PAYLOAD###"; | 461 std::string test_payload = "###TEST PAYLOAD###"; |
458 http_bridge->SetPostPayload("text/html", test_payload.length() + 1, | 462 http_bridge->SetPostPayload("text/html", test_payload.length() + 1, |
459 test_payload.c_str()); | 463 test_payload.c_str()); |
460 | 464 |
461 int os_error = 0; | 465 int os_error = 0; |
462 int response_code = 0; | 466 int response_code = 0; |
463 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); | 467 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); |
464 EXPECT_TRUE(success); | 468 EXPECT_TRUE(success); |
465 EXPECT_EQ(200, response_code); | 469 EXPECT_EQ(200, response_code); |
466 EXPECT_EQ(0, os_error); | 470 EXPECT_EQ(0, os_error); |
467 | 471 |
468 EXPECT_EQ(http_bridge->GetResponseHeaderValue("Content-type"), "text/html"); | 472 EXPECT_EQ(http_bridge->GetResponseHeaderValue("Content-type"), "text/html"); |
469 EXPECT_TRUE(http_bridge->GetResponseHeaderValue("invalid-header").empty()); | 473 EXPECT_TRUE(http_bridge->GetResponseHeaderValue("invalid-header").empty()); |
470 } | 474 } |
471 | 475 |
472 TEST_F(SyncHttpBridgeTest, Abort) { | 476 TEST_F(MAYBE_SyncHttpBridgeTest, Abort) { |
473 scoped_refptr<net::URLRequestContextGetter> ctx_getter( | 477 scoped_refptr<net::URLRequestContextGetter> ctx_getter( |
474 new net::TestURLRequestContextGetter(io_thread()->task_runner())); | 478 new net::TestURLRequestContextGetter(io_thread()->task_runner())); |
475 scoped_refptr<ShuntedHttpBridge> http_bridge( | 479 scoped_refptr<ShuntedHttpBridge> http_bridge( |
476 new ShuntedHttpBridge(ctx_getter.get(), this, true)); | 480 new ShuntedHttpBridge(ctx_getter.get(), this, true)); |
477 http_bridge->SetURL("http://www.google.com", 9999); | 481 http_bridge->SetURL("http://www.google.com", 9999); |
478 http_bridge->SetPostPayload("text/plain", 2, " "); | 482 http_bridge->SetPostPayload("text/plain", 2, " "); |
479 | 483 |
480 int os_error = 0; | 484 int os_error = 0; |
481 int response_code = 0; | 485 int response_code = 0; |
482 | 486 |
483 io_thread()->task_runner()->PostTask( | 487 io_thread()->task_runner()->PostTask( |
484 FROM_HERE, | 488 FROM_HERE, |
485 base::Bind(&SyncHttpBridgeTest::Abort, http_bridge)); | 489 base::Bind(&MAYBE_SyncHttpBridgeTest::Abort, http_bridge)); |
486 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); | 490 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); |
487 EXPECT_FALSE(success); | 491 EXPECT_FALSE(success); |
488 EXPECT_EQ(net::ERR_ABORTED, os_error); | 492 EXPECT_EQ(net::ERR_ABORTED, os_error); |
489 } | 493 } |
490 | 494 |
491 TEST_F(SyncHttpBridgeTest, AbortLate) { | 495 TEST_F(MAYBE_SyncHttpBridgeTest, AbortLate) { |
492 scoped_refptr<net::URLRequestContextGetter> ctx_getter( | 496 scoped_refptr<net::URLRequestContextGetter> ctx_getter( |
493 new net::TestURLRequestContextGetter(io_thread()->task_runner())); | 497 new net::TestURLRequestContextGetter(io_thread()->task_runner())); |
494 scoped_refptr<ShuntedHttpBridge> http_bridge( | 498 scoped_refptr<ShuntedHttpBridge> http_bridge( |
495 new ShuntedHttpBridge(ctx_getter.get(), this, false)); | 499 new ShuntedHttpBridge(ctx_getter.get(), this, false)); |
496 http_bridge->SetURL("http://www.google.com", 9999); | 500 http_bridge->SetURL("http://www.google.com", 9999); |
497 http_bridge->SetPostPayload("text/plain", 2, " "); | 501 http_bridge->SetPostPayload("text/plain", 2, " "); |
498 | 502 |
499 int os_error = 0; | 503 int os_error = 0; |
500 int response_code = 0; | 504 int response_code = 0; |
501 | 505 |
502 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); | 506 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); |
503 ASSERT_TRUE(success); | 507 ASSERT_TRUE(success); |
504 http_bridge->Abort(); | 508 http_bridge->Abort(); |
505 // Ensures no double-free of URLFetcher, etc. | 509 // Ensures no double-free of URLFetcher, etc. |
506 } | 510 } |
507 | 511 |
508 // Tests an interesting case where code using the HttpBridge aborts the fetch | 512 // Tests an interesting case where code using the HttpBridge aborts the fetch |
509 // and releases ownership before a pending fetch completed callback is issued by | 513 // and releases ownership before a pending fetch completed callback is issued by |
510 // the underlying URLFetcher (and before that URLFetcher is destroyed, which | 514 // the underlying URLFetcher (and before that URLFetcher is destroyed, which |
511 // would cancel the callback). | 515 // would cancel the callback). |
512 TEST_F(SyncHttpBridgeTest, AbortAndReleaseBeforeFetchComplete) { | 516 TEST_F(MAYBE_SyncHttpBridgeTest, AbortAndReleaseBeforeFetchComplete) { |
513 base::Thread sync_thread("SyncThread"); | 517 base::Thread sync_thread("SyncThread"); |
514 sync_thread.Start(); | 518 sync_thread.Start(); |
515 | 519 |
516 // First, block the sync thread on the post. | 520 // First, block the sync thread on the post. |
517 base::WaitableEvent signal_when_created(false, false); | 521 base::WaitableEvent signal_when_created(false, false); |
518 base::WaitableEvent signal_when_released(false, false); | 522 base::WaitableEvent signal_when_released(false, false); |
519 sync_thread.message_loop()->PostTask(FROM_HERE, | 523 sync_thread.message_loop()->PostTask(FROM_HERE, |
520 base::Bind(&SyncHttpBridgeTest::RunSyncThreadBridgeUseTest, | 524 base::Bind(&MAYBE_SyncHttpBridgeTest::RunSyncThreadBridgeUseTest, |
521 base::Unretained(this), | 525 base::Unretained(this), |
522 &signal_when_created, | 526 &signal_when_created, |
523 &signal_when_released)); | 527 &signal_when_released)); |
524 | 528 |
525 // Stop IO so we can control order of operations. | 529 // Stop IO so we can control order of operations. |
526 base::WaitableEvent io_waiter(false, false); | 530 base::WaitableEvent io_waiter(false, false); |
527 ASSERT_TRUE(io_thread()->task_runner()->PostTask( | 531 ASSERT_TRUE(io_thread()->task_runner()->PostTask( |
528 FROM_HERE, | 532 FROM_HERE, |
529 base::Bind(&base::WaitableEvent::Wait, base::Unretained(&io_waiter)))); | 533 base::Bind(&base::WaitableEvent::Wait, base::Unretained(&io_waiter)))); |
530 | 534 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 } | 592 } |
589 | 593 |
590 void WaitOnIOThread(base::WaitableEvent* signal_wait_start, | 594 void WaitOnIOThread(base::WaitableEvent* signal_wait_start, |
591 base::WaitableEvent* wait_done) { | 595 base::WaitableEvent* wait_done) { |
592 signal_wait_start->Signal(); | 596 signal_wait_start->Signal(); |
593 wait_done->Wait(); | 597 wait_done->Wait(); |
594 } | 598 } |
595 | 599 |
596 // Tests RequestContextGetter is properly released on IO thread even when | 600 // Tests RequestContextGetter is properly released on IO thread even when |
597 // IO thread stops before sync thread. | 601 // IO thread stops before sync thread. |
598 TEST_F(SyncHttpBridgeTest, RequestContextGetterReleaseOrder) { | 602 TEST_F(MAYBE_SyncHttpBridgeTest, RequestContextGetterReleaseOrder) { |
599 base::Thread sync_thread("SyncThread"); | 603 base::Thread sync_thread("SyncThread"); |
600 sync_thread.Start(); | 604 sync_thread.Start(); |
601 | 605 |
602 syncer::HttpPostProviderFactory* factory = NULL; | 606 syncer::HttpPostProviderFactory* factory = NULL; |
603 syncer::HttpPostProviderInterface* bridge = NULL; | 607 syncer::HttpPostProviderInterface* bridge = NULL; |
604 | 608 |
605 scoped_refptr<net::URLRequestContextGetter> baseline_context_getter( | 609 scoped_refptr<net::URLRequestContextGetter> baseline_context_getter( |
606 new net::TestURLRequestContextGetter(io_thread()->task_runner())); | 610 new net::TestURLRequestContextGetter(io_thread()->task_runner())); |
607 | 611 |
608 base::WaitableEvent signal_when_created(false, false); | 612 base::WaitableEvent signal_when_created(false, false); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 wait_done.Signal(); | 645 wait_done.Signal(); |
642 io_thread()->Stop(); | 646 io_thread()->Stop(); |
643 | 647 |
644 // Unblock and stop sync thread. | 648 // Unblock and stop sync thread. |
645 wait_for_shutdown.Signal(); | 649 wait_for_shutdown.Signal(); |
646 sync_thread.Stop(); | 650 sync_thread.Stop(); |
647 } | 651 } |
648 | 652 |
649 // Attempt to release the URLRequestContextGetter before the HttpBridgeFactory | 653 // Attempt to release the URLRequestContextGetter before the HttpBridgeFactory |
650 // is initialized. | 654 // is initialized. |
651 TEST_F(SyncHttpBridgeTest, EarlyAbortFactory) { | 655 TEST_F(MAYBE_SyncHttpBridgeTest, EarlyAbortFactory) { |
652 // In a real scenario, the following would happen on many threads. For | 656 // In a real scenario, the following would happen on many threads. For |
653 // simplicity, this test uses only one thread. | 657 // simplicity, this test uses only one thread. |
654 | 658 |
655 scoped_refptr<net::URLRequestContextGetter> baseline_context_getter( | 659 scoped_refptr<net::URLRequestContextGetter> baseline_context_getter( |
656 new net::TestURLRequestContextGetter(io_thread()->task_runner())); | 660 new net::TestURLRequestContextGetter(io_thread()->task_runner())); |
657 CancelationSignal release_request_context_signal; | 661 CancelationSignal release_request_context_signal; |
658 | 662 |
659 // UI Thread: Initialize the HttpBridgeFactory. The next step would be to | 663 // UI Thread: Initialize the HttpBridgeFactory. The next step would be to |
660 // post a task to SBH::Core to have it initialized. | 664 // post a task to SBH::Core to have it initialized. |
661 scoped_ptr<syncer::HttpBridgeFactory> factory( | 665 scoped_ptr<syncer::HttpBridgeFactory> factory( |
662 new HttpBridgeFactory(baseline_context_getter.get(), | 666 new HttpBridgeFactory(baseline_context_getter.get(), |
663 NetworkTimeUpdateCallback(), | 667 NetworkTimeUpdateCallback(), |
664 &release_request_context_signal)); | 668 &release_request_context_signal)); |
665 | 669 |
666 // UI Thread: A very early shutdown request arrives and executes on the UI | 670 // UI Thread: A very early shutdown request arrives and executes on the UI |
667 // thread before the posted sync thread task is run. | 671 // thread before the posted sync thread task is run. |
668 release_request_context_signal.Signal(); | 672 release_request_context_signal.Signal(); |
669 | 673 |
670 // Sync thread: Finally run the posted task, only to find that our | 674 // Sync thread: Finally run the posted task, only to find that our |
671 // HttpBridgeFactory has been neutered. Should not crash. | 675 // HttpBridgeFactory has been neutered. Should not crash. |
672 factory->Init("TestUserAgent"); | 676 factory->Init("TestUserAgent"); |
673 | 677 |
674 // At this point, attempting to use the factory would trigger a crash. Both | 678 // At this point, attempting to use the factory would trigger a crash. Both |
675 // this test and the real world code should make sure this never happens. | 679 // this test and the real world code should make sure this never happens. |
676 }; | 680 }; |
677 | 681 |
678 } // namespace syncer | 682 } // namespace syncer |
OLD | NEW |