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

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: Wez feedback. 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..1e91f87123290a5e206a4c9cc773f70b74e063e6
--- /dev/null
+++ b/blimp/net/blob_channel/blob_channel_sender_unittest.cc
@@ -0,0 +1,85 @@
+// 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 "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;
+}
+
+// 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());
+}
+
+class MockSenderDelegate : public BlobChannelSender::Delegate {
+ public:
+ MockSenderDelegate() {}
+ ~MockSenderDelegate() {}
+
+ MOCK_METHOD2(Deliver, void(const BlobId&, BlobData));
+};
+
+class BlobChannelSenderTest : public testing::Test {
+ public:
+ BlobChannelSenderTest() : blob_sender_(&mock_cache_, &mock_delegate_) {}
+ ~BlobChannelSenderTest() override {}
+
+ testing::StrictMock<MockSenderDelegate> mock_delegate_;
+ 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, CreatePayload(kBlobPayload));
+}
+
+TEST_F(BlobChannelSenderTest, TestPutDuplicate) {
+ EXPECT_CALL(mock_cache_, Contains(kBlobId)).WillOnce(Return(true));
+ blob_sender_.Put(kBlobId, CreatePayload(kBlobPayload));
+}
+
+TEST_F(BlobChannelSenderTest, TestPush) {
+ auto payload = CreatePayload(kBlobPayload);
+ EXPECT_CALL(
+ mock_delegate_,
+ Deliver(kBlobId,
+ Pointee(RefCountedEqualsContainer(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,
+ CreatePayload(kBlobPayload));
+ blob_sender_.Deliver(kBlobId);
+}
+
+} // namespace
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698