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 "chrome/browser/sync/js_sync_manager_observer.h" | 5 #include "chrome/browser/sync/js_sync_manager_observer.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 | 172 |
173 TestDirectorySetterUpper setter_upper; | 173 TestDirectorySetterUpper setter_upper; |
174 sync_api::UserShare share; | 174 sync_api::UserShare share; |
175 setter_upper.SetUp(); | 175 setter_upper.SetUp(); |
176 share.dir_manager.reset(setter_upper.manager()); | 176 share.dir_manager.reset(setter_upper.manager()); |
177 share.name = setter_upper.name(); | 177 share.name = setter_upper.name(); |
178 | 178 |
179 // We don't test with passwords as that requires additional setup. | 179 // We don't test with passwords as that requires additional setup. |
180 | 180 |
181 // Build a list of example ChangeRecords. | 181 // Build a list of example ChangeRecords. |
182 sync_api::SyncManager::ChangeRecord changes[syncable::PASSWORDS]; | 182 sync_api::SyncManager::ChangeRecord changes[syncable::MODEL_TYPE_COUNT]; |
183 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 183 for (int i = syncable::AUTOFILL_PROFILE; |
184 i < syncable::PASSWORDS; ++i) { | 184 i < syncable::MODEL_TYPE_COUNT; ++i) { |
185 changes[i].id = MakeNode(&share, syncable::ModelTypeFromInt(i)); | 185 changes[i].id = MakeNode(&share, syncable::ModelTypeFromInt(i)); |
186 switch (i % 3) { | 186 switch (i % 3) { |
187 case 0: | 187 case 0: |
188 changes[i].action = | 188 changes[i].action = |
189 sync_api::SyncManager::ChangeRecord::ACTION_ADD; | 189 sync_api::SyncManager::ChangeRecord::ACTION_ADD; |
190 break; | 190 break; |
191 case 1: | 191 case 1: |
192 changes[i].action = | 192 changes[i].action = |
193 sync_api::SyncManager::ChangeRecord::ACTION_UPDATE; | 193 sync_api::SyncManager::ChangeRecord::ACTION_UPDATE; |
194 break; | 194 break; |
195 default: | 195 default: |
196 changes[i].action = | 196 changes[i].action = |
197 sync_api::SyncManager::ChangeRecord::ACTION_DELETE; | 197 sync_api::SyncManager::ChangeRecord::ACTION_DELETE; |
198 break; | 198 break; |
199 } | 199 } |
200 { | 200 { |
201 sync_api::ReadTransaction trans(&share); | 201 sync_api::ReadTransaction trans(&share); |
202 sync_api::ReadNode node(&trans); | 202 sync_api::ReadNode node(&trans); |
203 EXPECT_TRUE(node.InitByIdLookup(changes[i].id)); | 203 EXPECT_TRUE(node.InitByIdLookup(changes[i].id)); |
204 changes[i].specifics = node.GetEntry()->Get(syncable::SPECIFICS); | 204 changes[i].specifics = node.GetEntry()->Get(syncable::SPECIFICS); |
205 } | 205 } |
206 } | 206 } |
207 | 207 |
208 // Set expectations for each data type. | 208 // Set expectations for each data type. |
209 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 209 for (int i = syncable::AUTOFILL_PROFILE; |
210 i < syncable::PASSWORDS; ++i) { | 210 i < syncable::MODEL_TYPE_COUNT; ++i) { |
211 const std::string& model_type_str = | 211 const std::string& model_type_str = |
212 syncable::ModelTypeToString(syncable::ModelTypeFromInt(i)); | 212 syncable::ModelTypeToString(syncable::ModelTypeFromInt(i)); |
213 ListValue expected_args; | 213 ListValue expected_args; |
214 expected_args.Append(Value::CreateStringValue(model_type_str)); | 214 expected_args.Append(Value::CreateStringValue(model_type_str)); |
215 ListValue* expected_changes = new ListValue(); | 215 ListValue* expected_changes = new ListValue(); |
216 expected_args.Append(expected_changes); | 216 expected_args.Append(expected_changes); |
217 for (int j = i; j < syncable::PASSWORDS; ++j) { | 217 for (int j = i; j < syncable::MODEL_TYPE_COUNT; ++j) { |
218 sync_api::ReadTransaction trans(&share); | 218 sync_api::ReadTransaction trans(&share); |
219 expected_changes->Append(changes[i].ToValue(&trans)); | 219 expected_changes->Append(changes[j].ToValue(&trans)); |
220 } | 220 } |
221 EXPECT_CALL(mock_router_, | 221 EXPECT_CALL(mock_router_, |
222 RouteJsEvent("onChangesApplied", | 222 RouteJsEvent("onChangesApplied", |
223 HasArgsAsList(expected_args), NULL)); | 223 HasArgsAsList(expected_args), NULL)); |
224 } | 224 } |
225 | 225 |
226 // Fire OnChangesApplied() for each data type. | 226 // Fire OnChangesApplied() for each data type. |
Nicolas Zea
2011/02/18 06:09:52
A comment here about the fact that you're building
akalin
2011/02/18 08:12:29
Added comment, but above the expectations too sinc
| |
227 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 227 for (int i = syncable::AUTOFILL_PROFILE; |
228 i < syncable::PASSWORDS; ++i) { | 228 i < syncable::MODEL_TYPE_COUNT; ++i) { |
229 sync_api::ReadTransaction trans(&share); | 229 sync_api::ReadTransaction trans(&share); |
230 sync_manager_observer_.OnChangesApplied(syncable::ModelTypeFromInt(i), | 230 sync_manager_observer_.OnChangesApplied(syncable::ModelTypeFromInt(i), |
231 &trans, &changes[i], | 231 &trans, &changes[i], |
232 syncable::PASSWORDS - i); | 232 syncable::MODEL_TYPE_COUNT - i); |
233 } | 233 } |
234 | 234 |
235 // |share.dir_manager| does not actually own its value. | 235 // |share.dir_manager| does not actually own its value. |
236 ignore_result(share.dir_manager.release()); | 236 ignore_result(share.dir_manager.release()); |
237 setter_upper.TearDown(); | 237 setter_upper.TearDown(); |
238 } | 238 } |
239 | 239 |
240 } // namespace | 240 } // namespace |
241 } // namespace browser_sync | 241 } // namespace browser_sync |
OLD | NEW |