Chromium Code Reviews| Index: chrome/browser/invalidation/invalidation_logger_unittest.cc |
| diff --git a/chrome/browser/invalidation/invalidation_logger_unittest.cc b/chrome/browser/invalidation/invalidation_logger_unittest.cc |
| index 60a5b5d072b243b7dfd55b2f599566e7d2bb22de..66f3b85580b2635d03a339d66e84387c446dc263 100644 |
| --- a/chrome/browser/invalidation/invalidation_logger_unittest.cc |
| +++ b/chrome/browser/invalidation/invalidation_logger_unittest.cc |
| @@ -16,15 +16,16 @@ class InvalidationLoggerTest : public testing::Test { |
| class InvalidationLoggerObserverTest : public InvalidationLoggerObserver { |
| public: |
| - InvalidationLoggerObserverTest() { resetStates(); } |
| + InvalidationLoggerObserverTest() { ResetStates(); } |
| - void resetStates() { |
| + void ResetStates() { |
| registrationReceived = false; |
|
Nicolas Zea
2014/02/11 21:58:25
all of these variables (and all variables in the r
mferreria_g
2014/02/12 00:03:46
They are not checked by cl format. Applied that mo
|
| unregistrationReceived = false; |
| stateReceived = false; |
| updateIdReceived = false; |
| debugMessageReceived = false; |
| invalidationReceived = false; |
| + updateIdsReplicated = std::map<std::string, syncer::ObjectIdSet>(); |
| } |
| virtual void OnRegistration(const base::DictionaryValue& details) OVERRIDE { |
| @@ -40,8 +41,10 @@ class InvalidationLoggerObserverTest : public InvalidationLoggerObserver { |
| stateReceived = true; |
| } |
| - virtual void OnUpdateIds(const base::DictionaryValue& details) OVERRIDE { |
| + virtual void OnUpdateIds(std::string handler, |
| + const syncer::ObjectIdSet& details) OVERRIDE { |
| updateIdReceived = true; |
| + updateIdsReplicated[handler] = details; |
| } |
| virtual void OnDebugMessage(const base::DictionaryValue& details) OVERRIDE { |
| @@ -59,6 +62,7 @@ class InvalidationLoggerObserverTest : public InvalidationLoggerObserver { |
| bool updateIdReceived; |
| bool debugMessageReceived; |
| bool invalidationReceived; |
| + std::map<std::string, syncer::ObjectIdSet> updateIdsReplicated; |
| }; |
| // Test that the callbacks are actually being called when observers are |
| @@ -76,7 +80,7 @@ TEST_F(InvalidationLoggerTest, TestCallbacks) { |
| EXPECT_FALSE(observerTest.unregistrationReceived); |
| EXPECT_FALSE(observerTest.debugMessageReceived); |
| - observerTest.resetStates(); |
| + observerTest.ResetStates(); |
| log.OnInvalidation(syncer::ObjectIdInvalidationMap()); |
| EXPECT_TRUE(observerTest.invalidationReceived); |
| @@ -104,7 +108,7 @@ TEST_F(InvalidationLoggerTest, TestReleaseOfObserver) { |
| log.OnRegistration(base::DictionaryValue()); |
| log.OnUnregistration(base::DictionaryValue()); |
| log.OnDebugMessage(base::DictionaryValue()); |
| - log.OnUpdateIds(base::DictionaryValue()); |
| + log.OnUpdateIds(std::map<std::string, syncer::ObjectIdSet>()); |
| EXPECT_FALSE(observerTest.registrationReceived); |
| EXPECT_FALSE(observerTest.unregistrationReceived); |
| EXPECT_FALSE(observerTest.updateIdReceived); |
| @@ -114,21 +118,74 @@ TEST_F(InvalidationLoggerTest, TestReleaseOfObserver) { |
| } |
| // Test the EmitContet in InvalidationLogger is actually |
| -// sending (only) state notifications. |
| +// sending state and updateIds notifications. |
| TEST_F(InvalidationLoggerTest, TestEmitContent) { |
| InvalidationLogger log; |
| InvalidationLoggerObserverTest observerTest; |
| log.RegisterForDebug(&observerTest); |
| EXPECT_FALSE(observerTest.stateReceived); |
| + EXPECT_FALSE(observerTest.updateIdReceived); |
| log.EmitContent(); |
| - |
| + // Only expect state because no Ids were registered. |
| EXPECT_TRUE(observerTest.stateReceived); |
| EXPECT_FALSE(observerTest.registrationReceived); |
| EXPECT_FALSE(observerTest.unregistrationReceived); |
| EXPECT_FALSE(observerTest.updateIdReceived); |
| EXPECT_FALSE(observerTest.invalidationReceived); |
| EXPECT_FALSE(observerTest.debugMessageReceived); |
| + |
| + observerTest.ResetStates(); |
| + std::map<std::string, syncer::ObjectIdSet> testMap; |
| + testMap["Test"] = syncer::ObjectIdSet(); |
| + log.OnUpdateIds(testMap); |
| + EXPECT_TRUE(observerTest.updateIdReceived); |
| + observerTest.ResetStates(); |
| + |
| + log.EmitContent(); |
| + // Expect now state and ids change. |
| + EXPECT_TRUE(observerTest.stateReceived); |
| + EXPECT_TRUE(observerTest.updateIdReceived); |
| + EXPECT_FALSE(observerTest.registrationReceived); |
| + EXPECT_FALSE(observerTest.unregistrationReceived); |
| + EXPECT_FALSE(observerTest.invalidationReceived); |
| + EXPECT_FALSE(observerTest.debugMessageReceived); |
| + log.UnregisterForDebug(&observerTest); |
| +} |
| + |
| +// Test that the updateId notification actually sends |
| +// what was is sent to the Observer. |
|
Nicolas Zea
2014/02/11 21:58:25
nit: what was is -> what was
mferreria_g
2014/02/12 00:03:46
Done.
|
| +// The ObserverTest rebuilds the map that is sent in pieces by the logger. |
|
Nicolas Zea
2014/02/11 21:58:25
nit: that is sent -> that was sent
mferreria_g
2014/02/12 00:03:46
Done.
|
| +TEST_F(InvalidationLoggerTest, TestUpdateIdsMap) { |
| + InvalidationLogger log; |
| + InvalidationLoggerObserverTest observerTest; |
| + std::map<std::string, syncer::ObjectIdSet> testMap; |
| + log.RegisterForDebug(&observerTest); |
| + |
| + syncer::ObjectIdSet syncSetA; |
| + syncSetA.insert(ObjectId(1000, "DataType1")); |
| + syncSetA.insert(ObjectId(1000, "DataType2")); |
| + syncer::ObjectIdSet syncSetB; |
| + syncSetB.insert(ObjectId(1020, "DataTypeA")); |
| + testMap["TestA"] = syncSetA; |
| + testMap["TestB"] = syncSetB; |
| + |
| + log.OnUpdateIds(testMap); |
| + EXPECT_EQ(testMap, observerTest.updateIdsReplicated); |
| + |
| + syncer::ObjectIdSet syncSetB2; |
| + syncSetB2.insert(ObjectId(1020, "DataTypeF")); |
| + syncSetB2.insert(ObjectId(1020, "DataTypeG")); |
| + testMap["TestB"] = syncSetB2; |
| + |
| + log.OnUpdateIds(testMap); |
| + EXPECT_EQ(testMap, observerTest.updateIdsReplicated); |
| + |
| + // The emit content should return the same map too. |
| + observerTest.ResetStates(); |
| + log.EmitContent(); |
| + EXPECT_EQ(testMap, observerTest.updateIdsReplicated); |
| + |
| log.UnregisterForDebug(&observerTest); |
| } |
| } // namespace invalidation |