OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
12 #include "base/timer.h" | 12 #include "base/timer.h" |
13 #include "chrome/browser/sync/glue/browser_thread_model_worker.h" | 13 #include "chrome/browser/sync/glue/browser_thread_model_worker.h" |
14 #include "chrome/browser/sync/util/unrecoverable_error_info.h" | |
15 #include "content/test/test_browser_thread.h" | 14 #include "content/test/test_browser_thread.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
17 | 16 |
18 using base::OneShotTimer; | 17 using base::OneShotTimer; |
19 using base::Thread; | 18 using base::Thread; |
20 using base::TimeDelta; | 19 using base::TimeDelta; |
21 using content::BrowserThread; | 20 using content::BrowserThread; |
22 | 21 |
23 namespace browser_sync { | 22 namespace browser_sync { |
24 | 23 |
(...skipping 22 matching lines...) Expand all Loading... |
47 base::Unretained(this)); | 46 base::Unretained(this)); |
48 timer()->Start( | 47 timer()->Start( |
49 FROM_HERE, | 48 FROM_HERE, |
50 TimeDelta::FromMilliseconds(TestTimeouts::action_timeout_ms()), | 49 TimeDelta::FromMilliseconds(TestTimeouts::action_timeout_ms()), |
51 this, | 50 this, |
52 &BrowserThreadModelWorkerTest::Timeout); | 51 &BrowserThreadModelWorkerTest::Timeout); |
53 worker()->DoWorkAndWaitUntilDone(c); | 52 worker()->DoWorkAndWaitUntilDone(c); |
54 } | 53 } |
55 | 54 |
56 // This is the work that will be scheduled to be done on the DB thread. | 55 // This is the work that will be scheduled to be done on the DB thread. |
57 UnrecoverableErrorInfo DoWork() { | 56 SyncerError DoWork() { |
58 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 57 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
59 timer_.Stop(); // Stop the failure timer so the test succeeds. | 58 timer_.Stop(); // Stop the failure timer so the test succeeds. |
60 BrowserThread::PostTask( | 59 BrowserThread::PostTask( |
61 BrowserThread::IO, FROM_HERE, MessageLoop::QuitClosure()); | 60 BrowserThread::IO, FROM_HERE, MessageLoop::QuitClosure()); |
62 did_do_work_ = true; | 61 did_do_work_ = true; |
63 return UnrecoverableErrorInfo(); | 62 return NO_ERROR; |
64 } | 63 } |
65 | 64 |
66 // This will be called by the OneShotTimer and make the test fail unless | 65 // This will be called by the OneShotTimer and make the test fail unless |
67 // DoWork is called first. | 66 // DoWork is called first. |
68 void Timeout() { | 67 void Timeout() { |
69 ADD_FAILURE() << "Timed out waiting for work to be done on the DB thread."; | 68 ADD_FAILURE() << "Timed out waiting for work to be done on the DB thread."; |
70 BrowserThread::PostTask( | 69 BrowserThread::PostTask( |
71 BrowserThread::IO, FROM_HERE, MessageLoop::QuitClosure()); | 70 BrowserThread::IO, FROM_HERE, MessageLoop::QuitClosure()); |
72 } | 71 } |
73 | 72 |
(...skipping 24 matching lines...) Expand all Loading... |
98 MessageLoop::current()->PostTask(FROM_HERE, | 97 MessageLoop::current()->PostTask(FROM_HERE, |
99 base::Bind(&BrowserThreadModelWorkerTest::ScheduleWork, | 98 base::Bind(&BrowserThreadModelWorkerTest::ScheduleWork, |
100 factory()->GetWeakPtr())); | 99 factory()->GetWeakPtr())); |
101 MessageLoop::current()->Run(); | 100 MessageLoop::current()->Run(); |
102 EXPECT_TRUE(did_do_work()); | 101 EXPECT_TRUE(did_do_work()); |
103 } | 102 } |
104 | 103 |
105 } // namespace | 104 } // namespace |
106 | 105 |
107 } // namespace browser_sync | 106 } // namespace browser_sync |
OLD | NEW |