| 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 "storage/browser/blob/blob_storage_registry.h" | 5 #include "storage/browser/blob/blob_storage_registry.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "url/gurl.h" | 9 #include "url/gurl.h" |
| 10 | 10 |
| 11 namespace storage { | 11 namespace storage { |
| 12 namespace { | 12 namespace { |
| 13 using Entry = BlobStorageRegistry::Entry; | 13 using Entry = BlobStorageRegistry::Entry; |
| 14 using BlobState = BlobStorageRegistry::BlobState; | 14 using BlobState = BlobStorageRegistry::BlobState; |
| 15 | 15 |
| 16 TEST(BlobStorageRegistry, UUIDRegistration) { | 16 TEST(BlobStorageRegistry, UUIDRegistration) { |
| 17 const std::string kBlob1 = "Blob1"; | 17 const std::string kBlob1 = "Blob1"; |
| 18 BlobStorageRegistry registry; | 18 BlobStorageRegistry registry; |
| 19 | 19 |
| 20 EXPECT_FALSE(registry.DeleteEntry(kBlob1)); | 20 EXPECT_FALSE(registry.DeleteEntry(kBlob1)); |
| 21 EXPECT_EQ(0u, registry.blob_count()); | 21 EXPECT_EQ(0u, registry.blob_count()); |
| 22 | 22 |
| 23 Entry* entry = registry.CreateEntry(kBlob1); | 23 Entry* entry = registry.CreateEntry(kBlob1); |
| 24 ASSERT_NE(nullptr, entry); | 24 ASSERT_NE(nullptr, entry); |
| 25 EXPECT_EQ(BlobState::RESERVED, entry->state); | 25 EXPECT_EQ(BlobState::PENDING, entry->state); |
| 26 EXPECT_EQ(1u, entry->refcount); | 26 EXPECT_EQ(1u, entry->refcount); |
| 27 EXPECT_FALSE(entry->exceeded_memory); | |
| 28 EXPECT_FALSE(entry->data.get() || entry->data_builder.get()); | 27 EXPECT_FALSE(entry->data.get() || entry->data_builder.get()); |
| 29 EXPECT_EQ(0u, entry->construction_complete_callbacks.size()); | 28 EXPECT_EQ(0u, entry->build_completion_callbacks.size()); |
| 30 | 29 |
| 31 EXPECT_EQ(entry, registry.GetEntry(kBlob1)); | 30 EXPECT_EQ(entry, registry.GetEntry(kBlob1)); |
| 32 EXPECT_TRUE(registry.DeleteEntry(kBlob1)); | 31 EXPECT_TRUE(registry.DeleteEntry(kBlob1)); |
| 33 entry = registry.CreateEntry(kBlob1); | 32 entry = registry.CreateEntry(kBlob1); |
| 34 | 33 |
| 35 EXPECT_TRUE(entry->TestAndSetState(BlobState::RESERVED, | |
| 36 BlobState::ASYNC_TRANSPORTATION)); | |
| 37 EXPECT_FALSE( | |
| 38 entry->TestAndSetState(BlobState::CONSTRUCTION, BlobState::RESERVED)); | |
| 39 EXPECT_FALSE(entry->TestAndSetState(BlobState::ACTIVE, BlobState::RESERVED)); | |
| 40 EXPECT_TRUE(entry->TestAndSetState(BlobState::ASYNC_TRANSPORTATION, | |
| 41 BlobState::CONSTRUCTION)); | |
| 42 EXPECT_EQ(BlobState::CONSTRUCTION, entry->state); | |
| 43 EXPECT_EQ(1u, registry.blob_count()); | 34 EXPECT_EQ(1u, registry.blob_count()); |
| 44 } | 35 } |
| 45 | 36 |
| 46 TEST(BlobStorageRegistry, URLRegistration) { | 37 TEST(BlobStorageRegistry, URLRegistration) { |
| 47 const std::string kBlob = "Blob1"; | 38 const std::string kBlob = "Blob1"; |
| 48 const std::string kBlob2 = "Blob2"; | 39 const std::string kBlob2 = "Blob2"; |
| 49 const GURL kURL = GURL("blob://Blob1"); | 40 const GURL kURL = GURL("blob://Blob1"); |
| 50 const GURL kURL2 = GURL("blob://Blob2"); | 41 const GURL kURL2 = GURL("blob://Blob2"); |
| 51 BlobStorageRegistry registry; | 42 BlobStorageRegistry registry; |
| 52 | 43 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 78 // Both urls point to the same blob. | 69 // Both urls point to the same blob. |
| 79 EXPECT_TRUE(registry.CreateUrlMapping(kURL2, kBlob)); | 70 EXPECT_TRUE(registry.CreateUrlMapping(kURL2, kBlob)); |
| 80 std::string uuid2; | 71 std::string uuid2; |
| 81 EXPECT_EQ(registry.GetEntryFromURL(kURL, &uuid), | 72 EXPECT_EQ(registry.GetEntryFromURL(kURL, &uuid), |
| 82 registry.GetEntryFromURL(kURL2, &uuid2)); | 73 registry.GetEntryFromURL(kURL2, &uuid2)); |
| 83 EXPECT_EQ(uuid, uuid2); | 74 EXPECT_EQ(uuid, uuid2); |
| 84 } | 75 } |
| 85 | 76 |
| 86 } // namespace | 77 } // namespace |
| 87 } // namespace storage | 78 } // namespace storage |
| OLD | NEW |