OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "blimp/engine/renderer/blob_channel_sender_proxy.h" |
| 6 |
| 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/run_loop.h" |
| 9 #include "blimp/common/blob_cache/id_util.h" |
| 10 #include "blimp/common/blob_cache/test_util.h" |
| 11 #include "blimp/engine/mojo/blob_channel.mojom.h" |
| 12 #include "blimp/engine/mojo/blob_channel_service.h" |
| 13 #include "blimp/net/blob_channel/mock_blob_channel_sender.h" |
| 14 #include "blimp/net/test_common.h" |
| 15 #include "mojo/public/cpp/bindings/interface_request.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 |
| 19 namespace blimp { |
| 20 namespace engine { |
| 21 namespace { |
| 22 |
| 23 const char kBlobId[] = "foo"; |
| 24 const char kBlobPayload[] = "bar"; |
| 25 |
| 26 class BlobChannelSenderProxyTest : public testing::Test { |
| 27 public: |
| 28 BlobChannelSenderProxyTest() {} |
| 29 |
| 30 void SetUp() override { |
| 31 // Set up communication path from the Proxy to a sender mock: |
| 32 // blob_channel_sender_proxy_ => (mojo) => mojo_service_impl_ => |
| 33 // mock_sender_; |
| 34 mojom::BlobChannelPtr mojo_ptr; |
| 35 BlobChannelService::Create(&mock_sender_, GetProxy(&mojo_ptr)); |
| 36 blob_channel_sender_proxy_ = |
| 37 BlobChannelSenderProxy::CreateForTest(std::move(mojo_ptr)); |
| 38 } |
| 39 |
| 40 protected: |
| 41 void DeliverMessages() { base::RunLoop().RunUntilIdle(); } |
| 42 |
| 43 const std::string blob_id_ = CalculateBlobId(kBlobId); |
| 44 base::MessageLoop message_loop_; |
| 45 std::unique_ptr<BlobChannelService> mojo_service_impl_; |
| 46 MockBlobChannelSender mock_sender_; |
| 47 std::unique_ptr<BlobChannelSenderProxy> blob_channel_sender_proxy_; |
| 48 |
| 49 private: |
| 50 DISALLOW_COPY_AND_ASSIGN(BlobChannelSenderProxyTest); |
| 51 }; |
| 52 |
| 53 TEST_F(BlobChannelSenderProxyTest, PutBlob) { |
| 54 EXPECT_CALL(mock_sender_, |
| 55 PutBlob(blob_id_, BlobDataPtrEqualsString(kBlobPayload))); |
| 56 blob_channel_sender_proxy_->PutBlob(blob_id_, |
| 57 CreateBlobDataPtr(kBlobPayload)); |
| 58 DeliverMessages(); |
| 59 EXPECT_TRUE(blob_channel_sender_proxy_->IsInEngineCache(blob_id_)); |
| 60 EXPECT_FALSE(blob_channel_sender_proxy_->IsInClientCache(blob_id_)); |
| 61 } |
| 62 |
| 63 TEST_F(BlobChannelSenderProxyTest, DeliverBlob) { |
| 64 EXPECT_CALL(mock_sender_, |
| 65 PutBlob(blob_id_, BlobDataPtrEqualsString(kBlobPayload))); |
| 66 EXPECT_CALL(mock_sender_, DeliverBlob(blob_id_)); |
| 67 |
| 68 blob_channel_sender_proxy_->PutBlob(blob_id_, |
| 69 CreateBlobDataPtr(kBlobPayload)); |
| 70 DeliverMessages(); |
| 71 EXPECT_TRUE(blob_channel_sender_proxy_->IsInEngineCache(blob_id_)); |
| 72 EXPECT_FALSE(blob_channel_sender_proxy_->IsInClientCache(blob_id_)); |
| 73 |
| 74 blob_channel_sender_proxy_->DeliverBlob(blob_id_); |
| 75 DeliverMessages(); |
| 76 EXPECT_TRUE(blob_channel_sender_proxy_->IsInEngineCache(blob_id_)); |
| 77 EXPECT_TRUE(blob_channel_sender_proxy_->IsInClientCache(blob_id_)); |
| 78 } |
| 79 |
| 80 TEST_F(BlobChannelSenderProxyTest, RedundantDeliver) { |
| 81 EXPECT_CALL(mock_sender_, |
| 82 PutBlob(blob_id_, BlobDataPtrEqualsString(kBlobPayload))); |
| 83 EXPECT_CALL(mock_sender_, DeliverBlob(blob_id_)); |
| 84 |
| 85 blob_channel_sender_proxy_->PutBlob(blob_id_, |
| 86 CreateBlobDataPtr(kBlobPayload)); |
| 87 DeliverMessages(); |
| 88 EXPECT_TRUE(blob_channel_sender_proxy_->IsInEngineCache(blob_id_)); |
| 89 EXPECT_FALSE(blob_channel_sender_proxy_->IsInClientCache(blob_id_)); |
| 90 |
| 91 blob_channel_sender_proxy_->DeliverBlob(blob_id_); |
| 92 DeliverMessages(); |
| 93 EXPECT_TRUE(blob_channel_sender_proxy_->IsInEngineCache(blob_id_)); |
| 94 EXPECT_TRUE(blob_channel_sender_proxy_->IsInClientCache(blob_id_)); |
| 95 |
| 96 blob_channel_sender_proxy_->DeliverBlob(blob_id_); |
| 97 DeliverMessages(); |
| 98 EXPECT_TRUE(blob_channel_sender_proxy_->IsInEngineCache(blob_id_)); |
| 99 EXPECT_TRUE(blob_channel_sender_proxy_->IsInClientCache(blob_id_)); |
| 100 } |
| 101 |
| 102 } // namespace |
| 103 } // namespace engine |
| 104 } // namespace blimp |
OLD | NEW |