| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <memory> | 6 #include <memory> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 InMemoryBlobCacheTest() {} | 27 InMemoryBlobCacheTest() {} |
| 28 ~InMemoryBlobCacheTest() override {} | 28 ~InMemoryBlobCacheTest() override {} |
| 29 | 29 |
| 30 protected: | 30 protected: |
| 31 InMemoryBlobCache cache_; | 31 InMemoryBlobCache cache_; |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 TEST_F(InMemoryBlobCacheTest, SimplePutContainsAndGetOperations) { | 34 TEST_F(InMemoryBlobCacheTest, SimplePutContainsAndGetOperations) { |
| 35 EXPECT_FALSE(cache_.Contains(kFoo)); | 35 EXPECT_FALSE(cache_.Contains(kFoo)); |
| 36 EXPECT_FALSE(cache_.Get(kFoo)); | 36 EXPECT_FALSE(cache_.Get(kFoo)); |
| 37 EXPECT_FALSE(cache_.Contains(kBar)); |
| 38 EXPECT_FALSE(cache_.Get(kBar)); |
| 37 | 39 |
| 38 BlobDataPtr blob_data = CreateBlobDataPtr(kDeadbeef); | 40 BlobDataPtr blob_data_1 = CreateBlobDataPtr(kDeadbeef); |
| 39 cache_.Put(kFoo, blob_data); | 41 cache_.Put(kFoo, blob_data_1); |
| 40 | 42 |
| 41 EXPECT_TRUE(cache_.Contains(kFoo)); | 43 EXPECT_TRUE(cache_.Contains(kFoo)); |
| 42 EXPECT_FALSE(cache_.Contains(kBar)); | 44 EXPECT_FALSE(cache_.Contains(kBar)); |
| 43 | 45 |
| 44 BlobDataPtr out = cache_.Get(kFoo); | 46 BlobDataPtr blob_data_2 = CreateBlobDataPtr(kDeadbeef); |
| 47 cache_.Put(kBar, blob_data_2); |
| 45 | 48 |
| 46 EXPECT_EQ(blob_data, out); | 49 EXPECT_EQ(blob_data_1, cache_.Get(kFoo)); |
| 50 EXPECT_EQ(blob_data_2, cache_.Get(kBar)); |
| 51 |
| 52 auto cache_state = cache_.GetCachedBlobIds(); |
| 53 EXPECT_EQ(2u, cache_state.size()); |
| 54 EXPECT_EQ(kBar, cache_state[0]); |
| 55 EXPECT_EQ(kFoo, cache_state[1]); |
| 47 } | 56 } |
| 48 | 57 |
| 49 TEST_F(InMemoryBlobCacheTest, TestDuplicatePut) { | 58 TEST_F(InMemoryBlobCacheTest, TestDuplicatePut) { |
| 50 BlobDataPtr first = CreateBlobDataPtr(kDeadbeef); | 59 BlobDataPtr first = CreateBlobDataPtr(kDeadbeef); |
| 51 BlobDataPtr duplicate = CreateBlobDataPtr(kForbiddenCode); | 60 BlobDataPtr duplicate = CreateBlobDataPtr(kForbiddenCode); |
| 52 cache_.Put(kFoo, first); | 61 cache_.Put(kFoo, first); |
| 53 | 62 |
| 54 BlobDataPtr out1 = cache_.Get(kFoo); | 63 BlobDataPtr out1 = cache_.Get(kFoo); |
| 55 EXPECT_EQ(first, out1); | 64 EXPECT_EQ(first, out1); |
| 56 | 65 |
| 57 // The second put should be ignored and retrieving kFoo should still retrieve | 66 // The second put should be ignored and retrieving kFoo should still retrieve |
| 58 // the first item. | 67 // the first item. |
| 59 cache_.Put(kFoo, duplicate); | 68 cache_.Put(kFoo, duplicate); |
| 60 BlobDataPtr out2 = cache_.Get(kFoo); | 69 BlobDataPtr out2 = cache_.Get(kFoo); |
| 61 EXPECT_EQ(first, out2); | 70 EXPECT_EQ(first, out2); |
| 71 |
| 72 auto cache_state = cache_.GetCachedBlobIds(); |
| 73 EXPECT_EQ(1u, cache_state.size()); |
| 74 EXPECT_EQ(kFoo, cache_state[0]); |
| 62 } | 75 } |
| 63 | 76 |
| 64 } // namespace | 77 } // namespace |
| 65 } // namespace blimp | 78 } // namespace blimp |
| OLD | NEW |