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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/callback.h" | 6 #include "base/callback.h" |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 TestTimeouts::action_timeout(), | 53 TestTimeouts::action_timeout(), |
54 this, | 54 this, |
55 &SyncBrowserThreadModelWorkerTest::Timeout); | 55 &SyncBrowserThreadModelWorkerTest::Timeout); |
56 worker()->DoWorkAndWaitUntilDone(c); | 56 worker()->DoWorkAndWaitUntilDone(c); |
57 } | 57 } |
58 | 58 |
59 // This is the work that will be scheduled to be done on the DB thread. | 59 // This is the work that will be scheduled to be done on the DB thread. |
60 syncer::SyncerError DoWork() { | 60 syncer::SyncerError DoWork() { |
61 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 61 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
62 timer_.Stop(); // Stop the failure timer so the test succeeds. | 62 timer_.Stop(); // Stop the failure timer so the test succeeds. |
63 BrowserThread::PostTask( | 63 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
64 BrowserThread::IO, FROM_HERE, base::MessageLoop::QuitClosure()); | 64 base::MessageLoop::QuitWhenIdleClosure()); |
65 did_do_work_ = true; | 65 did_do_work_ = true; |
66 return syncer::SYNCER_OK; | 66 return syncer::SYNCER_OK; |
67 } | 67 } |
68 | 68 |
69 // This will be called by the OneShotTimer and make the test fail unless | 69 // This will be called by the OneShotTimer and make the test fail unless |
70 // DoWork is called first. | 70 // DoWork is called first. |
71 void Timeout() { | 71 void Timeout() { |
72 ADD_FAILURE() << "Timed out waiting for work to be done on the DB thread."; | 72 ADD_FAILURE() << "Timed out waiting for work to be done on the DB thread."; |
73 BrowserThread::PostTask( | 73 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
74 BrowserThread::IO, FROM_HERE, base::MessageLoop::QuitClosure()); | 74 base::MessageLoop::QuitWhenIdleClosure()); |
75 } | 75 } |
76 | 76 |
77 protected: | 77 protected: |
78 void SetUp() override { | 78 void SetUp() override { |
79 worker_ = new BrowserThreadModelWorker( | 79 worker_ = new BrowserThreadModelWorker( |
80 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), | 80 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), |
81 syncer::GROUP_DB, NULL); | 81 syncer::GROUP_DB, NULL); |
82 } | 82 } |
83 | 83 |
84 virtual void Teardown() { | 84 virtual void Teardown() { |
(...skipping 14 matching lines...) Expand all Loading... |
99 base::ThreadTaskRunnerHandle::Get()->PostTask( | 99 base::ThreadTaskRunnerHandle::Get()->PostTask( |
100 FROM_HERE, base::Bind(&SyncBrowserThreadModelWorkerTest::ScheduleWork, | 100 FROM_HERE, base::Bind(&SyncBrowserThreadModelWorkerTest::ScheduleWork, |
101 factory()->GetWeakPtr())); | 101 factory()->GetWeakPtr())); |
102 base::MessageLoop::current()->Run(); | 102 base::MessageLoop::current()->Run(); |
103 EXPECT_TRUE(did_do_work()); | 103 EXPECT_TRUE(did_do_work()); |
104 } | 104 } |
105 | 105 |
106 } // namespace | 106 } // namespace |
107 | 107 |
108 } // namespace browser_sync | 108 } // namespace browser_sync |
OLD | NEW |