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

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

Issue 340643002: Use TestBrowserThreadBundle instead of TestBrowserThread in sync code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 6 years, 6 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 | Annotate | Revision Log
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 "chrome/browser/sync/glue/sync_backend_registrar.h" 5 #include "chrome/browser/sync/glue/sync_backend_registrar.h"
6 6
7 #include "chrome/browser/sync/glue/ui_model_worker.h" 7 #include "chrome/browser/sync/glue/ui_model_worker.h"
8 #include "chrome/test/base/testing_profile.h" 8 #include "chrome/test/base/testing_profile.h"
9 #include "components/sync_driver/change_processor_mock.h" 9 #include "components/sync_driver/change_processor_mock.h"
10 #include "content/public/test/test_browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
11 #include "content/public/test/test_browser_thread_bundle.h"
11 #include "sync/internal_api/public/base/model_type.h" 12 #include "sync/internal_api/public/base/model_type.h"
12 #include "sync/internal_api/public/test/test_user_share.h" 13 #include "sync/internal_api/public/test/test_user_share.h"
13 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 namespace browser_sync { 17 namespace browser_sync {
17 18
18 namespace { 19 namespace {
19 20
20 using ::testing::_; 21 using ::testing::_;
(...skipping 29 matching lines...) Expand all
50 test_user_share_.user_share()); 51 test_user_share_.user_share());
51 syncer::ModelSafeRoutingInfo expected_routing_info; 52 syncer::ModelSafeRoutingInfo expected_routing_info;
52 expected_routing_info[AUTOFILL] = syncer::GROUP_DB; 53 expected_routing_info[AUTOFILL] = syncer::GROUP_DB;
53 ExpectRoutingInfo(registrar_.get(), expected_routing_info); 54 ExpectRoutingInfo(registrar_.get(), expected_routing_info);
54 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet(AUTOFILL)); 55 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet(AUTOFILL));
55 TriggerChanges(registrar_.get(), AUTOFILL); 56 TriggerChanges(registrar_.get(), AUTOFILL);
56 done->Signal(); 57 done->Signal();
57 } 58 }
58 59
59 protected: 60 protected:
60 SyncBackendRegistrarTest() : 61 SyncBackendRegistrarTest()
61 sync_thread_(NULL), 62 : sync_thread_(NULL),
62 ui_thread_(BrowserThread::UI, &ui_loop_), 63 thread_bundle_(content::TestBrowserThreadBundle::REAL_DB_THREAD |
63 db_thread_(BrowserThread::DB), 64 content::TestBrowserThreadBundle::REAL_FILE_THREAD |
64 file_thread_(BrowserThread::FILE), 65 content::TestBrowserThreadBundle::REAL_IO_THREAD) {}
65 io_thread_(BrowserThread::IO) {}
66 66
67 virtual ~SyncBackendRegistrarTest() {} 67 virtual ~SyncBackendRegistrarTest() {}
68 68
69 virtual void SetUp() { 69 virtual void SetUp() {
70 db_thread_.Start();
71 file_thread_.Start();
72 io_thread_.Start();
73 test_user_share_.SetUp(); 70 test_user_share_.SetUp();
74 registrar_.reset(new SyncBackendRegistrar("test", &profile_, 71 registrar_.reset(new SyncBackendRegistrar("test", &profile_,
75 scoped_ptr<base::Thread>())); 72 scoped_ptr<base::Thread>()));
76 sync_thread_ = registrar_->sync_thread(); 73 sync_thread_ = registrar_->sync_thread();
77 } 74 }
78 75
79 virtual void TearDown() { 76 virtual void TearDown() {
80 registrar_->RequestWorkerStopOnUIThread(); 77 registrar_->RequestWorkerStopOnUIThread();
81 test_user_share_.TearDown(); 78 test_user_share_.TearDown();
82 sync_thread_->message_loop()->PostTask( 79 sync_thread_->message_loop()->PostTask(
83 FROM_HERE, 80 FROM_HERE,
84 base::Bind(&SyncBackendRegistrar::Shutdown, 81 base::Bind(&SyncBackendRegistrar::Shutdown,
85 base::Unretained(registrar_.release()))); 82 base::Unretained(registrar_.release())));
86 sync_thread_->message_loop()->RunUntilIdle(); 83 sync_thread_->message_loop()->RunUntilIdle();
87 io_thread_.Stop();
88 file_thread_.Stop();
89 db_thread_.Stop();
90 } 84 }
91 85
92 void ExpectRoutingInfo( 86 void ExpectRoutingInfo(
93 SyncBackendRegistrar* registrar, 87 SyncBackendRegistrar* registrar,
94 const syncer::ModelSafeRoutingInfo& expected_routing_info) { 88 const syncer::ModelSafeRoutingInfo& expected_routing_info) {
95 syncer::ModelSafeRoutingInfo routing_info; 89 syncer::ModelSafeRoutingInfo routing_info;
96 registrar->GetModelSafeRoutingInfo(&routing_info); 90 registrar->GetModelSafeRoutingInfo(&routing_info);
97 EXPECT_EQ(expected_routing_info, routing_info); 91 EXPECT_EQ(expected_routing_info, routing_info);
98 } 92 }
99 93
100 void ExpectHasProcessorsForTypes(const SyncBackendRegistrar& registrar, 94 void ExpectHasProcessorsForTypes(const SyncBackendRegistrar& registrar,
101 ModelTypeSet types) { 95 ModelTypeSet types) {
102 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { 96 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) {
103 ModelType model_type = ModelTypeFromInt(i); 97 ModelType model_type = ModelTypeFromInt(i);
104 EXPECT_EQ(types.Has(model_type), 98 EXPECT_EQ(types.Has(model_type),
105 registrar_->IsTypeActivatedForTest(model_type)); 99 registrar_->IsTypeActivatedForTest(model_type));
106 } 100 }
107 } 101 }
108 102
109 base::MessageLoop ui_loop_;
110 syncer::TestUserShare test_user_share_; 103 syncer::TestUserShare test_user_share_;
111 TestingProfile profile_; 104 TestingProfile profile_;
112 scoped_ptr<SyncBackendRegistrar> registrar_; 105 scoped_ptr<SyncBackendRegistrar> registrar_;
113 106
114 base::Thread* sync_thread_; 107 base::Thread* sync_thread_;
115 content::TestBrowserThread ui_thread_; 108 content::TestBrowserThreadBundle thread_bundle_;
116 content::TestBrowserThread db_thread_;
117 content::TestBrowserThread file_thread_;
118 content::TestBrowserThread io_thread_;
119 }; 109 };
120 110
121 TEST_F(SyncBackendRegistrarTest, ConstructorEmpty) { 111 TEST_F(SyncBackendRegistrarTest, ConstructorEmpty) {
122 registrar_->SetInitialTypes(ModelTypeSet()); 112 registrar_->SetInitialTypes(ModelTypeSet());
123 EXPECT_FALSE(registrar_->IsNigoriEnabled()); 113 EXPECT_FALSE(registrar_->IsNigoriEnabled());
124 { 114 {
125 std::vector<scoped_refptr<syncer::ModelSafeWorker> > workers; 115 std::vector<scoped_refptr<syncer::ModelSafeWorker> > workers;
126 registrar_->GetWorkers(&workers); 116 registrar_->GetWorkers(&workers);
127 EXPECT_EQ(4u, workers.size()); 117 EXPECT_EQ(4u, workers.size());
128 } 118 }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 ExpectRoutingInfo(registrar_.get(), syncer::ModelSafeRoutingInfo()); 252 ExpectRoutingInfo(registrar_.get(), syncer::ModelSafeRoutingInfo());
263 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet()); 253 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet());
264 254
265 // Should do nothing. 255 // Should do nothing.
266 TriggerChanges(registrar_.get(), AUTOFILL); 256 TriggerChanges(registrar_.get(), AUTOFILL);
267 } 257 }
268 258
269 } // namespace 259 } // namespace
270 260
271 } // namespace browser_sync 261 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698