| OLD | NEW |
| 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_database.h" | 5 #include "content/browser/indexed_db/indexed_db_database.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 } | 28 } |
| 29 | 29 |
| 30 namespace content { | 30 namespace content { |
| 31 | 31 |
| 32 TEST(IndexedDBDatabaseTest, BackingStoreRetention) { | 32 TEST(IndexedDBDatabaseTest, BackingStoreRetention) { |
| 33 scoped_refptr<IndexedDBFakeBackingStore> backing_store = | 33 scoped_refptr<IndexedDBFakeBackingStore> backing_store = |
| 34 new IndexedDBFakeBackingStore(); | 34 new IndexedDBFakeBackingStore(); |
| 35 EXPECT_TRUE(backing_store->HasOneRef()); | 35 EXPECT_TRUE(backing_store->HasOneRef()); |
| 36 | 36 |
| 37 IndexedDBFactory* factory = 0; | 37 IndexedDBFactory* factory = 0; |
| 38 scoped_refptr<IndexedDBDatabase> db = IndexedDBDatabase::Create( | 38 leveldb::Status s; |
| 39 ASCIIToUTF16("db"), | 39 scoped_refptr<IndexedDBDatabase> db = |
| 40 backing_store, | 40 IndexedDBDatabase::Create(ASCIIToUTF16("db"), |
| 41 factory, | 41 backing_store, |
| 42 IndexedDBDatabase::Identifier()); | 42 factory, |
| 43 IndexedDBDatabase::Identifier(), |
| 44 s); |
| 43 EXPECT_FALSE(backing_store->HasOneRef()); // local and db | 45 EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
| 44 db = NULL; | 46 db = NULL; |
| 45 EXPECT_TRUE(backing_store->HasOneRef()); // local | 47 EXPECT_TRUE(backing_store->HasOneRef()); // local |
| 46 } | 48 } |
| 47 | 49 |
| 48 TEST(IndexedDBDatabaseTest, ConnectionLifecycle) { | 50 TEST(IndexedDBDatabaseTest, ConnectionLifecycle) { |
| 49 scoped_refptr<IndexedDBFakeBackingStore> backing_store = | 51 scoped_refptr<IndexedDBFakeBackingStore> backing_store = |
| 50 new IndexedDBFakeBackingStore(); | 52 new IndexedDBFakeBackingStore(); |
| 51 EXPECT_TRUE(backing_store->HasOneRef()); // local | 53 EXPECT_TRUE(backing_store->HasOneRef()); // local |
| 52 | 54 |
| 53 IndexedDBFactory* factory = 0; | 55 IndexedDBFactory* factory = 0; |
| 56 leveldb::Status s; |
| 54 scoped_refptr<IndexedDBDatabase> db = | 57 scoped_refptr<IndexedDBDatabase> db = |
| 55 IndexedDBDatabase::Create(ASCIIToUTF16("db"), | 58 IndexedDBDatabase::Create(ASCIIToUTF16("db"), |
| 56 backing_store, | 59 backing_store, |
| 57 factory, | 60 factory, |
| 58 IndexedDBDatabase::Identifier()); | 61 IndexedDBDatabase::Identifier(), |
| 62 s); |
| 59 | 63 |
| 60 EXPECT_FALSE(backing_store->HasOneRef()); // local and db | 64 EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
| 61 | 65 |
| 62 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks()); | 66 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks()); |
| 63 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1( | 67 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1( |
| 64 new MockIndexedDBDatabaseCallbacks()); | 68 new MockIndexedDBDatabaseCallbacks()); |
| 65 const int64 transaction_id1 = 1; | 69 const int64 transaction_id1 = 1; |
| 66 IndexedDBPendingConnection connection1( | 70 IndexedDBPendingConnection connection1( |
| 67 request1, | 71 request1, |
| 68 callbacks1, | 72 callbacks1, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 | 104 |
| 101 db = NULL; | 105 db = NULL; |
| 102 } | 106 } |
| 103 | 107 |
| 104 TEST(IndexedDBDatabaseTest, ForcedClose) { | 108 TEST(IndexedDBDatabaseTest, ForcedClose) { |
| 105 scoped_refptr<IndexedDBFakeBackingStore> backing_store = | 109 scoped_refptr<IndexedDBFakeBackingStore> backing_store = |
| 106 new IndexedDBFakeBackingStore(); | 110 new IndexedDBFakeBackingStore(); |
| 107 EXPECT_TRUE(backing_store->HasOneRef()); | 111 EXPECT_TRUE(backing_store->HasOneRef()); |
| 108 | 112 |
| 109 IndexedDBFactory* factory = 0; | 113 IndexedDBFactory* factory = 0; |
| 114 leveldb::Status s; |
| 110 scoped_refptr<IndexedDBDatabase> database = | 115 scoped_refptr<IndexedDBDatabase> database = |
| 111 IndexedDBDatabase::Create(ASCIIToUTF16("db"), | 116 IndexedDBDatabase::Create(ASCIIToUTF16("db"), |
| 112 backing_store, | 117 backing_store, |
| 113 factory, | 118 factory, |
| 114 IndexedDBDatabase::Identifier()); | 119 IndexedDBDatabase::Identifier(), |
| 120 s); |
| 115 | 121 |
| 116 EXPECT_FALSE(backing_store->HasOneRef()); // local and db | 122 EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
| 117 | 123 |
| 118 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks( | 124 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks( |
| 119 new MockIndexedDBDatabaseCallbacks()); | 125 new MockIndexedDBDatabaseCallbacks()); |
| 120 scoped_refptr<MockIndexedDBCallbacks> request(new MockIndexedDBCallbacks()); | 126 scoped_refptr<MockIndexedDBCallbacks> request(new MockIndexedDBCallbacks()); |
| 121 const int64 upgrade_transaction_id = 3; | 127 const int64 upgrade_transaction_id = 3; |
| 122 IndexedDBPendingConnection connection( | 128 IndexedDBPendingConnection connection( |
| 123 request, | 129 request, |
| 124 callbacks, | 130 callbacks, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 bool blocked_called_; | 167 bool blocked_called_; |
| 162 bool success_void_called_; | 168 bool success_void_called_; |
| 163 }; | 169 }; |
| 164 | 170 |
| 165 TEST(IndexedDBDatabaseTest, PendingDelete) { | 171 TEST(IndexedDBDatabaseTest, PendingDelete) { |
| 166 scoped_refptr<IndexedDBFakeBackingStore> backing_store = | 172 scoped_refptr<IndexedDBFakeBackingStore> backing_store = |
| 167 new IndexedDBFakeBackingStore(); | 173 new IndexedDBFakeBackingStore(); |
| 168 EXPECT_TRUE(backing_store->HasOneRef()); // local | 174 EXPECT_TRUE(backing_store->HasOneRef()); // local |
| 169 | 175 |
| 170 IndexedDBFactory* factory = 0; | 176 IndexedDBFactory* factory = 0; |
| 177 leveldb::Status s; |
| 171 scoped_refptr<IndexedDBDatabase> db = | 178 scoped_refptr<IndexedDBDatabase> db = |
| 172 IndexedDBDatabase::Create(ASCIIToUTF16("db"), | 179 IndexedDBDatabase::Create(ASCIIToUTF16("db"), |
| 173 backing_store, | 180 backing_store, |
| 174 factory, | 181 factory, |
| 175 IndexedDBDatabase::Identifier()); | 182 IndexedDBDatabase::Identifier(), |
| 183 s); |
| 176 | 184 |
| 177 EXPECT_FALSE(backing_store->HasOneRef()); // local and db | 185 EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
| 178 | 186 |
| 179 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks()); | 187 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks()); |
| 180 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1( | 188 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1( |
| 181 new MockIndexedDBDatabaseCallbacks()); | 189 new MockIndexedDBDatabaseCallbacks()); |
| 182 const int64 transaction_id1 = 1; | 190 const int64 transaction_id1 = 1; |
| 183 IndexedDBPendingConnection connection( | 191 IndexedDBPendingConnection connection( |
| 184 request1, | 192 request1, |
| 185 callbacks1, | 193 callbacks1, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 196 EXPECT_TRUE(request2->blocked_called()); | 204 EXPECT_TRUE(request2->blocked_called()); |
| 197 EXPECT_FALSE(backing_store->HasOneRef()); // local and db | 205 EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
| 198 | 206 |
| 199 db->Close(request1->connection(), true /* forced */); | 207 db->Close(request1->connection(), true /* forced */); |
| 200 | 208 |
| 201 EXPECT_FALSE(db->backing_store()); | 209 EXPECT_FALSE(db->backing_store()); |
| 202 EXPECT_TRUE(backing_store->HasOneRef()); // local | 210 EXPECT_TRUE(backing_store->HasOneRef()); // local |
| 203 } | 211 } |
| 204 | 212 |
| 205 } // namespace content | 213 } // namespace content |
| OLD | NEW |