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

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

Issue 261683005: Revert of 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: 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
« no previous file with comments | « no previous file | content/browser/loader/upload_data_stream_builder_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/run_loop.h"
10 #include "base/time/time.h" 9 #include "base/time/time.h"
11 #include "content/browser/fileapi/blob_storage_host.h" 10 #include "content/browser/fileapi/blob_storage_host.h"
12 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
13 #include "webkit/browser/blob/blob_data_handle.h" 12 #include "webkit/browser/blob/blob_data_handle.h"
14 #include "webkit/browser/blob/blob_storage_context.h" 13 #include "webkit/browser/blob/blob_storage_context.h"
15 14
16 using webkit_blob::BlobDataHandle; 15 using webkit_blob::BlobDataHandle;
17 16
18 namespace content { 17 namespace content {
19 18
(...skipping 15 matching lines...) Expand all
35 34
36 // Build up a basic blob. 35 // Build up a basic blob.
37 const std::string kId("id"); 36 const std::string kId("id");
38 SetupBasicBlob(&host, kId); 37 SetupBasicBlob(&host, kId);
39 38
40 // 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.
41 scoped_ptr<BlobDataHandle> blob_data_handle; 40 scoped_ptr<BlobDataHandle> blob_data_handle;
42 blob_data_handle = context.GetBlobDataFromUUID(kId); 41 blob_data_handle = context.GetBlobDataFromUUID(kId);
43 EXPECT_TRUE(blob_data_handle); 42 EXPECT_TRUE(blob_data_handle);
44 blob_data_handle.reset(); 43 blob_data_handle.reset();
45 { // Clean up for ASAN
46 base::RunLoop run_loop;
47 run_loop.RunUntilIdle();
48 }
49 44
50 // Make sure its still there after inc/dec. 45 // Make sure its still there after inc/dec.
51 EXPECT_TRUE(host.IncrementBlobRefCount(kId)); 46 EXPECT_TRUE(host.IncrementBlobRefCount(kId));
52 EXPECT_TRUE(host.DecrementBlobRefCount(kId)); 47 EXPECT_TRUE(host.DecrementBlobRefCount(kId));
53 blob_data_handle = context.GetBlobDataFromUUID(kId); 48 blob_data_handle = context.GetBlobDataFromUUID(kId);
54 EXPECT_TRUE(blob_data_handle); 49 EXPECT_TRUE(blob_data_handle);
55 blob_data_handle.reset(); 50 blob_data_handle.reset();
56 { // Clean up for ASAN
57 base::RunLoop run_loop;
58 run_loop.RunUntilIdle();
59 }
60 51
61 // Make sure it goes away in the end. 52 // Make sure it goes away in the end.
62 EXPECT_TRUE(host.DecrementBlobRefCount(kId)); 53 EXPECT_TRUE(host.DecrementBlobRefCount(kId));
63 blob_data_handle = context.GetBlobDataFromUUID(kId); 54 blob_data_handle = context.GetBlobDataFromUUID(kId);
64 EXPECT_FALSE(blob_data_handle); 55 EXPECT_FALSE(blob_data_handle);
65 EXPECT_FALSE(host.DecrementBlobRefCount(kId)); 56 EXPECT_FALSE(host.DecrementBlobRefCount(kId));
66 EXPECT_FALSE(host.IncrementBlobRefCount(kId)); 57 EXPECT_FALSE(host.IncrementBlobRefCount(kId));
67 } 58 }
68 59
69 TEST(BlobStorageContextTest, BlobDataHandle) { 60 TEST(BlobStorageContextTest, BlobDataHandle) {
(...skipping 14 matching lines...) Expand all
84 EXPECT_TRUE(host.DecrementBlobRefCount(kId)); 75 EXPECT_TRUE(host.DecrementBlobRefCount(kId));
85 76
86 // Should still be there due to the handle. 77 // Should still be there due to the handle.
87 scoped_ptr<BlobDataHandle> another_handle = 78 scoped_ptr<BlobDataHandle> another_handle =
88 context.GetBlobDataFromUUID(kId); 79 context.GetBlobDataFromUUID(kId);
89 EXPECT_TRUE(another_handle); 80 EXPECT_TRUE(another_handle);
90 81
91 // Should disappear after dropping both handles. 82 // Should disappear after dropping both handles.
92 blob_data_handle.reset(); 83 blob_data_handle.reset();
93 another_handle.reset(); 84 another_handle.reset();
94 { // Clean up for ASAN
95 base::RunLoop run_loop;
96 run_loop.RunUntilIdle();
97 }
98 blob_data_handle = context.GetBlobDataFromUUID(kId); 85 blob_data_handle = context.GetBlobDataFromUUID(kId);
99 EXPECT_FALSE(blob_data_handle); 86 EXPECT_FALSE(blob_data_handle);
100 } 87 }
101 88
102 TEST(BlobStorageContextTest, CompoundBlobs) { 89 TEST(BlobStorageContextTest, CompoundBlobs) {
103 const std::string kId1("id1"); 90 const std::string kId1("id1");
104 const std::string kId2("id2"); 91 const std::string kId2("id2");
105 const std::string kId2Prime("id2.prime"); 92 const std::string kId2Prime("id2.prime");
106 93
107 base::MessageLoop fake_io_message_loop; 94 base::MessageLoop fake_io_message_loop;
(...skipping 29 matching lines...) Expand all
137 124
138 // Test a blob referring to only data and a file. 125 // Test a blob referring to only data and a file.
139 blob_data_handle = context.AddFinishedBlob(blob_data1.get()); 126 blob_data_handle = context.AddFinishedBlob(blob_data1.get());
140 ASSERT_TRUE(blob_data_handle.get()); 127 ASSERT_TRUE(blob_data_handle.get());
141 EXPECT_TRUE(*(blob_data_handle->data()) == *blob_data1.get()); 128 EXPECT_TRUE(*(blob_data_handle->data()) == *blob_data1.get());
142 129
143 // Test a blob composed in part with another blob. 130 // Test a blob composed in part with another blob.
144 blob_data_handle = context.AddFinishedBlob(blob_data2.get()); 131 blob_data_handle = context.AddFinishedBlob(blob_data2.get());
145 ASSERT_TRUE(blob_data_handle.get()); 132 ASSERT_TRUE(blob_data_handle.get());
146 EXPECT_TRUE(*(blob_data_handle->data()) == *canonicalized_blob_data2.get()); 133 EXPECT_TRUE(*(blob_data_handle->data()) == *canonicalized_blob_data2.get());
147
148 blob_data_handle.reset();
149 { // Clean up for ASAN
150 base::RunLoop run_loop;
151 run_loop.RunUntilIdle();
152 }
153 } 134 }
154 135
155 TEST(BlobStorageContextTest, PublicBlobUrls) { 136 TEST(BlobStorageContextTest, PublicBlobUrls) {
156 BlobStorageContext context; 137 BlobStorageContext context;
157 BlobStorageHost host(&context); 138 BlobStorageHost host(&context);
158 base::MessageLoop fake_io_message_loop; 139 base::MessageLoop fake_io_message_loop;
159 140
160 // Build up a basic blob. 141 // Build up a basic blob.
161 const std::string kId("id"); 142 const std::string kId("id");
162 SetupBasicBlob(&host, kId); 143 SetupBasicBlob(&host, kId);
163 144
164 // Now register a url for that blob. 145 // Now register a url for that blob.
165 GURL kUrl("blob:id"); 146 GURL kUrl("blob:id");
166 EXPECT_TRUE(host.RegisterPublicBlobURL(kUrl, kId)); 147 EXPECT_TRUE(host.RegisterPublicBlobURL(kUrl, kId));
167 scoped_ptr<BlobDataHandle> blob_data_handle = 148 scoped_ptr<BlobDataHandle> blob_data_handle =
168 context.GetBlobDataFromPublicURL(kUrl); 149 context.GetBlobDataFromPublicURL(kUrl);
169 ASSERT_TRUE(blob_data_handle.get()); 150 ASSERT_TRUE(blob_data_handle.get());
170 EXPECT_EQ(kId, blob_data_handle->data()->uuid()); 151 EXPECT_EQ(kId, blob_data_handle->data()->uuid());
171 blob_data_handle.reset(); 152 blob_data_handle.reset();
172 { // Clean up for ASAN
173 base::RunLoop run_loop;
174 run_loop.RunUntilIdle();
175 }
176 153
177 // The url registration should keep the blob alive even after 154 // The url registration should keep the blob alive even after
178 // explicit references are dropped. 155 // explicit references are dropped.
179 EXPECT_TRUE(host.DecrementBlobRefCount(kId)); 156 EXPECT_TRUE(host.DecrementBlobRefCount(kId));
180 blob_data_handle = context.GetBlobDataFromPublicURL(kUrl); 157 blob_data_handle = context.GetBlobDataFromPublicURL(kUrl);
181 EXPECT_TRUE(blob_data_handle); 158 EXPECT_TRUE(blob_data_handle);
182 blob_data_handle.reset(); 159 blob_data_handle.reset();
183 { // Clean up for ASAN
184 base::RunLoop run_loop;
185 run_loop.RunUntilIdle();
186 }
187 160
188 // Finally get rid of the url registration and the blob. 161 // Finally get rid of the url registration and the blob.
189 EXPECT_TRUE(host.RevokePublicBlobURL(kUrl)); 162 EXPECT_TRUE(host.RevokePublicBlobURL(kUrl));
190 blob_data_handle = context.GetBlobDataFromPublicURL(kUrl); 163 blob_data_handle = context.GetBlobDataFromPublicURL(kUrl);
191 EXPECT_TRUE(!blob_data_handle.get()); 164 EXPECT_TRUE(!blob_data_handle.get());
192 EXPECT_FALSE(host.RevokePublicBlobURL(kUrl)); 165 EXPECT_FALSE(host.RevokePublicBlobURL(kUrl));
193 } 166 }
194 167
195 TEST(BlobStorageContextTest, HostCleanup) { 168 TEST(BlobStorageContextTest, HostCleanup) {
196 BlobStorageContext context; 169 BlobStorageContext context;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 EXPECT_FALSE(host.FinishBuildingBlob(kId, "text/plain")); 201 EXPECT_FALSE(host.FinishBuildingBlob(kId, "text/plain"));
229 EXPECT_FALSE(host.RegisterPublicBlobURL(kUrl, kId)); 202 EXPECT_FALSE(host.RegisterPublicBlobURL(kUrl, kId));
230 EXPECT_FALSE(host.IncrementBlobRefCount(kId)); 203 EXPECT_FALSE(host.IncrementBlobRefCount(kId));
231 EXPECT_FALSE(host.DecrementBlobRefCount(kId)); 204 EXPECT_FALSE(host.DecrementBlobRefCount(kId));
232 EXPECT_FALSE(host.RevokePublicBlobURL(kUrl)); 205 EXPECT_FALSE(host.RevokePublicBlobURL(kUrl));
233 } 206 }
234 207
235 // TODO(michaeln): tests for the depcrecated url stuff 208 // TODO(michaeln): tests for the depcrecated url stuff
236 209
237 } // namespace content 210 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/loader/upload_data_stream_builder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698