| 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 #include "chrome/browser/sync/glue/sync_backend_host.h" | 5 #include "chrome/browser/sync/glue/sync_backend_host.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 | 8 |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
| 13 #include "base/test/test_timeouts.h" | 13 #include "base/test/test_timeouts.h" |
| 14 #include "chrome/browser/sync/invalidations/invalidator_storage.h" | 14 #include "chrome/browser/sync/invalidations/invalidator_storage.h" |
| 15 #include "chrome/browser/sync/sync_prefs.h" | 15 #include "chrome/browser/sync/sync_prefs.h" |
| 16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 17 #include "content/public/test/test_browser_thread.h" | 17 #include "content/public/test/test_browser_thread.h" |
| 18 #include "google/cacheinvalidation/include/types.h" | 18 #include "google/cacheinvalidation/include/types.h" |
| 19 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
| 20 #include "net/url_request/test_url_fetcher_factory.h" | 20 #include "net/url_request/test_url_fetcher_factory.h" |
| 21 #include "sync/internal_api/public/base/model_type.h" | 21 #include "sync/internal_api/public/base/model_type.h" |
| 22 #include "sync/internal_api/public/engine/model_safe_worker.h" | 22 #include "sync/internal_api/public/engine/model_safe_worker.h" |
| 23 #include "sync/internal_api/public/sync_manager_factory.h" | 23 #include "sync/internal_api/public/sync_manager_factory.h" |
| 24 #include "sync/internal_api/public/test/fake_sync_manager.h" | 24 #include "sync/internal_api/public/test/fake_sync_manager.h" |
| 25 #include "sync/internal_api/public/util/experiments.h" | 25 #include "sync/internal_api/public/util/experiments.h" |
| 26 #include "sync/notifier/mock_sync_notifier_observer.h" | 26 #include "sync/notifier/mock_sync_notifier_observer.h" |
| 27 #include "sync/notifier/notifications_disabled_reason.h" | 27 #include "sync/notifier/notifications_disabled_reason.h" |
| 28 #include "sync/notifier/object_id_state_map_test_util.h" |
| 28 #include "sync/protocol/encryption.pb.h" | 29 #include "sync/protocol/encryption.pb.h" |
| 29 #include "sync/protocol/sync_protocol_error.h" | 30 #include "sync/protocol/sync_protocol_error.h" |
| 30 #include "sync/util/test_unrecoverable_error_handler.h" | 31 #include "sync/util/test_unrecoverable_error_handler.h" |
| 31 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 33 | 34 |
| 34 using content::BrowserThread; | 35 using content::BrowserThread; |
| 35 using syncer::FakeSyncManager; | 36 using syncer::FakeSyncManager; |
| 36 using syncer::SyncManager; | 37 using syncer::SyncManager; |
| 37 using ::testing::InvokeWithoutArgs; | 38 using ::testing::InvokeWithoutArgs; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 55 } | 56 } |
| 56 | 57 |
| 57 class MockSyncFrontend : public SyncFrontend { | 58 class MockSyncFrontend : public SyncFrontend { |
| 58 public: | 59 public: |
| 59 virtual ~MockSyncFrontend() {} | 60 virtual ~MockSyncFrontend() {} |
| 60 | 61 |
| 61 MOCK_METHOD0(OnNotificationsEnabled, void()); | 62 MOCK_METHOD0(OnNotificationsEnabled, void()); |
| 62 MOCK_METHOD1(OnNotificationsDisabled, | 63 MOCK_METHOD1(OnNotificationsDisabled, |
| 63 void(syncer::NotificationsDisabledReason)); | 64 void(syncer::NotificationsDisabledReason)); |
| 64 MOCK_METHOD2(OnIncomingNotification, | 65 MOCK_METHOD2(OnIncomingNotification, |
| 65 void(const syncer::ObjectIdPayloadMap&, | 66 void(const syncer::ObjectIdStateMap&, |
| 66 syncer::IncomingNotificationSource)); | 67 syncer::IncomingNotificationSource)); |
| 67 MOCK_METHOD2(OnBackendInitialized, | 68 MOCK_METHOD2(OnBackendInitialized, |
| 68 void(const syncer::WeakHandle<syncer::JsBackend>&, bool)); | 69 void(const syncer::WeakHandle<syncer::JsBackend>&, bool)); |
| 69 MOCK_METHOD0(OnSyncCycleCompleted, void()); | 70 MOCK_METHOD0(OnSyncCycleCompleted, void()); |
| 70 MOCK_METHOD1(OnConnectionStatusChange, | 71 MOCK_METHOD1(OnConnectionStatusChange, |
| 71 void(syncer::ConnectionStatus status)); | 72 void(syncer::ConnectionStatus status)); |
| 72 MOCK_METHOD0(OnStopSyncingPermanently, void()); | 73 MOCK_METHOD0(OnStopSyncingPermanently, void()); |
| 73 MOCK_METHOD0(OnClearServerDataSucceeded, void()); | 74 MOCK_METHOD0(OnClearServerDataSucceeded, void()); |
| 74 MOCK_METHOD0(OnClearServerDataFailed, void()); | 75 MOCK_METHOD0(OnClearServerDataFailed, void()); |
| 75 MOCK_METHOD2(OnPassphraseRequired, | 76 MOCK_METHOD2(OnPassphraseRequired, |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 } | 565 } |
| 565 | 566 |
| 566 // Register for some IDs and trigger an invalidation. This should | 567 // Register for some IDs and trigger an invalidation. This should |
| 567 // propagate all the way to the frontend. | 568 // propagate all the way to the frontend. |
| 568 TEST_F(SyncBackendHostTest, Invalidate) { | 569 TEST_F(SyncBackendHostTest, Invalidate) { |
| 569 InitializeBackend(); | 570 InitializeBackend(); |
| 570 | 571 |
| 571 syncer::ObjectIdSet ids; | 572 syncer::ObjectIdSet ids; |
| 572 ids.insert(invalidation::ObjectId(1, "id1")); | 573 ids.insert(invalidation::ObjectId(1, "id1")); |
| 573 ids.insert(invalidation::ObjectId(2, "id2")); | 574 ids.insert(invalidation::ObjectId(2, "id2")); |
| 574 const syncer::ObjectIdPayloadMap& id_payloads = | 575 const syncer::ObjectIdStateMap& id_state_map = |
| 575 syncer::ObjectIdSetToPayloadMap(ids, "payload"); | 576 syncer::ObjectIdSetToStateMap(ids, "payload"); |
| 576 | 577 |
| 577 EXPECT_CALL( | 578 EXPECT_CALL( |
| 578 mock_frontend_, | 579 mock_frontend_, |
| 579 OnIncomingNotification(id_payloads, syncer::REMOTE_NOTIFICATION)) | 580 OnIncomingNotification(id_state_map, syncer::REMOTE_NOTIFICATION)) |
| 580 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); | 581 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); |
| 581 | 582 |
| 582 backend_->UpdateRegisteredInvalidationIds(ids); | 583 backend_->UpdateRegisteredInvalidationIds(ids); |
| 583 fake_manager_->Invalidate(id_payloads, syncer::REMOTE_NOTIFICATION); | 584 fake_manager_->Invalidate(id_state_map, syncer::REMOTE_NOTIFICATION); |
| 584 ui_loop_.PostDelayedTask( | 585 ui_loop_.PostDelayedTask( |
| 585 FROM_HERE, ui_loop_.QuitClosure(), TestTimeouts::action_timeout()); | 586 FROM_HERE, ui_loop_.QuitClosure(), TestTimeouts::action_timeout()); |
| 586 ui_loop_.Run(); | 587 ui_loop_.Run(); |
| 587 } | 588 } |
| 588 | 589 |
| 589 // Register for some IDs and turn on notifications. This should | 590 // Register for some IDs and turn on notifications. This should |
| 590 // propagate all the way to the frontend. | 591 // propagate all the way to the frontend. |
| 591 TEST_F(SyncBackendHostTest, EnableNotifications) { | 592 TEST_F(SyncBackendHostTest, EnableNotifications) { |
| 592 InitializeBackend(); | 593 InitializeBackend(); |
| 593 | 594 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 | 630 |
| 630 syncer::ObjectIdSet ids; | 631 syncer::ObjectIdSet ids; |
| 631 ids.insert(invalidation::ObjectId(5, "id5")); | 632 ids.insert(invalidation::ObjectId(5, "id5")); |
| 632 backend_->UpdateRegisteredInvalidationIds(ids); | 633 backend_->UpdateRegisteredInvalidationIds(ids); |
| 633 | 634 |
| 634 backend_->StopSyncingForShutdown(); | 635 backend_->StopSyncingForShutdown(); |
| 635 | 636 |
| 636 // Should not trigger anything. | 637 // Should not trigger anything. |
| 637 fake_manager_->DisableNotifications(syncer::TRANSIENT_NOTIFICATION_ERROR); | 638 fake_manager_->DisableNotifications(syncer::TRANSIENT_NOTIFICATION_ERROR); |
| 638 fake_manager_->EnableNotifications(); | 639 fake_manager_->EnableNotifications(); |
| 639 const syncer::ObjectIdPayloadMap& id_payloads = | 640 const syncer::ObjectIdStateMap& id_state_map = |
| 640 syncer::ObjectIdSetToPayloadMap(ids, "payload"); | 641 syncer::ObjectIdSetToStateMap(ids, "payload"); |
| 641 fake_manager_->Invalidate(id_payloads, syncer::REMOTE_NOTIFICATION); | 642 fake_manager_->Invalidate(id_state_map, syncer::REMOTE_NOTIFICATION); |
| 642 | 643 |
| 643 // Make sure the above calls take effect before we continue. | 644 // Make sure the above calls take effect before we continue. |
| 644 fake_manager_->WaitForSyncThread(); | 645 fake_manager_->WaitForSyncThread(); |
| 645 | 646 |
| 646 backend_->Shutdown(false); | 647 backend_->Shutdown(false); |
| 647 backend_.reset(); | 648 backend_.reset(); |
| 648 | 649 |
| 649 TearDown(); | 650 TearDown(); |
| 650 SetUp(); | 651 SetUp(); |
| 651 } | 652 } |
| 652 | 653 |
| 653 } // namespace | 654 } // namespace |
| 654 | 655 |
| 655 } // namespace browser_sync | 656 } // namespace browser_sync |
| OLD | NEW |