OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/scoped_ptr.h" | 5 #include "base/scoped_ptr.h" |
6 #include "base/thread.h" | 6 #include "base/thread.h" |
7 #include "base/timer.h" | 7 #include "base/timer.h" |
8 #include "chrome/browser/chrome_thread.h" | 8 #include "chrome/browser/chrome_thread.h" |
9 #include "chrome/browser/sync/glue/database_model_worker.h" | 9 #include "chrome/browser/sync/glue/database_model_worker.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 bool did_do_work() { return did_do_work_; } | 27 bool did_do_work() { return did_do_work_; } |
28 DatabaseModelWorker* worker() { return worker_.get(); } | 28 DatabaseModelWorker* worker() { return worker_.get(); } |
29 OneShotTimer<DatabaseModelWorkerTest>* timer() { return &timer_; } | 29 OneShotTimer<DatabaseModelWorkerTest>* timer() { return &timer_; } |
30 ScopedRunnableMethodFactory<DatabaseModelWorkerTest>* factory() { | 30 ScopedRunnableMethodFactory<DatabaseModelWorkerTest>* factory() { |
31 return &method_factory_; | 31 return &method_factory_; |
32 } | 32 } |
33 | 33 |
34 // Schedule DoWork to be executed on the DB thread and have the test fail if | 34 // Schedule DoWork to be executed on the DB thread and have the test fail if |
35 // DoWork hasn't executed within 10 seconds. | 35 // DoWork hasn't executed within 10 seconds. |
36 void ScheduleWork() { | 36 void ScheduleWork() { |
| 37 scoped_ptr<Closure> c(NewCallback(this, &DatabaseModelWorkerTest::DoWork)); |
37 timer()->Start(TimeDelta::FromSeconds(10), | 38 timer()->Start(TimeDelta::FromSeconds(10), |
38 this, &DatabaseModelWorkerTest::Timeout); | 39 this, &DatabaseModelWorkerTest::Timeout); |
39 worker()->DoWorkAndWaitUntilDone( | 40 worker()->DoWorkAndWaitUntilDone(c.get()); |
40 NewCallback(this, &DatabaseModelWorkerTest::DoWork)); | |
41 } | 41 } |
42 | 42 |
43 // This is the work that will be scheduled to be done on the DB thread. | 43 // This is the work that will be scheduled to be done on the DB thread. |
44 void DoWork() { | 44 void DoWork() { |
45 EXPECT_TRUE(ChromeThread::CurrentlyOn(ChromeThread::DB)); | 45 EXPECT_TRUE(ChromeThread::CurrentlyOn(ChromeThread::DB)); |
46 timer_.Stop(); // Stop the failure timer so the test succeeds. | 46 timer_.Stop(); // Stop the failure timer so the test succeeds. |
47 ChromeThread::PostTask( | 47 ChromeThread::PostTask( |
48 ChromeThread::IO, FROM_HERE, new MessageLoop::QuitTask()); | 48 ChromeThread::IO, FROM_HERE, new MessageLoop::QuitTask()); |
49 did_do_work_ = true; | 49 did_do_work_ = true; |
50 } | 50 } |
(...skipping 30 matching lines...) Expand all Loading... |
81 }; | 81 }; |
82 | 82 |
83 TEST_F(DatabaseModelWorkerTest, DoesWorkOnDatabaseThread) { | 83 TEST_F(DatabaseModelWorkerTest, DoesWorkOnDatabaseThread) { |
84 MessageLoop::current()->PostTask(FROM_HERE, factory()->NewRunnableMethod( | 84 MessageLoop::current()->PostTask(FROM_HERE, factory()->NewRunnableMethod( |
85 &DatabaseModelWorkerTest::ScheduleWork)); | 85 &DatabaseModelWorkerTest::ScheduleWork)); |
86 MessageLoop::current()->Run(); | 86 MessageLoop::current()->Run(); |
87 EXPECT_TRUE(did_do_work()); | 87 EXPECT_TRUE(did_do_work()); |
88 } | 88 } |
89 | 89 |
90 } // namespace | 90 } // namespace |
OLD | NEW |