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

Side by Side Diff: blimp/net/blob_channel/blob_channel_sender_unittest.cc

Issue 2056993003: Add Mojo IPC for seeding new Renderer with Browser's cached blob state. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blobchannel-master
Patch Set: STL containers yay Created 4 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 #include <memory> 6 #include <memory>
7 7
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "blimp/common/blob_cache/id_util.h"
9 #include "blimp/common/blob_cache/mock_blob_cache.h" 10 #include "blimp/common/blob_cache/mock_blob_cache.h"
10 #include "blimp/net/blob_channel/blob_channel_sender_impl.h" 11 #include "blimp/net/blob_channel/blob_channel_sender_impl.h"
11 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
15 using testing::_;
16 using testing::Pointee;
17 using testing::Return;
18 using testing::UnorderedElementsAre;
19
14 namespace blimp { 20 namespace blimp {
15 namespace { 21 namespace {
16 22
17 using testing::_;
18 using testing::Pointee;
19 using testing::Return;
20
21 const char kBlobId[] = "blob-1"; 23 const char kBlobId[] = "blob-1";
22 const char kBlobPayload[] = "blob-1-payload"; 24 const char kBlobPayload[] = "blob-1-payload";
25 const char kBlobId2[] = "blob-2";
23 26
24 // Helper function for creating a cache payload vector from a string. 27 // Helper function for creating a cache payload vector from a string.
25 BlobDataPtr CreatePayload(const std::string& input) { 28 BlobDataPtr CreatePayload(const std::string& input) {
26 BlobDataPtr output(new BlobData(input)); 29 BlobDataPtr output(new BlobData(input));
27 return output; 30 return output;
28 } 31 }
29 32
30 MATCHER_P(BlobDataEqual, expected, "") { 33 MATCHER_P(BlobDataEqual, expected, "") {
31 return expected->data == arg->data; 34 return expected->data == arg->data;
32 } 35 }
(...skipping 14 matching lines...) Expand all
47 blob_sender_( 50 blob_sender_(
48 new BlobChannelSenderImpl(base::WrapUnique(mock_cache_), 51 new BlobChannelSenderImpl(base::WrapUnique(mock_cache_),
49 base::WrapUnique(mock_delegate_))) {} 52 base::WrapUnique(mock_delegate_))) {}
50 ~BlobChannelSenderTest() override {} 53 ~BlobChannelSenderTest() override {}
51 54
52 testing::StrictMock<MockSenderDelegate>* mock_delegate_; 55 testing::StrictMock<MockSenderDelegate>* mock_delegate_;
53 testing::StrictMock<MockBlobCache>* mock_cache_; 56 testing::StrictMock<MockBlobCache>* mock_cache_;
54 std::unique_ptr<BlobChannelSender> blob_sender_; 57 std::unique_ptr<BlobChannelSender> blob_sender_;
55 }; 58 };
56 59
57 TEST_F(BlobChannelSenderTest, TestPutBlob) { 60 TEST_F(BlobChannelSenderTest, PutBlob) {
58 EXPECT_CALL(*mock_cache_, 61 EXPECT_CALL(*mock_cache_,
59 Put(kBlobId, BlobDataEqual(CreatePayload(kBlobPayload)))); 62 Put(kBlobId, BlobDataEqual(CreatePayload(kBlobPayload))));
60 EXPECT_CALL(*mock_cache_, Contains(kBlobId)).WillOnce(Return(false)); 63 EXPECT_CALL(*mock_cache_, Contains(kBlobId)).WillOnce(Return(false));
61 blob_sender_->PutBlob(kBlobId, CreatePayload(kBlobPayload)); 64 blob_sender_->PutBlob(kBlobId, CreatePayload(kBlobPayload));
62 } 65 }
63 66
64 TEST_F(BlobChannelSenderTest, TestPutBlobDuplicate) { 67 TEST_F(BlobChannelSenderTest, PutBlobDuplicate) {
65 EXPECT_CALL(*mock_cache_, Contains(kBlobId)).WillOnce(Return(true)); 68 EXPECT_CALL(*mock_cache_, Contains(kBlobId)).WillOnce(Return(true));
66 blob_sender_->PutBlob(kBlobId, CreatePayload(kBlobPayload)); 69 blob_sender_->PutBlob(kBlobId, CreatePayload(kBlobPayload));
67 } 70 }
68 71
69 TEST_F(BlobChannelSenderTest, TestPush) { 72 TEST_F(BlobChannelSenderTest, Push) {
70 auto payload = CreatePayload(kBlobPayload); 73 auto payload = CreatePayload(kBlobPayload);
71 EXPECT_CALL(*mock_delegate_, DeliverBlob(kBlobId, BlobDataEqual(payload))); 74 EXPECT_CALL(*mock_delegate_, DeliverBlob(kBlobId, BlobDataEqual(payload)));
72 EXPECT_CALL(*mock_cache_, Contains(kBlobId)) 75 EXPECT_CALL(*mock_cache_, Contains(kBlobId))
73 .WillOnce(Return(false)) 76 .WillOnce(Return(false))
74 .WillOnce(Return(true)); 77 .WillOnce(Return(true));
75 EXPECT_CALL(*mock_cache_, Put(kBlobId, BlobDataEqual(payload))); 78 EXPECT_CALL(*mock_cache_, Put(kBlobId, BlobDataEqual(payload)));
76 EXPECT_CALL(*mock_cache_, Get(kBlobId)).WillOnce(Return(payload)); 79 EXPECT_CALL(*mock_cache_, Get(kBlobId)).WillOnce(Return(payload));
77 blob_sender_->PutBlob(kBlobId, payload); 80 blob_sender_->PutBlob(kBlobId, payload);
78 blob_sender_->DeliverBlob(kBlobId); 81 blob_sender_->DeliverBlob(kBlobId);
79 } 82 }
80 83
84 TEST_F(BlobChannelSenderTest, GetCachedBlobIds) {
85 std::string blob_id1 = CalculateBlobId(kBlobId);
86 std::string blob_id2 = CalculateBlobId(kBlobId2);
87 BlobDataPtr blob_payload1 = CreatePayload(kBlobPayload);
88
89 EXPECT_CALL(*mock_cache_, Contains(blob_id1)).WillOnce(Return(true));
90 EXPECT_CALL(*mock_cache_, Get(blob_id1)).WillOnce(Return(blob_payload1));
91
92 std::vector<BlobId> cache_state;
93 cache_state.push_back(blob_id1);
94 cache_state.push_back(blob_id2);
95
96 EXPECT_CALL(*mock_cache_, GetCachedBlobIds()).WillOnce(Return(cache_state));
97 EXPECT_CALL(*mock_delegate_,
98 DeliverBlob(blob_id1, BlobDataEqual(blob_payload1)));
99
100 // Mark one of the blobs as delivered.
101 blob_sender_->DeliverBlob(blob_id1);
102
103 std::vector<BlobChannelSender::CacheStateEntry> actual =
104 blob_sender_->GetCachedBlobIds();
105 EXPECT_EQ(2u, actual.size());
106 EXPECT_EQ(blob_id1, actual[0].id);
107 EXPECT_TRUE(actual[0].was_delivered);
108 EXPECT_EQ(blob_id2, actual[1].id);
109 EXPECT_FALSE(actual[1].was_delivered);
110 }
111
81 } // namespace 112 } // namespace
82 } // namespace blimp 113 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/net/blob_channel/blob_channel_sender_impl.cc ('k') | blimp/net/blob_channel/mock_blob_channel_sender.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698