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 | 5 |
6 #include "chrome/browser/sync/invalidations/invalidator_storage.h" | 6 #include "chrome/browser/sync/invalidations/invalidator_storage.h" |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 storage.SetMaxVersionAndPayload(kPreferencesId_, 5, "b"); | 100 storage.SetMaxVersionAndPayload(kPreferencesId_, 5, "b"); |
101 EXPECT_EQ(expected_states, storage.GetAllInvalidationStates()); | 101 EXPECT_EQ(expected_states, storage.GetAllInvalidationStates()); |
102 | 102 |
103 expected_states.erase(kPreferencesId_); | 103 expected_states.erase(kPreferencesId_); |
104 syncer::ObjectIdSet to_forget; | 104 syncer::ObjectIdSet to_forget; |
105 to_forget.insert(kPreferencesId_); | 105 to_forget.insert(kPreferencesId_); |
106 storage.Forget(to_forget); | 106 storage.Forget(to_forget); |
107 EXPECT_EQ(expected_states, storage.GetAllInvalidationStates()); | 107 EXPECT_EQ(expected_states, storage.GetAllInvalidationStates()); |
108 } | 108 } |
109 | 109 |
110 // Clearing the storage should erase all version map entries and the bootstrap | 110 // Clearing the storage should erase all version map entries, bootstrap data, |
111 // data. | 111 // and the client ID. |
112 TEST_F(InvalidatorStorageTest, Clear) { | 112 TEST_F(InvalidatorStorageTest, Clear) { |
113 InvalidatorStorage storage(&pref_service_); | 113 InvalidatorStorage storage(&pref_service_); |
114 EXPECT_TRUE(storage.GetAllInvalidationStates().empty()); | 114 EXPECT_TRUE(storage.GetAllInvalidationStates().empty()); |
115 EXPECT_TRUE(storage.GetBootstrapData().empty()); | 115 EXPECT_TRUE(storage.GetBootstrapData().empty()); |
| 116 EXPECT_TRUE(storage.GetInvalidatorClientId().empty()); |
| 117 |
| 118 storage.SetInvalidatorClientId("fake_id"); |
| 119 EXPECT_EQ("fake_id", storage.GetInvalidatorClientId()); |
116 | 120 |
117 storage.SetBootstrapData("test"); | 121 storage.SetBootstrapData("test"); |
118 EXPECT_EQ("test", storage.GetBootstrapData()); | 122 EXPECT_EQ("test", storage.GetBootstrapData()); |
| 123 |
119 { | 124 { |
120 InvalidationStateMap expected_states; | 125 InvalidationStateMap expected_states; |
121 expected_states[kAppNotificationsId_].version = 3; | 126 expected_states[kAppNotificationsId_].version = 3; |
122 storage.SetMaxVersionAndPayload(kAppNotificationsId_, 3, std::string()); | 127 storage.SetMaxVersionAndPayload(kAppNotificationsId_, 3, std::string()); |
123 EXPECT_EQ(expected_states, storage.GetAllInvalidationStates()); | 128 EXPECT_EQ(expected_states, storage.GetAllInvalidationStates()); |
124 } | 129 } |
125 | 130 |
126 storage.Clear(); | 131 storage.Clear(); |
127 | 132 |
128 EXPECT_TRUE(storage.GetAllInvalidationStates().empty()); | 133 EXPECT_TRUE(storage.GetAllInvalidationStates().empty()); |
129 EXPECT_TRUE(storage.GetBootstrapData().empty()); | 134 EXPECT_TRUE(storage.GetBootstrapData().empty()); |
| 135 EXPECT_TRUE(storage.GetInvalidatorClientId().empty()); |
130 } | 136 } |
131 | 137 |
132 TEST_F(InvalidatorStorageTest, SerializeEmptyMap) { | 138 TEST_F(InvalidatorStorageTest, SerializeEmptyMap) { |
133 InvalidationStateMap empty_map; | 139 InvalidationStateMap empty_map; |
134 base::ListValue list; | 140 base::ListValue list; |
135 InvalidatorStorage::SerializeToList(empty_map, &list); | 141 InvalidatorStorage::SerializeToList(empty_map, &list); |
136 EXPECT_TRUE(list.empty()); | 142 EXPECT_TRUE(list.empty()); |
137 } | 143 } |
138 | 144 |
139 // Make sure we don't choke on a variety of malformed input. | 145 // Make sure we don't choke on a variety of malformed input. |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 const base::ListValue* list = | 400 const base::ListValue* list = |
395 pref_service_.GetList(prefs::kInvalidatorMaxInvalidationVersions); | 401 pref_service_.GetList(prefs::kInvalidatorMaxInvalidationVersions); |
396 InvalidatorStorage::DeserializeFromList(*list, &map); | 402 InvalidatorStorage::DeserializeFromList(*list, &map); |
397 | 403 |
398 EXPECT_EQ(3U, map.size()); | 404 EXPECT_EQ(3U, map.size()); |
399 EXPECT_EQ(10, map[kAutofillId_].version); | 405 EXPECT_EQ(10, map[kAutofillId_].version); |
400 EXPECT_EQ(32, map[kBookmarksId_].version); | 406 EXPECT_EQ(32, map[kBookmarksId_].version); |
401 EXPECT_EQ(54, map[kPreferencesId_].version); | 407 EXPECT_EQ(54, map[kPreferencesId_].version); |
402 } | 408 } |
403 | 409 |
| 410 TEST_F(InvalidatorStorageTest, SetGetNotifierClientId) { |
| 411 InvalidatorStorage storage(&pref_service_); |
| 412 const std::string client_id("fK6eDzAIuKqx9A4+93bljg=="); |
| 413 |
| 414 storage.SetInvalidatorClientId(client_id); |
| 415 EXPECT_EQ(client_id, storage.GetInvalidatorClientId()); |
| 416 } |
| 417 |
404 TEST_F(InvalidatorStorageTest, SetGetBootstrapData) { | 418 TEST_F(InvalidatorStorageTest, SetGetBootstrapData) { |
405 InvalidatorStorage storage(&pref_service_); | 419 InvalidatorStorage storage(&pref_service_); |
406 const std::string mess("n\0tK\0\0l\344", 8); | 420 const std::string mess("n\0tK\0\0l\344", 8); |
407 ASSERT_FALSE(IsStringUTF8(mess)); | 421 ASSERT_FALSE(IsStringUTF8(mess)); |
408 | 422 |
409 storage.SetBootstrapData(mess); | 423 storage.SetBootstrapData(mess); |
410 EXPECT_EQ(mess, storage.GetBootstrapData()); | 424 EXPECT_EQ(mess, storage.GetBootstrapData()); |
411 } | 425 } |
412 | 426 |
413 // Test that we correctly generate ack handles, acknowledge them, and persist | 427 // Test that we correctly generate ack handles, acknowledge them, and persist |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 EXPECT_TRUE(it->second.IsValid()); | 494 EXPECT_TRUE(it->second.IsValid()); |
481 state_map[kBookmarksId_].expected = it->second; | 495 state_map[kBookmarksId_].expected = it->second; |
482 EXPECT_EQ(state_map, storage.GetAllInvalidationStates()); | 496 EXPECT_EQ(state_map, storage.GetAllInvalidationStates()); |
483 | 497 |
484 storage.Acknowledge(kBookmarksId_, it->second); | 498 storage.Acknowledge(kBookmarksId_, it->second); |
485 state_map[kBookmarksId_].current = it->second; | 499 state_map[kBookmarksId_].current = it->second; |
486 EXPECT_EQ(state_map, storage.GetAllInvalidationStates()); | 500 EXPECT_EQ(state_map, storage.GetAllInvalidationStates()); |
487 } | 501 } |
488 | 502 |
489 } // namespace browser_sync | 503 } // namespace browser_sync |
OLD | NEW |