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/edk/embedder/embedder.h" | |
16 #include "mojo/public/cpp/bindings/interface_request.h" | |
17 #include "testing/gmock/include/gmock/gmock.h" | |
18 #include "testing/gtest/include/gtest/gtest.h" | |
19 | |
20 namespace blimp { | |
21 namespace engine { | |
22 namespace { | |
23 | |
24 const char kBlobId[] = "foo"; | |
25 const char kBlobPayload[] = "bar"; | |
26 | |
27 class BlobChannelSenderProxyTest : public testing::Test { | |
28 public: | |
29 BlobChannelSenderProxyTest() {} | |
30 | |
31 void SetUp() override { | |
32 // Set up communication path from the Proxy to a sender mock: | |
33 // blob_channel_sender_proxy_ => (mojo) => mojo_service_impl_ => | |
34 // mock_sender_; | |
35 mojo::edk::Init(); | |
Ken Rockot(use gerrit already)
2016/06/09 17:55:40
This should almost definitely hit a DCHECK - you c
Kevin M
2016/06/09 19:59:43
Thanks for that pointer. I added a new run_all_uni
| |
36 mojom::BlobChannelPtr mojo_ptr; | |
37 BlobChannelService::Create(&mock_sender_, GetProxy(&mojo_ptr)); | |
38 blob_channel_sender_proxy_.reset( | |
39 new BlobChannelSenderProxy(std::move(mojo_ptr))); | |
40 } | |
41 | |
42 protected: | |
43 void DeliverMessages() { base::RunLoop().RunUntilIdle(); } | |
44 | |
45 const std::string blob_id_ = CalculateBlobId(kBlobId); | |
46 base::MessageLoop message_loop_; | |
47 std::unique_ptr<BlobChannelService> mojo_service_impl_; | |
48 MockBlobChannelSender mock_sender_; | |
49 std::unique_ptr<BlobChannelSenderProxy> blob_channel_sender_proxy_; | |
50 | |
51 private: | |
52 DISALLOW_COPY_AND_ASSIGN(BlobChannelSenderProxyTest); | |
53 }; | |
54 | |
55 TEST_F(BlobChannelSenderProxyTest, PutBlob) { | |
56 EXPECT_CALL(mock_sender_, | |
57 PutBlob(blob_id_, BlobDataPtrEqualsString(kBlobPayload))); | |
58 blob_channel_sender_proxy_->PutBlob(blob_id_, | |
59 CreateBlobDataPtr(kBlobPayload)); | |
60 DeliverMessages(); | |
61 EXPECT_TRUE(blob_channel_sender_proxy_->IsInEngineCache(blob_id_)); | |
62 EXPECT_FALSE(blob_channel_sender_proxy_->IsInClientCache(blob_id_)); | |
63 } | |
64 | |
65 TEST_F(BlobChannelSenderProxyTest, DeliverBlob) { | |
66 EXPECT_CALL(mock_sender_, | |
67 PutBlob(blob_id_, BlobDataPtrEqualsString(kBlobPayload))); | |
68 EXPECT_CALL(mock_sender_, DeliverBlob(blob_id_)); | |
69 | |
70 blob_channel_sender_proxy_->PutBlob(blob_id_, | |
71 CreateBlobDataPtr(kBlobPayload)); | |
72 DeliverMessages(); | |
73 EXPECT_TRUE(blob_channel_sender_proxy_->IsInEngineCache(blob_id_)); | |
74 EXPECT_FALSE(blob_channel_sender_proxy_->IsInClientCache(blob_id_)); | |
75 | |
76 blob_channel_sender_proxy_->DeliverBlob(blob_id_); | |
77 DeliverMessages(); | |
78 EXPECT_TRUE(blob_channel_sender_proxy_->IsInEngineCache(blob_id_)); | |
79 EXPECT_TRUE(blob_channel_sender_proxy_->IsInClientCache(blob_id_)); | |
80 } | |
81 | |
82 TEST_F(BlobChannelSenderProxyTest, RedundantPut) { | |
83 EXPECT_CALL(mock_sender_, | |
84 PutBlob(blob_id_, BlobDataPtrEqualsString(kBlobPayload))); | |
85 blob_channel_sender_proxy_->PutBlob(blob_id_, | |
86 CreateBlobDataPtr(kBlobPayload)); | |
87 blob_channel_sender_proxy_->PutBlob(blob_id_, | |
88 CreateBlobDataPtr(kBlobPayload)); | |
89 DeliverMessages(); | |
90 EXPECT_TRUE(blob_channel_sender_proxy_->IsInEngineCache(blob_id_)); | |
91 EXPECT_FALSE(blob_channel_sender_proxy_->IsInClientCache(blob_id_)); | |
92 } | |
93 | |
94 TEST_F(BlobChannelSenderProxyTest, DeliverInvalid) { | |
95 blob_channel_sender_proxy_->DeliverBlob(blob_id_); | |
96 DeliverMessages(); | |
97 EXPECT_FALSE(blob_channel_sender_proxy_->IsInEngineCache(blob_id_)); | |
98 EXPECT_FALSE(blob_channel_sender_proxy_->IsInClientCache(blob_id_)); | |
99 } | |
100 | |
101 TEST_F(BlobChannelSenderProxyTest, RedundantDeliver) { | |
102 EXPECT_CALL(mock_sender_, | |
103 PutBlob(blob_id_, BlobDataPtrEqualsString(kBlobPayload))); | |
104 EXPECT_CALL(mock_sender_, DeliverBlob(blob_id_)); | |
105 | |
106 blob_channel_sender_proxy_->PutBlob(blob_id_, | |
107 CreateBlobDataPtr(kBlobPayload)); | |
108 DeliverMessages(); | |
109 EXPECT_TRUE(blob_channel_sender_proxy_->IsInEngineCache(blob_id_)); | |
110 EXPECT_FALSE(blob_channel_sender_proxy_->IsInClientCache(blob_id_)); | |
111 | |
112 blob_channel_sender_proxy_->DeliverBlob(blob_id_); | |
113 DeliverMessages(); | |
114 EXPECT_TRUE(blob_channel_sender_proxy_->IsInEngineCache(blob_id_)); | |
115 EXPECT_TRUE(blob_channel_sender_proxy_->IsInClientCache(blob_id_)); | |
116 | |
117 blob_channel_sender_proxy_->DeliverBlob(blob_id_); | |
118 DeliverMessages(); | |
119 EXPECT_TRUE(blob_channel_sender_proxy_->IsInEngineCache(blob_id_)); | |
120 EXPECT_TRUE(blob_channel_sender_proxy_->IsInClientCache(blob_id_)); | |
121 } | |
122 } // namespace | |
123 } // namespace engine | |
124 } // namespace blimp | |
OLD | NEW |