| 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/bridged_invalidator.h" | 5 #include "chrome/browser/sync/glue/bridged_invalidator.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 DestroyInvalidator(); | 45 DestroyInvalidator(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void CreateInvalidator( | 48 void CreateInvalidator( |
| 49 const std::string& /* initial_state (unused) */, | 49 const std::string& /* initial_state (unused) */, |
| 50 const base::WeakPtr<syncer::InvalidationStateTracker>& | 50 const base::WeakPtr<syncer::InvalidationStateTracker>& |
| 51 /* invalidation_state_tracker (unused) */) { | 51 /* invalidation_state_tracker (unused) */) { |
| 52 DCHECK(!fake_delegate_); | 52 DCHECK(!fake_delegate_); |
| 53 DCHECK(!invalidator_.get()); | 53 DCHECK(!invalidator_.get()); |
| 54 fake_delegate_ = new syncer::FakeInvalidator(); | 54 fake_delegate_ = new syncer::FakeInvalidator(); |
| 55 invalidator_.reset(new BridgedInvalidator(&bridge_, fake_delegate_)); | 55 invalidator_.reset(new BridgedInvalidator( |
| 56 &bridge_, fake_delegate_, syncer::DEFAULT_INVALIDATION_ERROR)); |
| 56 } | 57 } |
| 57 | 58 |
| 58 BridgedInvalidator* GetInvalidator() { | 59 BridgedInvalidator* GetInvalidator() { |
| 59 return invalidator_.get(); | 60 return invalidator_.get(); |
| 60 } | 61 } |
| 61 | 62 |
| 62 ChromeSyncNotificationBridge* GetBridge() { | 63 ChromeSyncNotificationBridge* GetBridge() { |
| 63 return &bridge_; | 64 return &bridge_; |
| 64 } | 65 } |
| 65 | 66 |
| 66 syncer::FakeInvalidator* GetFakeDelegate() { | 67 syncer::FakeInvalidator* GetFakeDelegate() { |
| 67 return fake_delegate_; | 68 return fake_delegate_; |
| 68 } | 69 } |
| 69 | 70 |
| 70 void DestroyInvalidator() { | 71 void DestroyInvalidator() { |
| 71 invalidator_.reset(); | 72 invalidator_.reset(); |
| 72 fake_delegate_ = NULL; | 73 fake_delegate_ = NULL; |
| 73 bridge_.StopForShutdown(); | 74 bridge_.StopForShutdown(); |
| 74 ui_loop_.RunAllPending(); | 75 ui_loop_.RunAllPending(); |
| 75 } | 76 } |
| 76 | 77 |
| 77 void WaitForInvalidator() { | 78 void WaitForInvalidator() { |
| 78 // Do nothing. | 79 // Do nothing. |
| 79 } | 80 } |
| 80 | 81 |
| 81 void TriggerOnNotificationsEnabled() { | 82 void TriggerOnInvalidatorStateChange(syncer::InvalidatorState state) { |
| 82 fake_delegate_->EmitOnNotificationsEnabled(); | 83 fake_delegate_->EmitOnInvalidatorStateChange(state); |
| 83 } | 84 } |
| 84 | 85 |
| 85 void TriggerOnIncomingNotification( | 86 void TriggerOnIncomingInvalidation( |
| 86 const syncer::ObjectIdStateMap& id_state_map, | 87 const syncer::ObjectIdStateMap& id_state_map, |
| 87 syncer::IncomingNotificationSource source) { | 88 syncer::IncomingInvalidationSource source) { |
| 88 fake_delegate_->EmitOnIncomingNotification(id_state_map, source); | 89 fake_delegate_->EmitOnIncomingInvalidation(id_state_map, source); |
| 89 } | |
| 90 | |
| 91 void TriggerOnNotificationsDisabled( | |
| 92 syncer::NotificationsDisabledReason reason) { | |
| 93 fake_delegate_->EmitOnNotificationsDisabled(reason); | |
| 94 } | 90 } |
| 95 | 91 |
| 96 static bool InvalidatorHandlesDeprecatedState() { | 92 static bool InvalidatorHandlesDeprecatedState() { |
| 97 return false; | 93 return false; |
| 98 } | 94 } |
| 99 | 95 |
| 100 private: | 96 private: |
| 101 MessageLoop ui_loop_; | 97 MessageLoop ui_loop_; |
| 102 content::TestBrowserThread ui_thread_; | 98 content::TestBrowserThread ui_thread_; |
| 103 ::testing::NiceMock<ProfileMock> mock_profile_; | 99 ::testing::NiceMock<ProfileMock> mock_profile_; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 119 delegate_.CreateInvalidator( | 115 delegate_.CreateInvalidator( |
| 120 "fake_state", base::WeakPtr<syncer::InvalidationStateTracker>()); | 116 "fake_state", base::WeakPtr<syncer::InvalidationStateTracker>()); |
| 121 } | 117 } |
| 122 | 118 |
| 123 virtual ~BridgedInvalidatorTest() {} | 119 virtual ~BridgedInvalidatorTest() {} |
| 124 | 120 |
| 125 protected: | 121 protected: |
| 126 BridgedInvalidatorTestDelegate delegate_; | 122 BridgedInvalidatorTestDelegate delegate_; |
| 127 }; | 123 }; |
| 128 | 124 |
| 129 TEST_F(BridgedInvalidatorTest, RegisterHandler) { | 125 TEST_F(BridgedInvalidatorTest, HandlerMethods) { |
| 130 syncer::ObjectIdSet ids; | 126 syncer::ObjectIdSet ids; |
| 131 ids.insert(invalidation::ObjectId(1, "id1")); | 127 ids.insert(invalidation::ObjectId(1, "id1")); |
| 132 | 128 |
| 133 syncer::FakeInvalidationHandler handler; | 129 syncer::FakeInvalidationHandler handler; |
| 134 | 130 |
| 135 delegate_.GetInvalidator()->RegisterHandler(&handler); | 131 delegate_.GetInvalidator()->RegisterHandler(&handler); |
| 136 EXPECT_TRUE(delegate_.GetFakeDelegate()->IsHandlerRegistered(&handler)); | 132 EXPECT_TRUE(delegate_.GetFakeDelegate()->IsHandlerRegistered(&handler)); |
| 137 EXPECT_TRUE(delegate_.GetBridge()->IsHandlerRegisteredForTest(&handler)); | 133 EXPECT_TRUE(delegate_.GetBridge()->IsHandlerRegisteredForTest(&handler)); |
| 138 | 134 |
| 139 delegate_.GetInvalidator()->UpdateRegisteredIds(&handler, ids); | 135 delegate_.GetInvalidator()->UpdateRegisteredIds(&handler, ids); |
| 140 EXPECT_EQ(ids, delegate_.GetFakeDelegate()->GetRegisteredIds(&handler)); | 136 EXPECT_EQ(ids, delegate_.GetFakeDelegate()->GetRegisteredIds(&handler)); |
| 141 EXPECT_EQ(ids, delegate_.GetBridge()->GetRegisteredIdsForTest(&handler)); | 137 EXPECT_EQ(ids, delegate_.GetBridge()->GetRegisteredIdsForTest(&handler)); |
| 142 | 138 |
| 143 delegate_.GetInvalidator()->UnregisterHandler(&handler); | 139 delegate_.GetInvalidator()->UnregisterHandler(&handler); |
| 144 EXPECT_FALSE(delegate_.GetFakeDelegate()->IsHandlerRegistered(&handler)); | 140 EXPECT_FALSE(delegate_.GetFakeDelegate()->IsHandlerRegistered(&handler)); |
| 145 EXPECT_FALSE(delegate_.GetBridge()->IsHandlerRegisteredForTest(&handler)); | 141 EXPECT_FALSE(delegate_.GetBridge()->IsHandlerRegisteredForTest(&handler)); |
| 146 } | 142 } |
| 147 | 143 |
| 144 TEST_F(BridgedInvalidatorTest, GetInvalidatorState) { |
| 145 EXPECT_EQ(syncer::DEFAULT_INVALIDATION_ERROR, |
| 146 delegate_.GetInvalidator()->GetInvalidatorState()); |
| 147 } |
| 148 |
| 148 TEST_F(BridgedInvalidatorTest, SetUniqueId) { | 149 TEST_F(BridgedInvalidatorTest, SetUniqueId) { |
| 149 const std::string& unique_id = "unique id"; | 150 const std::string& unique_id = "unique id"; |
| 150 delegate_.GetInvalidator()->SetUniqueId(unique_id); | 151 delegate_.GetInvalidator()->SetUniqueId(unique_id); |
| 151 EXPECT_EQ(unique_id, delegate_.GetFakeDelegate()->GetUniqueId()); | 152 EXPECT_EQ(unique_id, delegate_.GetFakeDelegate()->GetUniqueId()); |
| 152 } | 153 } |
| 153 | 154 |
| 154 TEST_F(BridgedInvalidatorTest, SetStateDeprecated) { | 155 TEST_F(BridgedInvalidatorTest, SetStateDeprecated) { |
| 155 const std::string& state = "state"; | 156 const std::string& state = "state"; |
| 156 delegate_.GetInvalidator()->SetStateDeprecated(state); | 157 delegate_.GetInvalidator()->SetStateDeprecated(state); |
| 157 EXPECT_EQ(state, delegate_.GetFakeDelegate()->GetStateDeprecated()); | 158 EXPECT_EQ(state, delegate_.GetFakeDelegate()->GetStateDeprecated()); |
| 158 } | 159 } |
| 159 | 160 |
| 160 TEST_F(BridgedInvalidatorTest, UpdateCredentials) { | 161 TEST_F(BridgedInvalidatorTest, UpdateCredentials) { |
| 161 const std::string& email = "email"; | 162 const std::string& email = "email"; |
| 162 const std::string& token = "token"; | 163 const std::string& token = "token"; |
| 163 delegate_.GetInvalidator()->UpdateCredentials(email, token); | 164 delegate_.GetInvalidator()->UpdateCredentials(email, token); |
| 164 EXPECT_EQ(email, delegate_.GetFakeDelegate()->GetCredentialsEmail()); | 165 EXPECT_EQ(email, delegate_.GetFakeDelegate()->GetCredentialsEmail()); |
| 165 EXPECT_EQ(token, delegate_.GetFakeDelegate()->GetCredentialsToken()); | 166 EXPECT_EQ(token, delegate_.GetFakeDelegate()->GetCredentialsToken()); |
| 166 } | 167 } |
| 167 | 168 |
| 168 TEST_F(BridgedInvalidatorTest, SendNotification) { | 169 TEST_F(BridgedInvalidatorTest, SendInvalidation) { |
| 169 syncer::ObjectIdSet ids; | 170 syncer::ObjectIdSet ids; |
| 170 ids.insert(invalidation::ObjectId(1, "id1")); | 171 ids.insert(invalidation::ObjectId(1, "id1")); |
| 171 ids.insert(invalidation::ObjectId(2, "id2")); | 172 ids.insert(invalidation::ObjectId(2, "id2")); |
| 172 const syncer::ObjectIdStateMap& id_state_map = | 173 const syncer::ObjectIdStateMap& id_state_map = |
| 173 syncer::ObjectIdSetToStateMap(ids, "payload"); | 174 syncer::ObjectIdSetToStateMap(ids, "payload"); |
| 174 delegate_.GetInvalidator()->SendNotification(id_state_map); | 175 delegate_.GetInvalidator()->SendInvalidation(id_state_map); |
| 175 EXPECT_THAT(id_state_map, | 176 EXPECT_THAT(id_state_map, |
| 176 Eq(delegate_.GetFakeDelegate()->GetLastSentIdStateMap())); | 177 Eq(delegate_.GetFakeDelegate()->GetLastSentIdStateMap())); |
| 177 } | 178 } |
| 178 | 179 |
| 179 } // namespace | 180 } // namespace |
| 180 } // namespace browser_sync | 181 } // namespace browser_sync |
| 181 | 182 |
| 182 namespace syncer { | 183 namespace syncer { |
| 183 namespace { | 184 namespace { |
| 184 | 185 |
| 185 INSTANTIATE_TYPED_TEST_CASE_P( | 186 INSTANTIATE_TYPED_TEST_CASE_P( |
| 186 BridgedInvalidatorTest, InvalidatorTest, | 187 BridgedInvalidatorTest, InvalidatorTest, |
| 187 ::browser_sync::BridgedInvalidatorTestDelegate); | 188 ::browser_sync::BridgedInvalidatorTestDelegate); |
| 188 | 189 |
| 189 } // namespace | 190 } // namespace |
| 190 } // namespace syncer | 191 } // namespace syncer |
| OLD | NEW |