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

Side by Side Diff: components/sync/core/http_bridge_unittest.cc

Issue 2388673002: Revert of [Sync] Move //components/sync to the syncer namespace. (patchset #5 id:40001 of https://co (Closed)
Patch Set: Created 4 years, 2 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 unified diff | Download patch
OLDNEW
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/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 io_waiter.Signal(); 458 io_waiter.Signal();
459 459
460 // Done. 460 // Done.
461 sync_thread.Stop(); 461 sync_thread.Stop();
462 io_thread()->Stop(); 462 io_thread()->Stop();
463 } 463 }
464 464
465 void HttpBridgeRunOnSyncThread( 465 void HttpBridgeRunOnSyncThread(
466 net::URLRequestContextGetter* baseline_context_getter, 466 net::URLRequestContextGetter* baseline_context_getter,
467 CancelationSignal* factory_cancelation_signal, 467 CancelationSignal* factory_cancelation_signal,
468 HttpPostProviderFactory** bridge_factory_out, 468 syncer::HttpPostProviderFactory** bridge_factory_out,
469 HttpPostProviderInterface** bridge_out, 469 syncer::HttpPostProviderInterface** bridge_out,
470 base::WaitableEvent* signal_when_created, 470 base::WaitableEvent* signal_when_created,
471 base::WaitableEvent* wait_for_shutdown) { 471 base::WaitableEvent* wait_for_shutdown) {
472 std::unique_ptr<HttpBridgeFactory> bridge_factory(new HttpBridgeFactory( 472 std::unique_ptr<syncer::HttpBridgeFactory> bridge_factory(
473 baseline_context_getter, NetworkTimeUpdateCallback(), 473 new syncer::HttpBridgeFactory(baseline_context_getter,
474 factory_cancelation_signal)); 474 NetworkTimeUpdateCallback(),
475 factory_cancelation_signal));
475 bridge_factory->Init("test", BindToTrackerCallback()); 476 bridge_factory->Init("test", BindToTrackerCallback());
476 *bridge_factory_out = bridge_factory.get(); 477 *bridge_factory_out = bridge_factory.get();
477 478
478 HttpPostProviderInterface* bridge = bridge_factory->Create(); 479 HttpPostProviderInterface* bridge = bridge_factory->Create();
479 *bridge_out = bridge; 480 *bridge_out = bridge;
480 481
481 signal_when_created->Signal(); 482 signal_when_created->Signal();
482 wait_for_shutdown->Wait(); 483 wait_for_shutdown->Wait();
483 484
484 bridge_factory->Destroy(bridge); 485 bridge_factory->Destroy(bridge);
485 } 486 }
486 487
487 void WaitOnIOThread(base::WaitableEvent* signal_wait_start, 488 void WaitOnIOThread(base::WaitableEvent* signal_wait_start,
488 base::WaitableEvent* wait_done) { 489 base::WaitableEvent* wait_done) {
489 signal_wait_start->Signal(); 490 signal_wait_start->Signal();
490 wait_done->Wait(); 491 wait_done->Wait();
491 } 492 }
492 493
493 // Tests RequestContextGetter is properly released on IO thread even when 494 // Tests RequestContextGetter is properly released on IO thread even when
494 // IO thread stops before sync thread. 495 // IO thread stops before sync thread.
495 TEST_F(MAYBE_SyncHttpBridgeTest, RequestContextGetterReleaseOrder) { 496 TEST_F(MAYBE_SyncHttpBridgeTest, RequestContextGetterReleaseOrder) {
496 base::Thread sync_thread("SyncThread"); 497 base::Thread sync_thread("SyncThread");
497 sync_thread.Start(); 498 sync_thread.Start();
498 499
499 HttpPostProviderFactory* factory = NULL; 500 syncer::HttpPostProviderFactory* factory = NULL;
500 HttpPostProviderInterface* bridge = NULL; 501 syncer::HttpPostProviderInterface* bridge = NULL;
501 502
502 scoped_refptr<net::URLRequestContextGetter> baseline_context_getter( 503 scoped_refptr<net::URLRequestContextGetter> baseline_context_getter(
503 new net::TestURLRequestContextGetter(io_thread()->task_runner())); 504 new net::TestURLRequestContextGetter(io_thread()->task_runner()));
504 505
505 base::WaitableEvent signal_when_created( 506 base::WaitableEvent signal_when_created(
506 base::WaitableEvent::ResetPolicy::AUTOMATIC, 507 base::WaitableEvent::ResetPolicy::AUTOMATIC,
507 base::WaitableEvent::InitialState::NOT_SIGNALED); 508 base::WaitableEvent::InitialState::NOT_SIGNALED);
508 base::WaitableEvent wait_for_shutdown( 509 base::WaitableEvent wait_for_shutdown(
509 base::WaitableEvent::ResetPolicy::AUTOMATIC, 510 base::WaitableEvent::ResetPolicy::AUTOMATIC,
510 base::WaitableEvent::InitialState::NOT_SIGNALED); 511 base::WaitableEvent::InitialState::NOT_SIGNALED);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 TEST_F(MAYBE_SyncHttpBridgeTest, EarlyAbortFactory) { 556 TEST_F(MAYBE_SyncHttpBridgeTest, EarlyAbortFactory) {
556 // In a real scenario, the following would happen on many threads. For 557 // In a real scenario, the following would happen on many threads. For
557 // simplicity, this test uses only one thread. 558 // simplicity, this test uses only one thread.
558 559
559 scoped_refptr<net::URLRequestContextGetter> baseline_context_getter( 560 scoped_refptr<net::URLRequestContextGetter> baseline_context_getter(
560 new net::TestURLRequestContextGetter(io_thread()->task_runner())); 561 new net::TestURLRequestContextGetter(io_thread()->task_runner()));
561 CancelationSignal release_request_context_signal; 562 CancelationSignal release_request_context_signal;
562 563
563 // UI Thread: Initialize the HttpBridgeFactory. The next step would be to 564 // UI Thread: Initialize the HttpBridgeFactory. The next step would be to
564 // post a task to SBH::Core to have it initialized. 565 // post a task to SBH::Core to have it initialized.
565 std::unique_ptr<HttpBridgeFactory> factory(new HttpBridgeFactory( 566 std::unique_ptr<syncer::HttpBridgeFactory> factory(new HttpBridgeFactory(
566 baseline_context_getter.get(), NetworkTimeUpdateCallback(), 567 baseline_context_getter.get(), NetworkTimeUpdateCallback(),
567 &release_request_context_signal)); 568 &release_request_context_signal));
568 569
569 // UI Thread: A very early shutdown request arrives and executes on the UI 570 // UI Thread: A very early shutdown request arrives and executes on the UI
570 // thread before the posted sync thread task is run. 571 // thread before the posted sync thread task is run.
571 release_request_context_signal.Signal(); 572 release_request_context_signal.Signal();
572 573
573 // Sync thread: Finally run the posted task, only to find that our 574 // Sync thread: Finally run the posted task, only to find that our
574 // HttpBridgeFactory has been neutered. Should not crash. 575 // HttpBridgeFactory has been neutered. Should not crash.
575 factory->Init("TestUserAgent", BindToTrackerCallback()); 576 factory->Init("TestUserAgent", BindToTrackerCallback());
576 577
577 // At this point, attempting to use the factory would trigger a crash. Both 578 // 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. 579 // this test and the real world code should make sure this never happens.
579 } 580 }
580 581
581 } // namespace syncer 582 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/core/delete_journal.cc ('k') | components/sync/core/internal_components_factory_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698