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

Unified Diff: blimp/net/blob_channel/blob_channel_sender_unittest.cc

Issue 1887013003: Blimp: Add BlobChannelSender implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blobchannel-blobcache
Patch Set: Remove erroneous namespace 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/net/blob_channel/blob_channel_sender_unittest.cc
diff --git a/blimp/net/blob_channel/blob_channel_sender_unittest.cc b/blimp/net/blob_channel/blob_channel_sender_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1aa654af202517c39ddd2b80abd35844ffbd9f4c
--- /dev/null
+++ b/blimp/net/blob_channel/blob_channel_sender_unittest.cc
@@ -0,0 +1,98 @@
+// Copyright 2016 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 "base/memory/ptr_util.h"
+#include "blimp/common/blob_cache/mock_blob_cache.h"
+#include "blimp/net/blob_channel/blob_channel_sender.h"
+#include "blimp/net/blob_channel/mock_blob_channel_bindings.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blimp {
+namespace {
+
+using testing::Pointee;
+using testing::Return;
+
+const char kBlobId[] = "blob-1";
+const char kBlobPayload[] = "blob-1-payload";
+
+// Helper function for creating a cache payload vector from a string.
+scoped_refptr<RefCountedVector> CreatePayload(const std::string& input) {
+ scoped_refptr<RefCountedVector> output(new RefCountedVector);
+ output->data.assign(input.begin(), input.end());
+ return output;
+}
+
+std::vector<uint8_t> StringToVector(const std::string& str) {
+ std::vector<uint8_t> output;
+ output.assign(str.begin(), str.end());
+ return output;
+}
+
+// Checks if a RefCountedVector matches |expected|.
+MATCHER_P(RefCountedEqualsContainer, expected, "") {
+ return (expected.size() == arg.data.size()) &&
+ std::equal(arg.data.begin(), arg.data.end(), expected.begin());
+}
+
+// Verifies that a sequence container's contents match those of another
+// container. The container types may differ (e.g. string & vector<char>).
+MATCHER_P(EqualsContainer, expected, "") {
+ return (expected.size() == arg.size()) &&
+ std::equal(arg.begin(), arg.end(), expected.begin());
+}
+
+class BlobChannelSenderTest : public testing::Test {
+ public:
+ BlobChannelSenderTest() : blob_sender_(&mock_cache_, &mock_bindings_) {}
+ ~BlobChannelSenderTest() override {}
+
+ testing::StrictMock<MockBlobSenderBindings> mock_bindings_;
+ testing::StrictMock<MockBlobCache> mock_cache_;
+ BlobChannelSender blob_sender_;
+};
+
+TEST_F(BlobChannelSenderTest, TestPut) {
+ EXPECT_CALL(mock_cache_, Put(kBlobId, Pointee(RefCountedEqualsContainer(
+ std::string(kBlobPayload)))));
+ EXPECT_CALL(mock_cache_, Contains(kBlobId)).WillOnce(Return(false));
+ blob_sender_.Put(
+ kBlobId,
+ base::WrapUnique(new std::vector<uint8_t>(StringToVector(kBlobPayload))));
+}
+
+TEST_F(BlobChannelSenderTest, TestPutDuplicate) {
+ EXPECT_CALL(mock_cache_, Contains(kBlobId)).WillOnce(Return(true));
+ blob_sender_.Put(
+ kBlobId,
+ base::WrapUnique(new std::vector<uint8_t>(StringToVector(kBlobPayload))));
+}
+
+TEST_F(BlobChannelSenderTest, TestPush) {
+ auto payload = CreatePayload(kBlobPayload);
+ EXPECT_CALL(mock_bindings_,
+ Send(kBlobId, EqualsContainer(std::string(kBlobPayload))));
+ EXPECT_CALL(mock_cache_, Contains(kBlobId))
+ .WillOnce(Return(false))
+ .WillOnce(Return(true));
+ EXPECT_CALL(mock_cache_, Put(kBlobId, Pointee(RefCountedEqualsContainer(
+ std::string(kBlobPayload)))));
+ EXPECT_CALL(mock_cache_, Get(kBlobId)).WillOnce(Return(payload.get()));
+ blob_sender_.Put(
+ kBlobId,
+ base::WrapUnique(new std::vector<uint8_t>(StringToVector(kBlobPayload))));
+ blob_sender_.Push(kBlobId);
+}
+
+TEST_F(BlobChannelSenderTest, TestPushUnknownBlobId) {
+ EXPECT_CALL(mock_cache_, Contains(kBlobId)).WillOnce(Return(false));
+ blob_sender_.Push(kBlobId);
+}
+
+} // namespace
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698