OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "content/browser/fileapi/blob_storage_host.h" | 10 #include "content/browser/fileapi/blob_storage_host.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 // Build up a basic blob. | 35 // Build up a basic blob. |
36 const std::string kId("id"); | 36 const std::string kId("id"); |
37 SetupBasicBlob(&host, kId); | 37 SetupBasicBlob(&host, kId); |
38 | 38 |
39 // Make sure it's there, finish building implies a ref of one. | 39 // Make sure it's there, finish building implies a ref of one. |
40 scoped_ptr<BlobDataHandle> blob_data_handle; | 40 scoped_ptr<BlobDataHandle> blob_data_handle; |
41 blob_data_handle = context.GetBlobDataFromUUID(kId); | 41 blob_data_handle = context.GetBlobDataFromUUID(kId); |
42 EXPECT_TRUE(blob_data_handle); | 42 EXPECT_TRUE(blob_data_handle); |
43 blob_data_handle.reset(); | 43 blob_data_handle.reset(); |
44 fake_io_message_loop.RunUntilIdle(); | |
45 | 44 |
46 // Make sure its still there after inc/dec. | 45 // Make sure its still there after inc/dec. |
47 EXPECT_TRUE(host.IncrementBlobRefCount(kId)); | 46 EXPECT_TRUE(host.IncrementBlobRefCount(kId)); |
48 EXPECT_TRUE(host.DecrementBlobRefCount(kId)); | 47 EXPECT_TRUE(host.DecrementBlobRefCount(kId)); |
49 blob_data_handle = context.GetBlobDataFromUUID(kId); | 48 blob_data_handle = context.GetBlobDataFromUUID(kId); |
50 EXPECT_TRUE(blob_data_handle); | 49 EXPECT_TRUE(blob_data_handle); |
51 blob_data_handle.reset(); | 50 blob_data_handle.reset(); |
52 fake_io_message_loop.RunUntilIdle(); | |
53 | 51 |
54 // Make sure it goes away in the end. | 52 // Make sure it goes away in the end. |
55 EXPECT_TRUE(host.DecrementBlobRefCount(kId)); | 53 EXPECT_TRUE(host.DecrementBlobRefCount(kId)); |
56 blob_data_handle = context.GetBlobDataFromUUID(kId); | 54 blob_data_handle = context.GetBlobDataFromUUID(kId); |
57 EXPECT_FALSE(blob_data_handle); | 55 EXPECT_FALSE(blob_data_handle); |
58 EXPECT_FALSE(host.DecrementBlobRefCount(kId)); | 56 EXPECT_FALSE(host.DecrementBlobRefCount(kId)); |
59 EXPECT_FALSE(host.IncrementBlobRefCount(kId)); | 57 EXPECT_FALSE(host.IncrementBlobRefCount(kId)); |
60 } | 58 } |
61 | 59 |
62 TEST(BlobStorageContextTest, BlobDataHandle) { | 60 TEST(BlobStorageContextTest, BlobDataHandle) { |
(...skipping 14 matching lines...) Expand all Loading... |
77 EXPECT_TRUE(host.DecrementBlobRefCount(kId)); | 75 EXPECT_TRUE(host.DecrementBlobRefCount(kId)); |
78 | 76 |
79 // Should still be there due to the handle. | 77 // Should still be there due to the handle. |
80 scoped_ptr<BlobDataHandle> another_handle = | 78 scoped_ptr<BlobDataHandle> another_handle = |
81 context.GetBlobDataFromUUID(kId); | 79 context.GetBlobDataFromUUID(kId); |
82 EXPECT_TRUE(another_handle); | 80 EXPECT_TRUE(another_handle); |
83 | 81 |
84 // Should disappear after dropping both handles. | 82 // Should disappear after dropping both handles. |
85 blob_data_handle.reset(); | 83 blob_data_handle.reset(); |
86 another_handle.reset(); | 84 another_handle.reset(); |
87 fake_io_message_loop.RunUntilIdle(); | |
88 blob_data_handle = context.GetBlobDataFromUUID(kId); | 85 blob_data_handle = context.GetBlobDataFromUUID(kId); |
89 EXPECT_FALSE(blob_data_handle); | 86 EXPECT_FALSE(blob_data_handle); |
90 } | 87 } |
91 | 88 |
92 TEST(BlobStorageContextTest, CompoundBlobs) { | 89 TEST(BlobStorageContextTest, CompoundBlobs) { |
93 const std::string kId1("id1"); | 90 const std::string kId1("id1"); |
94 const std::string kId2("id2"); | 91 const std::string kId2("id2"); |
95 const std::string kId2Prime("id2.prime"); | 92 const std::string kId2Prime("id2.prime"); |
96 | 93 |
97 base::MessageLoop fake_io_message_loop; | 94 base::MessageLoop fake_io_message_loop; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 SetupBasicBlob(&host, kId); | 143 SetupBasicBlob(&host, kId); |
147 | 144 |
148 // Now register a url for that blob. | 145 // Now register a url for that blob. |
149 GURL kUrl("blob:id"); | 146 GURL kUrl("blob:id"); |
150 EXPECT_TRUE(host.RegisterPublicBlobURL(kUrl, kId)); | 147 EXPECT_TRUE(host.RegisterPublicBlobURL(kUrl, kId)); |
151 scoped_ptr<BlobDataHandle> blob_data_handle = | 148 scoped_ptr<BlobDataHandle> blob_data_handle = |
152 context.GetBlobDataFromPublicURL(kUrl); | 149 context.GetBlobDataFromPublicURL(kUrl); |
153 ASSERT_TRUE(blob_data_handle.get()); | 150 ASSERT_TRUE(blob_data_handle.get()); |
154 EXPECT_EQ(kId, blob_data_handle->data()->uuid()); | 151 EXPECT_EQ(kId, blob_data_handle->data()->uuid()); |
155 blob_data_handle.reset(); | 152 blob_data_handle.reset(); |
156 fake_io_message_loop.RunUntilIdle(); | |
157 | 153 |
158 // The url registration should keep the blob alive even after | 154 // The url registration should keep the blob alive even after |
159 // explicit references are dropped. | 155 // explicit references are dropped. |
160 EXPECT_TRUE(host.DecrementBlobRefCount(kId)); | 156 EXPECT_TRUE(host.DecrementBlobRefCount(kId)); |
161 blob_data_handle = context.GetBlobDataFromPublicURL(kUrl); | 157 blob_data_handle = context.GetBlobDataFromPublicURL(kUrl); |
162 EXPECT_TRUE(blob_data_handle); | 158 EXPECT_TRUE(blob_data_handle); |
163 blob_data_handle.reset(); | 159 blob_data_handle.reset(); |
164 fake_io_message_loop.RunUntilIdle(); | |
165 | 160 |
166 // Finally get rid of the url registration and the blob. | 161 // Finally get rid of the url registration and the blob. |
167 EXPECT_TRUE(host.RevokePublicBlobURL(kUrl)); | 162 EXPECT_TRUE(host.RevokePublicBlobURL(kUrl)); |
168 blob_data_handle = context.GetBlobDataFromPublicURL(kUrl); | 163 blob_data_handle = context.GetBlobDataFromPublicURL(kUrl); |
169 EXPECT_TRUE(!blob_data_handle.get()); | 164 EXPECT_TRUE(!blob_data_handle.get()); |
170 EXPECT_FALSE(host.RevokePublicBlobURL(kUrl)); | 165 EXPECT_FALSE(host.RevokePublicBlobURL(kUrl)); |
171 } | 166 } |
172 | 167 |
173 TEST(BlobStorageContextTest, HostCleanup) { | 168 TEST(BlobStorageContextTest, HostCleanup) { |
174 BlobStorageContext context; | 169 BlobStorageContext context; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 EXPECT_FALSE(host.FinishBuildingBlob(kId, "text/plain")); | 201 EXPECT_FALSE(host.FinishBuildingBlob(kId, "text/plain")); |
207 EXPECT_FALSE(host.RegisterPublicBlobURL(kUrl, kId)); | 202 EXPECT_FALSE(host.RegisterPublicBlobURL(kUrl, kId)); |
208 EXPECT_FALSE(host.IncrementBlobRefCount(kId)); | 203 EXPECT_FALSE(host.IncrementBlobRefCount(kId)); |
209 EXPECT_FALSE(host.DecrementBlobRefCount(kId)); | 204 EXPECT_FALSE(host.DecrementBlobRefCount(kId)); |
210 EXPECT_FALSE(host.RevokePublicBlobURL(kUrl)); | 205 EXPECT_FALSE(host.RevokePublicBlobURL(kUrl)); |
211 } | 206 } |
212 | 207 |
213 // TODO(michaeln): tests for the depcrecated url stuff | 208 // TODO(michaeln): tests for the depcrecated url stuff |
214 | 209 |
215 } // namespace content | 210 } // namespace content |
OLD | NEW |