| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "modules/indexeddb/IDBTransaction.h" | 32 #include "modules/indexeddb/IDBTransaction.h" |
| 33 | 33 |
| 34 #include "bindings/core/v8/V8BindingForTesting.h" | 34 #include "bindings/core/v8/V8BindingForTesting.h" |
| 35 #include "core/dom/DOMError.h" | 35 #include "core/dom/DOMException.h" |
| 36 #include "core/dom/Document.h" | 36 #include "core/dom/Document.h" |
| 37 #include "core/dom/ExceptionCode.h" |
| 37 #include "modules/indexeddb/IDBDatabase.h" | 38 #include "modules/indexeddb/IDBDatabase.h" |
| 38 #include "modules/indexeddb/IDBDatabaseCallbacks.h" | 39 #include "modules/indexeddb/IDBDatabaseCallbacks.h" |
| 39 #include "platform/SharedBuffer.h" | 40 #include "platform/SharedBuffer.h" |
| 40 #include "public/platform/modules/indexeddb/WebIDBDatabase.h" | 41 #include "public/platform/modules/indexeddb/WebIDBDatabase.h" |
| 41 #include <gtest/gtest.h> | 42 #include <gtest/gtest.h> |
| 42 #include <v8.h> | 43 #include <v8.h> |
| 43 | 44 |
| 44 namespace blink { | 45 namespace blink { |
| 45 namespace { | 46 namespace { |
| 46 | 47 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 88 |
| 88 private: | 89 private: |
| 89 FakeWebIDBDatabase() { } | 90 FakeWebIDBDatabase() { } |
| 90 }; | 91 }; |
| 91 | 92 |
| 92 class FakeIDBDatabaseCallbacks final : public IDBDatabaseCallbacks { | 93 class FakeIDBDatabaseCallbacks final : public IDBDatabaseCallbacks { |
| 93 public: | 94 public: |
| 94 static FakeIDBDatabaseCallbacks* create() { return new FakeIDBDatabaseCallba
cks(); } | 95 static FakeIDBDatabaseCallbacks* create() { return new FakeIDBDatabaseCallba
cks(); } |
| 95 void onVersionChange(int64_t oldVersion, int64_t newVersion) override { } | 96 void onVersionChange(int64_t oldVersion, int64_t newVersion) override { } |
| 96 void onForcedClose() override { } | 97 void onForcedClose() override { } |
| 97 void onAbort(int64_t transactionId, DOMError* error) override { } | 98 void onAbort(int64_t transactionId, DOMException* error) override { } |
| 98 void onComplete(int64_t transactionId) override { } | 99 void onComplete(int64_t transactionId) override { } |
| 99 private: | 100 private: |
| 100 FakeIDBDatabaseCallbacks() { } | 101 FakeIDBDatabaseCallbacks() { } |
| 101 }; | 102 }; |
| 102 | 103 |
| 103 TEST_F(IDBTransactionTest, EnsureLifetime) | 104 TEST_F(IDBTransactionTest, EnsureLifetime) |
| 104 { | 105 { |
| 105 OwnPtr<FakeWebIDBDatabase> backend = FakeWebIDBDatabase::create(); | 106 OwnPtr<FakeWebIDBDatabase> backend = FakeWebIDBDatabase::create(); |
| 106 Persistent<IDBDatabase> db = IDBDatabase::create(executionContext(), backend
.release(), FakeIDBDatabaseCallbacks::create()); | 107 Persistent<IDBDatabase> db = IDBDatabase::create(executionContext(), backend
.release(), FakeIDBDatabaseCallbacks::create()); |
| 107 | 108 |
| 108 const int64_t transactionId = 1234; | 109 const int64_t transactionId = 1234; |
| 109 const HashSet<String> transactionScope = HashSet<String>(); | 110 const HashSet<String> transactionScope = HashSet<String>(); |
| 110 Persistent<IDBTransaction> transaction = IDBTransaction::create(scriptState(
), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.get()); | 111 Persistent<IDBTransaction> transaction = IDBTransaction::create(scriptState(
), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.get()); |
| 111 PersistentHeapHashSet<WeakMember<IDBTransaction>> set; | 112 PersistentHeapHashSet<WeakMember<IDBTransaction>> set; |
| 112 set.add(transaction); | 113 set.add(transaction); |
| 113 | 114 |
| 114 Heap::collectAllGarbage(); | 115 Heap::collectAllGarbage(); |
| 115 EXPECT_EQ(1u, set.size()); | 116 EXPECT_EQ(1u, set.size()); |
| 116 | 117 |
| 117 Persistent<IDBRequest> request = IDBRequest::create(scriptState(), IDBAny::c
reateUndefined(), transaction.get()); | 118 Persistent<IDBRequest> request = IDBRequest::create(scriptState(), IDBAny::c
reateUndefined(), transaction.get()); |
| 118 deactivateNewTransactions(); | 119 deactivateNewTransactions(); |
| 119 | 120 |
| 120 Heap::collectAllGarbage(); | 121 Heap::collectAllGarbage(); |
| 121 EXPECT_EQ(1u, set.size()); | 122 EXPECT_EQ(1u, set.size()); |
| 122 | 123 |
| 123 // This will generate an abort() call to the back end which is dropped by th
e fake proxy, | 124 // This will generate an abort() call to the back end which is dropped by th
e fake proxy, |
| 124 // so an explicit onAbort call is made. | 125 // so an explicit onAbort call is made. |
| 125 executionContext()->stopActiveDOMObjects(); | 126 executionContext()->stopActiveDOMObjects(); |
| 126 transaction->onAbort(DOMError::create(AbortError, "Aborted")); | 127 transaction->onAbort(DOMException::create(AbortError, "Aborted")); |
| 127 transaction.clear(); | 128 transaction.clear(); |
| 128 | 129 |
| 129 Heap::collectAllGarbage(); | 130 Heap::collectAllGarbage(); |
| 130 EXPECT_EQ(0u, set.size()); | 131 EXPECT_EQ(0u, set.size()); |
| 131 } | 132 } |
| 132 | 133 |
| 133 TEST_F(IDBTransactionTest, TransactionFinish) | 134 TEST_F(IDBTransactionTest, TransactionFinish) |
| 134 { | 135 { |
| 135 OwnPtr<FakeWebIDBDatabase> backend = FakeWebIDBDatabase::create(); | 136 OwnPtr<FakeWebIDBDatabase> backend = FakeWebIDBDatabase::create(); |
| 136 Persistent<IDBDatabase> db = IDBDatabase::create(executionContext(), backend
.release(), FakeIDBDatabaseCallbacks::create()); | 137 Persistent<IDBDatabase> db = IDBDatabase::create(executionContext(), backend
.release(), FakeIDBDatabaseCallbacks::create()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 152 transaction.clear(); | 153 transaction.clear(); |
| 153 | 154 |
| 154 Heap::collectAllGarbage(); | 155 Heap::collectAllGarbage(); |
| 155 EXPECT_EQ(1u, set.size()); | 156 EXPECT_EQ(1u, set.size()); |
| 156 | 157 |
| 157 // Stop the context, so events don't get queued (which would keep the transa
ction alive). | 158 // Stop the context, so events don't get queued (which would keep the transa
ction alive). |
| 158 executionContext()->stopActiveDOMObjects(); | 159 executionContext()->stopActiveDOMObjects(); |
| 159 | 160 |
| 160 // Fire an abort to make sure this doesn't free the transaction during use.
The test | 161 // Fire an abort to make sure this doesn't free the transaction during use.
The test |
| 161 // will not fail if it is, but ASAN would notice the error. | 162 // will not fail if it is, but ASAN would notice the error. |
| 162 db->onAbort(transactionId, DOMError::create(AbortError, "Aborted")); | 163 db->onAbort(transactionId, DOMException::create(AbortError, "Aborted")); |
| 163 | 164 |
| 164 // onAbort() should have cleared the transaction's reference to the database
. | 165 // onAbort() should have cleared the transaction's reference to the database
. |
| 165 Heap::collectAllGarbage(); | 166 Heap::collectAllGarbage(); |
| 166 EXPECT_EQ(0u, set.size()); | 167 EXPECT_EQ(0u, set.size()); |
| 167 } | 168 } |
| 168 | 169 |
| 169 } // namespace | 170 } // namespace |
| 170 } // namespace blink | 171 } // namespace blink |
| OLD | NEW |