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

Side by Side Diff: content/browser/blob_storage/blob_async_builder_host_unittest.cc

Issue 2055053003: [BlobAsync] Disk support for blob storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added back transport controller test, small cleanups 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 2015 The Chromium Authors. All rights reserved. 1 //// Copyright 2015 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 "storage/browser/blob/blob_async_builder_host.h" 5 //#include "storage/browser/blob/blob_async_builder_host.h"
6 6 //
7 #include <stddef.h> 7 //#include <stddef.h>
8 #include <stdint.h> 8 //#include <stdint.h>
9 #include <string.h> 9 //#include <string.h>
10 10 //
11 #include "base/bind.h" 11 //#include "base/bind.h"
12 #include "base/logging.h" 12 //#include "base/logging.h"
13 #include "base/memory/shared_memory.h" 13 //#include "base/memory/shared_memory.h"
14 #include "base/run_loop.h" 14 //#include "base/run_loop.h"
15 #include "content/public/test/test_browser_thread_bundle.h" 15 //#include "content/public/test/test_browser_thread_bundle.h"
16 #include "storage/browser/blob/blob_data_builder.h" 16 //#include "storage/browser/blob/blob_data_builder.h"
17 #include "storage/browser/blob/blob_data_handle.h" 17 //#include "storage/browser/blob/blob_data_handle.h"
18 #include "storage/browser/blob/blob_storage_context.h" 18 //#include "storage/browser/blob/blob_storage_context.h"
19 #include "storage/common/blob_storage/blob_storage_constants.h" 19 //#include "storage/common/blob_storage/blob_storage_constants.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 //#include "testing/gtest/include/gtest/gtest.h"
21 21 //
22 namespace storage { 22 // namespace storage {
23 namespace { 23 // namespace {
24 const std::string kBlobUUID = "blobUUIDYAY"; 24 // const std::string kBlobUUID = "blobUUIDYAY";
25 const std::string kContentType = "content_type"; 25 // const std::string kContentType = "content_type";
26 const std::string kContentDisposition = "content_disposition"; 26 // const std::string kContentDisposition = "content_disposition";
27 const std::string kCompletedBlobUUID = "completedBlob"; 27 // const std::string kCompletedBlobUUID = "completedBlob";
28 const std::string kCompletedBlobData = "completedBlobData"; 28 // const std::string kCompletedBlobData = "completedBlobData";
29 29 //
30 const size_t kTestBlobStorageIPCThresholdBytes = 5; 30 // const size_t kTestBlobStorageIPCThresholdBytes = 5;
31 const size_t kTestBlobStorageMaxSharedMemoryBytes = 20; 31 // const size_t kTestBlobStorageMaxSharedMemoryBytes = 20;
32 const uint64_t kTestBlobStorageMaxFileSizeBytes = 100; 32 // const uint64_t kTestBlobStorageMaxFileSizeBytes = 100;
33 33 //
34 void PopulateBytes(char* bytes, size_t length) { 34 // void PopulateBytes(char* bytes, size_t length) {
35 for (size_t i = 0; i < length; i++) { 35 // for (size_t i = 0; i < length; i++) {
36 bytes[i] = static_cast<char>(i); 36 // bytes[i] = static_cast<char>(i);
37 } 37 // }
38 } 38 //}
39 39 //
40 void AddMemoryItem(size_t length, std::vector<DataElement>* out) { 40 // void AddMemoryItem(size_t length, std::vector<DataElement>* out) {
41 DataElement bytes; 41 // DataElement bytes;
42 bytes.SetToBytesDescription(length); 42 // bytes.SetToBytesDescription(length);
43 out->push_back(bytes); 43 // out->push_back(bytes);
44 } 44 //}
45 45 //
46 void AddShortcutMemoryItem(size_t length, std::vector<DataElement>* out) { 46 // void AddShortcutMemoryItem(size_t length, std::vector<DataElement>* out) {
47 DataElement bytes; 47 // DataElement bytes;
48 bytes.SetToAllocatedBytes(length); 48 // bytes.SetToAllocatedBytes(length);
49 PopulateBytes(bytes.mutable_bytes(), length); 49 // PopulateBytes(bytes.mutable_bytes(), length);
50 out->push_back(bytes); 50 // out->push_back(bytes);
51 } 51 //}
52 52 //
53 void AddShortcutMemoryItem(size_t length, BlobDataBuilder* out) { 53 // void AddShortcutMemoryItem(size_t length, BlobDataBuilder* out) {
54 DataElement bytes; 54 // DataElement bytes;
55 bytes.SetToAllocatedBytes(length); 55 // bytes.SetToAllocatedBytes(length);
56 PopulateBytes(bytes.mutable_bytes(), length); 56 // PopulateBytes(bytes.mutable_bytes(), length);
57 out->AppendData(bytes.bytes(), length); 57 // out->AppendData(bytes.bytes(), length);
58 } 58 //}
59 59 //
60 void AddBlobItem(std::vector<DataElement>* out) { 60 // void AddBlobItem(std::vector<DataElement>* out) {
61 DataElement blob; 61 // DataElement blob;
62 blob.SetToBlob(kCompletedBlobUUID); 62 // blob.SetToBlob(kCompletedBlobUUID);
63 out->push_back(blob); 63 // out->push_back(blob);
64 } 64 //}
65 } // namespace 65 //} // namespace
66 66 //
67 class BlobAsyncBuilderHostTest : public testing::Test { 67 // class BlobAsyncBuilderHostTest : public testing::Test {
68 public: 68 // public:
69 BlobAsyncBuilderHostTest() 69 // BlobAsyncBuilderHostTest()
70 : cancel_code_(IPCBlobCreationCancelCode::UNKNOWN), 70 // : cancel_code_(IPCBlobCreationCancelCode::UNKNOWN),
71 request_called_(false) {} 71 // request_called_(false) {}
72 ~BlobAsyncBuilderHostTest() override {} 72 // ~BlobAsyncBuilderHostTest() override {}
73 73 //
74 void SetUp() override { 74 // void SetUp() override {
75 cancel_code_ = IPCBlobCreationCancelCode::UNKNOWN; 75 // cancel_code_ = IPCBlobCreationCancelCode::UNKNOWN;
76 request_called_ = false; 76 // request_called_ = false;
77 requests_.clear(); 77 // requests_.clear();
78 memory_handles_.clear(); 78 // memory_handles_.clear();
79 host_.SetMemoryConstantsForTesting(kTestBlobStorageIPCThresholdBytes, 79 // host_.SetMemoryConstantsForTesting(kTestBlobStorageIPCThresholdBytes,
80 kTestBlobStorageMaxSharedMemoryBytes, 80 // kTestBlobStorageMaxSharedMemoryBytes,
81 kTestBlobStorageMaxFileSizeBytes); 81 // kTestBlobStorageMaxFileSizeBytes);
82 BlobDataBuilder builder(kCompletedBlobUUID); 82 // BlobDataBuilder builder(kCompletedBlobUUID);
83 builder.AppendData(kCompletedBlobData); 83 // builder.AppendData(kCompletedBlobData);
84 completed_blob_handle_ = context_.AddFinishedBlob(builder); 84 // completed_blob_handle_ = context_.AddFinishedBlob(builder);
85 completed_blob_uuid_set_ = {kCompletedBlobUUID}; 85 // completed_blob_uuid_set_ = {kCompletedBlobUUID};
86 } 86 // }
87 87 //
88 void RequestMemoryCallback( 88 // void RequestMemoryCallback(
89 std::unique_ptr<std::vector<storage::BlobItemBytesRequest>> requests, 89 // std::unique_ptr<std::vector<storage::BlobItemBytesRequest>> requests,
90 std::unique_ptr<std::vector<base::SharedMemoryHandle>> 90 // std::unique_ptr<std::vector<base::SharedMemoryHandle>>
91 shared_memory_handles, 91 // shared_memory_handles,
92 std::unique_ptr<std::vector<base::File>> files) { 92 // std::unique_ptr<std::vector<base::File>> files) {
93 requests_ = std::move(*requests); 93 // requests_ = std::move(*requests);
94 memory_handles_ = std::move(*shared_memory_handles); 94 // memory_handles_ = std::move(*shared_memory_handles);
95 request_called_ = true; 95 // request_called_ = true;
96 } 96 // }
97 97 //
98 BlobTransportResult BuildBlobAsync( 98 // BlobTransportResult BuildBlobAsync(
99 const std::vector<DataElement>& descriptions, 99 // const std::vector<DataElement>& descriptions,
100 const std::set<std::string>& referenced_blob_uuids, 100 // const std::set<std::string>& referenced_blob_uuids,
101 size_t memory_available) { 101 // size_t memory_available) {
102 request_called_ = false; 102 // request_called_ = false;
103 BlobTransportResult register_result = 103 // return host_.RegisterBlob(kBlobUUID, kContentType, kContentDisposition,
104 host_.RegisterBlobUUID(kBlobUUID, kContentType, kContentDisposition, 104 // descriptions, &context_);
105 referenced_blob_uuids, &context_); 105 // if (register_result != BlobTransportResult::DONE) {
106 if (register_result != BlobTransportResult::DONE) { 106 // return register_result;
107 return register_result; 107 // }
108 } 108 // return host_.StartBuildingBlob(
109 return host_.StartBuildingBlob( 109 // kBlobUUID, descriptions, memory_available, &context_,
110 kBlobUUID, descriptions, memory_available, &context_, 110 // base::Bind(&BlobAsyncBuilderHostTest::RequestMemoryCallback,
111 base::Bind(&BlobAsyncBuilderHostTest::RequestMemoryCallback, 111 // base::Unretained(this)));
112 base::Unretained(this))); 112 // }
113 } 113 //
114 114 // void DecrementBlobRefCount(const std::string& uuid) {
115 void DecrementBlobRefCount(const std::string& uuid) { 115 // context_.DecrementBlobRefCount(uuid);
116 context_.DecrementBlobRefCount(uuid); 116 // }
117 } 117 //
118 118 // bool IsBeingBuiltInContext(const std::string& uuid) {
119 bool IsBeingBuiltInContext(const std::string& uuid) { 119 // return context_.IsBeingBuilt(uuid);
120 return context_.IsBeingBuilt(uuid); 120 // }
121 } 121 //
122 122 // content::TestBrowserThreadBundle browser_thread_bundle_;
123 content::TestBrowserThreadBundle browser_thread_bundle_; 123 // BlobStorageContext context_;
124 BlobStorageContext context_; 124 // BlobAsyncBuilderHost host_;
125 BlobAsyncBuilderHost host_; 125 // IPCBlobCreationCancelCode cancel_code_;
126 IPCBlobCreationCancelCode cancel_code_; 126 //
127 127 // bool request_called_;
128 bool request_called_; 128 // std::vector<storage::BlobItemBytesRequest> requests_;
129 std::vector<storage::BlobItemBytesRequest> requests_; 129 // std::vector<base::SharedMemoryHandle> memory_handles_;
130 std::vector<base::SharedMemoryHandle> memory_handles_; 130 // std::set<std::string> completed_blob_uuid_set_;
131 std::set<std::string> completed_blob_uuid_set_; 131 //
132 132 // std::unique_ptr<BlobDataHandle> completed_blob_handle_;
133 std::unique_ptr<BlobDataHandle> completed_blob_handle_; 133 //};
134 }; 134 //
135 135 //// The 'shortcut' method is when the data is included in the initial IPCs and
136 // The 'shortcut' method is when the data is included in the initial IPCs and 136 //// the browser uses that instead of requesting the memory.
137 // the browser uses that instead of requesting the memory. 137 // TEST_F(BlobAsyncBuilderHostTest, TestShortcut) {
138 TEST_F(BlobAsyncBuilderHostTest, TestShortcut) { 138 // std::vector<DataElement> descriptions;
139 std::vector<DataElement> descriptions; 139 //
140 140 // AddShortcutMemoryItem(10, &descriptions);
141 AddShortcutMemoryItem(10, &descriptions); 141 // AddBlobItem(&descriptions);
142 AddBlobItem(&descriptions); 142 // AddShortcutMemoryItem(5000, &descriptions);
143 AddShortcutMemoryItem(5000, &descriptions); 143 //
144 144 // BlobDataBuilder expected(kBlobUUID);
145 BlobDataBuilder expected(kBlobUUID); 145 // expected.set_content_type(kContentType);
146 expected.set_content_type(kContentType); 146 // expected.set_content_disposition(kContentDisposition);
147 expected.set_content_disposition(kContentDisposition); 147 // AddShortcutMemoryItem(10, &expected);
148 AddShortcutMemoryItem(10, &expected); 148 // expected.AppendData(kCompletedBlobData);
149 expected.AppendData(kCompletedBlobData); 149 // AddShortcutMemoryItem(5000, &expected);
150 AddShortcutMemoryItem(5000, &expected); 150 //
151 151 // EXPECT_EQ(BlobTransportResult::DONE,
152 EXPECT_EQ(BlobTransportResult::DONE, 152 // BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5010));
153 BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5010)); 153 //
154 154 // EXPECT_FALSE(request_called_);
155 EXPECT_FALSE(request_called_); 155 // EXPECT_EQ(0u, host_.blob_building_count());
156 EXPECT_EQ(0u, host_.blob_building_count()); 156 // std::unique_ptr<BlobDataHandle> handle =
157 std::unique_ptr<BlobDataHandle> handle = 157 // context_.GetBlobDataFromUUID(kBlobUUID);
158 context_.GetBlobDataFromUUID(kBlobUUID); 158 // EXPECT_FALSE(handle->IsBeingBuilt());
159 EXPECT_FALSE(handle->IsBeingBuilt()); 159 // EXPECT_FALSE(handle->IsBroken());
160 EXPECT_FALSE(handle->IsBroken()); 160 // std::unique_ptr<BlobDataSnapshot> data = handle->CreateSnapshot();
161 std::unique_ptr<BlobDataSnapshot> data = handle->CreateSnapshot(); 161 // EXPECT_EQ(expected, *data);
162 EXPECT_EQ(expected, *data); 162 // data.reset();
163 data.reset(); 163 // handle.reset();
164 handle.reset(); 164 // base::RunLoop().RunUntilIdle();
165 base::RunLoop().RunUntilIdle(); 165 //};
166 }; 166 //
167 167 // TEST_F(BlobAsyncBuilderHostTest, TestShortcutNoRoom) {
168 TEST_F(BlobAsyncBuilderHostTest, TestShortcutNoRoom) { 168 // std::vector<DataElement> descriptions;
169 std::vector<DataElement> descriptions; 169 //
170 170 // AddShortcutMemoryItem(10, &descriptions);
171 AddShortcutMemoryItem(10, &descriptions); 171 // AddBlobItem(&descriptions);
172 AddBlobItem(&descriptions); 172 // AddShortcutMemoryItem(5000, &descriptions);
173 AddShortcutMemoryItem(5000, &descriptions); 173 //
174 174 // EXPECT_EQ(BlobTransportResult::CANCEL_MEMORY_FULL,
175 EXPECT_EQ(BlobTransportResult::CANCEL_MEMORY_FULL, 175 // BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5000));
176 BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5000)); 176 //
177 177 // EXPECT_FALSE(request_called_);
178 EXPECT_FALSE(request_called_); 178 // EXPECT_EQ(0u, host_.blob_building_count());
179 EXPECT_EQ(0u, host_.blob_building_count()); 179 //};
180 }; 180 //
181 181 // TEST_F(BlobAsyncBuilderHostTest, TestSingleSharedMemRequest) {
182 TEST_F(BlobAsyncBuilderHostTest, TestSingleSharedMemRequest) { 182 // std::vector<DataElement> descriptions;
183 std::vector<DataElement> descriptions; 183 // const size_t kSize = kTestBlobStorageIPCThresholdBytes + 1;
184 const size_t kSize = kTestBlobStorageIPCThresholdBytes + 1; 184 // AddMemoryItem(kSize, &descriptions);
185 AddMemoryItem(kSize, &descriptions); 185 //
186 186 // EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES,
187 EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES, 187 // BuildBlobAsync(descriptions, std::set<std::string>(),
188 BuildBlobAsync(descriptions, std::set<std::string>(), 188 // kTestBlobStorageIPCThresholdBytes + 1));
189 kTestBlobStorageIPCThresholdBytes + 1)); 189 //
190 190 // EXPECT_TRUE(request_called_);
191 EXPECT_TRUE(request_called_); 191 // EXPECT_EQ(1u, host_.blob_building_count());
192 EXPECT_EQ(1u, host_.blob_building_count()); 192 // ASSERT_EQ(1u, requests_.size());
193 ASSERT_EQ(1u, requests_.size()); 193 // request_called_ = false;
194 request_called_ = false; 194 //
195 195 // EXPECT_EQ(
196 EXPECT_EQ( 196 // BlobItemBytesRequest::CreateSharedMemoryRequest(0, 0, 0, kSize, 0, 0),
197 BlobItemBytesRequest::CreateSharedMemoryRequest(0, 0, 0, kSize, 0, 0), 197 // requests_.at(0));
198 requests_.at(0)); 198 //};
199 }; 199 //
200 200 // TEST_F(BlobAsyncBuilderHostTest, TestMultipleSharedMemRequests) {
201 TEST_F(BlobAsyncBuilderHostTest, TestMultipleSharedMemRequests) { 201 // std::vector<DataElement> descriptions;
202 std::vector<DataElement> descriptions; 202 // const size_t kSize = kTestBlobStorageMaxSharedMemoryBytes + 1;
203 const size_t kSize = kTestBlobStorageMaxSharedMemoryBytes + 1; 203 // const char kFirstBlockByte = 7;
204 const char kFirstBlockByte = 7; 204 // const char kSecondBlockByte = 19;
205 const char kSecondBlockByte = 19; 205 // AddMemoryItem(kSize, &descriptions);
206 AddMemoryItem(kSize, &descriptions); 206 //
207 207 // BlobDataBuilder expected(kBlobUUID);
208 BlobDataBuilder expected(kBlobUUID); 208 // expected.set_content_type(kContentType);
209 expected.set_content_type(kContentType); 209 // expected.set_content_disposition(kContentDisposition);
210 expected.set_content_disposition(kContentDisposition); 210 // char data[kSize];
211 char data[kSize]; 211 // memset(data, kFirstBlockByte, kTestBlobStorageMaxSharedMemoryBytes);
212 memset(data, kFirstBlockByte, kTestBlobStorageMaxSharedMemoryBytes); 212 // expected.AppendData(data, kTestBlobStorageMaxSharedMemoryBytes);
213 expected.AppendData(data, kTestBlobStorageMaxSharedMemoryBytes); 213 // expected.AppendData(&kSecondBlockByte, 1);
214 expected.AppendData(&kSecondBlockByte, 1); 214 //
215 215 // EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES,
216 EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES, 216 // BuildBlobAsync(descriptions, std::set<std::string>(),
217 BuildBlobAsync(descriptions, std::set<std::string>(), 217 // kTestBlobStorageMaxSharedMemoryBytes + 1));
218 kTestBlobStorageMaxSharedMemoryBytes + 1)); 218 //
219 219 // EXPECT_TRUE(request_called_);
220 EXPECT_TRUE(request_called_); 220 // EXPECT_EQ(1u, host_.blob_building_count());
221 EXPECT_EQ(1u, host_.blob_building_count()); 221 // ASSERT_EQ(1u, requests_.size());
222 ASSERT_EQ(1u, requests_.size()); 222 // request_called_ = false;
223 request_called_ = false; 223 //
224 224 // // We need to grab a duplicate handle so we can have two blocks open at the
225 // We need to grab a duplicate handle so we can have two blocks open at the 225 // // same time.
226 // same time. 226 // base::SharedMemoryHandle handle =
227 base::SharedMemoryHandle handle = 227 // base::SharedMemory::DuplicateHandle(memory_handles_.at(0));
228 base::SharedMemory::DuplicateHandle(memory_handles_.at(0)); 228 // EXPECT_TRUE(base::SharedMemory::IsHandleValid(handle));
229 EXPECT_TRUE(base::SharedMemory::IsHandleValid(handle)); 229 // base::SharedMemory shared_memory(handle, false);
230 base::SharedMemory shared_memory(handle, false); 230 // EXPECT_TRUE(shared_memory.Map(kTestBlobStorageMaxSharedMemoryBytes));
231 EXPECT_TRUE(shared_memory.Map(kTestBlobStorageMaxSharedMemoryBytes)); 231 //
232 232 // EXPECT_EQ(BlobItemBytesRequest::CreateSharedMemoryRequest(
233 EXPECT_EQ(BlobItemBytesRequest::CreateSharedMemoryRequest( 233 // 0, 0, 0, kTestBlobStorageMaxSharedMemoryBytes, 0, 0),
234 0, 0, 0, kTestBlobStorageMaxSharedMemoryBytes, 0, 0), 234 // requests_.at(0));
235 requests_.at(0)); 235 //
236 236 // memset(shared_memory.memory(), kFirstBlockByte,
237 memset(shared_memory.memory(), kFirstBlockByte, 237 // kTestBlobStorageMaxSharedMemoryBytes);
238 kTestBlobStorageMaxSharedMemoryBytes); 238 //
239 239 // BlobItemBytesResponse response(0);
240 BlobItemBytesResponse response(0); 240 // std::vector<BlobItemBytesResponse> responses = {response};
241 std::vector<BlobItemBytesResponse> responses = {response}; 241 // EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES,
242 EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES, 242 // host_.OnMemoryResponses(kBlobUUID, responses, &context_));
243 host_.OnMemoryResponses(kBlobUUID, responses, &context_)); 243 //
244 244 // EXPECT_TRUE(request_called_);
245 EXPECT_TRUE(request_called_); 245 // EXPECT_EQ(1u, host_.blob_building_count());
246 EXPECT_EQ(1u, host_.blob_building_count()); 246 // ASSERT_EQ(1u, requests_.size());
247 ASSERT_EQ(1u, requests_.size()); 247 // request_called_ = false;
248 request_called_ = false; 248 //
249 249 // EXPECT_EQ(BlobItemBytesRequest::CreateSharedMemoryRequest(
250 EXPECT_EQ(BlobItemBytesRequest::CreateSharedMemoryRequest( 250 // 1, 0, kTestBlobStorageMaxSharedMemoryBytes, 1, 0, 0),
251 1, 0, kTestBlobStorageMaxSharedMemoryBytes, 1, 0, 0), 251 // requests_.at(0));
252 requests_.at(0)); 252 //
253 253 // memset(shared_memory.memory(), kSecondBlockByte, 1);
254 memset(shared_memory.memory(), kSecondBlockByte, 1); 254 //
255 255 // response.request_number = 1;
256 response.request_number = 1; 256 // responses[0] = response;
257 responses[0] = response; 257 // EXPECT_EQ(BlobTransportResult::DONE,
258 EXPECT_EQ(BlobTransportResult::DONE, 258 // host_.OnMemoryResponses(kBlobUUID, responses, &context_));
259 host_.OnMemoryResponses(kBlobUUID, responses, &context_)); 259 // EXPECT_FALSE(request_called_);
260 EXPECT_FALSE(request_called_); 260 // EXPECT_EQ(0u, host_.blob_building_count());
261 EXPECT_EQ(0u, host_.blob_building_count()); 261 // std::unique_ptr<BlobDataHandle> blob_handle =
262 std::unique_ptr<BlobDataHandle> blob_handle = 262 // context_.GetBlobDataFromUUID(kBlobUUID);
263 context_.GetBlobDataFromUUID(kBlobUUID); 263 // EXPECT_FALSE(blob_handle->IsBeingBuilt());
264 EXPECT_FALSE(blob_handle->IsBeingBuilt()); 264 // EXPECT_FALSE(blob_handle->IsBroken());
265 EXPECT_FALSE(blob_handle->IsBroken()); 265 // std::unique_ptr<BlobDataSnapshot> blob_data = blob_handle->CreateSnapshot();
266 std::unique_ptr<BlobDataSnapshot> blob_data = blob_handle->CreateSnapshot(); 266 // EXPECT_EQ(expected, *blob_data);
267 EXPECT_EQ(expected, *blob_data); 267 //};
268 }; 268 //
269 269 // TEST_F(BlobAsyncBuilderHostTest, TestBasicIPCAndStopBuilding) {
270 TEST_F(BlobAsyncBuilderHostTest, TestBasicIPCAndStopBuilding) { 270 // std::vector<DataElement> descriptions;
271 std::vector<DataElement> descriptions; 271 //
272 272 // AddMemoryItem(2, &descriptions);
273 AddMemoryItem(2, &descriptions); 273 // AddBlobItem(&descriptions);
274 AddBlobItem(&descriptions); 274 // AddMemoryItem(2, &descriptions);
275 AddMemoryItem(2, &descriptions); 275 //
276 276 // BlobDataBuilder expected(kBlobUUID);
277 BlobDataBuilder expected(kBlobUUID); 277 // expected.set_content_type(kContentType);
278 expected.set_content_type(kContentType); 278 // expected.set_content_disposition(kContentDisposition);
279 expected.set_content_disposition(kContentDisposition); 279 // AddShortcutMemoryItem(2, &expected);
280 AddShortcutMemoryItem(2, &expected); 280 // expected.AppendData(kCompletedBlobData);
281 expected.AppendData(kCompletedBlobData); 281 // AddShortcutMemoryItem(2, &expected);
282 AddShortcutMemoryItem(2, &expected); 282 //
283 283 // EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES,
284 EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES, 284 // BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5010));
285 BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5010)); 285 // host_.CancelBuildingBlob(kBlobUUID, IPCBlobCreationCancelCode::UNKNOWN,
286 host_.CancelBuildingBlob(kBlobUUID, IPCBlobCreationCancelCode::UNKNOWN, 286 // &context_);
287 &context_); 287 //
288 288 // // Check that we're broken, and then remove the blob.
289 // Check that we're broken, and then remove the blob. 289 // std::unique_ptr<BlobDataHandle> blob_handle =
290 std::unique_ptr<BlobDataHandle> blob_handle = 290 // context_.GetBlobDataFromUUID(kBlobUUID);
291 context_.GetBlobDataFromUUID(kBlobUUID); 291 // EXPECT_FALSE(blob_handle->IsBeingBuilt());
292 EXPECT_FALSE(blob_handle->IsBeingBuilt()); 292 // EXPECT_TRUE(blob_handle->IsBroken());
293 EXPECT_TRUE(blob_handle->IsBroken()); 293 // blob_handle.reset();
294 blob_handle.reset(); 294 // DecrementBlobRefCount(kBlobUUID);
295 DecrementBlobRefCount(kBlobUUID); 295 // base::RunLoop().RunUntilIdle();
296 base::RunLoop().RunUntilIdle(); 296 // blob_handle = context_.GetBlobDataFromUUID(kBlobUUID);
297 blob_handle = context_.GetBlobDataFromUUID(kBlobUUID); 297 // EXPECT_FALSE(blob_handle.get());
298 EXPECT_FALSE(blob_handle.get()); 298 //
299 299 // // This should succeed because we've removed all references to the blob.
300 // This should succeed because we've removed all references to the blob. 300 // EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES,
301 EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES, 301 // BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5010));
302 BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5010)); 302 //
303 303 // EXPECT_TRUE(request_called_);
304 EXPECT_TRUE(request_called_); 304 // EXPECT_EQ(1u, host_.blob_building_count());
305 EXPECT_EQ(1u, host_.blob_building_count()); 305 // request_called_ = false;
306 request_called_ = false; 306 //
307 307 // BlobItemBytesResponse response1(0);
308 BlobItemBytesResponse response1(0); 308 // PopulateBytes(response1.allocate_mutable_data(2), 2);
309 PopulateBytes(response1.allocate_mutable_data(2), 2); 309 // BlobItemBytesResponse response2(1);
310 BlobItemBytesResponse response2(1); 310 // PopulateBytes(response2.allocate_mutable_data(2), 2);
311 PopulateBytes(response2.allocate_mutable_data(2), 2); 311 // std::vector<BlobItemBytesResponse> responses = {response1, response2};
312 std::vector<BlobItemBytesResponse> responses = {response1, response2}; 312 //
313 313 // EXPECT_EQ(BlobTransportResult::DONE,
314 EXPECT_EQ(BlobTransportResult::DONE, 314 // host_.OnMemoryResponses(kBlobUUID, responses, &context_));
315 host_.OnMemoryResponses(kBlobUUID, responses, &context_)); 315 // EXPECT_FALSE(request_called_);
316 EXPECT_FALSE(request_called_); 316 // EXPECT_EQ(0u, host_.blob_building_count());
317 EXPECT_EQ(0u, host_.blob_building_count()); 317 // blob_handle = context_.GetBlobDataFromUUID(kBlobUUID);
318 blob_handle = context_.GetBlobDataFromUUID(kBlobUUID); 318 // EXPECT_FALSE(blob_handle->IsBeingBuilt());
319 EXPECT_FALSE(blob_handle->IsBeingBuilt()); 319 // EXPECT_FALSE(blob_handle->IsBroken());
320 EXPECT_FALSE(blob_handle->IsBroken()); 320 // std::unique_ptr<BlobDataSnapshot> blob_data = blob_handle->CreateSnapshot();
321 std::unique_ptr<BlobDataSnapshot> blob_data = blob_handle->CreateSnapshot(); 321 // EXPECT_EQ(expected, *blob_data);
322 EXPECT_EQ(expected, *blob_data); 322 //};
323 }; 323 //
324 324 // TEST_F(BlobAsyncBuilderHostTest, TestBreakingAllBuilding) {
325 TEST_F(BlobAsyncBuilderHostTest, TestBreakingAllBuilding) { 325 // const std::string& kBlob1 = "blob1";
326 const std::string& kBlob1 = "blob1"; 326 // const std::string& kBlob2 = "blob2";
327 const std::string& kBlob2 = "blob2"; 327 // const std::string& kBlob3 = "blob3";
328 const std::string& kBlob3 = "blob3"; 328 //
329 329 // // Register blobs.
330 // Register blobs. 330 // EXPECT_EQ(BlobTransportResult::DONE,
331 EXPECT_EQ(BlobTransportResult::DONE, 331 // host_.RegisterBlobUUID(kBlob1, kContentType, kContentDisposition,
332 host_.RegisterBlobUUID(kBlob1, kContentType, kContentDisposition, 332 // std::set<std::string>(), &context_));
333 std::set<std::string>(), &context_)); 333 // EXPECT_EQ(BlobTransportResult::DONE,
334 EXPECT_EQ(BlobTransportResult::DONE, 334 // host_.RegisterBlobUUID(kBlob2, kContentType, kContentDisposition,
335 host_.RegisterBlobUUID(kBlob2, kContentType, kContentDisposition, 335 // std::set<std::string>(), &context_));
336 std::set<std::string>(), &context_)); 336 // EXPECT_EQ(BlobTransportResult::DONE,
337 EXPECT_EQ(BlobTransportResult::DONE, 337 // host_.RegisterBlobUUID(kBlob3, kContentType, kContentDisposition,
338 host_.RegisterBlobUUID(kBlob3, kContentType, kContentDisposition, 338 // std::set<std::string>(), &context_));
339 std::set<std::string>(), &context_)); 339 //
340 340 // // Start building one of them.
341 // Start building one of them. 341 // std::vector<DataElement> descriptions;
342 std::vector<DataElement> descriptions; 342 // AddMemoryItem(2, &descriptions);
343 AddMemoryItem(2, &descriptions); 343 // EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES,
344 EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES, 344 // host_.StartBuildingBlob(
345 host_.StartBuildingBlob( 345 // kBlob1, descriptions, 2, &context_,
346 kBlob1, descriptions, 2, &context_, 346 // base::Bind(&BlobAsyncBuilderHostTest::RequestMemoryCallback,
347 base::Bind(&BlobAsyncBuilderHostTest::RequestMemoryCallback, 347 // base::Unretained(this))));
348 base::Unretained(this)))); 348 // EXPECT_TRUE(request_called_);
349 EXPECT_TRUE(request_called_); 349 //
350 350 // std::unique_ptr<BlobDataHandle> blob_handle1 =
351 std::unique_ptr<BlobDataHandle> blob_handle1 = 351 // context_.GetBlobDataFromUUID(kBlob1);
352 context_.GetBlobDataFromUUID(kBlob1); 352 // std::unique_ptr<BlobDataHandle> blob_handle2 =
353 std::unique_ptr<BlobDataHandle> blob_handle2 = 353 // context_.GetBlobDataFromUUID(kBlob2);
354 context_.GetBlobDataFromUUID(kBlob2); 354 // std::unique_ptr<BlobDataHandle> blob_handle3 =
355 std::unique_ptr<BlobDataHandle> blob_handle3 = 355 // context_.GetBlobDataFromUUID(kBlob2);
356 context_.GetBlobDataFromUUID(kBlob2); 356 // EXPECT_TRUE(blob_handle1->IsBeingBuilt() && blob_handle2->IsBeingBuilt() &&
357 EXPECT_TRUE(blob_handle1->IsBeingBuilt() && blob_handle2->IsBeingBuilt() && 357 // blob_handle3->IsBeingBuilt());
358 blob_handle3->IsBeingBuilt()); 358 // EXPECT_FALSE(blob_handle1->IsBroken() || blob_handle2->IsBroken() ||
359 EXPECT_FALSE(blob_handle1->IsBroken() || blob_handle2->IsBroken() || 359 // blob_handle3->IsBroken());
360 blob_handle3->IsBroken()); 360 //
361 361 // host_.CancelAll(&context_);
362 host_.CancelAll(&context_); 362 //
363 363 // EXPECT_FALSE(blob_handle1->IsBeingBuilt() || blob_handle2->IsBeingBuilt() ||
364 EXPECT_FALSE(blob_handle1->IsBeingBuilt() || blob_handle2->IsBeingBuilt() || 364 // blob_handle3->IsBeingBuilt());
365 blob_handle3->IsBeingBuilt()); 365 // EXPECT_TRUE(blob_handle1->IsBroken() && blob_handle2->IsBroken() &&
366 EXPECT_TRUE(blob_handle1->IsBroken() && blob_handle2->IsBroken() && 366 // blob_handle3->IsBroken());
367 blob_handle3->IsBroken()); 367 // blob_handle1.reset();
368 blob_handle1.reset(); 368 // blob_handle2.reset();
369 blob_handle2.reset(); 369 // blob_handle3.reset();
370 blob_handle3.reset(); 370 // base::RunLoop().RunUntilIdle();
371 base::RunLoop().RunUntilIdle(); 371 //};
372 }; 372 //
373 373 // TEST_F(BlobAsyncBuilderHostTest, TestBadIPCs) {
374 TEST_F(BlobAsyncBuilderHostTest, TestBadIPCs) { 374 // std::vector<DataElement> descriptions;
375 std::vector<DataElement> descriptions; 375 //
376 376 // // Test reusing same blob uuid.
377 // Test reusing same blob uuid. 377 // AddMemoryItem(10, &descriptions);
378 AddMemoryItem(10, &descriptions); 378 // AddBlobItem(&descriptions);
379 AddBlobItem(&descriptions); 379 // AddMemoryItem(5000, &descriptions);
380 AddMemoryItem(5000, &descriptions); 380 // EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES,
381 EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES, 381 // BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5010));
382 BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5010)); 382 // EXPECT_EQ(BlobTransportResult::BAD_IPC,
383 EXPECT_EQ(BlobTransportResult::BAD_IPC, 383 // BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5010));
384 BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5010)); 384 // EXPECT_FALSE(request_called_);
385 EXPECT_FALSE(request_called_); 385 // host_.CancelBuildingBlob(kBlobUUID, IPCBlobCreationCancelCode::UNKNOWN,
386 host_.CancelBuildingBlob(kBlobUUID, IPCBlobCreationCancelCode::UNKNOWN, 386 // &context_);
387 &context_); 387 // base::RunLoop().RunUntilIdle();
388 base::RunLoop().RunUntilIdle(); 388 // DecrementBlobRefCount(kBlobUUID);
389 DecrementBlobRefCount(kBlobUUID); 389 // EXPECT_FALSE(context_.GetBlobDataFromUUID(kBlobUUID).get());
390 EXPECT_FALSE(context_.GetBlobDataFromUUID(kBlobUUID).get()); 390 //
391 391 // // Test we're an error if we get a bad uuid for responses.
392 // Test we're an error if we get a bad uuid for responses. 392 // BlobItemBytesResponse response(0);
393 BlobItemBytesResponse response(0); 393 // std::vector<BlobItemBytesResponse> responses = {response};
394 std::vector<BlobItemBytesResponse> responses = {response}; 394 // EXPECT_EQ(BlobTransportResult::BAD_IPC,
395 EXPECT_EQ(BlobTransportResult::BAD_IPC, 395 // host_.OnMemoryResponses(kBlobUUID, responses, &context_));
396 host_.OnMemoryResponses(kBlobUUID, responses, &context_)); 396 //
397 397 // // Test empty responses.
398 // Test empty responses. 398 // responses.clear();
399 responses.clear(); 399 // EXPECT_EQ(BlobTransportResult::BAD_IPC,
400 EXPECT_EQ(BlobTransportResult::BAD_IPC, 400 // host_.OnMemoryResponses(kBlobUUID, responses, &context_));
401 host_.OnMemoryResponses(kBlobUUID, responses, &context_)); 401 //
402 402 // // Test response problems below here.
403 // Test response problems below here. 403 // descriptions.clear();
404 descriptions.clear(); 404 // AddMemoryItem(2, &descriptions);
405 AddMemoryItem(2, &descriptions); 405 // AddBlobItem(&descriptions);
406 AddBlobItem(&descriptions); 406 // AddMemoryItem(2, &descriptions);
407 AddMemoryItem(2, &descriptions); 407 // EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES,
408 EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES, 408 // BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5010));
409 BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5010)); 409 //
410 410 // // Invalid request number.
411 // Invalid request number. 411 // BlobItemBytesResponse response1(3);
412 BlobItemBytesResponse response1(3); 412 // PopulateBytes(response1.allocate_mutable_data(2), 2);
413 PopulateBytes(response1.allocate_mutable_data(2), 2); 413 // responses = {response1};
414 responses = {response1}; 414 // EXPECT_EQ(BlobTransportResult::BAD_IPC,
415 EXPECT_EQ(BlobTransportResult::BAD_IPC, 415 // host_.OnMemoryResponses(kBlobUUID, responses, &context_));
416 host_.OnMemoryResponses(kBlobUUID, responses, &context_)); 416 // EXPECT_TRUE(context_.GetBlobDataFromUUID(kBlobUUID)->IsBroken());
417 EXPECT_TRUE(context_.GetBlobDataFromUUID(kBlobUUID)->IsBroken()); 417 // DecrementBlobRefCount(kBlobUUID);
418 DecrementBlobRefCount(kBlobUUID); 418 // base::RunLoop().RunUntilIdle();
419 base::RunLoop().RunUntilIdle(); 419 //
420 420 // // Duplicate request number responses.
421 // Duplicate request number responses. 421 // EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES,
422 EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES, 422 // BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5010));
423 BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5010)); 423 // response1.request_number = 0;
424 response1.request_number = 0; 424 // BlobItemBytesResponse response2(0);
425 BlobItemBytesResponse response2(0); 425 // PopulateBytes(response2.allocate_mutable_data(2), 2);
426 PopulateBytes(response2.allocate_mutable_data(2), 2); 426 // responses = {response1, response2};
427 responses = {response1, response2}; 427 // EXPECT_EQ(BlobTransportResult::BAD_IPC,
428 EXPECT_EQ(BlobTransportResult::BAD_IPC, 428 // host_.OnMemoryResponses(kBlobUUID, responses, &context_));
429 host_.OnMemoryResponses(kBlobUUID, responses, &context_)); 429 // EXPECT_TRUE(context_.GetBlobDataFromUUID(kBlobUUID)->IsBroken());
430 EXPECT_TRUE(context_.GetBlobDataFromUUID(kBlobUUID)->IsBroken()); 430 // DecrementBlobRefCount(kBlobUUID);
431 DecrementBlobRefCount(kBlobUUID); 431 // base::RunLoop().RunUntilIdle();
432 base::RunLoop().RunUntilIdle(); 432 //};
433 }; 433 //
434 434 // TEST_F(BlobAsyncBuilderHostTest, WaitOnReferencedBlob) {
435 TEST_F(BlobAsyncBuilderHostTest, WaitOnReferencedBlob) { 435 // const std::string& kBlob1 = "blob1";
436 const std::string& kBlob1 = "blob1"; 436 // const std::string& kBlob2 = "blob2";
437 const std::string& kBlob2 = "blob2"; 437 // const std::string& kBlob3 = "blob3";
438 const std::string& kBlob3 = "blob3"; 438 //
439 439 // // Register blobs.
440 // Register blobs. 440 // EXPECT_EQ(BlobTransportResult::DONE,
441 EXPECT_EQ(BlobTransportResult::DONE, 441 // host_.RegisterBlobUUID(kBlob1, kContentType, kContentDisposition,
442 host_.RegisterBlobUUID(kBlob1, kContentType, kContentDisposition, 442 // std::set<std::string>(), &context_));
443 std::set<std::string>(), &context_)); 443 // EXPECT_EQ(BlobTransportResult::DONE,
444 EXPECT_EQ(BlobTransportResult::DONE, 444 // host_.RegisterBlobUUID(kBlob2, kContentType, kContentDisposition,
445 host_.RegisterBlobUUID(kBlob2, kContentType, kContentDisposition, 445 // std::set<std::string>(), &context_));
446 std::set<std::string>(), &context_)); 446 // EXPECT_EQ(BlobTransportResult::DONE,
447 EXPECT_EQ(BlobTransportResult::DONE, 447 // host_.RegisterBlobUUID(kBlob3, kContentType, kContentDisposition,
448 host_.RegisterBlobUUID(kBlob3, kContentType, kContentDisposition, 448 // {kBlob1, kBlob2}, &context_));
449 {kBlob1, kBlob2}, &context_)); 449 //
450 450 // // Finish the third one, with a reference to the first and second blob.
451 // Finish the third one, with a reference to the first and second blob. 451 // std::vector<DataElement> descriptions;
452 std::vector<DataElement> descriptions; 452 // AddShortcutMemoryItem(2, &descriptions);
453 AddShortcutMemoryItem(2, &descriptions); 453 // DataElement element;
454 DataElement element; 454 // element.SetToBlob(kBlob1);
455 element.SetToBlob(kBlob1); 455 // descriptions.push_back(element);
456 descriptions.push_back(element); 456 // element.SetToBlob(kBlob2);
457 element.SetToBlob(kBlob2); 457 // descriptions.push_back(element);
458 descriptions.push_back(element); 458 //
459 459 // // Finish the third, but we should still be 'building' it.
460 // Finish the third, but we should still be 'building' it. 460 // EXPECT_EQ(BlobTransportResult::DONE,
461 EXPECT_EQ(BlobTransportResult::DONE, 461 // host_.StartBuildingBlob(
462 host_.StartBuildingBlob( 462 // kBlob3, descriptions, 2, &context_,
463 kBlob3, descriptions, 2, &context_, 463 // base::Bind(&BlobAsyncBuilderHostTest::RequestMemoryCallback,
464 base::Bind(&BlobAsyncBuilderHostTest::RequestMemoryCallback, 464 // base::Unretained(this))));
465 base::Unretained(this)))); 465 // EXPECT_FALSE(request_called_);
466 EXPECT_FALSE(request_called_); 466 // EXPECT_TRUE(host_.IsBeingBuilt(kBlob3));
467 EXPECT_TRUE(host_.IsBeingBuilt(kBlob3)); 467 // EXPECT_TRUE(IsBeingBuiltInContext(kBlob3));
468 EXPECT_TRUE(IsBeingBuiltInContext(kBlob3)); 468 //
469 469 // // Finish the first.
470 // Finish the first. 470 // descriptions.clear();
471 descriptions.clear(); 471 // AddShortcutMemoryItem(2, &descriptions);
472 AddShortcutMemoryItem(2, &descriptions); 472 // EXPECT_EQ(BlobTransportResult::DONE,
473 EXPECT_EQ(BlobTransportResult::DONE, 473 // host_.StartBuildingBlob(
474 host_.StartBuildingBlob( 474 // kBlob1, descriptions, 2, &context_,
475 kBlob1, descriptions, 2, &context_, 475 // base::Bind(&BlobAsyncBuilderHostTest::RequestMemoryCallback,
476 base::Bind(&BlobAsyncBuilderHostTest::RequestMemoryCallback, 476 // base::Unretained(this))));
477 base::Unretained(this)))); 477 // EXPECT_FALSE(request_called_);
478 EXPECT_FALSE(request_called_); 478 // EXPECT_FALSE(host_.IsBeingBuilt(kBlob1));
479 EXPECT_FALSE(host_.IsBeingBuilt(kBlob1)); 479 // EXPECT_FALSE(IsBeingBuiltInContext(kBlob1));
480 EXPECT_FALSE(IsBeingBuiltInContext(kBlob1)); 480 // EXPECT_TRUE(context_.GetBlobDataFromUUID(kBlob1));
481 EXPECT_TRUE(context_.GetBlobDataFromUUID(kBlob1)); 481 //
482 482 // // Run the message loop so we propogate the construction complete callbacks.
483 // Run the message loop so we propogate the construction complete callbacks. 483 // base::RunLoop().RunUntilIdle();
484 base::RunLoop().RunUntilIdle(); 484 // // Verify we're not done.
485 // Verify we're not done. 485 // EXPECT_TRUE(host_.IsBeingBuilt(kBlob3));
486 EXPECT_TRUE(host_.IsBeingBuilt(kBlob3)); 486 // EXPECT_TRUE(IsBeingBuiltInContext(kBlob3));
487 EXPECT_TRUE(IsBeingBuiltInContext(kBlob3)); 487 //
488 488 // // Finish the second.
489 // Finish the second. 489 // EXPECT_EQ(BlobTransportResult::DONE,
490 EXPECT_EQ(BlobTransportResult::DONE, 490 // host_.StartBuildingBlob(
491 host_.StartBuildingBlob( 491 // kBlob2, descriptions, 2, &context_,
492 kBlob2, descriptions, 2, &context_, 492 // base::Bind(&BlobAsyncBuilderHostTest::RequestMemoryCallback,
493 base::Bind(&BlobAsyncBuilderHostTest::RequestMemoryCallback, 493 // base::Unretained(this))));
494 base::Unretained(this)))); 494 // EXPECT_FALSE(request_called_);
495 EXPECT_FALSE(request_called_); 495 // EXPECT_FALSE(host_.IsBeingBuilt(kBlob2));
496 EXPECT_FALSE(host_.IsBeingBuilt(kBlob2)); 496 // EXPECT_FALSE(IsBeingBuiltInContext(kBlob2));
497 EXPECT_FALSE(IsBeingBuiltInContext(kBlob2)); 497 // EXPECT_TRUE(context_.GetBlobDataFromUUID(kBlob2));
498 EXPECT_TRUE(context_.GetBlobDataFromUUID(kBlob2)); 498 //
499 499 // // Run the message loop so we propogate the construction complete callbacks.
500 // Run the message loop so we propogate the construction complete callbacks. 500 // base::RunLoop().RunUntilIdle();
501 base::RunLoop().RunUntilIdle(); 501 // // Finally, we should be finished with third blob.
502 // Finally, we should be finished with third blob. 502 // EXPECT_FALSE(host_.IsBeingBuilt(kBlob3));
503 EXPECT_FALSE(host_.IsBeingBuilt(kBlob3)); 503 // EXPECT_FALSE(IsBeingBuiltInContext(kBlob3));
504 EXPECT_FALSE(IsBeingBuiltInContext(kBlob3)); 504 // EXPECT_TRUE(context_.GetBlobDataFromUUID(kBlob3));
505 EXPECT_TRUE(context_.GetBlobDataFromUUID(kBlob3)); 505 //};
506 }; 506 //
507 507 // TEST_F(BlobAsyncBuilderHostTest, IncorrectBlobDependencies) {
508 TEST_F(BlobAsyncBuilderHostTest, IncorrectBlobDependencies) { 508 // const std::string& kGoodBlob = "goodBlob";
509 const std::string& kGoodBlob = "goodBlob"; 509 // const std::string& kBlob1 = "blob1";
510 const std::string& kBlob1 = "blob1"; 510 // const std::string& kBlob2 = "blob2";
511 const std::string& kBlob2 = "blob2"; 511 // const std::string& kBlob3 = "blob3";
512 const std::string& kBlob3 = "blob3"; 512 //
513 513 // // Register blobs. Blob 1 has a reference to itself, Blob 2 has a reference
514 // Register blobs. Blob 1 has a reference to itself, Blob 2 has a reference 514 // // but doesn't use it, and blob 3 doesn't list it's reference.
515 // but doesn't use it, and blob 3 doesn't list it's reference. 515 // EXPECT_EQ(BlobTransportResult::DONE,
516 EXPECT_EQ(BlobTransportResult::DONE, 516 // host_.RegisterBlobUUID(kGoodBlob, kContentType,
517 host_.RegisterBlobUUID(kGoodBlob, kContentType, kContentDisposition, 517 // kContentDisposition,
518 std::set<std::string>(), &context_)); 518 // std::set<std::string>(), &context_));
519 EXPECT_EQ(BlobTransportResult::BAD_IPC, 519 // EXPECT_EQ(BlobTransportResult::BAD_IPC,
520 host_.RegisterBlobUUID(kBlob1, kContentType, kContentDisposition, 520 // host_.RegisterBlobUUID(kBlob1, kContentType, kContentDisposition,
521 {kBlob1}, &context_)); 521 // {kBlob1}, &context_));
522 EXPECT_EQ(BlobTransportResult::DONE, 522 // EXPECT_EQ(BlobTransportResult::DONE,
523 host_.RegisterBlobUUID(kBlob2, kContentType, kContentDisposition, 523 // host_.RegisterBlobUUID(kBlob2, kContentType, kContentDisposition,
524 {kGoodBlob}, &context_)); 524 // {kGoodBlob}, &context_));
525 EXPECT_EQ(BlobTransportResult::DONE, 525 // EXPECT_EQ(BlobTransportResult::DONE,
526 host_.RegisterBlobUUID(kBlob3, kContentType, kContentDisposition, 526 // host_.RegisterBlobUUID(kBlob3, kContentType, kContentDisposition,
527 std::set<std::string>(), &context_)); 527 // std::set<std::string>(), &context_));
528 528 //
529 // The first blob shouldn't be building anymore. 529 // // The first blob shouldn't be building anymore.
530 EXPECT_FALSE(host_.IsBeingBuilt(kBlob1)); 530 // EXPECT_FALSE(host_.IsBeingBuilt(kBlob1));
531 531 //
532 // Try to finish the second one, without a reference to the first. 532 // // Try to finish the second one, without a reference to the first.
533 std::vector<DataElement> descriptions; 533 // std::vector<DataElement> descriptions;
534 AddShortcutMemoryItem(2, &descriptions); 534 // AddShortcutMemoryItem(2, &descriptions);
535 EXPECT_EQ(BlobTransportResult::BAD_IPC, 535 // EXPECT_EQ(BlobTransportResult::BAD_IPC,
536 host_.StartBuildingBlob( 536 // host_.StartBuildingBlob(
537 kBlob2, descriptions, 2, &context_, 537 // kBlob2, descriptions, 2, &context_,
538 base::Bind(&BlobAsyncBuilderHostTest::RequestMemoryCallback, 538 // base::Bind(&BlobAsyncBuilderHostTest::RequestMemoryCallback,
539 base::Unretained(this)))); 539 // base::Unretained(this))));
540 EXPECT_FALSE(host_.IsBeingBuilt(kBlob2)); 540 // EXPECT_FALSE(host_.IsBeingBuilt(kBlob2));
541 541 //
542 // Try to finish the third one with the reference we didn't declare earlier. 542 // // Try to finish the third one with the reference we didn't declare earlier.
543 descriptions.clear(); 543 // descriptions.clear();
544 AddShortcutMemoryItem(2, &descriptions); 544 // AddShortcutMemoryItem(2, &descriptions);
545 DataElement element; 545 // DataElement element;
546 element.SetToBlob(kGoodBlob); 546 // element.SetToBlob(kGoodBlob);
547 descriptions.push_back(element); 547 // descriptions.push_back(element);
548 EXPECT_EQ(BlobTransportResult::BAD_IPC, 548 // EXPECT_EQ(BlobTransportResult::BAD_IPC,
549 host_.StartBuildingBlob( 549 // host_.StartBuildingBlob(
550 kBlob3, descriptions, 2, &context_, 550 // kBlob3, descriptions, 2, &context_,
551 base::Bind(&BlobAsyncBuilderHostTest::RequestMemoryCallback, 551 // base::Bind(&BlobAsyncBuilderHostTest::RequestMemoryCallback,
552 base::Unretained(this)))); 552 // base::Unretained(this))));
553 EXPECT_FALSE(host_.IsBeingBuilt(kBlob3)); 553 // EXPECT_FALSE(host_.IsBeingBuilt(kBlob3));
554 }; 554 //};
555 555 //
556 TEST_F(BlobAsyncBuilderHostTest, BlobBreaksWhenReferenceBreaks) { 556 // TEST_F(BlobAsyncBuilderHostTest, BlobBreaksWhenReferenceBreaks) {
557 const std::string& kBlob1 = "blob1"; 557 // const std::string& kBlob1 = "blob1";
558 const std::string& kBlob2 = "blob2"; 558 // const std::string& kBlob2 = "blob2";
559 559 //
560 // Register blobs. 560 // // Register blobs.
561 EXPECT_EQ(BlobTransportResult::DONE, 561 // EXPECT_EQ(BlobTransportResult::DONE,
562 host_.RegisterBlobUUID(kBlob1, kContentType, kContentDisposition, 562 // host_.RegisterBlobUUID(kBlob1, kContentType, kContentDisposition,
563 std::set<std::string>(), &context_)); 563 // std::set<std::string>(), &context_));
564 EXPECT_EQ(BlobTransportResult::DONE, 564 // EXPECT_EQ(BlobTransportResult::DONE,
565 host_.RegisterBlobUUID(kBlob2, kContentType, kContentDisposition, 565 // host_.RegisterBlobUUID(kBlob2, kContentType, kContentDisposition,
566 {kBlob1}, &context_)); 566 // {kBlob1}, &context_));
567 567 //
568 // Finish the second one, with a reference to the first. 568 // // Finish the second one, with a reference to the first.
569 std::vector<DataElement> descriptions; 569 // std::vector<DataElement> descriptions;
570 AddShortcutMemoryItem(2, &descriptions); 570 // AddShortcutMemoryItem(2, &descriptions);
571 DataElement element; 571 // DataElement element;
572 element.SetToBlob(kBlob1); 572 // element.SetToBlob(kBlob1);
573 descriptions.push_back(element); 573 // descriptions.push_back(element);
574 EXPECT_EQ(BlobTransportResult::DONE, 574 // EXPECT_EQ(BlobTransportResult::DONE,
575 host_.StartBuildingBlob( 575 // host_.StartBuildingBlob(
576 kBlob2, descriptions, 2, &context_, 576 // kBlob2, descriptions, 2, &context_,
577 base::Bind(&BlobAsyncBuilderHostTest::RequestMemoryCallback, 577 // base::Bind(&BlobAsyncBuilderHostTest::RequestMemoryCallback,
578 base::Unretained(this)))); 578 // base::Unretained(this))));
579 EXPECT_FALSE(request_called_); 579 // EXPECT_FALSE(request_called_);
580 EXPECT_TRUE(host_.IsBeingBuilt(kBlob2)); 580 // EXPECT_TRUE(host_.IsBeingBuilt(kBlob2));
581 EXPECT_TRUE(IsBeingBuiltInContext(kBlob2)); 581 // EXPECT_TRUE(IsBeingBuiltInContext(kBlob2));
582 582 //
583 // Break the first. 583 // // Break the first.
584 descriptions.clear(); 584 // descriptions.clear();
585 host_.CancelBuildingBlob(kBlob1, IPCBlobCreationCancelCode::UNKNOWN, 585 // host_.CancelBuildingBlob(kBlob1, IPCBlobCreationCancelCode::UNKNOWN,
586 &context_); 586 // &context_);
587 EXPECT_FALSE(host_.IsBeingBuilt(kBlob1)); 587 // EXPECT_FALSE(host_.IsBeingBuilt(kBlob1));
588 EXPECT_FALSE(IsBeingBuiltInContext(kBlob1)); 588 // EXPECT_FALSE(IsBeingBuiltInContext(kBlob1));
589 EXPECT_TRUE(context_.GetBlobDataFromUUID(kBlob1)->IsBroken()); 589 // EXPECT_TRUE(context_.GetBlobDataFromUUID(kBlob1)->IsBroken());
590 590 //
591 // Run the message loop so we propogate the construction complete callbacks. 591 // // Run the message loop so we propogate the construction complete callbacks.
592 base::RunLoop().RunUntilIdle(); 592 // base::RunLoop().RunUntilIdle();
593 // We should be finished with third blob, and it should be broken. 593 // // We should be finished with third blob, and it should be broken.
594 EXPECT_FALSE(host_.IsBeingBuilt(kBlob2)); 594 // EXPECT_FALSE(host_.IsBeingBuilt(kBlob2));
595 EXPECT_FALSE(IsBeingBuiltInContext(kBlob2)); 595 // EXPECT_FALSE(IsBeingBuiltInContext(kBlob2));
596 EXPECT_TRUE(context_.GetBlobDataFromUUID(kBlob2)->IsBroken()); 596 // EXPECT_TRUE(context_.GetBlobDataFromUUID(kBlob2)->IsBroken());
597 }; 597 //};
598 598 //
599 TEST_F(BlobAsyncBuilderHostTest, BlobBreaksWhenReferenceBroken) { 599 // TEST_F(BlobAsyncBuilderHostTest, BlobBreaksWhenReferenceBroken) {
600 const std::string& kBlob1 = "blob1"; 600 // const std::string& kBlob1 = "blob1";
601 const std::string& kBlob2 = "blob2"; 601 // const std::string& kBlob2 = "blob2";
602 602 //
603 // Register blobs. 603 // // Register blobs.
604 EXPECT_EQ(BlobTransportResult::DONE, 604 // EXPECT_EQ(BlobTransportResult::DONE,
605 host_.RegisterBlobUUID(kBlob1, kContentType, kContentDisposition, 605 // host_.RegisterBlobUUID(kBlob1, kContentType, kContentDisposition,
606 std::set<std::string>(), &context_)); 606 // std::set<std::string>(), &context_));
607 host_.CancelBuildingBlob(kBlob1, IPCBlobCreationCancelCode::UNKNOWN, 607 // host_.CancelBuildingBlob(kBlob1, IPCBlobCreationCancelCode::UNKNOWN,
608 &context_); 608 // &context_);
609 EXPECT_EQ(BlobTransportResult::CANCEL_REFERENCED_BLOB_BROKEN, 609 // EXPECT_EQ(BlobTransportResult::CANCEL_REFERENCED_BLOB_BROKEN,
610 host_.RegisterBlobUUID(kBlob2, kContentType, kContentDisposition, 610 // host_.RegisterBlobUUID(kBlob2, kContentType, kContentDisposition,
611 {kBlob1}, &context_)); 611 // {kBlob1}, &context_));
612 EXPECT_FALSE(host_.IsBeingBuilt(kBlob2)); 612 // EXPECT_FALSE(host_.IsBeingBuilt(kBlob2));
613 EXPECT_FALSE(IsBeingBuiltInContext(kBlob2)); 613 // EXPECT_FALSE(IsBeingBuiltInContext(kBlob2));
614 EXPECT_TRUE(context_.GetBlobDataFromUUID(kBlob2)->IsBroken()); 614 // EXPECT_TRUE(context_.GetBlobDataFromUUID(kBlob2)->IsBroken());
615 }; 615 //};
616 616 //
617 } // namespace storage 617 //} // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698