Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(424)

Unified Diff: chrome/common/instant_restricted_id_cache_unittest.cc

Issue 12742014: Instant: Allow empty sets to be added to the cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: DCHECK Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/instant_restricted_id_cache.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/instant_restricted_id_cache_unittest.cc
diff --git a/chrome/common/instant_restricted_id_cache_unittest.cc b/chrome/common/instant_restricted_id_cache_unittest.cc
index 57f1f26230b8e4378da90333553a8081d5ff7edf..e7e97be5fc6e823e51a232f9bb71ae1d37a7f76b 100644
--- a/chrome/common/instant_restricted_id_cache_unittest.cc
+++ b/chrome/common/instant_restricted_id_cache_unittest.cc
@@ -346,3 +346,49 @@ TEST_F(InstantRestrictedIDCacheTest, MixIDGeneration) {
EXPECT_TRUE(cache.GetItemWithRestrictedID(7, &t));
EXPECT_EQ(input3[2].second, t);
}
+
+TEST_F(InstantRestrictedIDCacheTest, AddEmptySet) {
+ InstantRestrictedIDCache<TestData> cache(9);
+ EXPECT_EQ(0u, cache.cache_.size());
+ EXPECT_EQ(0, cache.last_restricted_id_);
+
+ // Add a non-empty set of items.
+ std::vector<TestData> input1;
+ input1.push_back(TestData("A"));
+ input1.push_back(TestData("B"));
+ input1.push_back(TestData("C"));
+ cache.AddItems(input1);
+ EXPECT_EQ(3u, cache.cache_.size());
+ EXPECT_EQ(3, cache.last_restricted_id_);
+
+ std::vector<ItemIDPair> output;
+ cache.GetCurrentItems(&output);
+ EXPECT_EQ(3u, output.size());
+
+ // Add an empty set.
+ cache.AddItems(std::vector<TestData>());
+ EXPECT_EQ(3u, cache.cache_.size());
+ EXPECT_EQ(3, cache.last_restricted_id_);
+
+ cache.GetCurrentItems(&output);
+ EXPECT_TRUE(output.empty());
+
+ // Manual IDs.
+ std::vector<ItemIDPair> input2;
+ input2.push_back(std::make_pair(10, TestData("A")));
+ input2.push_back(std::make_pair(11, TestData("B")));
+ input2.push_back(std::make_pair(12, TestData("C")));
+ cache.AddItemsWithRestrictedID(input2);
+ EXPECT_EQ(6u, cache.cache_.size());
+ EXPECT_EQ(12, cache.last_restricted_id_);
+
+ cache.GetCurrentItems(&output);
+ EXPECT_EQ(3u, output.size());
+
+ cache.AddItemsWithRestrictedID(std::vector<ItemIDPair>());
+ EXPECT_EQ(6u, cache.cache_.size());
+ EXPECT_EQ(12, cache.last_restricted_id_);
+
+ cache.GetCurrentItems(&output);
+ EXPECT_TRUE(output.empty());
+}
« no previous file with comments | « chrome/common/instant_restricted_id_cache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698