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/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 // 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 |
67 // DoWork is called first. | 67 // DoWork is called first. |
68 void Timeout() { | 68 void Timeout() { |
69 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."; |
70 BrowserThread::PostTask( | 70 BrowserThread::PostTask( |
71 BrowserThread::IO, FROM_HERE, base::MessageLoop::QuitClosure()); | 71 BrowserThread::IO, FROM_HERE, base::MessageLoop::QuitClosure()); |
72 } | 72 } |
73 | 73 |
74 protected: | 74 protected: |
75 virtual void SetUp() { | 75 void SetUp() override { worker_ = new DatabaseModelWorker(NULL); } |
76 worker_ = new DatabaseModelWorker(NULL); | |
77 } | |
78 | 76 |
79 virtual void Teardown() { | 77 virtual void Teardown() { |
80 worker_ = NULL; | 78 worker_ = NULL; |
81 } | 79 } |
82 | 80 |
83 private: | 81 private: |
84 bool did_do_work_; | 82 bool did_do_work_; |
85 scoped_refptr<BrowserThreadModelWorker> worker_; | 83 scoped_refptr<BrowserThreadModelWorker> worker_; |
86 OneShotTimer<SyncBrowserThreadModelWorkerTest> timer_; | 84 OneShotTimer<SyncBrowserThreadModelWorkerTest> timer_; |
87 | 85 |
88 content::TestBrowserThreadBundle thread_bundle_; | 86 content::TestBrowserThreadBundle thread_bundle_; |
89 | 87 |
90 base::WeakPtrFactory<SyncBrowserThreadModelWorkerTest> weak_factory_; | 88 base::WeakPtrFactory<SyncBrowserThreadModelWorkerTest> weak_factory_; |
91 }; | 89 }; |
92 | 90 |
93 TEST_F(SyncBrowserThreadModelWorkerTest, DoesWorkOnDatabaseThread) { | 91 TEST_F(SyncBrowserThreadModelWorkerTest, DoesWorkOnDatabaseThread) { |
94 base::MessageLoop::current()->PostTask(FROM_HERE, | 92 base::MessageLoop::current()->PostTask(FROM_HERE, |
95 base::Bind(&SyncBrowserThreadModelWorkerTest::ScheduleWork, | 93 base::Bind(&SyncBrowserThreadModelWorkerTest::ScheduleWork, |
96 factory()->GetWeakPtr())); | 94 factory()->GetWeakPtr())); |
97 base::MessageLoop::current()->Run(); | 95 base::MessageLoop::current()->Run(); |
98 EXPECT_TRUE(did_do_work()); | 96 EXPECT_TRUE(did_do_work()); |
99 } | 97 } |
100 | 98 |
101 } // namespace | 99 } // namespace |
102 | 100 |
103 } // namespace browser_sync | 101 } // namespace browser_sync |
OLD | NEW |