| 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 <gtest/gtest.h> | 7 #include <gtest/gtest.h> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/string16.h" | 11 #include "base/string16.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "content/browser/indexed_db/indexed_db.h" | 13 #include "content/browser/indexed_db/indexed_db.h" |
| 14 #include "content/browser/indexed_db/indexed_db_backing_store.h" | 14 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
| 15 #include "content/browser/indexed_db/indexed_db_callbacks_wrapper.h" | 15 #include "content/browser/indexed_db/indexed_db_callbacks_wrapper.h" |
| 16 #include "content/browser/indexed_db/indexed_db_cursor.h" | 16 #include "content/browser/indexed_db/indexed_db_cursor.h" |
| 17 #include "content/browser/indexed_db/indexed_db_database_impl.h" | 17 #include "content/browser/indexed_db/indexed_db_database.h" |
| 18 #include "content/browser/indexed_db/indexed_db_factory_impl.h" | 18 #include "content/browser/indexed_db/indexed_db_factory.h" |
| 19 #include "content/browser/indexed_db/indexed_db_fake_backing_store.h" | 19 #include "content/browser/indexed_db/indexed_db_fake_backing_store.h" |
| 20 #include "content/browser/indexed_db/indexed_db_transaction.h" | 20 #include "content/browser/indexed_db/indexed_db_transaction.h" |
| 21 #include "content/browser/indexed_db/webidbdatabase_impl.h" | 21 #include "content/browser/indexed_db/webidbdatabase_impl.h" |
| 22 | 22 |
| 23 using WebKit::WebIDBDatabase; | 23 using WebKit::WebIDBDatabase; |
| 24 using WebKit::WebIDBDatabaseError; | 24 using WebKit::WebIDBDatabaseError; |
| 25 using WebKit::WebIDBDatabaseCallbacks; | 25 using WebKit::WebIDBDatabaseCallbacks; |
| 26 | 26 |
| 27 namespace content { | 27 namespace content { |
| 28 | 28 |
| 29 TEST(IndexedDBDatabaseTest, BackingStoreRetention) { | 29 TEST(IndexedDBDatabaseTest, BackingStoreRetention) { |
| 30 scoped_refptr<IndexedDBFakeBackingStore> backing_store = | 30 scoped_refptr<IndexedDBFakeBackingStore> backing_store = |
| 31 new IndexedDBFakeBackingStore(); | 31 new IndexedDBFakeBackingStore(); |
| 32 EXPECT_TRUE(backing_store->HasOneRef()); | 32 EXPECT_TRUE(backing_store->HasOneRef()); |
| 33 | 33 |
| 34 IndexedDBFactoryImpl* factory = 0; | 34 IndexedDBFactory* factory = 0; |
| 35 scoped_refptr<IndexedDBDatabaseImpl> db = | 35 scoped_refptr<IndexedDBDatabase> db = |
| 36 IndexedDBDatabaseImpl::Create(ASCIIToUTF16("db"), | 36 IndexedDBDatabase::Create(ASCIIToUTF16("db"), |
| 37 backing_store.get(), | 37 backing_store.get(), |
| 38 factory, | 38 factory, |
| 39 ASCIIToUTF16("uniqueid")); | 39 ASCIIToUTF16("uniqueid")); |
| 40 EXPECT_FALSE(backing_store->HasOneRef()); // local and db | 40 EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
| 41 db = NULL; | 41 db = NULL; |
| 42 EXPECT_TRUE(backing_store->HasOneRef()); // local | 42 EXPECT_TRUE(backing_store->HasOneRef()); // local |
| 43 } | 43 } |
| 44 | 44 |
| 45 class MockIDBCallbacks : public IndexedDBCallbacksWrapper { | 45 class MockIDBCallbacks : public IndexedDBCallbacksWrapper { |
| 46 public: | 46 public: |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 friend class base::RefCounted<FakeIDBDatabaseCallbacks>; | 94 friend class base::RefCounted<FakeIDBDatabaseCallbacks>; |
| 95 virtual ~FakeIDBDatabaseCallbacks() {} | 95 virtual ~FakeIDBDatabaseCallbacks() {} |
| 96 FakeIDBDatabaseCallbacks() : IndexedDBDatabaseCallbacksWrapper(NULL) {} | 96 FakeIDBDatabaseCallbacks() : IndexedDBDatabaseCallbacksWrapper(NULL) {} |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 TEST(IndexedDBDatabaseTest, ConnectionLifecycle) { | 99 TEST(IndexedDBDatabaseTest, ConnectionLifecycle) { |
| 100 scoped_refptr<IndexedDBFakeBackingStore> backing_store = | 100 scoped_refptr<IndexedDBFakeBackingStore> backing_store = |
| 101 new IndexedDBFakeBackingStore(); | 101 new IndexedDBFakeBackingStore(); |
| 102 EXPECT_TRUE(backing_store->HasOneRef()); // local | 102 EXPECT_TRUE(backing_store->HasOneRef()); // local |
| 103 | 103 |
| 104 IndexedDBFactoryImpl* factory = 0; | 104 IndexedDBFactory* factory = 0; |
| 105 scoped_refptr<IndexedDBDatabaseImpl> db = | 105 scoped_refptr<IndexedDBDatabase> db = |
| 106 IndexedDBDatabaseImpl::Create(ASCIIToUTF16("db"), | 106 IndexedDBDatabase::Create(ASCIIToUTF16("db"), |
| 107 backing_store.get(), | 107 backing_store.get(), |
| 108 factory, | 108 factory, |
| 109 ASCIIToUTF16("uniqueid")); | 109 ASCIIToUTF16("uniqueid")); |
| 110 | 110 |
| 111 EXPECT_FALSE(backing_store->HasOneRef()); // local and db | 111 EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
| 112 | 112 |
| 113 scoped_refptr<MockIDBCallbacks> request1 = MockIDBCallbacks::Create(); | 113 scoped_refptr<MockIDBCallbacks> request1 = MockIDBCallbacks::Create(); |
| 114 scoped_refptr<FakeIDBDatabaseCallbacks> connection1 = | 114 scoped_refptr<FakeIDBDatabaseCallbacks> connection1 = |
| 115 FakeIDBDatabaseCallbacks::Create(); | 115 FakeIDBDatabaseCallbacks::Create(); |
| 116 const int64 transaction_id1 = 1; | 116 const int64 transaction_id1 = 1; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 184 |
| 185 private: | 185 private: |
| 186 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> callbacks_; | 186 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> callbacks_; |
| 187 }; | 187 }; |
| 188 | 188 |
| 189 TEST(IndexedDBDatabaseTest, ForcedClose) { | 189 TEST(IndexedDBDatabaseTest, ForcedClose) { |
| 190 scoped_refptr<IndexedDBFakeBackingStore> backing_store = | 190 scoped_refptr<IndexedDBFakeBackingStore> backing_store = |
| 191 new IndexedDBFakeBackingStore(); | 191 new IndexedDBFakeBackingStore(); |
| 192 EXPECT_TRUE(backing_store->HasOneRef()); | 192 EXPECT_TRUE(backing_store->HasOneRef()); |
| 193 | 193 |
| 194 IndexedDBFactoryImpl* factory = 0; | 194 IndexedDBFactory* factory = 0; |
| 195 scoped_refptr<IndexedDBDatabaseImpl> backend = | 195 scoped_refptr<IndexedDBDatabase> backend = |
| 196 IndexedDBDatabaseImpl::Create(ASCIIToUTF16("db"), | 196 IndexedDBDatabase::Create(ASCIIToUTF16("db"), |
| 197 backing_store.get(), | 197 backing_store.get(), |
| 198 factory, | 198 factory, |
| 199 ASCIIToUTF16("uniqueid")); | 199 ASCIIToUTF16("uniqueid")); |
| 200 | 200 |
| 201 EXPECT_FALSE(backing_store->HasOneRef()); // local and db | 201 EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
| 202 | 202 |
| 203 scoped_refptr<MockIDBDatabaseCallbacks> connection = | 203 scoped_refptr<MockIDBDatabaseCallbacks> connection = |
| 204 MockIDBDatabaseCallbacks::Create(); | 204 MockIDBDatabaseCallbacks::Create(); |
| 205 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> connection_proxy = | 205 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> connection_proxy = |
| 206 IndexedDBDatabaseCallbacksWrapper::Create( | 206 IndexedDBDatabaseCallbacksWrapper::Create( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 218 const std::vector<int64> scope; | 218 const std::vector<int64> scope; |
| 219 web_database.createTransaction( | 219 web_database.createTransaction( |
| 220 transaction_id, 0, scope, indexed_db::TRANSACTION_READ_ONLY); | 220 transaction_id, 0, scope, indexed_db::TRANSACTION_READ_ONLY); |
| 221 | 221 |
| 222 web_database.forceClose(); | 222 web_database.forceClose(); |
| 223 | 223 |
| 224 EXPECT_TRUE(backing_store->HasOneRef()); // local | 224 EXPECT_TRUE(backing_store->HasOneRef()); // local |
| 225 } | 225 } |
| 226 | 226 |
| 227 } // namespace content | 227 } // namespace content |
| OLD | NEW |