Index: blimp/engine/renderer/blob_channel_sender_proxy_unittest.cc |
diff --git a/blimp/engine/renderer/blob_channel_sender_proxy_unittest.cc b/blimp/engine/renderer/blob_channel_sender_proxy_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..169a29f3448f1062163684b8449023f2306a61a7 |
--- /dev/null |
+++ b/blimp/engine/renderer/blob_channel_sender_proxy_unittest.cc |
@@ -0,0 +1,124 @@ |
+// 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 "blimp/engine/renderer/blob_channel_sender_proxy.h" |
+ |
+#include "base/message_loop/message_loop.h" |
+#include "base/run_loop.h" |
+#include "blimp/common/blob_cache/id_util.h" |
+#include "blimp/common/blob_cache/test_util.h" |
+#include "blimp/engine/mojo/blob_channel.mojom.h" |
+#include "blimp/engine/mojo/blob_channel_service.h" |
+#include "blimp/net/blob_channel/mock_blob_channel_sender.h" |
+#include "blimp/net/test_common.h" |
+#include "content/app/mojo/mojo_init.h" |
jam
2016/06/09 15:55:04
code outside of content/ can only include content/
Kevin M
2016/06/09 17:51:19
Done.
|
+#include "mojo/public/cpp/bindings/interface_request.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace blimp { |
+namespace engine { |
+namespace { |
+ |
+const char kBlobId[] = "foo"; |
+const char kBlobPayload[] = "bar"; |
+ |
+class BlobChannelSenderProxyTest : public testing::Test { |
+ public: |
+ BlobChannelSenderProxyTest() {} |
+ |
+ void SetUp() override { |
+ // Set up communication path from the Proxy to a sender mock: |
+ // blob_channel_sender_proxy_ => (mojo) => mojo_service_impl_ => |
+ // mock_sender_; |
+ content::InitializeMojo(); |
+ mojom::BlobChannelPtr mojo_ptr; |
+ BlobChannelService::Create(&mock_sender_, GetProxy(&mojo_ptr)); |
+ blob_channel_sender_proxy_.reset( |
+ new BlobChannelSenderProxy(std::move(mojo_ptr))); |
+ } |
+ |
+ protected: |
+ void DeliverMessages() { base::RunLoop().RunUntilIdle(); } |
+ |
+ const std::string blob_id_ = CalculateBlobId(kBlobId); |
+ base::MessageLoop message_loop_; |
+ std::unique_ptr<BlobChannelService> mojo_service_impl_; |
+ MockBlobChannelSender mock_sender_; |
+ std::unique_ptr<BlobChannelSenderProxy> blob_channel_sender_proxy_; |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(BlobChannelSenderProxyTest); |
+}; |
+ |
+TEST_F(BlobChannelSenderProxyTest, PutBlob) { |
+ EXPECT_CALL(mock_sender_, |
+ PutBlob(blob_id_, BlobDataPtrEqualsString(kBlobPayload))); |
+ blob_channel_sender_proxy_->PutBlob(blob_id_, |
+ CreateBlobDataPtr(kBlobPayload)); |
+ DeliverMessages(); |
+ EXPECT_TRUE(blob_channel_sender_proxy_->IsInEngineCache(blob_id_)); |
+ EXPECT_FALSE(blob_channel_sender_proxy_->IsInClientCache(blob_id_)); |
+} |
+ |
+TEST_F(BlobChannelSenderProxyTest, DeliverBlob) { |
+ EXPECT_CALL(mock_sender_, |
+ PutBlob(blob_id_, BlobDataPtrEqualsString(kBlobPayload))); |
+ EXPECT_CALL(mock_sender_, DeliverBlob(blob_id_)); |
+ |
+ blob_channel_sender_proxy_->PutBlob(blob_id_, |
+ CreateBlobDataPtr(kBlobPayload)); |
+ DeliverMessages(); |
+ EXPECT_TRUE(blob_channel_sender_proxy_->IsInEngineCache(blob_id_)); |
+ EXPECT_FALSE(blob_channel_sender_proxy_->IsInClientCache(blob_id_)); |
+ |
+ blob_channel_sender_proxy_->DeliverBlob(blob_id_); |
+ DeliverMessages(); |
+ EXPECT_TRUE(blob_channel_sender_proxy_->IsInEngineCache(blob_id_)); |
+ EXPECT_TRUE(blob_channel_sender_proxy_->IsInClientCache(blob_id_)); |
+} |
+ |
+TEST_F(BlobChannelSenderProxyTest, RedundantPut) { |
+ EXPECT_CALL(mock_sender_, |
+ PutBlob(blob_id_, BlobDataPtrEqualsString(kBlobPayload))); |
+ blob_channel_sender_proxy_->PutBlob(blob_id_, |
+ CreateBlobDataPtr(kBlobPayload)); |
+ blob_channel_sender_proxy_->PutBlob(blob_id_, |
+ CreateBlobDataPtr(kBlobPayload)); |
+ DeliverMessages(); |
+ EXPECT_TRUE(blob_channel_sender_proxy_->IsInEngineCache(blob_id_)); |
+ EXPECT_FALSE(blob_channel_sender_proxy_->IsInClientCache(blob_id_)); |
+} |
+ |
+TEST_F(BlobChannelSenderProxyTest, DeliverInvalid) { |
+ blob_channel_sender_proxy_->DeliverBlob(blob_id_); |
+ DeliverMessages(); |
+ EXPECT_FALSE(blob_channel_sender_proxy_->IsInEngineCache(blob_id_)); |
+ EXPECT_FALSE(blob_channel_sender_proxy_->IsInClientCache(blob_id_)); |
+} |
+ |
+TEST_F(BlobChannelSenderProxyTest, RedundantDeliver) { |
+ EXPECT_CALL(mock_sender_, |
+ PutBlob(blob_id_, BlobDataPtrEqualsString(kBlobPayload))); |
+ EXPECT_CALL(mock_sender_, DeliverBlob(blob_id_)); |
+ |
+ blob_channel_sender_proxy_->PutBlob(blob_id_, |
+ CreateBlobDataPtr(kBlobPayload)); |
+ DeliverMessages(); |
+ EXPECT_TRUE(blob_channel_sender_proxy_->IsInEngineCache(blob_id_)); |
+ EXPECT_FALSE(blob_channel_sender_proxy_->IsInClientCache(blob_id_)); |
+ |
+ blob_channel_sender_proxy_->DeliverBlob(blob_id_); |
+ DeliverMessages(); |
+ EXPECT_TRUE(blob_channel_sender_proxy_->IsInEngineCache(blob_id_)); |
+ EXPECT_TRUE(blob_channel_sender_proxy_->IsInClientCache(blob_id_)); |
+ |
+ blob_channel_sender_proxy_->DeliverBlob(blob_id_); |
+ DeliverMessages(); |
+ EXPECT_TRUE(blob_channel_sender_proxy_->IsInEngineCache(blob_id_)); |
+ EXPECT_TRUE(blob_channel_sender_proxy_->IsInClientCache(blob_id_)); |
+} |
+} // namespace |
+} // namespace engine |
+} // namespace blimp |