OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "platform/blob/BlobBytesProvider.h" | 5 #include "platform/blob/BlobBytesProvider.h" |
6 | 6 |
7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/test/scoped_task_environment.h" | 9 #include "base/test/scoped_task_environment.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 namespace { | 13 namespace { |
14 | 14 |
15 class BlobBytesProviderTest : public testing::Test { | 15 class BlobBytesProviderTest : public ::testing::Test { |
16 public: | 16 public: |
17 void SetUp() override { | 17 void SetUp() override { |
18 test_bytes1_.resize(128); | 18 test_bytes1_.resize(128); |
19 for (size_t i = 0; i < test_bytes1_.size(); ++i) | 19 for (size_t i = 0; i < test_bytes1_.size(); ++i) |
20 test_bytes1_[i] = i % 191; | 20 test_bytes1_[i] = i % 191; |
21 test_data1_ = RawData::Create(); | 21 test_data1_ = RawData::Create(); |
22 test_data1_->MutableData()->AppendVector(test_bytes1_); | 22 test_data1_->MutableData()->AppendVector(test_bytes1_); |
23 test_bytes2_.resize(64); | 23 test_bytes2_.resize(64); |
24 for (size_t i = 0; i < test_bytes2_.size(); ++i) | 24 for (size_t i = 0; i < test_bytes2_.size(); ++i) |
25 test_bytes2_[i] = i; | 25 test_bytes2_[i] = i; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 struct FileTestData { | 71 struct FileTestData { |
72 uint64_t offset; | 72 uint64_t offset; |
73 uint64_t size; | 73 uint64_t size; |
74 }; | 74 }; |
75 | 75 |
76 void PrintTo(const FileTestData& test, std::ostream* os) { | 76 void PrintTo(const FileTestData& test, std::ostream* os) { |
77 *os << "offset: " << test.offset << ", size: " << test.size; | 77 *os << "offset: " << test.offset << ", size: " << test.size; |
78 } | 78 } |
79 | 79 |
80 class RequestAsFile : public BlobBytesProviderTest, | 80 class RequestAsFile : public BlobBytesProviderTest, |
81 public testing::WithParamInterface<FileTestData> { | 81 public ::testing::WithParamInterface<FileTestData> { |
82 public: | 82 public: |
83 void SetUp() override { | 83 void SetUp() override { |
84 BlobBytesProviderTest::SetUp(); | 84 BlobBytesProviderTest::SetUp(); |
85 test_provider_ = WTF::MakeUnique<BlobBytesProvider>(test_data1_); | 85 test_provider_ = WTF::MakeUnique<BlobBytesProvider>(test_data1_); |
86 test_provider_->AppendData(test_data2_); | 86 test_provider_->AppendData(test_data2_); |
87 test_provider_->AppendData(test_data3_); | 87 test_provider_->AppendData(test_data3_); |
88 | 88 |
89 sliced_data_.AppendRange( | 89 sliced_data_.AppendRange( |
90 combined_bytes_.begin() + GetParam().offset, | 90 combined_bytes_.begin() + GetParam().offset, |
91 combined_bytes_.begin() + GetParam().offset + GetParam().size); | 91 combined_bytes_.begin() + GetParam().offset + GetParam().size); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 {10, 128}, // Parts of both the first and second chunk. | 202 {10, 128}, // Parts of both the first and second chunk. |
203 {128, 64}, // The entire second chunk. | 203 {128, 64}, // The entire second chunk. |
204 {0, 0}, // Zero bytes from the beginning. | 204 {0, 0}, // Zero bytes from the beginning. |
205 {130, 10}, // Just a subset of the second chunk. | 205 {130, 10}, // Just a subset of the second chunk. |
206 {140, 0}, // Zero bytes from the middle of the second chunk. | 206 {140, 0}, // Zero bytes from the middle of the second chunk. |
207 {10, 128 + 64}, // Parts of all three chunks. | 207 {10, 128 + 64}, // Parts of all three chunks. |
208 }; | 208 }; |
209 | 209 |
210 INSTANTIATE_TEST_CASE_P(BlobBytesProviderTest, | 210 INSTANTIATE_TEST_CASE_P(BlobBytesProviderTest, |
211 RequestAsFile, | 211 RequestAsFile, |
212 testing::ValuesIn(file_tests)); | 212 ::testing::ValuesIn(file_tests)); |
213 | 213 |
214 TEST_F(BlobBytesProviderTest, RequestAsFile_MultipleChunks) { | 214 TEST_F(BlobBytesProviderTest, RequestAsFile_MultipleChunks) { |
215 auto provider = WTF::MakeUnique<BlobBytesProvider>(test_data1_); | 215 auto provider = WTF::MakeUnique<BlobBytesProvider>(test_data1_); |
216 provider->AppendData(test_data2_); | 216 provider->AppendData(test_data2_); |
217 provider->AppendData(test_data3_); | 217 provider->AppendData(test_data3_); |
218 | 218 |
219 base::FilePath path; | 219 base::FilePath path; |
220 base::CreateTemporaryFile(&path); | 220 base::CreateTemporaryFile(&path); |
221 | 221 |
222 Vector<uint8_t> expected_data; | 222 Vector<uint8_t> expected_data; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 }, | 309 }, |
310 pipe.consumer_handle.get(), loop.QuitClosure(), &received_data)); | 310 pipe.consumer_handle.get(), loop.QuitClosure(), &received_data)); |
311 loop.Run(); | 311 loop.Run(); |
312 | 312 |
313 EXPECT_EQ(combined_bytes_, received_data); | 313 EXPECT_EQ(combined_bytes_, received_data); |
314 } | 314 } |
315 | 315 |
316 } // namespace | 316 } // namespace |
317 | 317 |
318 } // namespace blink | 318 } // namespace blink |
OLD | NEW |