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

Side by Side Diff: content/browser/fileapi/blob_storage_context_unittest.cc

Issue 259773006: Allow BlobDataHandles to be copied, and have their UUIDs read, on any thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Experimental Windows build fix Created 6 years, 7 months 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 | Annotate | Revision Log
OLDNEW
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
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();
44 45
45 // Make sure its still there after inc/dec. 46 // Make sure its still there after inc/dec.
46 EXPECT_TRUE(host.IncrementBlobRefCount(kId)); 47 EXPECT_TRUE(host.IncrementBlobRefCount(kId));
47 EXPECT_TRUE(host.DecrementBlobRefCount(kId)); 48 EXPECT_TRUE(host.DecrementBlobRefCount(kId));
48 blob_data_handle = context.GetBlobDataFromUUID(kId); 49 blob_data_handle = context.GetBlobDataFromUUID(kId);
49 EXPECT_TRUE(blob_data_handle); 50 EXPECT_TRUE(blob_data_handle);
50 blob_data_handle.reset(); 51 blob_data_handle.reset();
52 fake_io_message_loop.RunUntilIdle();
51 53
52 // Make sure it goes away in the end. 54 // Make sure it goes away in the end.
53 EXPECT_TRUE(host.DecrementBlobRefCount(kId)); 55 EXPECT_TRUE(host.DecrementBlobRefCount(kId));
54 blob_data_handle = context.GetBlobDataFromUUID(kId); 56 blob_data_handle = context.GetBlobDataFromUUID(kId);
55 EXPECT_FALSE(blob_data_handle); 57 EXPECT_FALSE(blob_data_handle);
56 EXPECT_FALSE(host.DecrementBlobRefCount(kId)); 58 EXPECT_FALSE(host.DecrementBlobRefCount(kId));
57 EXPECT_FALSE(host.IncrementBlobRefCount(kId)); 59 EXPECT_FALSE(host.IncrementBlobRefCount(kId));
58 } 60 }
59 61
60 TEST(BlobStorageContextTest, BlobDataHandle) { 62 TEST(BlobStorageContextTest, BlobDataHandle) {
(...skipping 14 matching lines...) Expand all
75 EXPECT_TRUE(host.DecrementBlobRefCount(kId)); 77 EXPECT_TRUE(host.DecrementBlobRefCount(kId));
76 78
77 // Should still be there due to the handle. 79 // Should still be there due to the handle.
78 scoped_ptr<BlobDataHandle> another_handle = 80 scoped_ptr<BlobDataHandle> another_handle =
79 context.GetBlobDataFromUUID(kId); 81 context.GetBlobDataFromUUID(kId);
80 EXPECT_TRUE(another_handle); 82 EXPECT_TRUE(another_handle);
81 83
82 // Should disappear after dropping both handles. 84 // Should disappear after dropping both handles.
83 blob_data_handle.reset(); 85 blob_data_handle.reset();
84 another_handle.reset(); 86 another_handle.reset();
87 fake_io_message_loop.RunUntilIdle();
85 blob_data_handle = context.GetBlobDataFromUUID(kId); 88 blob_data_handle = context.GetBlobDataFromUUID(kId);
86 EXPECT_FALSE(blob_data_handle); 89 EXPECT_FALSE(blob_data_handle);
87 } 90 }
88 91
89 TEST(BlobStorageContextTest, CompoundBlobs) { 92 TEST(BlobStorageContextTest, CompoundBlobs) {
90 const std::string kId1("id1"); 93 const std::string kId1("id1");
91 const std::string kId2("id2"); 94 const std::string kId2("id2");
92 const std::string kId2Prime("id2.prime"); 95 const std::string kId2Prime("id2.prime");
93 96
94 base::MessageLoop fake_io_message_loop; 97 base::MessageLoop fake_io_message_loop;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 SetupBasicBlob(&host, kId); 146 SetupBasicBlob(&host, kId);
144 147
145 // Now register a url for that blob. 148 // Now register a url for that blob.
146 GURL kUrl("blob:id"); 149 GURL kUrl("blob:id");
147 EXPECT_TRUE(host.RegisterPublicBlobURL(kUrl, kId)); 150 EXPECT_TRUE(host.RegisterPublicBlobURL(kUrl, kId));
148 scoped_ptr<BlobDataHandle> blob_data_handle = 151 scoped_ptr<BlobDataHandle> blob_data_handle =
149 context.GetBlobDataFromPublicURL(kUrl); 152 context.GetBlobDataFromPublicURL(kUrl);
150 ASSERT_TRUE(blob_data_handle.get()); 153 ASSERT_TRUE(blob_data_handle.get());
151 EXPECT_EQ(kId, blob_data_handle->data()->uuid()); 154 EXPECT_EQ(kId, blob_data_handle->data()->uuid());
152 blob_data_handle.reset(); 155 blob_data_handle.reset();
156 fake_io_message_loop.RunUntilIdle();
153 157
154 // The url registration should keep the blob alive even after 158 // The url registration should keep the blob alive even after
155 // explicit references are dropped. 159 // explicit references are dropped.
156 EXPECT_TRUE(host.DecrementBlobRefCount(kId)); 160 EXPECT_TRUE(host.DecrementBlobRefCount(kId));
157 blob_data_handle = context.GetBlobDataFromPublicURL(kUrl); 161 blob_data_handle = context.GetBlobDataFromPublicURL(kUrl);
158 EXPECT_TRUE(blob_data_handle); 162 EXPECT_TRUE(blob_data_handle);
159 blob_data_handle.reset(); 163 blob_data_handle.reset();
164 fake_io_message_loop.RunUntilIdle();
160 165
161 // Finally get rid of the url registration and the blob. 166 // Finally get rid of the url registration and the blob.
162 EXPECT_TRUE(host.RevokePublicBlobURL(kUrl)); 167 EXPECT_TRUE(host.RevokePublicBlobURL(kUrl));
163 blob_data_handle = context.GetBlobDataFromPublicURL(kUrl); 168 blob_data_handle = context.GetBlobDataFromPublicURL(kUrl);
164 EXPECT_TRUE(!blob_data_handle.get()); 169 EXPECT_TRUE(!blob_data_handle.get());
165 EXPECT_FALSE(host.RevokePublicBlobURL(kUrl)); 170 EXPECT_FALSE(host.RevokePublicBlobURL(kUrl));
166 } 171 }
167 172
168 TEST(BlobStorageContextTest, HostCleanup) { 173 TEST(BlobStorageContextTest, HostCleanup) {
169 BlobStorageContext context; 174 BlobStorageContext context;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 EXPECT_FALSE(host.FinishBuildingBlob(kId, "text/plain")); 206 EXPECT_FALSE(host.FinishBuildingBlob(kId, "text/plain"));
202 EXPECT_FALSE(host.RegisterPublicBlobURL(kUrl, kId)); 207 EXPECT_FALSE(host.RegisterPublicBlobURL(kUrl, kId));
203 EXPECT_FALSE(host.IncrementBlobRefCount(kId)); 208 EXPECT_FALSE(host.IncrementBlobRefCount(kId));
204 EXPECT_FALSE(host.DecrementBlobRefCount(kId)); 209 EXPECT_FALSE(host.DecrementBlobRefCount(kId));
205 EXPECT_FALSE(host.RevokePublicBlobURL(kUrl)); 210 EXPECT_FALSE(host.RevokePublicBlobURL(kUrl));
206 } 211 }
207 212
208 // TODO(michaeln): tests for the depcrecated url stuff 213 // TODO(michaeln): tests for the depcrecated url stuff
209 214
210 } // namespace content 215 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | webkit/browser/blob/blob_data_handle.h » ('j') | webkit/browser/blob/blob_data_handle.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698