OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <string> | 5 #include <string> |
6 #include <utility> | 6 #include <utility> |
7 #include <vector> | 7 #include <vector> |
8 #include "chrome/common/instant_restricted_id_cache.h" | 8 #include "chrome/common/instant_restricted_id_cache.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 EXPECT_FALSE(cache.GetItemWithRestrictedID(2, &t)); | 339 EXPECT_FALSE(cache.GetItemWithRestrictedID(2, &t)); |
340 EXPECT_TRUE(cache.GetItemWithRestrictedID(4, &t)); | 340 EXPECT_TRUE(cache.GetItemWithRestrictedID(4, &t)); |
341 EXPECT_EQ(input1[2].second, t); | 341 EXPECT_EQ(input1[2].second, t); |
342 EXPECT_TRUE(cache.GetItemWithRestrictedID(5, &t)); | 342 EXPECT_TRUE(cache.GetItemWithRestrictedID(5, &t)); |
343 EXPECT_EQ(input3[1].second, t); | 343 EXPECT_EQ(input3[1].second, t); |
344 EXPECT_TRUE(cache.GetItemWithRestrictedID(6, &t)); | 344 EXPECT_TRUE(cache.GetItemWithRestrictedID(6, &t)); |
345 EXPECT_EQ(input2[1], t); | 345 EXPECT_EQ(input2[1], t); |
346 EXPECT_TRUE(cache.GetItemWithRestrictedID(7, &t)); | 346 EXPECT_TRUE(cache.GetItemWithRestrictedID(7, &t)); |
347 EXPECT_EQ(input3[2].second, t); | 347 EXPECT_EQ(input3[2].second, t); |
348 } | 348 } |
| 349 |
| 350 TEST_F(InstantRestrictedIDCacheTest, AddEmptySet) { |
| 351 InstantRestrictedIDCache<TestData> cache(9); |
| 352 EXPECT_EQ(0u, cache.cache_.size()); |
| 353 EXPECT_EQ(0, cache.last_restricted_id_); |
| 354 |
| 355 // Add a non-empty set of items. |
| 356 std::vector<TestData> input1; |
| 357 input1.push_back(TestData("A")); |
| 358 input1.push_back(TestData("B")); |
| 359 input1.push_back(TestData("C")); |
| 360 cache.AddItems(input1); |
| 361 EXPECT_EQ(3u, cache.cache_.size()); |
| 362 EXPECT_EQ(3, cache.last_restricted_id_); |
| 363 |
| 364 std::vector<ItemIDPair> output; |
| 365 cache.GetCurrentItems(&output); |
| 366 EXPECT_EQ(3u, output.size()); |
| 367 |
| 368 // Add an empty set. |
| 369 cache.AddItems(std::vector<TestData>()); |
| 370 EXPECT_EQ(3u, cache.cache_.size()); |
| 371 EXPECT_EQ(3, cache.last_restricted_id_); |
| 372 |
| 373 cache.GetCurrentItems(&output); |
| 374 EXPECT_TRUE(output.empty()); |
| 375 |
| 376 // Manual IDs. |
| 377 std::vector<ItemIDPair> input2; |
| 378 input2.push_back(std::make_pair(10, TestData("A"))); |
| 379 input2.push_back(std::make_pair(11, TestData("B"))); |
| 380 input2.push_back(std::make_pair(12, TestData("C"))); |
| 381 cache.AddItemsWithRestrictedID(input2); |
| 382 EXPECT_EQ(6u, cache.cache_.size()); |
| 383 EXPECT_EQ(12, cache.last_restricted_id_); |
| 384 |
| 385 cache.GetCurrentItems(&output); |
| 386 EXPECT_EQ(3u, output.size()); |
| 387 |
| 388 cache.AddItemsWithRestrictedID(std::vector<ItemIDPair>()); |
| 389 EXPECT_EQ(6u, cache.cache_.size()); |
| 390 EXPECT_EQ(12, cache.last_restricted_id_); |
| 391 |
| 392 cache.GetCurrentItems(&output); |
| 393 EXPECT_TRUE(output.empty()); |
| 394 } |
OLD | NEW |