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

Unified Diff: blimp/common/blob_cache/in_memory_blob_cache_unittest.cc

Issue 1867653002: Initial version of Blimp BlobCache. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed to use BlobId and BlobData Created 4 years, 8 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
Index: blimp/common/blob_cache/in_memory_blob_cache_unittest.cc
diff --git a/blimp/common/blob_cache/in_memory_blob_cache_unittest.cc b/blimp/common/blob_cache/in_memory_blob_cache_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..14c348e842e23a8d2cc9539e0046fbe3a5424f29
--- /dev/null
+++ b/blimp/common/blob_cache/in_memory_blob_cache_unittest.cc
@@ -0,0 +1,68 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <algorithm>
+#include <memory>
+#include <vector>
+
+#include "base/logging.h"
+#include "base/memory/ptr_util.h"
+#include "base/memory/ref_counted.h"
+#include "blimp/common/blob_cache/blob_cache.h"
+#include "blimp/common/blob_cache/in_memory_blob_cache.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blimp {
+namespace {
+
+const char kFoo[] = "foo";
+const char kBar[] = "bar";
+const char kDeadbeef[] = "\xde\xad\xbe\xef";
+const char kForbiddenCode[] = "\x4b\x1d\xc0\xd3";
+
+BlobData CreateBlobData(const std::string& data) {
+ return new base::RefCountedData<const std::string>(data);
+}
+
+class InMemoryBlobCacheTest : public testing::Test {
+ public:
+ InMemoryBlobCacheTest() {}
+ ~InMemoryBlobCacheTest() override {}
+
+ protected:
+ InMemoryBlobCache cache_;
+};
+
+TEST_F(InMemoryBlobCacheTest, SimplePutContainsAndGetOperations) {
+ EXPECT_FALSE(cache_.Contains(kFoo));
+ EXPECT_EQ(nullptr, cache_.Get(kFoo));
+
+ BlobData blob_data = CreateBlobData(kDeadbeef);
+ cache_.Put(kFoo, blob_data);
+
+ EXPECT_TRUE(cache_.Contains(kFoo));
+ EXPECT_FALSE(cache_.Contains(kBar));
+
+ BlobData out = cache_.Get(kFoo);
+
+ EXPECT_EQ(blob_data, out);
+}
+
+TEST_F(InMemoryBlobCacheTest, TestDuplicatePut) {
+ BlobData first = CreateBlobData(kDeadbeef);
+ BlobData duplicate = CreateBlobData(kForbiddenCode);
+ cache_.Put(kFoo, first);
+
+ BlobData out1 = cache_.Get(kFoo);
+ EXPECT_EQ(first, out1);
+
+ // The second put should be ignored and retrieving kFoo should still retrieve
+ // the first item.
+ cache_.Put(kFoo, duplicate);
+ BlobData out2 = cache_.Get(kFoo);
+ EXPECT_EQ(first, out2);
+}
+
+} // namespace
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698