| 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/in_process_webkit/indexed_db_database_callbacks.h" |
| 13 #include "content/browser/indexed_db/indexed_db.h" | 14 #include "content/browser/indexed_db/indexed_db.h" |
| 14 #include "content/browser/indexed_db/indexed_db_backing_store.h" | 15 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
| 15 #include "content/browser/indexed_db/indexed_db_callbacks_wrapper.h" | 16 #include "content/browser/indexed_db/indexed_db_callbacks_wrapper.h" |
| 16 #include "content/browser/indexed_db/indexed_db_cursor.h" | 17 #include "content/browser/indexed_db/indexed_db_cursor.h" |
| 17 #include "content/browser/indexed_db/indexed_db_database.h" | 18 #include "content/browser/indexed_db/indexed_db_database.h" |
| 18 #include "content/browser/indexed_db/indexed_db_factory.h" | 19 #include "content/browser/indexed_db/indexed_db_factory.h" |
| 19 #include "content/browser/indexed_db/indexed_db_fake_backing_store.h" | 20 #include "content/browser/indexed_db/indexed_db_fake_backing_store.h" |
| 20 #include "content/browser/indexed_db/indexed_db_transaction.h" | 21 #include "content/browser/indexed_db/indexed_db_transaction.h" |
| 21 #include "content/browser/indexed_db/webidbdatabase_impl.h" | 22 #include "content/browser/indexed_db/webidbdatabase_impl.h" |
| 22 | 23 |
| 23 using WebKit::WebIDBDatabase; | |
| 24 using WebKit::WebIDBDatabaseError; | 24 using WebKit::WebIDBDatabaseError; |
| 25 using WebKit::WebIDBDatabaseCallbacks; | |
| 26 | 25 |
| 27 namespace content { | 26 namespace content { |
| 28 | 27 |
| 29 TEST(IndexedDBDatabaseTest, BackingStoreRetention) { | 28 TEST(IndexedDBDatabaseTest, BackingStoreRetention) { |
| 30 scoped_refptr<IndexedDBFakeBackingStore> backing_store = | 29 scoped_refptr<IndexedDBFakeBackingStore> backing_store = |
| 31 new IndexedDBFakeBackingStore(); | 30 new IndexedDBFakeBackingStore(); |
| 32 EXPECT_TRUE(backing_store->HasOneRef()); | 31 EXPECT_TRUE(backing_store->HasOneRef()); |
| 33 | 32 |
| 34 IndexedDBFactory* factory = 0; | 33 IndexedDBFactory* factory = 0; |
| 35 scoped_refptr<IndexedDBDatabase> db = | 34 scoped_refptr<IndexedDBDatabase> db = |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 } | 155 } |
| 157 virtual void OnComplete(int64 transaction_id) OVERRIDE {} | 156 virtual void OnComplete(int64 transaction_id) OVERRIDE {} |
| 158 | 157 |
| 159 private: | 158 private: |
| 160 MockIDBDatabaseCallbacks() | 159 MockIDBDatabaseCallbacks() |
| 161 : IndexedDBDatabaseCallbacksWrapper(NULL), was_abort_called_(false) {} | 160 : IndexedDBDatabaseCallbacksWrapper(NULL), was_abort_called_(false) {} |
| 162 virtual ~MockIDBDatabaseCallbacks() { EXPECT_TRUE(was_abort_called_); } | 161 virtual ~MockIDBDatabaseCallbacks() { EXPECT_TRUE(was_abort_called_); } |
| 163 bool was_abort_called_; | 162 bool was_abort_called_; |
| 164 }; | 163 }; |
| 165 | 164 |
| 166 class WebIDBDatabaseCallbacksImpl : public WebIDBDatabaseCallbacks { | |
| 167 public: | |
| 168 explicit WebIDBDatabaseCallbacksImpl( | |
| 169 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> callbacks) | |
| 170 : callbacks_(callbacks) {} | |
| 171 virtual ~WebIDBDatabaseCallbacksImpl() {} | |
| 172 | |
| 173 virtual void onForcedClose() { callbacks_->OnForcedClose(); } | |
| 174 virtual void onVersionChange(long long old_version, long long new_version) { | |
| 175 callbacks_->OnVersionChange(old_version, new_version); | |
| 176 } | |
| 177 virtual void onAbort(long long transaction_id, | |
| 178 const WebIDBDatabaseError& error) { | |
| 179 callbacks_->OnAbort(transaction_id, IndexedDBDatabaseError(error)); | |
| 180 } | |
| 181 virtual void onComplete(long long transaction_id) { | |
| 182 callbacks_->OnComplete(transaction_id); | |
| 183 } | |
| 184 | |
| 185 private: | |
| 186 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> callbacks_; | |
| 187 }; | |
| 188 | |
| 189 TEST(IndexedDBDatabaseTest, ForcedClose) { | 165 TEST(IndexedDBDatabaseTest, ForcedClose) { |
| 190 scoped_refptr<IndexedDBFakeBackingStore> backing_store = | 166 scoped_refptr<IndexedDBFakeBackingStore> backing_store = |
| 191 new IndexedDBFakeBackingStore(); | 167 new IndexedDBFakeBackingStore(); |
| 192 EXPECT_TRUE(backing_store->HasOneRef()); | 168 EXPECT_TRUE(backing_store->HasOneRef()); |
| 193 | 169 |
| 194 IndexedDBFactory* factory = 0; | 170 IndexedDBFactory* factory = 0; |
| 195 scoped_refptr<IndexedDBDatabase> backend = | 171 scoped_refptr<IndexedDBDatabase> backend = |
| 196 IndexedDBDatabase::Create(ASCIIToUTF16("db"), | 172 IndexedDBDatabase::Create(ASCIIToUTF16("db"), |
| 197 backing_store.get(), | 173 backing_store.get(), |
| 198 factory, | 174 factory, |
| 199 ASCIIToUTF16("uniqueid")); | 175 ASCIIToUTF16("uniqueid")); |
| 200 | 176 |
| 201 EXPECT_FALSE(backing_store->HasOneRef()); // local and db | 177 EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
| 202 | 178 |
| 203 scoped_refptr<MockIDBDatabaseCallbacks> connection = | 179 scoped_refptr<MockIDBDatabaseCallbacks> connection = |
| 204 MockIDBDatabaseCallbacks::Create(); | 180 MockIDBDatabaseCallbacks::Create(); |
| 205 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> connection_proxy = | 181 WebIDBDatabaseImpl web_database(backend, connection); |
| 206 IndexedDBDatabaseCallbacksWrapper::Create( | |
| 207 new WebIDBDatabaseCallbacksImpl(connection)); | |
| 208 WebIDBDatabaseImpl web_database(backend, connection_proxy); | |
| 209 | 182 |
| 210 scoped_refptr<MockIDBCallbacks> request = MockIDBCallbacks::Create(); | 183 scoped_refptr<MockIDBCallbacks> request = MockIDBCallbacks::Create(); |
| 211 const int64 upgrade_transaction_id = 3; | 184 const int64 upgrade_transaction_id = 3; |
| 212 backend->OpenConnection(request, | 185 backend->OpenConnection(request, |
| 213 connection_proxy, | 186 connection, |
| 214 upgrade_transaction_id, | 187 upgrade_transaction_id, |
| 215 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION); | 188 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION); |
| 216 | 189 |
| 217 const int64 transaction_id = 123; | 190 const int64 transaction_id = 123; |
| 218 const std::vector<int64> scope; | 191 const std::vector<int64> scope; |
| 219 web_database.createTransaction( | 192 web_database.createTransaction( |
| 220 transaction_id, 0, scope, indexed_db::TRANSACTION_READ_ONLY); | 193 transaction_id, 0, scope, indexed_db::TRANSACTION_READ_ONLY); |
| 221 | 194 |
| 222 web_database.forceClose(); | 195 web_database.forceClose(); |
| 223 | 196 |
| 224 EXPECT_TRUE(backing_store->HasOneRef()); // local | 197 EXPECT_TRUE(backing_store->HasOneRef()); // local |
| 225 } | 198 } |
| 226 | 199 |
| 227 } // namespace content | 200 } // namespace content |
| OLD | NEW |