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 23 matching lines...) Expand all Loading... |
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/test_user_share.h" | 37 #include "sync/internal_api/public/test/test_user_share.h" |
38 #include "sync/internal_api/public/write_node.h" | 38 #include "sync/internal_api/public/write_node.h" |
39 #include "sync/internal_api/public/write_transaction.h" | 39 #include "sync/internal_api/public/write_transaction.h" |
40 #include "sync/syncable/mutable_entry.h" // TODO(tim): Remove. Bug 131130. | 40 #include "sync/syncable/mutable_entry.h" // TODO(tim): Remove. Bug 131130. |
41 #include "sync/test/engine/test_id_factory.h" | 41 #include "sync/test/engine/test_id_factory.h" |
42 #include "testing/gmock/include/gmock/gmock.h" | 42 #include "testing/gmock/include/gmock/gmock.h" |
43 #include "testing/gtest/include/gtest/gtest.h" | 43 #include "testing/gtest/include/gtest/gtest.h" |
| 44 #include "sync/test/fake_sync_encryption_handler.h" |
44 | 45 |
45 namespace browser_sync { | 46 namespace browser_sync { |
46 | 47 |
47 using content::BrowserThread; | 48 using content::BrowserThread; |
48 using syncer::BaseNode; | 49 using syncer::BaseNode; |
49 using testing::_; | 50 using testing::_; |
50 using testing::InvokeWithoutArgs; | 51 using testing::InvokeWithoutArgs; |
51 using testing::Mock; | 52 using testing::Mock; |
52 using testing::StrictMock; | 53 using testing::StrictMock; |
53 | 54 |
(...skipping 278 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()->SetNigoriHandler(&fake_encryption_handler_); |
| 354 } |
| 355 |
348 // Load (or re-load) the bookmark model. |load| controls use of the | 356 // Load (or re-load) the bookmark model. |load| controls use of the |
349 // bookmarks file on disk. |save| controls whether the newly loaded | 357 // bookmarks file on disk. |save| controls whether the newly loaded |
350 // bookmark model will write out a bookmark file as it goes. | 358 // bookmark model will write out a bookmark file as it goes. |
351 void LoadBookmarkModel(LoadOption load, SaveOption save) { | 359 void LoadBookmarkModel(LoadOption load, SaveOption save) { |
352 bool delete_bookmarks = load == DELETE_EXISTING_STORAGE; | 360 bool delete_bookmarks = load == DELETE_EXISTING_STORAGE; |
353 profile_.CreateBookmarkModel(delete_bookmarks); | 361 profile_.CreateBookmarkModel(delete_bookmarks); |
354 model_ = BookmarkModelFactory::GetForProfile(&profile_); | 362 model_ = BookmarkModelFactory::GetForProfile(&profile_); |
355 // Wait for the bookmarks model to load. | 363 // Wait for the bookmarks model to load. |
356 profile_.BlockUntilBookmarkModelLoaded(); | 364 profile_.BlockUntilBookmarkModelLoaded(); |
357 // This noticeably speeds up the unit tests that request it. | 365 // 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_; | 560 content::TestBrowserThread file_thread_; |
553 | 561 |
554 TestingProfile profile_; | 562 TestingProfile profile_; |
555 scoped_ptr<TestBookmarkModelAssociator> model_associator_; | 563 scoped_ptr<TestBookmarkModelAssociator> model_associator_; |
556 | 564 |
557 protected: | 565 protected: |
558 BookmarkModel* model_; | 566 BookmarkModel* model_; |
559 syncer::TestUserShare test_user_share_; | 567 syncer::TestUserShare test_user_share_; |
560 scoped_ptr<BookmarkChangeProcessor> change_processor_; | 568 scoped_ptr<BookmarkChangeProcessor> change_processor_; |
561 StrictMock<DataTypeErrorHandlerMock> mock_error_handler_; | 569 StrictMock<DataTypeErrorHandlerMock> mock_error_handler_; |
| 570 syncer::FakeSyncEncryptionHandler fake_encryption_handler_; |
562 }; | 571 }; |
563 | 572 |
564 TEST_F(ProfileSyncServiceBookmarkTest, InitialState) { | 573 TEST_F(ProfileSyncServiceBookmarkTest, InitialState) { |
565 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); | 574 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); |
566 StartSync(); | 575 StartSync(); |
567 | 576 |
568 EXPECT_TRUE(other_bookmarks_id()); | 577 EXPECT_TRUE(other_bookmarks_id()); |
569 EXPECT_TRUE(bookmark_bar_id()); | 578 EXPECT_TRUE(bookmark_bar_id()); |
570 EXPECT_TRUE(mobile_bookmarks_id()); | 579 EXPECT_TRUE(mobile_bookmarks_id()); |
571 | 580 |
(...skipping 888 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1460 TEST_F(ProfileSyncServiceBookmarkTestWithData, | 1469 TEST_F(ProfileSyncServiceBookmarkTestWithData, |
1461 RecoverAfterDeletingSyncDataDirectory) { | 1470 RecoverAfterDeletingSyncDataDirectory) { |
1462 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE); | 1471 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE); |
1463 StartSync(); | 1472 StartSync(); |
1464 | 1473 |
1465 WriteTestDataToBookmarkModel(); | 1474 WriteTestDataToBookmarkModel(); |
1466 | 1475 |
1467 StopSync(); | 1476 StopSync(); |
1468 | 1477 |
1469 // Nuke the sync DB and reload. | 1478 // Nuke the sync DB and reload. |
1470 test_user_share_.TearDown(); | 1479 TearDown(); |
1471 test_user_share_.SetUp(); | 1480 SetUp(); |
1472 | 1481 |
1473 StartSync(); | 1482 StartSync(); |
1474 | 1483 |
1475 // Make sure we're back in sync. In real life, the user would need | 1484 // 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 | 1485 // to reauthenticate before this happens, but in the test, authentication |
1477 // is sidestepped. | 1486 // is sidestepped. |
1478 ExpectBookmarkModelMatchesTestData(); | 1487 ExpectBookmarkModelMatchesTestData(); |
1479 ExpectModelMatch(); | 1488 ExpectModelMatch(); |
1480 } | 1489 } |
1481 | 1490 |
(...skipping 10 matching lines...) Expand all Loading... |
1492 EXPECT_EQ(1, observer.get_started()); | 1501 EXPECT_EQ(1, observer.get_started()); |
1493 EXPECT_EQ(0, observer.get_completed_count_at_started()); | 1502 EXPECT_EQ(0, observer.get_completed_count_at_started()); |
1494 EXPECT_EQ(1, observer.get_completed()); | 1503 EXPECT_EQ(1, observer.get_completed()); |
1495 | 1504 |
1496 model_->RemoveObserver(&observer); | 1505 model_->RemoveObserver(&observer); |
1497 } | 1506 } |
1498 | 1507 |
1499 } // namespace | 1508 } // namespace |
1500 | 1509 |
1501 } // namespace browser_sync | 1510 } // namespace browser_sync |
OLD | NEW |