| OLD | NEW |
| 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 "platform/blob/BlobData.h" | 5 #include "platform/blob/BlobData.h" |
| 6 | 6 |
| 7 #include <memory> |
| 8 #include "platform/wtf/PtrUtil.h" |
| 7 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "wtf/PtrUtil.h" | |
| 10 #include <memory> | |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 TEST(BlobDataTest, Consolidation) { | 14 TEST(BlobDataTest, Consolidation) { |
| 15 const size_t kMaxConsolidatedItemSizeInBytes = 15 * 1024; | 15 const size_t kMaxConsolidatedItemSizeInBytes = 15 * 1024; |
| 16 BlobData data(BlobData::FileCompositionStatus::NO_UNKNOWN_SIZE_FILES); | 16 BlobData data(BlobData::FileCompositionStatus::NO_UNKNOWN_SIZE_FILES); |
| 17 const char* text1 = "abc"; | 17 const char* text1 = "abc"; |
| 18 const char* text2 = "def"; | 18 const char* text2 = "def"; |
| 19 data.AppendBytes(text1, 3u); | 19 data.AppendBytes(text1, 3u); |
| 20 data.AppendBytes(text2, 3u); | 20 data.AppendBytes(text2, 3u); |
| 21 data.AppendText("ps1", false); | 21 data.AppendText("ps1", false); |
| 22 data.AppendText("ps2", false); | 22 data.AppendText("ps2", false); |
| 23 | 23 |
| 24 EXPECT_EQ(1u, data.items_.size()); | 24 EXPECT_EQ(1u, data.items_.size()); |
| 25 EXPECT_EQ(12u, data.items_[0].data->length()); | 25 EXPECT_EQ(12u, data.items_[0].data->length()); |
| 26 EXPECT_EQ(0, memcmp(data.items_[0].data->Data(), "abcdefps1ps2", 12)); | 26 EXPECT_EQ(0, memcmp(data.items_[0].data->Data(), "abcdefps1ps2", 12)); |
| 27 | 27 |
| 28 std::unique_ptr<char[]> large_data = | 28 std::unique_ptr<char[]> large_data = |
| 29 WrapArrayUnique(new char[kMaxConsolidatedItemSizeInBytes]); | 29 WrapArrayUnique(new char[kMaxConsolidatedItemSizeInBytes]); |
| 30 data.AppendBytes(large_data.get(), kMaxConsolidatedItemSizeInBytes); | 30 data.AppendBytes(large_data.get(), kMaxConsolidatedItemSizeInBytes); |
| 31 | 31 |
| 32 EXPECT_EQ(2u, data.items_.size()); | 32 EXPECT_EQ(2u, data.items_.size()); |
| 33 EXPECT_EQ(12u, data.items_[0].data->length()); | 33 EXPECT_EQ(12u, data.items_[0].data->length()); |
| 34 EXPECT_EQ(kMaxConsolidatedItemSizeInBytes, data.items_[1].data->length()); | 34 EXPECT_EQ(kMaxConsolidatedItemSizeInBytes, data.items_[1].data->length()); |
| 35 } | 35 } |
| 36 | 36 |
| 37 } // namespace blink | 37 } // namespace blink |
| OLD | NEW |