OLD | NEW |
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 // TODO(akalin): This file is basically just a unit test for | 5 // TODO(akalin): This file is basically just a unit test for |
6 // BookmarkChangeProcessor. Write unit tests for | 6 // BookmarkChangeProcessor. Write unit tests for |
7 // BookmarkModelAssociator separately. | 7 // BookmarkModelAssociator separately. |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <queue> | 10 #include <queue> |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 // bookmark model will write out a bookmark file as it goes. | 286 // bookmark model will write out a bookmark file as it goes. |
287 void LoadBookmarkModel(LoadOption load, SaveOption save) { | 287 void LoadBookmarkModel(LoadOption load, SaveOption save) { |
288 bool delete_bookmarks = load == DELETE_EXISTING_STORAGE; | 288 bool delete_bookmarks = load == DELETE_EXISTING_STORAGE; |
289 profile_.CreateBookmarkModel(delete_bookmarks); | 289 profile_.CreateBookmarkModel(delete_bookmarks); |
290 model_ = BookmarkModelFactory::GetForProfile(&profile_); | 290 model_ = BookmarkModelFactory::GetForProfile(&profile_); |
291 // Wait for the bookmarks model to load. | 291 // Wait for the bookmarks model to load. |
292 profile_.BlockUntilBookmarkModelLoaded(); | 292 profile_.BlockUntilBookmarkModelLoaded(); |
293 // This noticeably speeds up the unit tests that request it. | 293 // This noticeably speeds up the unit tests that request it. |
294 if (save == DONT_SAVE_TO_STORAGE) | 294 if (save == DONT_SAVE_TO_STORAGE) |
295 model_->ClearStore(); | 295 model_->ClearStore(); |
296 message_loop_.RunAllPending(); | 296 message_loop_.RunUntilIdle(); |
297 } | 297 } |
298 | 298 |
299 int GetSyncBookmarkCount() { | 299 int GetSyncBookmarkCount() { |
300 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 300 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
301 syncer::ReadNode node(&trans); | 301 syncer::ReadNode node(&trans); |
302 if (node.InitByTagLookup(syncer::ModelTypeToRootTag(syncer::BOOKMARKS)) != | 302 if (node.InitByTagLookup(syncer::ModelTypeToRootTag(syncer::BOOKMARKS)) != |
303 syncer::BaseNode::INIT_OK) | 303 syncer::BaseNode::INIT_OK) |
304 return 0; | 304 return 0; |
305 return node.GetTotalNodeCount(); | 305 return node.GetTotalNodeCount(); |
306 } | 306 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 local_merge_result_.num_items_deleted()); | 401 local_merge_result_.num_items_deleted()); |
402 EXPECT_EQ(syncer_merge_result_.num_items_after_association(), | 402 EXPECT_EQ(syncer_merge_result_.num_items_after_association(), |
403 syncer_merge_result_.num_items_before_association() + | 403 syncer_merge_result_.num_items_before_association() + |
404 syncer_merge_result_.num_items_added() - | 404 syncer_merge_result_.num_items_added() - |
405 syncer_merge_result_.num_items_deleted()); | 405 syncer_merge_result_.num_items_deleted()); |
406 EXPECT_EQ(model_->root_node()->GetTotalNodeCount(), | 406 EXPECT_EQ(model_->root_node()->GetTotalNodeCount(), |
407 local_merge_result_.num_items_after_association()); | 407 local_merge_result_.num_items_after_association()); |
408 EXPECT_EQ(GetSyncBookmarkCount(), | 408 EXPECT_EQ(GetSyncBookmarkCount(), |
409 syncer_merge_result_.num_items_after_association()); | 409 syncer_merge_result_.num_items_after_association()); |
410 | 410 |
411 MessageLoop::current()->RunAllPending(); | 411 MessageLoop::current()->RunUntilIdle(); |
412 | 412 |
413 // Set up change processor. | 413 // Set up change processor. |
414 change_processor_.reset( | 414 change_processor_.reset( |
415 new BookmarkChangeProcessor(model_associator_.get(), | 415 new BookmarkChangeProcessor(model_associator_.get(), |
416 &mock_error_handler_)); | 416 &mock_error_handler_)); |
417 change_processor_->Start(&profile_, test_user_share_.user_share()); | 417 change_processor_->Start(&profile_, test_user_share_.user_share()); |
418 } | 418 } |
419 | 419 |
420 void StopSync() { | 420 void StopSync() { |
421 change_processor_.reset(); | 421 change_processor_.reset(); |
422 syncer::SyncError error = model_associator_->DisassociateModels(); | 422 syncer::SyncError error = model_associator_->DisassociateModels(); |
423 EXPECT_FALSE(error.IsSet()); | 423 EXPECT_FALSE(error.IsSet()); |
424 model_associator_.reset(); | 424 model_associator_.reset(); |
425 | 425 |
426 message_loop_.RunAllPending(); | 426 message_loop_.RunUntilIdle(); |
427 | 427 |
428 // TODO(akalin): Actually close the database and flush it to disk | 428 // TODO(akalin): Actually close the database and flush it to disk |
429 // (and make StartSync reload from disk). This would require | 429 // (and make StartSync reload from disk). This would require |
430 // refactoring TestUserShare. | 430 // refactoring TestUserShare. |
431 } | 431 } |
432 | 432 |
433 void UnloadBookmarkModel() { | 433 void UnloadBookmarkModel() { |
434 profile_.CreateBookmarkModel(false /* delete_bookmarks */); | 434 profile_.CreateBookmarkModel(false /* delete_bookmarks */); |
435 model_ = NULL; | 435 model_ = NULL; |
436 message_loop_.RunAllPending(); | 436 message_loop_.RunUntilIdle(); |
437 } | 437 } |
438 | 438 |
439 bool InitSyncNodeFromChromeNode(const BookmarkNode* bnode, | 439 bool InitSyncNodeFromChromeNode(const BookmarkNode* bnode, |
440 syncer::BaseNode* sync_node) { | 440 syncer::BaseNode* sync_node) { |
441 return model_associator_->InitSyncNodeFromChromeId(bnode->id(), | 441 return model_associator_->InitSyncNodeFromChromeId(bnode->id(), |
442 sync_node); | 442 sync_node); |
443 } | 443 } |
444 | 444 |
445 void ExpectSyncerNodeMatching(syncer::BaseTransaction* trans, | 445 void ExpectSyncerNodeMatching(syncer::BaseTransaction* trans, |
446 const BookmarkNode* bnode) { | 446 const BookmarkNode* bnode) { |
(...skipping 1296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1743 new_versions[changed_bookmark->id()]); | 1743 new_versions[changed_bookmark->id()]); |
1744 initial_versions.erase(changed_bookmark->id()); | 1744 initial_versions.erase(changed_bookmark->id()); |
1745 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), initial_versions); | 1745 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), initial_versions); |
1746 ExpectTransactionVersionMatch(model_->other_node(), initial_versions); | 1746 ExpectTransactionVersionMatch(model_->other_node(), initial_versions); |
1747 ExpectTransactionVersionMatch(model_->mobile_node(), initial_versions); | 1747 ExpectTransactionVersionMatch(model_->mobile_node(), initial_versions); |
1748 } | 1748 } |
1749 | 1749 |
1750 } // namespace | 1750 } // namespace |
1751 | 1751 |
1752 } // namespace browser_sync | 1752 } // namespace browser_sync |
OLD | NEW |