| 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/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 BrowserThreadModelWorker* worker() { return worker_.get(); } | 35 BrowserThreadModelWorker* worker() { return worker_.get(); } |
| 36 OneShotTimer<SyncBrowserThreadModelWorkerTest>* timer() { return &timer_; } | 36 OneShotTimer<SyncBrowserThreadModelWorkerTest>* timer() { return &timer_; } |
| 37 base::WeakPtrFactory<SyncBrowserThreadModelWorkerTest>* factory() { | 37 base::WeakPtrFactory<SyncBrowserThreadModelWorkerTest>* factory() { |
| 38 return &weak_factory_; | 38 return &weak_factory_; |
| 39 } | 39 } |
| 40 | 40 |
| 41 // Schedule DoWork to be executed on the DB thread and have the test fail if | 41 // Schedule DoWork to be executed on the DB thread and have the test fail if |
| 42 // DoWork hasn't executed within action_timeout_ms() ms. | 42 // DoWork hasn't executed within action_timeout_ms() ms. |
| 43 void ScheduleWork() { | 43 void ScheduleWork() { |
| 44 // We wait until the callback is done. So it is safe to use unretained. | 44 // We wait until the callback is done. So it is safe to use unretained. |
| 45 csync::WorkCallback c = base::Bind(&SyncBrowserThreadModelWorkerTest::DoWork, | 45 syncer::WorkCallback c = |
| 46 base::Unretained(this)); | 46 base::Bind(&SyncBrowserThreadModelWorkerTest::DoWork, |
| 47 base::Unretained(this)); |
| 47 timer()->Start( | 48 timer()->Start( |
| 48 FROM_HERE, | 49 FROM_HERE, |
| 49 TimeDelta::FromMilliseconds(TestTimeouts::action_timeout_ms()), | 50 TimeDelta::FromMilliseconds(TestTimeouts::action_timeout_ms()), |
| 50 this, | 51 this, |
| 51 &SyncBrowserThreadModelWorkerTest::Timeout); | 52 &SyncBrowserThreadModelWorkerTest::Timeout); |
| 52 worker()->DoWorkAndWaitUntilDone(c); | 53 worker()->DoWorkAndWaitUntilDone(c); |
| 53 } | 54 } |
| 54 | 55 |
| 55 // This is the work that will be scheduled to be done on the DB thread. | 56 // This is the work that will be scheduled to be done on the DB thread. |
| 56 csync::SyncerError DoWork() { | 57 syncer::SyncerError DoWork() { |
| 57 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 58 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 58 timer_.Stop(); // Stop the failure timer so the test succeeds. | 59 timer_.Stop(); // Stop the failure timer so the test succeeds. |
| 59 BrowserThread::PostTask( | 60 BrowserThread::PostTask( |
| 60 BrowserThread::IO, FROM_HERE, MessageLoop::QuitClosure()); | 61 BrowserThread::IO, FROM_HERE, MessageLoop::QuitClosure()); |
| 61 did_do_work_ = true; | 62 did_do_work_ = true; |
| 62 return csync::SYNCER_OK; | 63 return syncer::SYNCER_OK; |
| 63 } | 64 } |
| 64 | 65 |
| 65 // This will be called by the OneShotTimer and make the test fail unless | 66 // This will be called by the OneShotTimer and make the test fail unless |
| 66 // DoWork is called first. | 67 // DoWork is called first. |
| 67 void Timeout() { | 68 void Timeout() { |
| 68 ADD_FAILURE() << "Timed out waiting for work to be done on the DB thread."; | 69 ADD_FAILURE() << "Timed out waiting for work to be done on the DB thread."; |
| 69 BrowserThread::PostTask( | 70 BrowserThread::PostTask( |
| 70 BrowserThread::IO, FROM_HERE, MessageLoop::QuitClosure()); | 71 BrowserThread::IO, FROM_HERE, MessageLoop::QuitClosure()); |
| 71 } | 72 } |
| 72 | 73 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 97 MessageLoop::current()->PostTask(FROM_HERE, | 98 MessageLoop::current()->PostTask(FROM_HERE, |
| 98 base::Bind(&SyncBrowserThreadModelWorkerTest::ScheduleWork, | 99 base::Bind(&SyncBrowserThreadModelWorkerTest::ScheduleWork, |
| 99 factory()->GetWeakPtr())); | 100 factory()->GetWeakPtr())); |
| 100 MessageLoop::current()->Run(); | 101 MessageLoop::current()->Run(); |
| 101 EXPECT_TRUE(did_do_work()); | 102 EXPECT_TRUE(did_do_work()); |
| 102 } | 103 } |
| 103 | 104 |
| 104 } // namespace | 105 } // namespace |
| 105 | 106 |
| 106 } // namespace browser_sync | 107 } // namespace browser_sync |
| OLD | NEW |