Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: chrome/browser/sync/glue/browser_thread_model_worker_unittest.cc

Issue 10689157: Switch to TimeDelta interfaces for TestTimeouts in sync code. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 21 matching lines...) Expand all
32 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {} 32 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {}
33 33
34 bool did_do_work() { return did_do_work_; } 34 bool did_do_work() { return did_do_work_; }
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.
akalin 2012/07/11 20:35:15 remove ' 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 syncer::WorkCallback c = 45 syncer::WorkCallback c =
46 base::Bind(&SyncBrowserThreadModelWorkerTest::DoWork, 46 base::Bind(&SyncBrowserThreadModelWorkerTest::DoWork,
47 base::Unretained(this)); 47 base::Unretained(this));
48 timer()->Start( 48 timer()->Start(
49 FROM_HERE, 49 FROM_HERE,
50 TimeDelta::FromMilliseconds(TestTimeouts::action_timeout_ms()), 50 TestTimeouts::action_timeout(),
51 this, 51 this,
52 &SyncBrowserThreadModelWorkerTest::Timeout); 52 &SyncBrowserThreadModelWorkerTest::Timeout);
53 worker()->DoWorkAndWaitUntilDone(c); 53 worker()->DoWorkAndWaitUntilDone(c);
54 } 54 }
55 55
56 // 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.
57 syncer::SyncerError DoWork() { 57 syncer::SyncerError DoWork() {
58 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); 58 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
59 timer_.Stop(); // Stop the failure timer so the test succeeds. 59 timer_.Stop(); // Stop the failure timer so the test succeeds.
60 BrowserThread::PostTask( 60 BrowserThread::PostTask(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 MessageLoop::current()->PostTask(FROM_HERE, 98 MessageLoop::current()->PostTask(FROM_HERE,
99 base::Bind(&SyncBrowserThreadModelWorkerTest::ScheduleWork, 99 base::Bind(&SyncBrowserThreadModelWorkerTest::ScheduleWork,
100 factory()->GetWeakPtr())); 100 factory()->GetWeakPtr()));
101 MessageLoop::current()->Run(); 101 MessageLoop::current()->Run();
102 EXPECT_TRUE(did_do_work()); 102 EXPECT_TRUE(did_do_work());
103 } 103 }
104 104
105 } // namespace 105 } // namespace
106 106
107 } // namespace browser_sync 107 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698