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

Side by Side Diff: components/sync/driver/ui_data_type_controller_unittest.cc

Issue 2376123003: [Sync] Move //components/sync to the syncer namespace. (Closed)
Patch Set: Rebase. Created 4 years, 2 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/sync/driver/ui_data_type_controller.h" 5 #include "components/sync/driver/ui_data_type_controller.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
15 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
16 #include "base/tracked_objects.h" 16 #include "base/tracked_objects.h"
17 #include "components/sync/api/fake_syncable_service.h" 17 #include "components/sync/api/fake_syncable_service.h"
18 #include "components/sync/base/model_type.h" 18 #include "components/sync/base/model_type.h"
19 #include "components/sync/driver/data_type_controller_mock.h" 19 #include "components/sync/driver/data_type_controller_mock.h"
20 #include "components/sync/driver/fake_generic_change_processor.h" 20 #include "components/sync/driver/fake_generic_change_processor.h"
21 #include "components/sync/driver/fake_sync_client.h" 21 #include "components/sync/driver/fake_sync_client.h"
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 23
24 using testing::_; 24 using testing::_;
25 using testing::Invoke; 25 using testing::Invoke;
26 using testing::InvokeWithoutArgs; 26 using testing::InvokeWithoutArgs;
27 using testing::Return; 27 using testing::Return;
28 28
29 namespace sync_driver { 29 namespace syncer {
30 namespace { 30 namespace {
31 31
32 class UIDataTypeControllerFake : public UIDataTypeController { 32 class UIDataTypeControllerFake : public UIDataTypeController {
33 public: 33 public:
34 UIDataTypeControllerFake(syncer::ModelType type, 34 UIDataTypeControllerFake(ModelType type,
35 const base::Closure& dump_stack, 35 const base::Closure& dump_stack,
36 SyncClient* sync_client) 36 SyncClient* sync_client)
37 : UIDataTypeController(type, dump_stack, sync_client) {} 37 : UIDataTypeController(type, dump_stack, sync_client) {}
38 38
39 void OnUnrecoverableError(const syncer::SyncError& error) { 39 void OnUnrecoverableError(const SyncError& error) {
40 CreateErrorHandler()->OnUnrecoverableError(error); 40 CreateErrorHandler()->OnUnrecoverableError(error);
41 } 41 }
42 }; 42 };
43 43
44 // TODO(zea): Expand this to make the dtc type paramterizable. This will let us 44 // TODO(zea): Expand this to make the dtc type paramterizable. This will let us
45 // test the basic functionality of all UIDataTypeControllers. We'll need to have 45 // test the basic functionality of all UIDataTypeControllers. We'll need to have
46 // intelligent default values for the methods queried in the dependent services 46 // intelligent default values for the methods queried in the dependent services
47 // (e.g. those queried in StartModels). 47 // (e.g. those queried in StartModels).
48 class SyncUIDataTypeControllerTest : public testing::Test, 48 class SyncUIDataTypeControllerTest : public testing::Test,
49 public FakeSyncClient { 49 public FakeSyncClient {
50 public: 50 public:
51 SyncUIDataTypeControllerTest() 51 SyncUIDataTypeControllerTest()
52 : type_(syncer::PREFERENCES), change_processor_(NULL) {} 52 : type_(PREFERENCES), change_processor_(NULL) {}
53 53
54 // FakeSyncClient overrides. 54 // FakeSyncClient overrides.
55 base::WeakPtr<syncer::SyncableService> GetSyncableServiceForType( 55 base::WeakPtr<SyncableService> GetSyncableServiceForType(
56 syncer::ModelType type) override { 56 ModelType type) override {
57 return syncable_service_.AsWeakPtr(); 57 return syncable_service_.AsWeakPtr();
58 } 58 }
59 59
60 void SetUp() override { 60 void SetUp() override {
61 preference_dtc_ = base::MakeUnique<UIDataTypeControllerFake>( 61 preference_dtc_ = base::MakeUnique<UIDataTypeControllerFake>(
62 type_, base::Closure(), this); 62 type_, base::Closure(), this);
63 SetStartExpectations(); 63 SetStartExpectations();
64 } 64 }
65 65
66 void TearDown() override { 66 void TearDown() override {
(...skipping 18 matching lines...) Expand all
85 preference_dtc_->LoadModels(base::Bind( 85 preference_dtc_->LoadModels(base::Bind(
86 &ModelLoadCallbackMock::Run, base::Unretained(&model_load_callback_))); 86 &ModelLoadCallbackMock::Run, base::Unretained(&model_load_callback_)));
87 preference_dtc_->StartAssociating(base::Bind( 87 preference_dtc_->StartAssociating(base::Bind(
88 &StartCallbackMock::Run, base::Unretained(&start_callback_))); 88 &StartCallbackMock::Run, base::Unretained(&start_callback_)));
89 PumpLoop(); 89 PumpLoop();
90 } 90 }
91 91
92 void PumpLoop() { base::RunLoop().RunUntilIdle(); } 92 void PumpLoop() { base::RunLoop().RunUntilIdle(); }
93 93
94 base::MessageLoop message_loop_; 94 base::MessageLoop message_loop_;
95 const syncer::ModelType type_; 95 const ModelType type_;
96 StartCallbackMock start_callback_; 96 StartCallbackMock start_callback_;
97 ModelLoadCallbackMock model_load_callback_; 97 ModelLoadCallbackMock model_load_callback_;
98 FakeGenericChangeProcessor* change_processor_; 98 FakeGenericChangeProcessor* change_processor_;
99 syncer::FakeSyncableService syncable_service_; 99 FakeSyncableService syncable_service_;
100 std::unique_ptr<UIDataTypeControllerFake> preference_dtc_; 100 std::unique_ptr<UIDataTypeControllerFake> preference_dtc_;
101 }; 101 };
102 102
103 // Start the DTC. Verify that the callback is called with OK, the 103 // Start the DTC. Verify that the callback is called with OK, the
104 // service has been told to start syncing and that the DTC is now in RUNNING 104 // service has been told to start syncing and that the DTC is now in RUNNING
105 // state. 105 // state.
106 TEST_F(SyncUIDataTypeControllerTest, Start) { 106 TEST_F(SyncUIDataTypeControllerTest, Start) {
107 EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _, _)); 107 EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _, _));
108 108
109 EXPECT_EQ(DataTypeController::NOT_RUNNING, preference_dtc_->state()); 109 EXPECT_EQ(DataTypeController::NOT_RUNNING, preference_dtc_->state());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 EXPECT_EQ(DataTypeController::NOT_RUNNING, preference_dtc_->state()); 156 EXPECT_EQ(DataTypeController::NOT_RUNNING, preference_dtc_->state());
157 EXPECT_FALSE(syncable_service_.syncing()); 157 EXPECT_FALSE(syncable_service_.syncing());
158 } 158 }
159 159
160 // Start the DTC, but have the service fail association. Verify the callback 160 // Start the DTC, but have the service fail association. Verify the callback
161 // is called with ASSOCIATION_FAILED, the DTC goes to state DISABLED, and the 161 // is called with ASSOCIATION_FAILED, the DTC goes to state DISABLED, and the
162 // service is not syncing. Then stop the DTC. 162 // service is not syncing. Then stop the DTC.
163 TEST_F(SyncUIDataTypeControllerTest, StartAssociationFailed) { 163 TEST_F(SyncUIDataTypeControllerTest, StartAssociationFailed) {
164 EXPECT_CALL(start_callback_, 164 EXPECT_CALL(start_callback_,
165 Run(DataTypeController::ASSOCIATION_FAILED, _, _)); 165 Run(DataTypeController::ASSOCIATION_FAILED, _, _));
166 syncable_service_.set_merge_data_and_start_syncing_error(syncer::SyncError( 166 syncable_service_.set_merge_data_and_start_syncing_error(
167 FROM_HERE, syncer::SyncError::DATATYPE_ERROR, "Error", type_)); 167 SyncError(FROM_HERE, SyncError::DATATYPE_ERROR, "Error", type_));
168 168
169 EXPECT_EQ(DataTypeController::NOT_RUNNING, preference_dtc_->state()); 169 EXPECT_EQ(DataTypeController::NOT_RUNNING, preference_dtc_->state());
170 EXPECT_FALSE(syncable_service_.syncing()); 170 EXPECT_FALSE(syncable_service_.syncing());
171 Start(); 171 Start();
172 EXPECT_EQ(DataTypeController::DISABLED, preference_dtc_->state()); 172 EXPECT_EQ(DataTypeController::DISABLED, preference_dtc_->state());
173 EXPECT_FALSE(syncable_service_.syncing()); 173 EXPECT_FALSE(syncable_service_.syncing());
174 preference_dtc_->Stop(); 174 preference_dtc_->Stop();
175 EXPECT_EQ(DataTypeController::NOT_RUNNING, preference_dtc_->state()); 175 EXPECT_EQ(DataTypeController::NOT_RUNNING, preference_dtc_->state());
176 EXPECT_FALSE(syncable_service_.syncing()); 176 EXPECT_FALSE(syncable_service_.syncing());
177 } 177 }
(...skipping 19 matching lines...) Expand all
197 TEST_F(SyncUIDataTypeControllerTest, OnSingleDatatypeUnrecoverableError) { 197 TEST_F(SyncUIDataTypeControllerTest, OnSingleDatatypeUnrecoverableError) {
198 EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _, _)); 198 EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _, _));
199 199
200 EXPECT_EQ(DataTypeController::NOT_RUNNING, preference_dtc_->state()); 200 EXPECT_EQ(DataTypeController::NOT_RUNNING, preference_dtc_->state());
201 EXPECT_FALSE(syncable_service_.syncing()); 201 EXPECT_FALSE(syncable_service_.syncing());
202 Start(); 202 Start();
203 EXPECT_TRUE(syncable_service_.syncing()); 203 EXPECT_TRUE(syncable_service_.syncing());
204 204
205 testing::Mock::VerifyAndClearExpectations(&start_callback_); 205 testing::Mock::VerifyAndClearExpectations(&start_callback_);
206 EXPECT_CALL(model_load_callback_, Run(_, _)); 206 EXPECT_CALL(model_load_callback_, Run(_, _));
207 syncer::SyncError error(FROM_HERE, syncer::SyncError::DATATYPE_ERROR, "error", 207 SyncError error(FROM_HERE, SyncError::DATATYPE_ERROR, "error", PREFERENCES);
208 syncer::PREFERENCES);
209 preference_dtc_->OnUnrecoverableError(error); 208 preference_dtc_->OnUnrecoverableError(error);
210 PumpLoop(); 209 PumpLoop();
211 } 210 }
212 211
213 } // namespace 212 } // namespace
214 } // namespace sync_driver 213 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/driver/ui_data_type_controller.cc ('k') | components/sync/driver/ui_model_type_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698