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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include "base/bit_cast.h" | 8 #include "base/bit_cast.h" |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 | 411 |
412 // Tests an interesting case where code using the HttpBridge aborts the fetch | 412 // Tests an interesting case where code using the HttpBridge aborts the fetch |
413 // and releases ownership before a pending fetch completed callback is issued by | 413 // and releases ownership before a pending fetch completed callback is issued by |
414 // the underlying URLFetcher (and before that URLFetcher is destroyed, which | 414 // the underlying URLFetcher (and before that URLFetcher is destroyed, which |
415 // would cancel the callback). | 415 // would cancel the callback). |
416 TEST_F(MAYBE_SyncHttpBridgeTest, AbortAndReleaseBeforeFetchComplete) { | 416 TEST_F(MAYBE_SyncHttpBridgeTest, AbortAndReleaseBeforeFetchComplete) { |
417 base::Thread sync_thread("SyncThread"); | 417 base::Thread sync_thread("SyncThread"); |
418 sync_thread.Start(); | 418 sync_thread.Start(); |
419 | 419 |
420 // First, block the sync thread on the post. | 420 // First, block the sync thread on the post. |
421 base::WaitableEvent signal_when_created(false, false); | 421 base::WaitableEvent signal_when_created( |
422 base::WaitableEvent signal_when_released(false, false); | 422 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 423 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 424 base::WaitableEvent signal_when_released( |
| 425 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 426 base::WaitableEvent::InitialState::NOT_SIGNALED); |
423 sync_thread.message_loop()->PostTask(FROM_HERE, | 427 sync_thread.message_loop()->PostTask(FROM_HERE, |
424 base::Bind(&MAYBE_SyncHttpBridgeTest::RunSyncThreadBridgeUseTest, | 428 base::Bind(&MAYBE_SyncHttpBridgeTest::RunSyncThreadBridgeUseTest, |
425 base::Unretained(this), | 429 base::Unretained(this), |
426 &signal_when_created, | 430 &signal_when_created, |
427 &signal_when_released)); | 431 &signal_when_released)); |
428 | 432 |
429 // Stop IO so we can control order of operations. | 433 // Stop IO so we can control order of operations. |
430 base::WaitableEvent io_waiter(false, false); | 434 base::WaitableEvent io_waiter( |
| 435 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 436 base::WaitableEvent::InitialState::NOT_SIGNALED); |
431 ASSERT_TRUE(io_thread()->task_runner()->PostTask( | 437 ASSERT_TRUE(io_thread()->task_runner()->PostTask( |
432 FROM_HERE, | 438 FROM_HERE, |
433 base::Bind(&base::WaitableEvent::Wait, base::Unretained(&io_waiter)))); | 439 base::Bind(&base::WaitableEvent::Wait, base::Unretained(&io_waiter)))); |
434 | 440 |
435 signal_when_created.Wait(); // Wait till we have a bridge to abort. | 441 signal_when_created.Wait(); // Wait till we have a bridge to abort. |
436 ASSERT_TRUE(bridge_for_race_test()); | 442 ASSERT_TRUE(bridge_for_race_test()); |
437 | 443 |
438 // Schedule the fetch completion callback (but don't run it yet). Don't take | 444 // Schedule the fetch completion callback (but don't run it yet). Don't take |
439 // a reference to the bridge to mimic URLFetcher's handling of the delegate. | 445 // a reference to the bridge to mimic URLFetcher's handling of the delegate. |
440 net::URLFetcherDelegate* delegate = | 446 net::URLFetcherDelegate* delegate = |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 TEST_F(MAYBE_SyncHttpBridgeTest, RequestContextGetterReleaseOrder) { | 508 TEST_F(MAYBE_SyncHttpBridgeTest, RequestContextGetterReleaseOrder) { |
503 base::Thread sync_thread("SyncThread"); | 509 base::Thread sync_thread("SyncThread"); |
504 sync_thread.Start(); | 510 sync_thread.Start(); |
505 | 511 |
506 syncer::HttpPostProviderFactory* factory = NULL; | 512 syncer::HttpPostProviderFactory* factory = NULL; |
507 syncer::HttpPostProviderInterface* bridge = NULL; | 513 syncer::HttpPostProviderInterface* bridge = NULL; |
508 | 514 |
509 scoped_refptr<net::URLRequestContextGetter> baseline_context_getter( | 515 scoped_refptr<net::URLRequestContextGetter> baseline_context_getter( |
510 new net::TestURLRequestContextGetter(io_thread()->task_runner())); | 516 new net::TestURLRequestContextGetter(io_thread()->task_runner())); |
511 | 517 |
512 base::WaitableEvent signal_when_created(false, false); | 518 base::WaitableEvent signal_when_created( |
513 base::WaitableEvent wait_for_shutdown(false, false); | 519 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 520 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 521 base::WaitableEvent wait_for_shutdown( |
| 522 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 523 base::WaitableEvent::InitialState::NOT_SIGNALED); |
514 | 524 |
515 CancelationSignal release_request_context_signal; | 525 CancelationSignal release_request_context_signal; |
516 | 526 |
517 // Create bridge factory and factory on sync thread and wait for the creation | 527 // Create bridge factory and factory on sync thread and wait for the creation |
518 // to finish. | 528 // to finish. |
519 sync_thread.message_loop()->PostTask( | 529 sync_thread.message_loop()->PostTask( |
520 FROM_HERE, base::Bind(&HttpBridgeRunOnSyncThread, | 530 FROM_HERE, base::Bind(&HttpBridgeRunOnSyncThread, |
521 base::Unretained(baseline_context_getter.get()), | 531 base::Unretained(baseline_context_getter.get()), |
522 &release_request_context_signal, &factory, &bridge, | 532 &release_request_context_signal, &factory, &bridge, |
523 &signal_when_created, &wait_for_shutdown)); | 533 &signal_when_created, &wait_for_shutdown)); |
524 signal_when_created.Wait(); | 534 signal_when_created.Wait(); |
525 | 535 |
526 // Simulate sync shutdown by aborting bridge and shutting down factory on | 536 // Simulate sync shutdown by aborting bridge and shutting down factory on |
527 // frontend. | 537 // frontend. |
528 bridge->Abort(); | 538 bridge->Abort(); |
529 release_request_context_signal.Signal(); | 539 release_request_context_signal.Signal(); |
530 | 540 |
531 // Wait for sync's RequestContextGetter to be cleared on IO thread and | 541 // Wait for sync's RequestContextGetter to be cleared on IO thread and |
532 // check for reference count. | 542 // check for reference count. |
533 base::WaitableEvent signal_wait_start(false, false); | 543 base::WaitableEvent signal_wait_start( |
534 base::WaitableEvent wait_done(false, false); | 544 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 545 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 546 base::WaitableEvent wait_done( |
| 547 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 548 base::WaitableEvent::InitialState::NOT_SIGNALED); |
535 io_thread()->message_loop()->PostTask( | 549 io_thread()->message_loop()->PostTask( |
536 FROM_HERE, | 550 FROM_HERE, |
537 base::Bind(&WaitOnIOThread, &signal_wait_start, &wait_done)); | 551 base::Bind(&WaitOnIOThread, &signal_wait_start, &wait_done)); |
538 signal_wait_start.Wait(); | 552 signal_wait_start.Wait(); |
539 // |baseline_context_getter| should have only one reference from local | 553 // |baseline_context_getter| should have only one reference from local |
540 // variable. | 554 // variable. |
541 EXPECT_TRUE(baseline_context_getter->HasOneRef()); | 555 EXPECT_TRUE(baseline_context_getter->HasOneRef()); |
542 baseline_context_getter = NULL; | 556 baseline_context_getter = NULL; |
543 | 557 |
544 // Unblock and stop IO thread before sync thread. | 558 // Unblock and stop IO thread before sync thread. |
(...skipping 27 matching lines...) Expand all Loading... |
572 | 586 |
573 // Sync thread: Finally run the posted task, only to find that our | 587 // Sync thread: Finally run the posted task, only to find that our |
574 // HttpBridgeFactory has been neutered. Should not crash. | 588 // HttpBridgeFactory has been neutered. Should not crash. |
575 factory->Init("TestUserAgent", BindToTrackerCallback()); | 589 factory->Init("TestUserAgent", BindToTrackerCallback()); |
576 | 590 |
577 // At this point, attempting to use the factory would trigger a crash. Both | 591 // At this point, attempting to use the factory would trigger a crash. Both |
578 // this test and the real world code should make sure this never happens. | 592 // this test and the real world code should make sure this never happens. |
579 } | 593 } |
580 | 594 |
581 } // namespace syncer | 595 } // namespace syncer |
OLD | NEW |