| 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 "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 21 |
| 22 namespace syncer { | 22 namespace syncer { |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 StrictMock<MockSyncNotifierObserver> mock_observer_; | 64 StrictMock<MockSyncNotifierObserver> mock_observer_; |
| 65 notifier::FakeBaseTask fake_base_task_; | 65 notifier::FakeBaseTask fake_base_task_; |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 // TODO(akalin): Add real unit tests (http://crbug.com/140410). | 68 // TODO(akalin): Add real unit tests (http://crbug.com/140410). |
| 69 | 69 |
| 70 TEST_F(NonBlockingInvalidationNotifierTest, Basic) { | 70 TEST_F(NonBlockingInvalidationNotifierTest, Basic) { |
| 71 InSequence dummy; | 71 InSequence dummy; |
| 72 | 72 |
| 73 const ModelTypeSet models(PREFERENCES, BOOKMARKS, AUTOFILL); | 73 const ModelTypeSet models(PREFERENCES, BOOKMARKS, AUTOFILL); |
| 74 const ModelTypePayloadMap& type_payloads = | 74 const ModelTypeStateMap& type_state_map = |
| 75 ModelTypePayloadMapFromEnumSet(models, "payload"); | 75 ModelTypeStateMapFromEnumSet(models, "payload"); |
| 76 EXPECT_CALL(mock_observer_, OnNotificationsEnabled()); | 76 EXPECT_CALL(mock_observer_, OnNotificationsEnabled()); |
| 77 EXPECT_CALL(mock_observer_, OnIncomingNotification( | 77 EXPECT_CALL(mock_observer_, OnIncomingNotification( |
| 78 ModelTypePayloadMapToObjectIdPayloadMap(type_payloads), | 78 ModelTypeStateMapToObjectIdStateMap(type_state_map), |
| 79 REMOTE_NOTIFICATION)); | 79 REMOTE_NOTIFICATION)); |
| 80 EXPECT_CALL(mock_observer_, | 80 EXPECT_CALL(mock_observer_, |
| 81 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); | 81 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); |
| 82 EXPECT_CALL(mock_observer_, | 82 EXPECT_CALL(mock_observer_, |
| 83 OnNotificationsDisabled(NOTIFICATION_CREDENTIALS_REJECTED)); | 83 OnNotificationsDisabled(NOTIFICATION_CREDENTIALS_REJECTED)); |
| 84 | 84 |
| 85 invalidation_notifier_->UpdateRegisteredIds( | 85 invalidation_notifier_->UpdateRegisteredIds( |
| 86 &mock_observer_, ModelTypeSetToObjectIdSet(models)); | 86 &mock_observer_, ModelTypeSetToObjectIdSet(models)); |
| 87 | 87 |
| 88 invalidation_notifier_->SetStateDeprecated("fake_state"); | 88 invalidation_notifier_->SetStateDeprecated("fake_state"); |
| 89 invalidation_notifier_->SetUniqueId("fake_id"); | 89 invalidation_notifier_->SetUniqueId("fake_id"); |
| 90 invalidation_notifier_->UpdateCredentials("foo@bar.com", "fake_token"); | 90 invalidation_notifier_->UpdateCredentials("foo@bar.com", "fake_token"); |
| 91 | 91 |
| 92 invalidation_notifier_->OnNotificationsEnabled(); | 92 invalidation_notifier_->OnNotificationsEnabled(); |
| 93 invalidation_notifier_->OnIncomingNotification( | 93 invalidation_notifier_->OnIncomingNotification( |
| 94 ModelTypePayloadMapToObjectIdPayloadMap(type_payloads), | 94 ModelTypeStateMapToObjectIdStateMap(type_state_map), |
| 95 REMOTE_NOTIFICATION); | 95 REMOTE_NOTIFICATION); |
| 96 invalidation_notifier_->OnNotificationsDisabled( | 96 invalidation_notifier_->OnNotificationsDisabled( |
| 97 TRANSIENT_NOTIFICATION_ERROR); | 97 TRANSIENT_NOTIFICATION_ERROR); |
| 98 invalidation_notifier_->OnNotificationsDisabled( | 98 invalidation_notifier_->OnNotificationsDisabled( |
| 99 NOTIFICATION_CREDENTIALS_REJECTED); | 99 NOTIFICATION_CREDENTIALS_REJECTED); |
| 100 | 100 |
| 101 ui_loop_.RunAllPending(); | 101 ui_loop_.RunAllPending(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 } // namespace | 104 } // namespace |
| 105 | 105 |
| 106 } // namespace syncer | 106 } // namespace syncer |
| OLD | NEW |