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

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: rebase Created 4 years, 7 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
« no previous file with comments | « blimp/net/blob_channel/blob_channel_sender.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..aa9a2f1f3e7f651ec964f2c7bdfead0d303c97fb
--- /dev/null
+++ b/blimp/net/blob_channel/blob_channel_sender_unittest.cc
@@ -0,0 +1,81 @@
+// 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::_;
+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.
+BlobDataPtr CreatePayload(const std::string& input) {
+ BlobDataPtr output(new BlobData(input));
+ return output;
+}
+
+MATCHER_P(BlobDataEqual, expected, "") {
+ return expected->data == arg->data;
+}
+
+class MockSenderDelegate : public BlobChannelSender::Delegate {
+ public:
+ MockSenderDelegate() {}
+ ~MockSenderDelegate() override {}
+
+ MOCK_METHOD2(DeliverBlob, void(const BlobId&, BlobDataPtr));
+};
+
+class BlobChannelSenderTest : public testing::Test {
+ public:
+ BlobChannelSenderTest()
+ : mock_delegate_(new testing::StrictMock<MockSenderDelegate>),
+ mock_cache_(new testing::StrictMock<MockBlobCache>),
+ blob_sender_(new BlobChannelSender(base::WrapUnique(mock_cache_),
+ base::WrapUnique(mock_delegate_))) {}
+ ~BlobChannelSenderTest() override {}
+
+ testing::StrictMock<MockSenderDelegate>* mock_delegate_;
+ testing::StrictMock<MockBlobCache>* mock_cache_;
+ std::unique_ptr<BlobChannelSender> blob_sender_;
+};
+
+TEST_F(BlobChannelSenderTest, TestPutBlob) {
+ EXPECT_CALL(*mock_cache_,
+ Put(kBlobId, BlobDataEqual(CreatePayload(kBlobPayload))));
+ EXPECT_CALL(*mock_cache_, Contains(kBlobId)).WillOnce(Return(false));
+ blob_sender_->PutBlob(kBlobId, CreatePayload(kBlobPayload));
+}
+
+TEST_F(BlobChannelSenderTest, TestPutBlobDuplicate) {
+ EXPECT_CALL(*mock_cache_, Contains(kBlobId)).WillOnce(Return(true));
+ blob_sender_->PutBlob(kBlobId, CreatePayload(kBlobPayload));
+}
+
+TEST_F(BlobChannelSenderTest, TestPush) {
+ auto payload = CreatePayload(kBlobPayload);
+ EXPECT_CALL(*mock_delegate_, DeliverBlob(kBlobId, BlobDataEqual(payload)));
+ EXPECT_CALL(*mock_cache_, Contains(kBlobId))
+ .WillOnce(Return(false))
+ .WillOnce(Return(true));
+ EXPECT_CALL(*mock_cache_, Put(kBlobId, BlobDataEqual(payload)));
+ EXPECT_CALL(*mock_cache_, Get(kBlobId)).WillOnce(Return(payload));
+ blob_sender_->PutBlob(kBlobId, payload);
+ blob_sender_->DeliverBlob(kBlobId);
+}
+
+} // namespace
+} // namespace blimp
« no previous file with comments | « blimp/net/blob_channel/blob_channel_sender.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698