| 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/js_sync_manager_observer.h" | 5 #include "chrome/browser/sync/js/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/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 } | 234 } |
| 235 | 235 |
| 236 EXPECT_CALL(mock_js_event_handler_, | 236 EXPECT_CALL(mock_js_event_handler_, |
| 237 HandleJsEvent("onEncryptionComplete", | 237 HandleJsEvent("onEncryptionComplete", |
| 238 HasDetailsAsDictionary(expected_details))); | 238 HasDetailsAsDictionary(expected_details))); |
| 239 | 239 |
| 240 js_sync_manager_observer_.OnEncryptionComplete(encrypted_types); | 240 js_sync_manager_observer_.OnEncryptionComplete(encrypted_types); |
| 241 PumpLoop(); | 241 PumpLoop(); |
| 242 } | 242 } |
| 243 | 243 |
| 244 TEST_F(JsSyncManagerObserverTest, OnMigrationNeededForTypes) { | |
| 245 DictionaryValue expected_details; | |
| 246 ListValue* type_values = new ListValue(); | |
| 247 expected_details.Set("types", type_values); | |
| 248 syncable::ModelTypeSet types; | |
| 249 | |
| 250 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | |
| 251 i < syncable::MODEL_TYPE_COUNT; ++i) { | |
| 252 syncable::ModelType type = syncable::ModelTypeFromInt(i); | |
| 253 types.insert(type); | |
| 254 type_values->Append(Value::CreateStringValue( | |
| 255 syncable::ModelTypeToString(type))); | |
| 256 } | |
| 257 | |
| 258 EXPECT_CALL(mock_js_event_handler_, | |
| 259 HandleJsEvent("onMigrationNeededForTypes", | |
| 260 HasDetailsAsDictionary(expected_details))); | |
| 261 | |
| 262 js_sync_manager_observer_.OnMigrationNeededForTypes(types); | |
| 263 PumpLoop(); | |
| 264 } | |
| 265 | |
| 266 namespace { | 244 namespace { |
| 267 | 245 |
| 268 // Makes a node of the given model type. Returns the id of the | 246 // Makes a node of the given model type. Returns the id of the |
| 269 // newly-created node. | 247 // newly-created node. |
| 270 int64 MakeNode(sync_api::UserShare* share, syncable::ModelType model_type) { | 248 int64 MakeNode(sync_api::UserShare* share, syncable::ModelType model_type) { |
| 271 sync_api::WriteTransaction trans(FROM_HERE, share); | 249 sync_api::WriteTransaction trans(FROM_HERE, share); |
| 272 sync_api::ReadNode root_node(&trans); | 250 sync_api::ReadNode root_node(&trans); |
| 273 root_node.InitByRootLookup(); | 251 root_node.InitByRootLookup(); |
| 274 sync_api::WriteNode node(&trans); | 252 sync_api::WriteNode node(&trans); |
| 275 EXPECT_TRUE(node.InitUniqueByCreation( | 253 EXPECT_TRUE(node.InitUniqueByCreation( |
| 276 model_type, root_node, | 254 model_type, root_node, |
| 277 syncable::ModelTypeToString(model_type))); | 255 syncable::ModelTypeToString(model_type))); |
| 278 node.SetIsFolder(false); | 256 node.SetIsFolder(false); |
| 279 return node.GetId(); | 257 return node.GetId(); |
| 280 } | 258 } |
| 281 | 259 |
| 282 } // namespace | 260 } // namespace |
| 283 | 261 |
| 284 TEST_F(JsSyncManagerObserverTest, OnChangesApplied) { | 262 TEST_F(JsSyncManagerObserverTest, OnChangesApplied) { |
| 285 InSequence dummy; | 263 InSequence dummy; |
| 286 | 264 |
| 287 TestUserShare test_user_share; | 265 TestUserShare test_user_share; |
| 288 test_user_share.SetUp(); | 266 test_user_share.SetUp(); |
| 289 | 267 |
| 290 // We don't test with passwords as that requires additional setup. | 268 // We don't test with passwords as that requires additional setup. |
| 291 | 269 |
| 292 // Build a list of example ChangeRecords. | 270 // Build a list of example ChangeRecords. |
| 293 sync_api::SyncManager::ChangeRecord changes[syncable::MODEL_TYPE_COUNT]; | 271 sync_api::ChangeRecord changes[syncable::MODEL_TYPE_COUNT]; |
| 294 for (int i = syncable::AUTOFILL_PROFILE; | 272 for (int i = syncable::AUTOFILL_PROFILE; |
| 295 i < syncable::MODEL_TYPE_COUNT; ++i) { | 273 i < syncable::MODEL_TYPE_COUNT; ++i) { |
| 296 changes[i].id = | 274 changes[i].id = |
| 297 MakeNode(test_user_share.user_share(), syncable::ModelTypeFromInt(i)); | 275 MakeNode(test_user_share.user_share(), syncable::ModelTypeFromInt(i)); |
| 298 switch (i % 3) { | 276 switch (i % 3) { |
| 299 case 0: | 277 case 0: |
| 300 changes[i].action = | 278 changes[i].action = |
| 301 sync_api::SyncManager::ChangeRecord::ACTION_ADD; | 279 sync_api::ChangeRecord::ACTION_ADD; |
| 302 break; | 280 break; |
| 303 case 1: | 281 case 1: |
| 304 changes[i].action = | 282 changes[i].action = |
| 305 sync_api::SyncManager::ChangeRecord::ACTION_UPDATE; | 283 sync_api::ChangeRecord::ACTION_UPDATE; |
| 306 break; | 284 break; |
| 307 default: | 285 default: |
| 308 changes[i].action = | 286 changes[i].action = |
| 309 sync_api::SyncManager::ChangeRecord::ACTION_DELETE; | 287 sync_api::ChangeRecord::ACTION_DELETE; |
| 310 break; | 288 break; |
| 311 } | 289 } |
| 312 { | 290 { |
| 313 sync_api::ReadTransaction trans(FROM_HERE, test_user_share.user_share()); | 291 sync_api::ReadTransaction trans(FROM_HERE, test_user_share.user_share()); |
| 314 sync_api::ReadNode node(&trans); | 292 sync_api::ReadNode node(&trans); |
| 315 EXPECT_TRUE(node.InitByIdLookup(changes[i].id)); | 293 EXPECT_TRUE(node.InitByIdLookup(changes[i].id)); |
| 316 changes[i].specifics = node.GetEntry()->Get(syncable::SPECIFICS); | 294 changes[i].specifics = node.GetEntry()->Get(syncable::SPECIFICS); |
| 317 } | 295 } |
| 318 } | 296 } |
| 319 | 297 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 336 } | 314 } |
| 337 EXPECT_CALL(mock_js_event_handler_, | 315 EXPECT_CALL(mock_js_event_handler_, |
| 338 HandleJsEvent("onChangesApplied", | 316 HandleJsEvent("onChangesApplied", |
| 339 HasDetailsAsDictionary(expected_details))); | 317 HasDetailsAsDictionary(expected_details))); |
| 340 } | 318 } |
| 341 | 319 |
| 342 // Fire OnChangesApplied() for each data type. | 320 // Fire OnChangesApplied() for each data type. |
| 343 for (int i = syncable::AUTOFILL_PROFILE; | 321 for (int i = syncable::AUTOFILL_PROFILE; |
| 344 i < syncable::MODEL_TYPE_COUNT; ++i) { | 322 i < syncable::MODEL_TYPE_COUNT; ++i) { |
| 345 sync_api::ReadTransaction trans(FROM_HERE, test_user_share.user_share()); | 323 sync_api::ReadTransaction trans(FROM_HERE, test_user_share.user_share()); |
| 346 js_sync_manager_observer_.OnChangesApplied(syncable::ModelTypeFromInt(i), | 324 sync_api::ChangeRecordList |
| 347 &trans, &changes[i], | 325 local_changes(changes + i, changes + arraysize(changes)); |
| 348 syncable::MODEL_TYPE_COUNT - i); | 326 js_sync_manager_observer_.OnChangesApplied( |
| 327 syncable::ModelTypeFromInt(i), |
| 328 &trans, |
| 329 sync_api::ImmutableChangeRecordList(&local_changes)); |
| 349 } | 330 } |
| 350 | 331 |
| 351 test_user_share.TearDown(); | 332 test_user_share.TearDown(); |
| 352 PumpLoop(); | 333 PumpLoop(); |
| 353 } | 334 } |
| 354 | 335 |
| 355 } // namespace | 336 } // namespace |
| 356 } // namespace browser_sync | 337 } // namespace browser_sync |
| OLD | NEW |