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