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 <stddef.h> | 9 #include <stddef.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 // Load (or re-load) the bookmark model. |load| controls use of the | 460 // Load (or re-load) the bookmark model. |load| controls use of the |
461 // bookmarks file on disk. |save| controls whether the newly loaded | 461 // bookmarks file on disk. |save| controls whether the newly loaded |
462 // bookmark model will write out a bookmark file as it goes. | 462 // bookmark model will write out a bookmark file as it goes. |
463 void LoadBookmarkModel(LoadOption load, SaveOption save) { | 463 void LoadBookmarkModel(LoadOption load, SaveOption save) { |
464 bool delete_bookmarks = load == DELETE_EXISTING_STORAGE; | 464 bool delete_bookmarks = load == DELETE_EXISTING_STORAGE; |
465 model_.reset(); | 465 model_.reset(); |
466 model_ = CreateBookmarkModel(delete_bookmarks); | 466 model_ = CreateBookmarkModel(delete_bookmarks); |
467 // This noticeably speeds up the unit tests that request it. | 467 // This noticeably speeds up the unit tests that request it. |
468 if (save == DONT_SAVE_TO_STORAGE) | 468 if (save == DONT_SAVE_TO_STORAGE) |
469 model_->ClearStore(); | 469 model_->ClearStore(); |
470 base::MessageLoop::current()->RunUntilIdle(); | 470 base::RunLoop().RunUntilIdle(); |
471 } | 471 } |
472 | 472 |
473 int GetSyncBookmarkCount() { | 473 int GetSyncBookmarkCount() { |
474 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 474 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
475 syncer::ReadNode node(&trans); | 475 syncer::ReadNode node(&trans); |
476 if (node.InitTypeRoot(syncer::BOOKMARKS) != BaseNode::INIT_OK) | 476 if (node.InitTypeRoot(syncer::BOOKMARKS) != BaseNode::INIT_OK) |
477 return 0; | 477 return 0; |
478 return node.GetTotalNodeCount(); | 478 return node.GetTotalNodeCount(); |
479 } | 479 } |
480 | 480 |
(...skipping 1958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2439 EXPECT_EQ(expected_ver_it->second, it->second); | 2439 EXPECT_EQ(expected_ver_it->second, it->second); |
2440 } | 2440 } |
2441 } | 2441 } |
2442 | 2442 |
2443 // Test transaction versions of model and nodes are incremented after changes | 2443 // Test transaction versions of model and nodes are incremented after changes |
2444 // are applied. | 2444 // are applied. |
2445 TEST_F(ProfileSyncServiceBookmarkTestWithData, UpdateTransactionVersion) { | 2445 TEST_F(ProfileSyncServiceBookmarkTestWithData, UpdateTransactionVersion) { |
2446 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); | 2446 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); |
2447 StartSync(); | 2447 StartSync(); |
2448 WriteTestDataToBookmarkModel(); | 2448 WriteTestDataToBookmarkModel(); |
2449 base::MessageLoop::current()->RunUntilIdle(); | 2449 base::RunLoop().RunUntilIdle(); |
2450 | 2450 |
2451 BookmarkNodeVersionMap initial_versions; | 2451 BookmarkNodeVersionMap initial_versions; |
2452 | 2452 |
2453 // Verify transaction versions in sync model and bookmark model (saved as | 2453 // Verify transaction versions in sync model and bookmark model (saved as |
2454 // transaction version of root node) are equal after | 2454 // transaction version of root node) are equal after |
2455 // WriteTestDataToBookmarkModel() created bookmarks. | 2455 // WriteTestDataToBookmarkModel() created bookmarks. |
2456 { | 2456 { |
2457 syncer::ReadTransaction trans(FROM_HERE, test_user_share()->user_share()); | 2457 syncer::ReadTransaction trans(FROM_HERE, test_user_share()->user_share()); |
2458 EXPECT_GT(trans.GetModelVersion(syncer::BOOKMARKS), 0); | 2458 EXPECT_GT(trans.GetModelVersion(syncer::BOOKMARKS), 0); |
2459 GetTransactionVersions(model()->root_node(), &initial_versions); | 2459 GetTransactionVersions(model()->root_node(), &initial_versions); |
2460 EXPECT_EQ(trans.GetModelVersion(syncer::BOOKMARKS), | 2460 EXPECT_EQ(trans.GetModelVersion(syncer::BOOKMARKS), |
2461 initial_versions[model()->root_node()->id()]); | 2461 initial_versions[model()->root_node()->id()]); |
2462 } | 2462 } |
2463 ExpectTransactionVersionMatch(model()->bookmark_bar_node(), | 2463 ExpectTransactionVersionMatch(model()->bookmark_bar_node(), |
2464 BookmarkNodeVersionMap()); | 2464 BookmarkNodeVersionMap()); |
2465 ExpectTransactionVersionMatch(model()->other_node(), | 2465 ExpectTransactionVersionMatch(model()->other_node(), |
2466 BookmarkNodeVersionMap()); | 2466 BookmarkNodeVersionMap()); |
2467 ExpectTransactionVersionMatch(model()->mobile_node(), | 2467 ExpectTransactionVersionMatch(model()->mobile_node(), |
2468 BookmarkNodeVersionMap()); | 2468 BookmarkNodeVersionMap()); |
2469 | 2469 |
2470 // Verify model version is incremented and bookmark node versions remain | 2470 // Verify model version is incremented and bookmark node versions remain |
2471 // the same. | 2471 // the same. |
2472 const BookmarkNode* bookmark_bar = model()->bookmark_bar_node(); | 2472 const BookmarkNode* bookmark_bar = model()->bookmark_bar_node(); |
2473 model()->Remove(bookmark_bar->GetChild(0)); | 2473 model()->Remove(bookmark_bar->GetChild(0)); |
2474 base::MessageLoop::current()->RunUntilIdle(); | 2474 base::RunLoop().RunUntilIdle(); |
2475 BookmarkNodeVersionMap new_versions; | 2475 BookmarkNodeVersionMap new_versions; |
2476 GetTransactionVersions(model()->root_node(), &new_versions); | 2476 GetTransactionVersions(model()->root_node(), &new_versions); |
2477 EXPECT_EQ(initial_versions[model()->root_node()->id()] + 1, | 2477 EXPECT_EQ(initial_versions[model()->root_node()->id()] + 1, |
2478 new_versions[model()->root_node()->id()]); | 2478 new_versions[model()->root_node()->id()]); |
2479 ExpectTransactionVersionMatch(model()->bookmark_bar_node(), initial_versions); | 2479 ExpectTransactionVersionMatch(model()->bookmark_bar_node(), initial_versions); |
2480 ExpectTransactionVersionMatch(model()->other_node(), initial_versions); | 2480 ExpectTransactionVersionMatch(model()->other_node(), initial_versions); |
2481 ExpectTransactionVersionMatch(model()->mobile_node(), initial_versions); | 2481 ExpectTransactionVersionMatch(model()->mobile_node(), initial_versions); |
2482 | 2482 |
2483 // Verify model version and version of changed bookmark are incremented and | 2483 // Verify model version and version of changed bookmark are incremented and |
2484 // versions of others remain same. | 2484 // versions of others remain same. |
2485 const BookmarkNode* changed_bookmark = | 2485 const BookmarkNode* changed_bookmark = |
2486 model()->bookmark_bar_node()->GetChild(0); | 2486 model()->bookmark_bar_node()->GetChild(0); |
2487 model()->SetTitle(changed_bookmark, base::ASCIIToUTF16("test")); | 2487 model()->SetTitle(changed_bookmark, base::ASCIIToUTF16("test")); |
2488 base::MessageLoop::current()->RunUntilIdle(); | 2488 base::RunLoop().RunUntilIdle(); |
2489 GetTransactionVersions(model()->root_node(), &new_versions); | 2489 GetTransactionVersions(model()->root_node(), &new_versions); |
2490 EXPECT_EQ(initial_versions[model()->root_node()->id()] + 2, | 2490 EXPECT_EQ(initial_versions[model()->root_node()->id()] + 2, |
2491 new_versions[model()->root_node()->id()]); | 2491 new_versions[model()->root_node()->id()]); |
2492 EXPECT_LT(initial_versions[changed_bookmark->id()], | 2492 EXPECT_LT(initial_versions[changed_bookmark->id()], |
2493 new_versions[changed_bookmark->id()]); | 2493 new_versions[changed_bookmark->id()]); |
2494 initial_versions.erase(changed_bookmark->id()); | 2494 initial_versions.erase(changed_bookmark->id()); |
2495 ExpectTransactionVersionMatch(model()->bookmark_bar_node(), initial_versions); | 2495 ExpectTransactionVersionMatch(model()->bookmark_bar_node(), initial_versions); |
2496 ExpectTransactionVersionMatch(model()->other_node(), initial_versions); | 2496 ExpectTransactionVersionMatch(model()->other_node(), initial_versions); |
2497 ExpectTransactionVersionMatch(model()->mobile_node(), initial_versions); | 2497 ExpectTransactionVersionMatch(model()->mobile_node(), initial_versions); |
2498 } | 2498 } |
2499 | 2499 |
2500 // Test that sync persistence errors are detected and trigger a failed | 2500 // Test that sync persistence errors are detected and trigger a failed |
2501 // association. | 2501 // association. |
2502 TEST_F(ProfileSyncServiceBookmarkTestWithData, PersistenceError) { | 2502 TEST_F(ProfileSyncServiceBookmarkTestWithData, PersistenceError) { |
2503 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); | 2503 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); |
2504 StartSync(); | 2504 StartSync(); |
2505 WriteTestDataToBookmarkModel(); | 2505 WriteTestDataToBookmarkModel(); |
2506 base::MessageLoop::current()->RunUntilIdle(); | 2506 base::RunLoop().RunUntilIdle(); |
2507 | 2507 |
2508 BookmarkNodeVersionMap initial_versions; | 2508 BookmarkNodeVersionMap initial_versions; |
2509 | 2509 |
2510 // Verify transaction versions in sync model and bookmark model (saved as | 2510 // Verify transaction versions in sync model and bookmark model (saved as |
2511 // transaction version of root node) are equal after | 2511 // transaction version of root node) are equal after |
2512 // WriteTestDataToBookmarkModel() created bookmarks. | 2512 // WriteTestDataToBookmarkModel() created bookmarks. |
2513 { | 2513 { |
2514 syncer::ReadTransaction trans(FROM_HERE, test_user_share()->user_share()); | 2514 syncer::ReadTransaction trans(FROM_HERE, test_user_share()->user_share()); |
2515 EXPECT_GT(trans.GetModelVersion(syncer::BOOKMARKS), 0); | 2515 EXPECT_GT(trans.GetModelVersion(syncer::BOOKMARKS), 0); |
2516 GetTransactionVersions(model()->root_node(), &initial_versions); | 2516 GetTransactionVersions(model()->root_node(), &initial_versions); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2585 EXPECT_EQ(syncer::kInvalidId, sync_id); | 2585 EXPECT_EQ(syncer::kInvalidId, sync_id); |
2586 | 2586 |
2587 // Verify that Sync ignores deleting this node. | 2587 // Verify that Sync ignores deleting this node. |
2588 model()->Remove(node); | 2588 model()->Remove(node); |
2589 EXPECT_EQ(sync_bookmark_count, GetSyncBookmarkCount()); | 2589 EXPECT_EQ(sync_bookmark_count, GetSyncBookmarkCount()); |
2590 } | 2590 } |
2591 | 2591 |
2592 } // namespace | 2592 } // namespace |
2593 | 2593 |
2594 } // namespace browser_sync | 2594 } // namespace browser_sync |
OLD | NEW |