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/invalidator_state.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_invalidation_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; |
37 using ::testing::InvokeWithoutArgs; | 37 using ::testing::InvokeWithoutArgs; |
(...skipping 12 matching lines...) Expand all Loading... |
50 MessageLoop::current()->Quit(); | 50 MessageLoop::current()->Quit(); |
51 } | 51 } |
52 | 52 |
53 class MockSyncFrontend : public SyncFrontend { | 53 class MockSyncFrontend : public SyncFrontend { |
54 public: | 54 public: |
55 virtual ~MockSyncFrontend() {} | 55 virtual ~MockSyncFrontend() {} |
56 | 56 |
57 MOCK_METHOD1(OnInvalidatorStateChange, | 57 MOCK_METHOD1(OnInvalidatorStateChange, |
58 void(syncer::InvalidatorState)); | 58 void(syncer::InvalidatorState)); |
59 MOCK_METHOD2(OnIncomingInvalidation, | 59 MOCK_METHOD2(OnIncomingInvalidation, |
60 void(const syncer::ObjectIdStateMap&, | 60 void(const syncer::ObjectIdInvalidationMap&, |
61 syncer::IncomingInvalidationSource)); | 61 syncer::IncomingInvalidationSource)); |
62 MOCK_METHOD2(OnBackendInitialized, | 62 MOCK_METHOD2(OnBackendInitialized, |
63 void(const syncer::WeakHandle<syncer::JsBackend>&, bool)); | 63 void(const syncer::WeakHandle<syncer::JsBackend>&, bool)); |
64 MOCK_METHOD0(OnSyncCycleCompleted, void()); | 64 MOCK_METHOD0(OnSyncCycleCompleted, void()); |
65 MOCK_METHOD1(OnConnectionStatusChange, | 65 MOCK_METHOD1(OnConnectionStatusChange, |
66 void(syncer::ConnectionStatus status)); | 66 void(syncer::ConnectionStatus status)); |
67 MOCK_METHOD0(OnStopSyncingPermanently, void()); | 67 MOCK_METHOD0(OnStopSyncingPermanently, void()); |
68 MOCK_METHOD0(OnClearServerDataSucceeded, void()); | 68 MOCK_METHOD0(OnClearServerDataSucceeded, void()); |
69 MOCK_METHOD0(OnClearServerDataFailed, void()); | 69 MOCK_METHOD0(OnClearServerDataFailed, void()); |
70 MOCK_METHOD2(OnPassphraseRequired, | 70 MOCK_METHOD2(OnPassphraseRequired, |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 } | 559 } |
560 | 560 |
561 // Register for some IDs and trigger an invalidation. This should | 561 // Register for some IDs and trigger an invalidation. This should |
562 // propagate all the way to the frontend. | 562 // propagate all the way to the frontend. |
563 TEST_F(SyncBackendHostTest, Invalidate) { | 563 TEST_F(SyncBackendHostTest, Invalidate) { |
564 InitializeBackend(); | 564 InitializeBackend(); |
565 | 565 |
566 syncer::ObjectIdSet ids; | 566 syncer::ObjectIdSet ids; |
567 ids.insert(invalidation::ObjectId(1, "id1")); | 567 ids.insert(invalidation::ObjectId(1, "id1")); |
568 ids.insert(invalidation::ObjectId(2, "id2")); | 568 ids.insert(invalidation::ObjectId(2, "id2")); |
569 const syncer::ObjectIdStateMap& id_state_map = | 569 const syncer::ObjectIdInvalidationMap& invalidation_map = |
570 syncer::ObjectIdSetToStateMap(ids, "payload"); | 570 syncer::ObjectIdSetToInvalidationMap(ids, "payload"); |
571 | 571 |
572 EXPECT_CALL( | 572 EXPECT_CALL( |
573 mock_frontend_, | 573 mock_frontend_, |
574 OnIncomingInvalidation(id_state_map, syncer::REMOTE_INVALIDATION)) | 574 OnIncomingInvalidation(invalidation_map, syncer::REMOTE_INVALIDATION)) |
575 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); | 575 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); |
576 | 576 |
577 backend_->UpdateRegisteredInvalidationIds(ids); | 577 backend_->UpdateRegisteredInvalidationIds(ids); |
578 fake_manager_->Invalidate(id_state_map, syncer::REMOTE_INVALIDATION); | 578 fake_manager_->Invalidate(invalidation_map, syncer::REMOTE_INVALIDATION); |
579 ui_loop_.PostDelayedTask( | 579 ui_loop_.PostDelayedTask( |
580 FROM_HERE, ui_loop_.QuitClosure(), TestTimeouts::action_timeout()); | 580 FROM_HERE, ui_loop_.QuitClosure(), TestTimeouts::action_timeout()); |
581 ui_loop_.Run(); | 581 ui_loop_.Run(); |
582 } | 582 } |
583 | 583 |
584 // Register for some IDs and update the invalidator state. This | 584 // Register for some IDs and update the invalidator state. This |
585 // should propagate all the way to the frontend. | 585 // should propagate all the way to the frontend. |
586 TEST_F(SyncBackendHostTest, UpdateInvalidatorState) { | 586 TEST_F(SyncBackendHostTest, UpdateInvalidatorState) { |
587 InitializeBackend(); | 587 InitializeBackend(); |
588 | 588 |
(...skipping 18 matching lines...) Expand all Loading... |
607 | 607 |
608 syncer::ObjectIdSet ids; | 608 syncer::ObjectIdSet ids; |
609 ids.insert(invalidation::ObjectId(5, "id5")); | 609 ids.insert(invalidation::ObjectId(5, "id5")); |
610 backend_->UpdateRegisteredInvalidationIds(ids); | 610 backend_->UpdateRegisteredInvalidationIds(ids); |
611 | 611 |
612 backend_->StopSyncingForShutdown(); | 612 backend_->StopSyncingForShutdown(); |
613 | 613 |
614 // Should not trigger anything. | 614 // Should not trigger anything. |
615 fake_manager_->UpdateInvalidatorState(syncer::TRANSIENT_INVALIDATION_ERROR); | 615 fake_manager_->UpdateInvalidatorState(syncer::TRANSIENT_INVALIDATION_ERROR); |
616 fake_manager_->UpdateInvalidatorState(syncer::INVALIDATIONS_ENABLED); | 616 fake_manager_->UpdateInvalidatorState(syncer::INVALIDATIONS_ENABLED); |
617 const syncer::ObjectIdStateMap& id_state_map = | 617 const syncer::ObjectIdInvalidationMap& invalidation_map = |
618 syncer::ObjectIdSetToStateMap(ids, "payload"); | 618 syncer::ObjectIdSetToInvalidationMap(ids, "payload"); |
619 fake_manager_->Invalidate(id_state_map, syncer::REMOTE_INVALIDATION); | 619 fake_manager_->Invalidate(invalidation_map, syncer::REMOTE_INVALIDATION); |
620 | 620 |
621 // Make sure the above calls take effect before we continue. | 621 // Make sure the above calls take effect before we continue. |
622 fake_manager_->WaitForSyncThread(); | 622 fake_manager_->WaitForSyncThread(); |
623 | 623 |
624 backend_->Shutdown(false); | 624 backend_->Shutdown(false); |
625 backend_.reset(); | 625 backend_.reset(); |
626 | 626 |
627 TearDown(); | 627 TearDown(); |
628 SetUp(); | 628 SetUp(); |
629 } | 629 } |
630 | 630 |
631 } // namespace | 631 } // namespace |
632 | 632 |
633 } // namespace browser_sync | 633 } // namespace browser_sync |
OLD | NEW |