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

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

Issue 2448353002: [BlobAsync] Moving async handling into BlobStorageContext & quota out. (Closed)
Patch Set: comments from Marijn Created 4 years, 1 month 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_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 "storage/browser/blob/blob_entry.h"
8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
9 #include "url/gurl.h" 10 #include "url/gurl.h"
10 11
11 namespace storage { 12 namespace storage {
12 namespace { 13 namespace {
13 using Entry = BlobStorageRegistry::Entry;
14 using BlobState = BlobStorageRegistry::BlobState;
15 14
16 TEST(BlobStorageRegistry, UUIDRegistration) { 15 TEST(BlobStorageRegistry, UUIDRegistration) {
17 const std::string kBlob1 = "Blob1"; 16 const std::string kBlob1 = "Blob1";
18 const std::string kType = "type1"; 17 const std::string kType = "type1";
19 const std::string kDisposition = "disp1"; 18 const std::string kDisposition = "disp1";
20 BlobStorageRegistry registry; 19 BlobStorageRegistry registry;
21 20
22 EXPECT_FALSE(registry.DeleteEntry(kBlob1)); 21 EXPECT_FALSE(registry.DeleteEntry(kBlob1));
23 EXPECT_EQ(0u, registry.blob_count()); 22 EXPECT_EQ(0u, registry.blob_count());
24 23
25 Entry* entry = registry.CreateEntry(kBlob1, kType, kDisposition); 24 BlobEntry* entry = registry.CreateEntry(kBlob1, kType, kDisposition);
26 ASSERT_NE(nullptr, entry); 25 ASSERT_NE(nullptr, entry);
27 EXPECT_EQ(BlobState::PENDING, entry->state); 26 EXPECT_EQ(BlobStatus::PENDING_QUOTA, entry->status());
28 EXPECT_EQ(kType, entry->content_type); 27 EXPECT_EQ(kType, entry->content_type());
29 EXPECT_EQ(kDisposition, entry->content_disposition); 28 EXPECT_EQ(kDisposition, entry->content_disposition());
30 EXPECT_EQ(1u, entry->refcount); 29 EXPECT_EQ(0u, entry->refcount());
31 EXPECT_FALSE(entry->data.get() || entry->data_builder.get());
32 EXPECT_EQ(0u, entry->build_completion_callbacks.size());
33 30
34 EXPECT_EQ(entry, registry.GetEntry(kBlob1)); 31 EXPECT_EQ(entry, registry.GetEntry(kBlob1));
35 EXPECT_TRUE(registry.DeleteEntry(kBlob1)); 32 EXPECT_TRUE(registry.DeleteEntry(kBlob1));
36 entry = registry.CreateEntry(kBlob1, kType, kDisposition); 33 entry = registry.CreateEntry(kBlob1, kType, kDisposition);
37 34
38 EXPECT_EQ(1u, registry.blob_count()); 35 EXPECT_EQ(1u, registry.blob_count());
39 } 36 }
40 37
41 TEST(BlobStorageRegistry, URLRegistration) { 38 TEST(BlobStorageRegistry, URLRegistration) {
42 const std::string kBlob = "Blob1"; 39 const std::string kBlob = "Blob1";
43 const std::string kType = "type1"; 40 const std::string kType = "type1";
44 const std::string kDisposition = "disp1"; 41 const std::string kDisposition = "disp1";
45 const std::string kBlob2 = "Blob2"; 42 const std::string kBlob2 = "Blob2";
46 const GURL kURL = GURL("blob://Blob1"); 43 const GURL kURL = GURL("blob://Blob1");
47 const GURL kURL2 = GURL("blob://Blob2"); 44 const GURL kURL2 = GURL("blob://Blob2");
48 BlobStorageRegistry registry; 45 BlobStorageRegistry registry;
49 46
50 EXPECT_FALSE(registry.IsURLMapped(kURL)); 47 EXPECT_FALSE(registry.IsURLMapped(kURL));
51 EXPECT_EQ(nullptr, registry.GetEntryFromURL(kURL, nullptr)); 48 EXPECT_EQ(nullptr, registry.GetEntryFromURL(kURL, nullptr));
52 EXPECT_FALSE(registry.DeleteURLMapping(kURL, nullptr)); 49 EXPECT_FALSE(registry.DeleteURLMapping(kURL, nullptr));
53 EXPECT_FALSE(registry.CreateUrlMapping(kURL, kBlob)); 50 EXPECT_FALSE(registry.CreateUrlMapping(kURL, kBlob));
54 EXPECT_EQ(0u, registry.url_count()); 51 EXPECT_EQ(0u, registry.url_count());
55 Entry* entry = registry.CreateEntry(kBlob, kType, kDisposition); 52 BlobEntry* entry = registry.CreateEntry(kBlob, kType, kDisposition);
56 53
57 EXPECT_FALSE(registry.IsURLMapped(kURL)); 54 EXPECT_FALSE(registry.IsURLMapped(kURL));
58 EXPECT_TRUE(registry.CreateUrlMapping(kURL, kBlob)); 55 EXPECT_TRUE(registry.CreateUrlMapping(kURL, kBlob));
59 EXPECT_FALSE(registry.CreateUrlMapping(kURL, kBlob2)); 56 EXPECT_FALSE(registry.CreateUrlMapping(kURL, kBlob2));
60 57
61 EXPECT_TRUE(registry.IsURLMapped(kURL)); 58 EXPECT_TRUE(registry.IsURLMapped(kURL));
62 EXPECT_EQ(entry, registry.GetEntryFromURL(kURL, nullptr)); 59 EXPECT_EQ(entry, registry.GetEntryFromURL(kURL, nullptr));
63 std::string uuid; 60 std::string uuid;
64 EXPECT_EQ(entry, registry.GetEntryFromURL(kURL, &uuid)); 61 EXPECT_EQ(entry, registry.GetEntryFromURL(kURL, &uuid));
65 EXPECT_EQ(kBlob, uuid); 62 EXPECT_EQ(kBlob, uuid);
66 EXPECT_EQ(1u, registry.url_count()); 63 EXPECT_EQ(1u, registry.url_count());
67 64
68 registry.CreateEntry(kBlob2, kType, kDisposition); 65 registry.CreateEntry(kBlob2, kType, kDisposition);
69 EXPECT_TRUE(registry.CreateUrlMapping(kURL2, kBlob2)); 66 EXPECT_TRUE(registry.CreateUrlMapping(kURL2, kBlob2));
70 EXPECT_EQ(2u, registry.url_count()); 67 EXPECT_EQ(2u, registry.url_count());
71 EXPECT_TRUE(registry.DeleteURLMapping(kURL2, &uuid)); 68 EXPECT_TRUE(registry.DeleteURLMapping(kURL2, &uuid));
72 EXPECT_EQ(kBlob2, uuid); 69 EXPECT_EQ(kBlob2, uuid);
73 EXPECT_FALSE(registry.IsURLMapped(kURL2)); 70 EXPECT_FALSE(registry.IsURLMapped(kURL2));
74 71
75 // Both urls point to the same blob. 72 // Both urls point to the same blob.
76 EXPECT_TRUE(registry.CreateUrlMapping(kURL2, kBlob)); 73 EXPECT_TRUE(registry.CreateUrlMapping(kURL2, kBlob));
77 std::string uuid2; 74 std::string uuid2;
78 EXPECT_EQ(registry.GetEntryFromURL(kURL, &uuid), 75 EXPECT_EQ(registry.GetEntryFromURL(kURL, &uuid),
79 registry.GetEntryFromURL(kURL2, &uuid2)); 76 registry.GetEntryFromURL(kURL2, &uuid2));
80 EXPECT_EQ(uuid, uuid2); 77 EXPECT_EQ(uuid, uuid2);
81 } 78 }
82 79
83 } // namespace 80 } // namespace
84 } // namespace storage 81 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698