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