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/notifications_disabled_reason.h" | 26 #include "sync/notifier/invalidator_state.h" |
27 #include "sync/notifier/object_id_state_map_test_util.h" | 27 #include "sync/notifier/object_id_state_map_test_util.h" |
28 #include "sync/protocol/encryption.pb.h" | 28 #include "sync/protocol/encryption.pb.h" |
29 #include "sync/protocol/sync_protocol_error.h" | 29 #include "sync/protocol/sync_protocol_error.h" |
30 #include "sync/util/test_unrecoverable_error_handler.h" | 30 #include "sync/util/test_unrecoverable_error_handler.h" |
31 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
32 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
33 | 33 |
34 using content::BrowserThread; | 34 using content::BrowserThread; |
35 using syncer::FakeSyncManager; | 35 using syncer::FakeSyncManager; |
36 using syncer::SyncManager; | 36 using syncer::SyncManager; |
(...skipping 14 matching lines...) Expand all Loading... |
51 } | 51 } |
52 | 52 |
53 static void QuitMessageLoop() { | 53 static void QuitMessageLoop() { |
54 MessageLoop::current()->Quit(); | 54 MessageLoop::current()->Quit(); |
55 } | 55 } |
56 | 56 |
57 class MockSyncFrontend : public SyncFrontend { | 57 class MockSyncFrontend : public SyncFrontend { |
58 public: | 58 public: |
59 virtual ~MockSyncFrontend() {} | 59 virtual ~MockSyncFrontend() {} |
60 | 60 |
61 MOCK_METHOD0(OnNotificationsEnabled, void()); | 61 MOCK_METHOD1(OnInvalidatorStateChange, |
62 MOCK_METHOD1(OnNotificationsDisabled, | 62 void(syncer::InvalidatorState)); |
63 void(syncer::NotificationsDisabledReason)); | 63 MOCK_METHOD2(OnIncomingInvalidation, |
64 MOCK_METHOD2(OnIncomingNotification, | |
65 void(const syncer::ObjectIdStateMap&, | 64 void(const syncer::ObjectIdStateMap&, |
66 syncer::IncomingNotificationSource)); | 65 syncer::IncomingInvalidationSource)); |
67 MOCK_METHOD2(OnBackendInitialized, | 66 MOCK_METHOD2(OnBackendInitialized, |
68 void(const syncer::WeakHandle<syncer::JsBackend>&, bool)); | 67 void(const syncer::WeakHandle<syncer::JsBackend>&, bool)); |
69 MOCK_METHOD0(OnSyncCycleCompleted, void()); | 68 MOCK_METHOD0(OnSyncCycleCompleted, void()); |
70 MOCK_METHOD1(OnConnectionStatusChange, | 69 MOCK_METHOD1(OnConnectionStatusChange, |
71 void(syncer::ConnectionStatus status)); | 70 void(syncer::ConnectionStatus status)); |
72 MOCK_METHOD0(OnStopSyncingPermanently, void()); | 71 MOCK_METHOD0(OnStopSyncingPermanently, void()); |
73 MOCK_METHOD0(OnClearServerDataSucceeded, void()); | 72 MOCK_METHOD0(OnClearServerDataSucceeded, void()); |
74 MOCK_METHOD0(OnClearServerDataFailed, void()); | 73 MOCK_METHOD0(OnClearServerDataFailed, void()); |
75 MOCK_METHOD2(OnPassphraseRequired, | 74 MOCK_METHOD2(OnPassphraseRequired, |
76 void(syncer::PassphraseRequiredReason, | 75 void(syncer::PassphraseRequiredReason, |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 InitializeBackend(); | 568 InitializeBackend(); |
570 | 569 |
571 syncer::ObjectIdSet ids; | 570 syncer::ObjectIdSet ids; |
572 ids.insert(invalidation::ObjectId(1, "id1")); | 571 ids.insert(invalidation::ObjectId(1, "id1")); |
573 ids.insert(invalidation::ObjectId(2, "id2")); | 572 ids.insert(invalidation::ObjectId(2, "id2")); |
574 const syncer::ObjectIdStateMap& id_state_map = | 573 const syncer::ObjectIdStateMap& id_state_map = |
575 syncer::ObjectIdSetToStateMap(ids, "payload"); | 574 syncer::ObjectIdSetToStateMap(ids, "payload"); |
576 | 575 |
577 EXPECT_CALL( | 576 EXPECT_CALL( |
578 mock_frontend_, | 577 mock_frontend_, |
579 OnIncomingNotification(id_state_map, syncer::REMOTE_NOTIFICATION)) | 578 OnIncomingInvalidation(id_state_map, syncer::REMOTE_INVALIDATION)) |
580 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); | 579 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); |
581 | 580 |
582 backend_->UpdateRegisteredInvalidationIds(ids); | 581 backend_->UpdateRegisteredInvalidationIds(ids); |
583 fake_manager_->Invalidate(id_state_map, syncer::REMOTE_NOTIFICATION); | 582 fake_manager_->Invalidate(id_state_map, syncer::REMOTE_INVALIDATION); |
584 ui_loop_.PostDelayedTask( | 583 ui_loop_.PostDelayedTask( |
585 FROM_HERE, ui_loop_.QuitClosure(), TestTimeouts::action_timeout()); | 584 FROM_HERE, ui_loop_.QuitClosure(), TestTimeouts::action_timeout()); |
586 ui_loop_.Run(); | 585 ui_loop_.Run(); |
587 } | 586 } |
588 | 587 |
589 // Register for some IDs and turn on notifications. This should | 588 // Register for some IDs and update the invalidator state. This |
590 // propagate all the way to the frontend. | 589 // should propagate all the way to the frontend. |
591 TEST_F(SyncBackendHostTest, EnableNotifications) { | 590 TEST_F(SyncBackendHostTest, UpdateInvalidatorState) { |
592 InitializeBackend(); | 591 InitializeBackend(); |
593 | 592 |
594 EXPECT_CALL(mock_frontend_, OnNotificationsEnabled()) | 593 EXPECT_CALL(mock_frontend_, |
| 594 OnInvalidatorStateChange(syncer::INVALIDATIONS_ENABLED)) |
595 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); | 595 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); |
596 | 596 |
597 syncer::ObjectIdSet ids; | 597 syncer::ObjectIdSet ids; |
598 ids.insert(invalidation::ObjectId(3, "id3")); | 598 ids.insert(invalidation::ObjectId(3, "id3")); |
599 backend_->UpdateRegisteredInvalidationIds(ids); | 599 backend_->UpdateRegisteredInvalidationIds(ids); |
600 fake_manager_->EnableNotifications(); | 600 fake_manager_->UpdateInvalidatorState(syncer::INVALIDATIONS_ENABLED); |
601 ui_loop_.PostDelayedTask( | 601 ui_loop_.PostDelayedTask( |
602 FROM_HERE, ui_loop_.QuitClosure(), TestTimeouts::action_timeout()); | 602 FROM_HERE, ui_loop_.QuitClosure(), TestTimeouts::action_timeout()); |
603 ui_loop_.Run(); | 603 ui_loop_.Run(); |
604 } | 604 } |
605 | 605 |
606 // Register for some IDs and turn off notifications. This should | 606 // Call StopSyncingForShutdown() on the backend and fire some invalidations |
607 // propagate all the way to the frontend. | |
608 TEST_F(SyncBackendHostTest, DisableNotifications) { | |
609 InitializeBackend(); | |
610 | |
611 EXPECT_CALL(mock_frontend_, | |
612 OnNotificationsDisabled(syncer::TRANSIENT_NOTIFICATION_ERROR)) | |
613 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); | |
614 | |
615 syncer::ObjectIdSet ids; | |
616 ids.insert(invalidation::ObjectId(4, "id4")); | |
617 backend_->UpdateRegisteredInvalidationIds(ids); | |
618 fake_manager_->DisableNotifications(syncer::TRANSIENT_NOTIFICATION_ERROR); | |
619 ui_loop_.PostDelayedTask( | |
620 FROM_HERE, ui_loop_.QuitClosure(), TestTimeouts::action_timeout()); | |
621 ui_loop_.Run(); | |
622 } | |
623 | |
624 // Call StopSyncingForShutdown() on the backend and fire some notifications | |
625 // before calling Shutdown(). Then start up and shut down the backend again. | 607 // before calling Shutdown(). Then start up and shut down the backend again. |
626 // Those notifications shouldn't propagate to the frontend. | 608 // Those notifications shouldn't propagate to the frontend. |
627 TEST_F(SyncBackendHostTest, NotificationsAfterStopSyncingForShutdown) { | 609 TEST_F(SyncBackendHostTest, InvalidationsAfterStopSyncingForShutdown) { |
628 InitializeBackend(); | 610 InitializeBackend(); |
629 | 611 |
630 syncer::ObjectIdSet ids; | 612 syncer::ObjectIdSet ids; |
631 ids.insert(invalidation::ObjectId(5, "id5")); | 613 ids.insert(invalidation::ObjectId(5, "id5")); |
632 backend_->UpdateRegisteredInvalidationIds(ids); | 614 backend_->UpdateRegisteredInvalidationIds(ids); |
633 | 615 |
634 backend_->StopSyncingForShutdown(); | 616 backend_->StopSyncingForShutdown(); |
635 | 617 |
636 // Should not trigger anything. | 618 // Should not trigger anything. |
637 fake_manager_->DisableNotifications(syncer::TRANSIENT_NOTIFICATION_ERROR); | 619 fake_manager_->UpdateInvalidatorState(syncer::TRANSIENT_INVALIDATION_ERROR); |
638 fake_manager_->EnableNotifications(); | 620 fake_manager_->UpdateInvalidatorState(syncer::INVALIDATIONS_ENABLED); |
639 const syncer::ObjectIdStateMap& id_state_map = | 621 const syncer::ObjectIdStateMap& id_state_map = |
640 syncer::ObjectIdSetToStateMap(ids, "payload"); | 622 syncer::ObjectIdSetToStateMap(ids, "payload"); |
641 fake_manager_->Invalidate(id_state_map, syncer::REMOTE_NOTIFICATION); | 623 fake_manager_->Invalidate(id_state_map, syncer::REMOTE_INVALIDATION); |
642 | 624 |
643 // Make sure the above calls take effect before we continue. | 625 // Make sure the above calls take effect before we continue. |
644 fake_manager_->WaitForSyncThread(); | 626 fake_manager_->WaitForSyncThread(); |
645 | 627 |
646 backend_->Shutdown(false); | 628 backend_->Shutdown(false); |
647 backend_.reset(); | 629 backend_.reset(); |
648 | 630 |
649 TearDown(); | 631 TearDown(); |
650 SetUp(); | 632 SetUp(); |
651 } | 633 } |
652 | 634 |
653 } // namespace | 635 } // namespace |
654 | 636 |
655 } // namespace browser_sync | 637 } // namespace browser_sync |
OLD | NEW |