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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/task.h" | 10 #include "base/task.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 CreateBookmarkSyncComponents(sync_service_, this); | 56 CreateBookmarkSyncComponents(sync_service_, this); |
57 model_associator_.reset(sync_components.model_associator); | 57 model_associator_.reset(sync_components.model_associator); |
58 change_processor_.reset(sync_components.change_processor); | 58 change_processor_.reset(sync_components.change_processor); |
59 } | 59 } |
60 | 60 |
61 // We mock the following methods because their default implementations do | 61 // We mock the following methods because their default implementations do |
62 // nothing, but we still want to make sure they're called appropriately. | 62 // nothing, but we still want to make sure they're called appropriately. |
63 virtual bool StartModels() { | 63 virtual bool StartModels() { |
64 return mock_->StartModels(); | 64 return mock_->StartModels(); |
65 } | 65 } |
66 virtual void CleanupState() { | 66 virtual void CleanUpState() { |
67 mock_->CleanupState(); | 67 mock_->CleanUpState(); |
68 } | 68 } |
69 virtual void RecordUnrecoverableError( | 69 virtual void RecordUnrecoverableError( |
70 const tracked_objects::Location& from_here, | 70 const tracked_objects::Location& from_here, |
71 const std::string& message) { | 71 const std::string& message) { |
72 mock_->RecordUnrecoverableError(from_here, message); | 72 mock_->RecordUnrecoverableError(from_here, message); |
73 } | 73 } |
74 virtual void RecordAssociationTime(base::TimeDelta time) { | 74 virtual void RecordAssociationTime(base::TimeDelta time) { |
75 mock_->RecordAssociationTime(time); | 75 mock_->RecordAssociationTime(time); |
76 } | 76 } |
77 virtual void RecordStartFailure(DataTypeController::StartResult result) { | 77 virtual void RecordStartFailure(DataTypeController::StartResult result) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 WillOnce(Return(true)); | 115 WillOnce(Return(true)); |
116 EXPECT_CALL(*dtc_mock_, RecordAssociationTime(_)); | 116 EXPECT_CALL(*dtc_mock_, RecordAssociationTime(_)); |
117 } | 117 } |
118 | 118 |
119 void SetActivateExpectations(DataTypeController::StartResult result) { | 119 void SetActivateExpectations(DataTypeController::StartResult result) { |
120 EXPECT_CALL(service_, ActivateDataType(_, _)); | 120 EXPECT_CALL(service_, ActivateDataType(_, _)); |
121 EXPECT_CALL(start_callback_, Run(result,_)); | 121 EXPECT_CALL(start_callback_, Run(result,_)); |
122 } | 122 } |
123 | 123 |
124 void SetStopExpectations() { | 124 void SetStopExpectations() { |
125 EXPECT_CALL(*dtc_mock_, CleanupState()); | 125 EXPECT_CALL(*dtc_mock_, CleanUpState()); |
126 EXPECT_CALL(service_, DeactivateDataType(_, _)); | 126 EXPECT_CALL(service_, DeactivateDataType(_, _)); |
127 EXPECT_CALL(*model_associator_, DisassociateModels()); | 127 EXPECT_CALL(*model_associator_, DisassociateModels()); |
128 } | 128 } |
129 | 129 |
130 void SetStartFailExpectations(DataTypeController::StartResult result) { | 130 void SetStartFailExpectations(DataTypeController::StartResult result) { |
131 EXPECT_CALL(*dtc_mock_, CleanupState()); | 131 EXPECT_CALL(*dtc_mock_, CleanUpState()); |
132 EXPECT_CALL(*dtc_mock_, RecordStartFailure(result)); | 132 EXPECT_CALL(*dtc_mock_, RecordStartFailure(result)); |
133 EXPECT_CALL(start_callback_, Run(result,_)); | 133 EXPECT_CALL(start_callback_, Run(result,_)); |
134 } | 134 } |
135 | 135 |
136 MessageLoopForUI message_loop_; | 136 MessageLoopForUI message_loop_; |
137 BrowserThread ui_thread_; | 137 BrowserThread ui_thread_; |
138 scoped_refptr<FrontendDataTypeControllerFake> frontend_dtc_; | 138 scoped_refptr<FrontendDataTypeControllerFake> frontend_dtc_; |
139 scoped_ptr<ProfileSyncFactoryMock> profile_sync_factory_; | 139 scoped_ptr<ProfileSyncFactoryMock> profile_sync_factory_; |
140 scoped_refptr<FrontendDataTypeControllerMock> dtc_mock_; | 140 scoped_refptr<FrontendDataTypeControllerMock> dtc_mock_; |
141 ProfileMock profile_; | 141 ProfileMock profile_; |
(...skipping 20 matching lines...) Expand all Loading... |
162 WillOnce(DoAll(SetArgumentPointee<0>(false), Return(true))); | 162 WillOnce(DoAll(SetArgumentPointee<0>(false), Return(true))); |
163 EXPECT_CALL(*model_associator_, AssociateModels()). | 163 EXPECT_CALL(*model_associator_, AssociateModels()). |
164 WillOnce(Return(true)); | 164 WillOnce(Return(true)); |
165 EXPECT_CALL(*dtc_mock_, RecordAssociationTime(_)); | 165 EXPECT_CALL(*dtc_mock_, RecordAssociationTime(_)); |
166 SetActivateExpectations(DataTypeController::OK_FIRST_RUN); | 166 SetActivateExpectations(DataTypeController::OK_FIRST_RUN); |
167 EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); | 167 EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); |
168 frontend_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); | 168 frontend_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); |
169 EXPECT_EQ(DataTypeController::RUNNING, frontend_dtc_->state()); | 169 EXPECT_EQ(DataTypeController::RUNNING, frontend_dtc_->state()); |
170 } | 170 } |
171 | 171 |
| 172 TEST_F(FrontendDataTypeControllerTest, AbortDuringStartModels) { |
| 173 EXPECT_CALL(*dtc_mock_, StartModels()).WillOnce(Return(false)); |
| 174 SetStartFailExpectations(DataTypeController::ABORTED); |
| 175 EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); |
| 176 frontend_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); |
| 177 EXPECT_EQ(DataTypeController::MODEL_STARTING, frontend_dtc_->state()); |
| 178 frontend_dtc_->Stop(); |
| 179 EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); |
| 180 } |
| 181 |
172 TEST_F(FrontendDataTypeControllerTest, StartAssociationFailed) { | 182 TEST_F(FrontendDataTypeControllerTest, StartAssociationFailed) { |
173 SetStartExpectations(); | 183 SetStartExpectations(); |
174 EXPECT_CALL(*model_associator_, CryptoReadyIfNecessary()). | 184 EXPECT_CALL(*model_associator_, CryptoReadyIfNecessary()). |
175 WillOnce(Return(true)); | 185 WillOnce(Return(true)); |
176 EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). | 186 EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). |
177 WillOnce(DoAll(SetArgumentPointee<0>(true), Return(true))); | 187 WillOnce(DoAll(SetArgumentPointee<0>(true), Return(true))); |
178 EXPECT_CALL(*model_associator_, AssociateModels()). | 188 EXPECT_CALL(*model_associator_, AssociateModels()). |
179 WillOnce(Return(false)); | 189 WillOnce(Return(false)); |
180 EXPECT_CALL(*dtc_mock_, RecordAssociationTime(_)); | 190 EXPECT_CALL(*dtc_mock_, RecordAssociationTime(_)); |
181 SetStartFailExpectations(DataTypeController::ASSOCIATION_FAILED); | 191 SetStartFailExpectations(DataTypeController::ASSOCIATION_FAILED); |
(...skipping 26 matching lines...) Expand all Loading... |
208 EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); | 218 EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); |
209 frontend_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); | 219 frontend_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); |
210 EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); | 220 EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); |
211 } | 221 } |
212 | 222 |
213 TEST_F(FrontendDataTypeControllerTest, Stop) { | 223 TEST_F(FrontendDataTypeControllerTest, Stop) { |
214 SetStartExpectations(); | 224 SetStartExpectations(); |
215 SetAssociateExpectations(); | 225 SetAssociateExpectations(); |
216 SetActivateExpectations(DataTypeController::OK); | 226 SetActivateExpectations(DataTypeController::OK); |
217 SetStopExpectations(); | 227 SetStopExpectations(); |
218 | |
219 EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); | 228 EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); |
220 frontend_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); | 229 frontend_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); |
221 EXPECT_EQ(DataTypeController::RUNNING, frontend_dtc_->state()); | 230 EXPECT_EQ(DataTypeController::RUNNING, frontend_dtc_->state()); |
222 frontend_dtc_->Stop(); | 231 frontend_dtc_->Stop(); |
223 EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); | 232 EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); |
224 } | 233 } |
225 | 234 |
226 TEST_F(FrontendDataTypeControllerTest, OnUnrecoverableError) { | 235 TEST_F(FrontendDataTypeControllerTest, OnUnrecoverableError) { |
227 SetStartExpectations(); | 236 SetStartExpectations(); |
228 SetAssociateExpectations(); | 237 SetAssociateExpectations(); |
229 SetActivateExpectations(DataTypeController::OK); | 238 SetActivateExpectations(DataTypeController::OK); |
230 EXPECT_CALL(*dtc_mock_, RecordUnrecoverableError(_, "Test")); | 239 EXPECT_CALL(*dtc_mock_, RecordUnrecoverableError(_, "Test")); |
231 EXPECT_CALL(service_, OnUnrecoverableError(_,_)). | 240 EXPECT_CALL(service_, OnUnrecoverableError(_,_)). |
232 WillOnce(InvokeWithoutArgs(frontend_dtc_.get(), | 241 WillOnce(InvokeWithoutArgs(frontend_dtc_.get(), |
233 &FrontendDataTypeController::Stop)); | 242 &FrontendDataTypeController::Stop)); |
234 SetStopExpectations(); | 243 SetStopExpectations(); |
235 | |
236 EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); | 244 EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); |
237 frontend_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); | 245 frontend_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); |
238 EXPECT_EQ(DataTypeController::RUNNING, frontend_dtc_->state()); | 246 EXPECT_EQ(DataTypeController::RUNNING, frontend_dtc_->state()); |
239 // This should cause frontend_dtc_->Stop() to be called. | 247 // This should cause frontend_dtc_->Stop() to be called. |
240 frontend_dtc_->OnUnrecoverableError(FROM_HERE, "Test"); | 248 frontend_dtc_->OnUnrecoverableError(FROM_HERE, "Test"); |
241 EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); | 249 EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); |
242 } | 250 } |
OLD | NEW |