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

Side by Side Diff: content/browser/indexed_db/indexed_db_factory_unittest.cc

Issue 18023022: Blob support for IDB [Chromium] (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: small cleanup Created 7 years 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/browser/indexed_db/indexed_db_factory.h" 5 #include "content/browser/indexed_db/indexed_db_factory.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 29 matching lines...) Expand all
40 scoped_refptr<IndexedDBBackingStore> TestOpenBackingStore( 40 scoped_refptr<IndexedDBBackingStore> TestOpenBackingStore(
41 const GURL& origin, 41 const GURL& origin,
42 const base::FilePath& data_directory) { 42 const base::FilePath& data_directory) {
43 blink::WebIDBDataLoss data_loss = 43 blink::WebIDBDataLoss data_loss =
44 blink::WebIDBDataLossNone; 44 blink::WebIDBDataLossNone;
45 std::string data_loss_message; 45 std::string data_loss_message;
46 bool disk_full; 46 bool disk_full;
47 scoped_refptr<IndexedDBBackingStore> backing_store = 47 scoped_refptr<IndexedDBBackingStore> backing_store =
48 OpenBackingStore(origin, 48 OpenBackingStore(origin,
49 data_directory, 49 data_directory,
50 NULL, /* request_context */
50 &data_loss, 51 &data_loss,
51 &data_loss_message, 52 &data_loss_message,
52 &disk_full); 53 &disk_full,
54 NULL /* TaskRunner */);
53 EXPECT_EQ(blink::WebIDBDataLossNone, data_loss); 55 EXPECT_EQ(blink::WebIDBDataLossNone, data_loss);
54 return backing_store; 56 return backing_store;
55 } 57 }
56 58
57 void TestCloseBackingStore(IndexedDBBackingStore* backing_store) { 59 void TestCloseBackingStore(IndexedDBBackingStore* backing_store) {
58 CloseBackingStore(backing_store->origin_url()); 60 CloseBackingStore(backing_store->origin_url());
59 } 61 }
60 62
61 void TestReleaseBackingStore(IndexedDBBackingStore* backing_store, 63 void TestReleaseBackingStore(IndexedDBBackingStore* backing_store,
62 bool immediate) { 64 bool immediate) {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 182
181 class DiskFullFactory : public IndexedDBFactory { 183 class DiskFullFactory : public IndexedDBFactory {
182 public: 184 public:
183 DiskFullFactory() : IndexedDBFactory(NULL) {} 185 DiskFullFactory() : IndexedDBFactory(NULL) {}
184 186
185 private: 187 private:
186 virtual ~DiskFullFactory() {} 188 virtual ~DiskFullFactory() {}
187 virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStore( 189 virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStore(
188 const GURL& origin_url, 190 const GURL& origin_url,
189 const base::FilePath& data_directory, 191 const base::FilePath& data_directory,
192 net::URLRequestContext* request_context,
190 blink::WebIDBDataLoss* data_loss, 193 blink::WebIDBDataLoss* data_loss,
191 std::string* data_loss_message, 194 std::string* data_loss_message,
192 bool* disk_full) OVERRIDE { 195 bool* disk_full,
196 base::TaskRunner* task_runner) OVERRIDE {
193 *disk_full = true; 197 *disk_full = true;
194 return scoped_refptr<IndexedDBBackingStore>(); 198 return scoped_refptr<IndexedDBBackingStore>();
195 } 199 }
196 }; 200 };
197 201
198 class LookingForQuotaErrorMockCallbacks : public IndexedDBCallbacks { 202 class LookingForQuotaErrorMockCallbacks : public IndexedDBCallbacks {
199 public: 203 public:
200 LookingForQuotaErrorMockCallbacks() 204 LookingForQuotaErrorMockCallbacks()
201 : IndexedDBCallbacks(NULL, 0, 0), error_called_(false) {} 205 : IndexedDBCallbacks(NULL, 0, 0), error_called_(false) {}
202 virtual void OnError(const IndexedDBDatabaseError& error) OVERRIDE { 206 virtual void OnError(const IndexedDBDatabaseError& error) OVERRIDE {
203 error_called_ = true; 207 error_called_ = true;
204 EXPECT_EQ(blink::WebIDBDatabaseExceptionQuotaError, error.code()); 208 EXPECT_EQ(blink::WebIDBDatabaseExceptionQuotaError, error.code());
205 } 209 }
206 210
207 private: 211 private:
208 virtual ~LookingForQuotaErrorMockCallbacks() { EXPECT_TRUE(error_called_); } 212 virtual ~LookingForQuotaErrorMockCallbacks() { EXPECT_TRUE(error_called_); }
209 bool error_called_; 213 bool error_called_;
210 }; 214 };
211 215
212 TEST_F(IndexedDBFactoryTest, QuotaErrorOnDiskFull) { 216 TEST_F(IndexedDBFactoryTest, QuotaErrorOnDiskFull) {
213 const GURL origin("http://localhost:81"); 217 const GURL origin("http://localhost:81");
218 base::ScopedTempDir temp_directory;
219 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
214 220
215 scoped_refptr<DiskFullFactory> factory = new DiskFullFactory; 221 scoped_refptr<DiskFullFactory> factory = new DiskFullFactory;
216 scoped_refptr<LookingForQuotaErrorMockCallbacks> callbacks = 222 scoped_refptr<LookingForQuotaErrorMockCallbacks> callbacks =
217 new LookingForQuotaErrorMockCallbacks; 223 new LookingForQuotaErrorMockCallbacks;
218 scoped_refptr<IndexedDBDatabaseCallbacks> dummy_database_callbacks = 224 scoped_refptr<IndexedDBDatabaseCallbacks> dummy_database_callbacks =
219 new IndexedDBDatabaseCallbacks(NULL, 0, 0); 225 new IndexedDBDatabaseCallbacks(NULL, 0, 0);
220 const string16 name(ASCIIToUTF16("name")); 226 const string16 name(ASCIIToUTF16("name"));
221 factory->Open(name, 227 factory->Open(name,
222 1, /* version */ 228 1, /* version */
229 NULL, /* request_context */
223 2, /* transaction_id */ 230 2, /* transaction_id */
224 callbacks, 231 callbacks,
225 dummy_database_callbacks, 232 dummy_database_callbacks,
226 origin, 233 origin,
227 base::FilePath(FILE_PATH_LITERAL("/dummy"))); 234 temp_directory.path(),
235 0, /* child_process_id */
236 NULL /* task_runner */);
228 } 237 }
229 238
230 TEST_F(IndexedDBFactoryTest, BackingStoreReleasedOnForcedClose) { 239 TEST_F(IndexedDBFactoryTest, BackingStoreReleasedOnForcedClose) {
231 GURL origin("http://localhost:81"); 240 GURL origin("http://localhost:81");
232 241
233 base::ScopedTempDir temp_directory; 242 base::ScopedTempDir temp_directory;
234 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); 243 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
235 244
236 scoped_refptr<IndexedDBFactory> factory = new IndexedDBFactory(NULL); 245 scoped_refptr<IndexedDBFactory> factory = new IndexedDBFactory(NULL);
237 246
238 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); 247 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks());
239 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( 248 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks(
240 new MockIndexedDBDatabaseCallbacks()); 249 new MockIndexedDBDatabaseCallbacks());
241 const int64 transaction_id = 1; 250 const int64 transaction_id = 1;
242 factory->Open(ASCIIToUTF16("db"), 251 factory->Open(ASCIIToUTF16("db"),
243 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION, 252 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION,
253 NULL, /* request_context */
244 transaction_id, 254 transaction_id,
245 callbacks, 255 callbacks,
246 db_callbacks, 256 db_callbacks,
247 origin, 257 origin,
248 temp_directory.path()); 258 temp_directory.path(),
259 0, /* child_process_id */
260 NULL /* task_runner */);
249 261
250 EXPECT_TRUE(callbacks->connection()); 262 EXPECT_TRUE(callbacks->connection());
251 263
252 EXPECT_TRUE(factory->IsBackingStoreOpenForTesting(origin)); 264 EXPECT_TRUE(factory->IsBackingStoreOpenForTesting(origin));
253 callbacks->connection()->ForceClose(); 265 callbacks->connection()->ForceClose();
254 EXPECT_FALSE(factory->IsBackingStoreOpenForTesting(origin)); 266 EXPECT_FALSE(factory->IsBackingStoreOpenForTesting(origin));
255 } 267 }
256 268
257 TEST_F(IndexedDBFactoryTest, BackingStoreReleaseDelayedOnClose) { 269 TEST_F(IndexedDBFactoryTest, BackingStoreReleaseDelayedOnClose) {
258 GURL origin("http://localhost:81"); 270 GURL origin("http://localhost:81");
259 271
260 base::ScopedTempDir temp_directory; 272 base::ScopedTempDir temp_directory;
261 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); 273 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
262 274
263 scoped_refptr<IndexedDBFactory> factory = new IndexedDBFactory(NULL); 275 scoped_refptr<IndexedDBFactory> factory = new IndexedDBFactory(NULL);
264 276
265 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); 277 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks());
266 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( 278 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks(
267 new MockIndexedDBDatabaseCallbacks()); 279 new MockIndexedDBDatabaseCallbacks());
268 const int64 transaction_id = 1; 280 const int64 transaction_id = 1;
269 factory->Open(ASCIIToUTF16("db"), 281 factory->Open(ASCIIToUTF16("db"),
270 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION, 282 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION,
283 NULL, /* request_context */
271 transaction_id, 284 transaction_id,
272 callbacks, 285 callbacks,
273 db_callbacks, 286 db_callbacks,
274 origin, 287 origin,
275 temp_directory.path()); 288 temp_directory.path(),
289 0, /* child_process_id */
290 NULL /* task_runner */);
276 291
277 EXPECT_TRUE(callbacks->connection()); 292 EXPECT_TRUE(callbacks->connection());
278 IndexedDBBackingStore* store = 293 IndexedDBBackingStore* store =
279 callbacks->connection()->database()->backing_store(); 294 callbacks->connection()->database()->backing_store();
280 EXPECT_FALSE(store->HasOneRef()); // Factory and database. 295 EXPECT_FALSE(store->HasOneRef()); // Factory and database.
281 296
282 EXPECT_TRUE(factory->IsBackingStoreOpenForTesting(origin)); 297 EXPECT_TRUE(factory->IsBackingStoreOpenForTesting(origin));
283 callbacks->connection()->Close(); 298 callbacks->connection()->Close();
284 EXPECT_TRUE(store->HasOneRef()); // Factory. 299 EXPECT_TRUE(store->HasOneRef()); // Factory.
285 EXPECT_TRUE(factory->IsBackingStoreOpenForTesting(origin)); 300 EXPECT_TRUE(factory->IsBackingStoreOpenForTesting(origin));
286 EXPECT_TRUE(store->close_timer()->IsRunning()); 301 EXPECT_TRUE(store->close_timer()->IsRunning());
287 302
288 // Take a ref so it won't be destroyed out from under the test. 303 // Take a ref so it won't be destroyed out from under the test.
289 scoped_refptr<IndexedDBBackingStore> store_ref = store; 304 scoped_refptr<IndexedDBBackingStore> store_ref = store;
290 // Now simulate shutdown, which should stop the timer. 305 // Now simulate shutdown, which should stop the timer.
291 factory->ContextDestroyed(); 306 factory->ContextDestroyed();
292 EXPECT_TRUE(store->HasOneRef()); // Local. 307 EXPECT_TRUE(store->HasOneRef()); // Local.
293 EXPECT_FALSE(store->close_timer()->IsRunning()); 308 EXPECT_FALSE(store->close_timer()->IsRunning());
294 EXPECT_FALSE(factory->IsBackingStoreOpenForTesting(origin)); 309 EXPECT_FALSE(factory->IsBackingStoreOpenForTesting(origin));
295 } 310 }
296 311
297 } // namespace 312 } // namespace
298 313
299 } // namespace content 314 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698