OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "components/sync/driver/glue/ui_model_worker.h" | 5 #include "components/sync/driver/glue/ui_model_worker.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 return base::Bind(&DoWork, base::ThreadTaskRunnerHandle::Get(), work); | 32 return base::Bind(&DoWork, base::ThreadTaskRunnerHandle::Get(), work); |
33 } | 33 } |
34 | 34 |
35 class SyncUIModelWorkerTest : public testing::Test { | 35 class SyncUIModelWorkerTest : public testing::Test { |
36 public: | 36 public: |
37 SyncUIModelWorkerTest() : sync_thread_("SyncThreadForTest") { | 37 SyncUIModelWorkerTest() : sync_thread_("SyncThreadForTest") { |
38 sync_thread_.Start(); | 38 sync_thread_.Start(); |
39 worker_ = new UIModelWorker(base::ThreadTaskRunnerHandle::Get()); | 39 worker_ = new UIModelWorker(base::ThreadTaskRunnerHandle::Get()); |
40 } | 40 } |
41 | 41 |
42 void PostWorkToSyncThread(WorkCallback work) { | 42 void PostWorkToSyncThread(base::Closure work) { |
43 sync_thread_.task_runner()->PostTask( | 43 sync_thread_.task_runner()->PostTask( |
44 FROM_HERE, | 44 FROM_HERE, |
45 base::Bind(base::IgnoreResult(&UIModelWorker::DoWorkAndWaitUntilDone), | 45 base::Bind(base::IgnoreResult(&UIModelWorker::DoWorkAndWaitUntilDone), |
46 worker_, work)); | 46 worker_, ClosureToWorkCallback(work))); |
| 47 } |
| 48 |
| 49 // Work function for ShutdownNoDeadlock below. |
| 50 void DeadlockTest(base::Closure quit_closure) { |
| 51 // Unblock the sync thread. |
| 52 worker_->RequestStop(); |
| 53 |
| 54 // Join the sync thread. |
| 55 sync_thread_.Stop(); |
| 56 |
| 57 // Let the test complete. |
| 58 quit_closure.Run(); |
47 } | 59 } |
48 | 60 |
49 private: | 61 private: |
50 base::MessageLoop ui_loop_; | 62 base::MessageLoop ui_loop_; |
51 base::Thread sync_thread_; | 63 base::Thread sync_thread_; |
52 scoped_refptr<UIModelWorker> worker_; | 64 scoped_refptr<UIModelWorker> worker_; |
53 }; | 65 }; |
54 | 66 |
55 TEST_F(SyncUIModelWorkerTest, ScheduledWorkRunsOnUILoop) { | 67 TEST_F(SyncUIModelWorkerTest, ScheduledWorkRunsOnUILoop) { |
56 base::RunLoop run_loop; | 68 base::RunLoop run_loop; |
57 PostWorkToSyncThread(ClosureToWorkCallback(run_loop.QuitClosure())); | 69 PostWorkToSyncThread(run_loop.QuitClosure()); |
58 // This won't quit until the QuitClosure is run. | 70 // This won't quit until the QuitClosure is run. |
59 run_loop.Run(); | 71 run_loop.Run(); |
60 } | 72 } |
61 | 73 |
| 74 TEST_F(SyncUIModelWorkerTest, ShutdownNoDeadlock) { |
| 75 base::RunLoop run_loop; |
| 76 PostWorkToSyncThread(base::Bind(&SyncUIModelWorkerTest::DeadlockTest, |
| 77 base::Unretained(this), |
| 78 run_loop.QuitClosure())); |
| 79 run_loop.Run(); |
| 80 } |
| 81 |
62 } // namespace | 82 } // namespace |
63 } // namespace syncer | 83 } // namespace syncer |
OLD | NEW |