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/callback.h" | 5 #include "base/callback.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
9 #include "base/timer.h" | 9 #include "base/timer.h" |
10 #include "chrome/browser/sync/glue/database_model_worker.h" | 10 #include "chrome/browser/sync/glue/database_model_worker.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 OneShotTimer<DatabaseModelWorkerTest>* timer() { return &timer_; } | 31 OneShotTimer<DatabaseModelWorkerTest>* timer() { return &timer_; } |
32 ScopedRunnableMethodFactory<DatabaseModelWorkerTest>* factory() { | 32 ScopedRunnableMethodFactory<DatabaseModelWorkerTest>* factory() { |
33 return &method_factory_; | 33 return &method_factory_; |
34 } | 34 } |
35 | 35 |
36 // Schedule DoWork to be executed on the DB thread and have the test fail if | 36 // Schedule DoWork to be executed on the DB thread and have the test fail if |
37 // DoWork hasn't executed within 10 seconds. | 37 // DoWork hasn't executed within 10 seconds. |
38 void ScheduleWork() { | 38 void ScheduleWork() { |
39 scoped_ptr<Callback0::Type> c(NewCallback(this, | 39 scoped_ptr<Callback0::Type> c(NewCallback(this, |
40 &DatabaseModelWorkerTest::DoWork)); | 40 &DatabaseModelWorkerTest::DoWork)); |
41 timer()->Start(FROM_HERE, TimeDelta::FromSeconds(10), | 41 timer()->Start(TimeDelta::FromSeconds(10), |
42 this, &DatabaseModelWorkerTest::Timeout); | 42 this, &DatabaseModelWorkerTest::Timeout); |
43 worker()->DoWorkAndWaitUntilDone(c.get()); | 43 worker()->DoWorkAndWaitUntilDone(c.get()); |
44 } | 44 } |
45 | 45 |
46 // This is the work that will be scheduled to be done on the DB thread. | 46 // This is the work that will be scheduled to be done on the DB thread. |
47 void DoWork() { | 47 void DoWork() { |
48 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 48 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
49 timer_.Stop(); // Stop the failure timer so the test succeeds. | 49 timer_.Stop(); // Stop the failure timer so the test succeeds. |
50 BrowserThread::PostTask( | 50 BrowserThread::PostTask( |
51 BrowserThread::IO, FROM_HERE, new MessageLoop::QuitTask()); | 51 BrowserThread::IO, FROM_HERE, new MessageLoop::QuitTask()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 }; | 84 }; |
85 | 85 |
86 TEST_F(DatabaseModelWorkerTest, DoesWorkOnDatabaseThread) { | 86 TEST_F(DatabaseModelWorkerTest, DoesWorkOnDatabaseThread) { |
87 MessageLoop::current()->PostTask(FROM_HERE, factory()->NewRunnableMethod( | 87 MessageLoop::current()->PostTask(FROM_HERE, factory()->NewRunnableMethod( |
88 &DatabaseModelWorkerTest::ScheduleWork)); | 88 &DatabaseModelWorkerTest::ScheduleWork)); |
89 MessageLoop::current()->Run(); | 89 MessageLoop::current()->Run(); |
90 EXPECT_TRUE(did_do_work()); | 90 EXPECT_TRUE(did_do_work()); |
91 } | 91 } |
92 | 92 |
93 } // namespace | 93 } // namespace |
OLD | NEW |