| 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 <stack> | 9 #include <stack> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "chrome/browser/sync/glue/bookmark_model_associator.h" | 27 #include "chrome/browser/sync/glue/bookmark_model_associator.h" |
| 28 #include "chrome/browser/sync/glue/data_type_error_handler.h" | 28 #include "chrome/browser/sync/glue/data_type_error_handler.h" |
| 29 #include "chrome/browser/sync/glue/data_type_error_handler_mock.h" | 29 #include "chrome/browser/sync/glue/data_type_error_handler_mock.h" |
| 30 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 31 #include "chrome/test/base/testing_profile.h" | 31 #include "chrome/test/base/testing_profile.h" |
| 32 #include "content/public/test/test_browser_thread.h" | 32 #include "content/public/test/test_browser_thread.h" |
| 33 #include "sync/api/sync_error.h" | 33 #include "sync/api/sync_error.h" |
| 34 #include "sync/internal_api/public/change_record.h" | 34 #include "sync/internal_api/public/change_record.h" |
| 35 #include "sync/internal_api/public/read_node.h" | 35 #include "sync/internal_api/public/read_node.h" |
| 36 #include "sync/internal_api/public/read_transaction.h" | 36 #include "sync/internal_api/public/read_transaction.h" |
| 37 #include "sync/internal_api/public/test/fake_sync_encryption_handler.h" |
| 37 #include "sync/internal_api/public/test/test_user_share.h" | 38 #include "sync/internal_api/public/test/test_user_share.h" |
| 38 #include "sync/internal_api/public/write_node.h" | 39 #include "sync/internal_api/public/write_node.h" |
| 39 #include "sync/internal_api/public/write_transaction.h" | 40 #include "sync/internal_api/public/write_transaction.h" |
| 40 #include "sync/syncable/mutable_entry.h" // TODO(tim): Remove. Bug 131130. | 41 #include "sync/syncable/mutable_entry.h" // TODO(tim): Remove. Bug 131130. |
| 41 #include "sync/test/engine/test_id_factory.h" | 42 #include "sync/test/engine/test_id_factory.h" |
| 42 #include "testing/gmock/include/gmock/gmock.h" | 43 #include "testing/gmock/include/gmock/gmock.h" |
| 43 #include "testing/gtest/include/gtest/gtest.h" | 44 #include "testing/gtest/include/gtest/gtest.h" |
| 44 | 45 |
| 45 namespace browser_sync { | 46 namespace browser_sync { |
| 46 | 47 |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 model_(NULL) { | 333 model_(NULL) { |
| 333 } | 334 } |
| 334 | 335 |
| 335 virtual ~ProfileSyncServiceBookmarkTest() { | 336 virtual ~ProfileSyncServiceBookmarkTest() { |
| 336 StopSync(); | 337 StopSync(); |
| 337 UnloadBookmarkModel(); | 338 UnloadBookmarkModel(); |
| 338 } | 339 } |
| 339 | 340 |
| 340 virtual void SetUp() { | 341 virtual void SetUp() { |
| 341 test_user_share_.SetUp(); | 342 test_user_share_.SetUp(); |
| 343 SetUpEncryption(); |
| 342 } | 344 } |
| 343 | 345 |
| 344 virtual void TearDown() { | 346 virtual void TearDown() { |
| 345 test_user_share_.TearDown(); | 347 test_user_share_.TearDown(); |
| 346 } | 348 } |
| 347 | 349 |
| 350 void SetUpEncryption() { |
| 351 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 352 fake_encryption_handler_.set_cryptographer(trans.GetCryptographer()); |
| 353 trans.GetCryptographer()->SetSyncEncryptionHandlerDelegate( |
| 354 &fake_encryption_handler_); |
| 355 } |
| 356 |
| 348 // Load (or re-load) the bookmark model. |load| controls use of the | 357 // Load (or re-load) the bookmark model. |load| controls use of the |
| 349 // bookmarks file on disk. |save| controls whether the newly loaded | 358 // bookmarks file on disk. |save| controls whether the newly loaded |
| 350 // bookmark model will write out a bookmark file as it goes. | 359 // bookmark model will write out a bookmark file as it goes. |
| 351 void LoadBookmarkModel(LoadOption load, SaveOption save) { | 360 void LoadBookmarkModel(LoadOption load, SaveOption save) { |
| 352 bool delete_bookmarks = load == DELETE_EXISTING_STORAGE; | 361 bool delete_bookmarks = load == DELETE_EXISTING_STORAGE; |
| 353 profile_.CreateBookmarkModel(delete_bookmarks); | 362 profile_.CreateBookmarkModel(delete_bookmarks); |
| 354 model_ = BookmarkModelFactory::GetForProfile(&profile_); | 363 model_ = BookmarkModelFactory::GetForProfile(&profile_); |
| 355 // Wait for the bookmarks model to load. | 364 // Wait for the bookmarks model to load. |
| 356 profile_.BlockUntilBookmarkModelLoaded(); | 365 profile_.BlockUntilBookmarkModelLoaded(); |
| 357 // This noticeably speeds up the unit tests that request it. | 366 // This noticeably speeds up the unit tests that request it. |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 content::TestBrowserThread file_thread_; | 561 content::TestBrowserThread file_thread_; |
| 553 | 562 |
| 554 TestingProfile profile_; | 563 TestingProfile profile_; |
| 555 scoped_ptr<TestBookmarkModelAssociator> model_associator_; | 564 scoped_ptr<TestBookmarkModelAssociator> model_associator_; |
| 556 | 565 |
| 557 protected: | 566 protected: |
| 558 BookmarkModel* model_; | 567 BookmarkModel* model_; |
| 559 syncer::TestUserShare test_user_share_; | 568 syncer::TestUserShare test_user_share_; |
| 560 scoped_ptr<BookmarkChangeProcessor> change_processor_; | 569 scoped_ptr<BookmarkChangeProcessor> change_processor_; |
| 561 StrictMock<DataTypeErrorHandlerMock> mock_error_handler_; | 570 StrictMock<DataTypeErrorHandlerMock> mock_error_handler_; |
| 571 syncer::FakeSyncEncryptionHandler fake_encryption_handler_; |
| 562 }; | 572 }; |
| 563 | 573 |
| 564 TEST_F(ProfileSyncServiceBookmarkTest, InitialState) { | 574 TEST_F(ProfileSyncServiceBookmarkTest, InitialState) { |
| 565 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); | 575 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); |
| 566 StartSync(); | 576 StartSync(); |
| 567 | 577 |
| 568 EXPECT_TRUE(other_bookmarks_id()); | 578 EXPECT_TRUE(other_bookmarks_id()); |
| 569 EXPECT_TRUE(bookmark_bar_id()); | 579 EXPECT_TRUE(bookmark_bar_id()); |
| 570 EXPECT_TRUE(mobile_bookmarks_id()); | 580 EXPECT_TRUE(mobile_bookmarks_id()); |
| 571 | 581 |
| (...skipping 888 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1460 TEST_F(ProfileSyncServiceBookmarkTestWithData, | 1470 TEST_F(ProfileSyncServiceBookmarkTestWithData, |
| 1461 RecoverAfterDeletingSyncDataDirectory) { | 1471 RecoverAfterDeletingSyncDataDirectory) { |
| 1462 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE); | 1472 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE); |
| 1463 StartSync(); | 1473 StartSync(); |
| 1464 | 1474 |
| 1465 WriteTestDataToBookmarkModel(); | 1475 WriteTestDataToBookmarkModel(); |
| 1466 | 1476 |
| 1467 StopSync(); | 1477 StopSync(); |
| 1468 | 1478 |
| 1469 // Nuke the sync DB and reload. | 1479 // Nuke the sync DB and reload. |
| 1470 test_user_share_.TearDown(); | 1480 TearDown(); |
| 1471 test_user_share_.SetUp(); | 1481 SetUp(); |
| 1472 | 1482 |
| 1473 StartSync(); | 1483 StartSync(); |
| 1474 | 1484 |
| 1475 // Make sure we're back in sync. In real life, the user would need | 1485 // Make sure we're back in sync. In real life, the user would need |
| 1476 // to reauthenticate before this happens, but in the test, authentication | 1486 // to reauthenticate before this happens, but in the test, authentication |
| 1477 // is sidestepped. | 1487 // is sidestepped. |
| 1478 ExpectBookmarkModelMatchesTestData(); | 1488 ExpectBookmarkModelMatchesTestData(); |
| 1479 ExpectModelMatch(); | 1489 ExpectModelMatch(); |
| 1480 } | 1490 } |
| 1481 | 1491 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1492 EXPECT_EQ(1, observer.get_started()); | 1502 EXPECT_EQ(1, observer.get_started()); |
| 1493 EXPECT_EQ(0, observer.get_completed_count_at_started()); | 1503 EXPECT_EQ(0, observer.get_completed_count_at_started()); |
| 1494 EXPECT_EQ(1, observer.get_completed()); | 1504 EXPECT_EQ(1, observer.get_completed()); |
| 1495 | 1505 |
| 1496 model_->RemoveObserver(&observer); | 1506 model_->RemoveObserver(&observer); |
| 1497 } | 1507 } |
| 1498 | 1508 |
| 1499 } // namespace | 1509 } // namespace |
| 1500 | 1510 |
| 1501 } // namespace browser_sync | 1511 } // namespace browser_sync |
| OLD | NEW |