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 "storage/browser/blob/blob_flattener.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "storage/browser/blob/blob_data_builder.h" |
| 10 #include "storage/browser/blob/blob_data_item.h" |
| 11 #include "storage/browser/blob/blob_storage_registry.h" |
| 12 #include "storage/browser/blob/internal_blob_data.h" |
| 13 #include "storage/browser/blob/shareable_blob_data_item.h" |
| 14 #include "storage/common/data_element.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 |
| 17 namespace storage { |
| 18 namespace { |
| 19 |
| 20 scoped_refptr<ShareableBlobDataItem> CreateDataItem(const char* memory, |
| 21 size_t size) { |
| 22 std::unique_ptr<DataElement> element(new DataElement()); |
| 23 element->SetToBytes(memory, size); |
| 24 return scoped_refptr<ShareableBlobDataItem>( |
| 25 new ShareableBlobDataItem(new BlobDataItem(std::move(element)))); |
| 26 }; |
| 27 |
| 28 void ExpectNoErrors(BlobFlattener* flattener) { |
| 29 EXPECT_FALSE(flattener->contains_invalid_references); |
| 30 EXPECT_FALSE(flattener->contains_broken_references); |
| 31 EXPECT_FALSE(flattener->contains_pending_content); |
| 32 } |
| 33 |
| 34 // |
| 35 // scoped_refptr<ShareableBlobDataItem> CreateFileItem(size_t offset, |
| 36 // size_t size) { |
| 37 // std::unique_ptr<DataElement> element(new DataElement()); |
| 38 // element->SetToFilePathRange(base::FilePath("kFakePath"), offset, size, |
| 39 // base::Time::Max()); |
| 40 // return scoped_refptr<ShareableBlobDataItem>( |
| 41 // new ShareableBlobDataItem(new BlobDataItem(std::move(element)))); |
| 42 //}; |
| 43 |
| 44 // |
| 45 // class BlobFlattenerTest : public testing::Test { |
| 46 // protected: |
| 47 // BlobFlattenerTest() {} |
| 48 // ~BlobFlattenerTest() override {} |
| 49 // |
| 50 // |
| 51 // void TearDown() override { |
| 52 // // Make sure we clean up the files. |
| 53 // base::RunLoop().RunUntilIdle(); |
| 54 // file_runner_->RunPendingTasks(); |
| 55 // ASSERT_EQ(true, base::DeleteFile(temp_dir_, true)); |
| 56 // } |
| 57 // |
| 58 // std::unique_ptr<BlobDataHandle> SetupBasicBlob(const std::string& id) { |
| 59 // BlobDataBuilder builder(id); |
| 60 // builder.AppendData("1", 1); |
| 61 // builder.set_content_type("text/plain"); |
| 62 // return context_.AddFinishedBlob(builder); |
| 63 // } |
| 64 // |
| 65 // |
| 66 // BlobStorageRegistry registry; |
| 67 //}; |
| 68 |
| 69 TEST(BlobFlattener, NoBlobItems) { |
| 70 BlobStorageRegistry registry; |
| 71 const std::string kBlobUUID = "kId"; |
| 72 |
| 73 BlobDataBuilder builder(kBlobUUID); |
| 74 builder.AppendData("hi", 2u); |
| 75 InternalBlobData output; |
| 76 BlobFlattener flattener(builder, &output, ®istry); |
| 77 |
| 78 ExpectNoErrors(&flattener); |
| 79 EXPECT_EQ(0u, flattener.dependent_blobs.size()); |
| 80 EXPECT_EQ(0u, flattener.copies.size()); |
| 81 EXPECT_EQ(2u, flattener.total_size.ValueOrDie()); |
| 82 EXPECT_EQ(2u, flattener.memory_needed.ValueOrDie()); |
| 83 |
| 84 ASSERT_EQ(1u, output.items().size()); |
| 85 EXPECT_EQ(*CreateDataItem("hi", 2u)->item(), *output.items()[0]->item()); |
| 86 } |
| 87 |
| 88 TEST(BlobFlattener, ErrorCases) { |
| 89 BlobStorageRegistry registry; |
| 90 const std::string kBlobUUID = "kId"; |
| 91 |
| 92 // Invalid blob reference. |
| 93 { |
| 94 BlobDataBuilder builder(kBlobUUID); |
| 95 builder.AppendBlob("doesnotexist"); |
| 96 InternalBlobData output; |
| 97 BlobFlattener flattener(builder, &output, ®istry); |
| 98 EXPECT_TRUE(flattener.contains_broken_references); |
| 99 } |
| 100 |
| 101 // Circular reference. |
| 102 { |
| 103 BlobDataBuilder builder(kBlobUUID); |
| 104 builder.AppendBlob(kBlobUUID); |
| 105 InternalBlobData output; |
| 106 BlobFlattener flattener(builder, &output, ®istry); |
| 107 EXPECT_TRUE(flattener.contains_broken_references); |
| 108 } |
| 109 |
| 110 // |
| 111 } |
| 112 |
| 113 } // namespace |
| 114 } // namespace storage |
OLD | NEW |