| 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 "sync/notifier/non_blocking_invalidation_notifier.h" | 5 #include "sync/notifier/non_blocking_invalidation_notifier.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| 11 #include "google/cacheinvalidation/types.pb.h" | 11 #include "google/cacheinvalidation/types.pb.h" |
| 12 #include "jingle/notifier/base/fake_base_task.h" | 12 #include "jingle/notifier/base/fake_base_task.h" |
| 13 #include "net/url_request/url_request_test_util.h" | 13 #include "net/url_request/url_request_test_util.h" |
| 14 #include "sync/internal_api/public/base/model_type.h" | 14 #include "sync/internal_api/public/base/model_type.h" |
| 15 #include "sync/internal_api/public/base/model_type_payload_map.h" | 15 #include "sync/internal_api/public/base/model_type_state_map.h" |
| 16 #include "sync/internal_api/public/util/weak_handle.h" | 16 #include "sync/internal_api/public/util/weak_handle.h" |
| 17 #include "sync/notifier/invalidation_state_tracker.h" | 17 #include "sync/notifier/invalidation_state_tracker.h" |
| 18 #include "sync/notifier/mock_sync_notifier_observer.h" | 18 #include "sync/notifier/mock_sync_notifier_observer.h" |
| 19 #include "sync/notifier/object_id_state_map_test_util.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 22 |
| 22 namespace syncer { | 23 namespace syncer { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 using ::testing::InSequence; | 27 using ::testing::InSequence; |
| 27 using ::testing::StrictMock; | 28 using ::testing::StrictMock; |
| 28 | 29 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 StrictMock<MockSyncNotifierObserver> mock_observer_; | 65 StrictMock<MockSyncNotifierObserver> mock_observer_; |
| 65 notifier::FakeBaseTask fake_base_task_; | 66 notifier::FakeBaseTask fake_base_task_; |
| 66 }; | 67 }; |
| 67 | 68 |
| 68 // TODO(akalin): Add real unit tests (http://crbug.com/140410). | 69 // TODO(akalin): Add real unit tests (http://crbug.com/140410). |
| 69 | 70 |
| 70 TEST_F(NonBlockingInvalidationNotifierTest, Basic) { | 71 TEST_F(NonBlockingInvalidationNotifierTest, Basic) { |
| 71 InSequence dummy; | 72 InSequence dummy; |
| 72 | 73 |
| 73 const ModelTypeSet models(PREFERENCES, BOOKMARKS, AUTOFILL); | 74 const ModelTypeSet models(PREFERENCES, BOOKMARKS, AUTOFILL); |
| 74 const ModelTypePayloadMap& type_payloads = | 75 const ModelTypeStateMap& type_state_map = |
| 75 ModelTypePayloadMapFromEnumSet(models, "payload"); | 76 ModelTypeStateMapFromEnumSet(models, "payload"); |
| 76 EXPECT_CALL(mock_observer_, OnNotificationsEnabled()); | 77 EXPECT_CALL(mock_observer_, OnNotificationsEnabled()); |
| 77 EXPECT_CALL(mock_observer_, OnIncomingNotification( | 78 EXPECT_CALL(mock_observer_, OnIncomingNotification( |
| 78 ModelTypePayloadMapToObjectIdPayloadMap(type_payloads), | 79 ModelTypeStateMapToObjectIdStateMap(type_state_map), |
| 79 REMOTE_NOTIFICATION)); | 80 REMOTE_NOTIFICATION)); |
| 80 EXPECT_CALL(mock_observer_, | 81 EXPECT_CALL(mock_observer_, |
| 81 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); | 82 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); |
| 82 EXPECT_CALL(mock_observer_, | 83 EXPECT_CALL(mock_observer_, |
| 83 OnNotificationsDisabled(NOTIFICATION_CREDENTIALS_REJECTED)); | 84 OnNotificationsDisabled(NOTIFICATION_CREDENTIALS_REJECTED)); |
| 84 | 85 |
| 85 invalidation_notifier_->UpdateRegisteredIds( | 86 invalidation_notifier_->UpdateRegisteredIds( |
| 86 &mock_observer_, ModelTypeSetToObjectIdSet(models)); | 87 &mock_observer_, ModelTypeSetToObjectIdSet(models)); |
| 87 | 88 |
| 88 invalidation_notifier_->SetStateDeprecated("fake_state"); | 89 invalidation_notifier_->SetStateDeprecated("fake_state"); |
| 89 invalidation_notifier_->SetUniqueId("fake_id"); | 90 invalidation_notifier_->SetUniqueId("fake_id"); |
| 90 invalidation_notifier_->UpdateCredentials("foo@bar.com", "fake_token"); | 91 invalidation_notifier_->UpdateCredentials("foo@bar.com", "fake_token"); |
| 91 | 92 |
| 92 invalidation_notifier_->OnNotificationsEnabled(); | 93 invalidation_notifier_->OnNotificationsEnabled(); |
| 93 invalidation_notifier_->OnIncomingNotification( | 94 invalidation_notifier_->OnIncomingNotification( |
| 94 ModelTypePayloadMapToObjectIdPayloadMap(type_payloads), | 95 ModelTypeStateMapToObjectIdStateMap(type_state_map), |
| 95 REMOTE_NOTIFICATION); | 96 REMOTE_NOTIFICATION); |
| 96 invalidation_notifier_->OnNotificationsDisabled( | 97 invalidation_notifier_->OnNotificationsDisabled( |
| 97 TRANSIENT_NOTIFICATION_ERROR); | 98 TRANSIENT_NOTIFICATION_ERROR); |
| 98 invalidation_notifier_->OnNotificationsDisabled( | 99 invalidation_notifier_->OnNotificationsDisabled( |
| 99 NOTIFICATION_CREDENTIALS_REJECTED); | 100 NOTIFICATION_CREDENTIALS_REJECTED); |
| 100 | 101 |
| 101 ui_loop_.RunAllPending(); | 102 ui_loop_.RunAllPending(); |
| 102 } | 103 } |
| 103 | 104 |
| 104 } // namespace | 105 } // namespace |
| 105 | 106 |
| 106 } // namespace syncer | 107 } // namespace syncer |
| OLD | NEW |