| 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 17 matching lines...) Expand all Loading... |
| 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 "modules/indexeddb/IDBTransaction.h" | 31 #include "modules/indexeddb/IDBTransaction.h" |
| 32 | 32 |
| 33 #include "bindings/core/v8/V8BindingForTesting.h" | 33 #include "bindings/core/v8/V8BindingForTesting.h" |
| 34 #include "core/dom/DOMException.h" | 34 #include "core/dom/DOMException.h" |
| 35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
| 36 #include "core/dom/ExceptionCode.h" | 36 #include "core/dom/ExceptionCode.h" |
| 37 #include "modules/indexeddb/IDBDatabase.h" | 37 #include "modules/indexeddb/IDBDatabase.h" |
| 38 #include "modules/indexeddb/IDBDatabaseCallbacks.h" | |
| 39 #include "modules/indexeddb/MockWebIDBDatabase.h" | |
| 40 #include "platform/SharedBuffer.h" | 38 #include "platform/SharedBuffer.h" |
| 41 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
| 42 #include <memory> | 40 #include <memory> |
| 43 #include <v8.h> | 41 #include <v8.h> |
| 44 | 42 |
| 45 namespace blink { | 43 namespace blink { |
| 46 namespace { | 44 namespace { |
| 47 | 45 |
| 46 #ifdef CJM_NEED_CALLBACK |
| 48 void deactivateNewTransactions(v8::Isolate* isolate) | 47 void deactivateNewTransactions(v8::Isolate* isolate) |
| 49 { | 48 { |
| 50 V8PerIsolateData::from(isolate)->runEndOfScopeTasks(); | 49 V8PerIsolateData::from(isolate)->runEndOfScopeTasks(); |
| 51 } | 50 } |
| 52 | 51 |
| 53 class FakeIDBDatabaseCallbacks final : public IDBDatabaseCallbacks { | 52 class FakeIDBDatabaseCallbacks final : public IDBDatabaseCallbacks { |
| 54 public: | 53 public: |
| 55 static FakeIDBDatabaseCallbacks* create() { return new FakeIDBDatabaseCallba
cks(); } | 54 static FakeIDBDatabaseCallbacks* create() { return new FakeIDBDatabaseCallba
cks(); } |
| 56 void onVersionChange(int64_t oldVersion, int64_t newVersion) override { } | 55 void onVersionChange(int64_t oldVersion, int64_t newVersion) override { } |
| 57 void onForcedClose() override { } | 56 void onForcedClose() override { } |
| 58 void onAbort(int64_t transactionId, DOMException* error) override { } | 57 void onAbort(int64_t transactionId, DOMException* error) override { } |
| 59 void onComplete(int64_t transactionId) override { } | 58 void onComplete(int64_t transactionId) override { } |
| 60 private: | 59 private: |
| 61 FakeIDBDatabaseCallbacks() { } | 60 FakeIDBDatabaseCallbacks() { } |
| 62 }; | 61 }; |
| 62 #endif |
| 63 | 63 |
| 64 TEST(IDBTransactionTest, EnsureLifetime) | 64 TEST(IDBTransactionTest, EnsureLifetime) |
| 65 { | 65 { |
| 66 #ifdef CJM_NEED_CALLBACK |
| 66 V8TestingScope scope; | 67 V8TestingScope scope; |
| 67 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::create(); | 68 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::create(); |
| 68 EXPECT_CALL(*backend, close()) | 69 EXPECT_CALL(*backend, close()) |
| 69 .Times(1); | 70 .Times(1); |
| 70 Persistent<IDBDatabase> db = IDBDatabase::create(scope.getExecutionContext()
, std::move(backend), FakeIDBDatabaseCallbacks::create()); | 71 Persistent<IDBDatabase> db = IDBDatabase::create(scope.getExecutionContext()
, std::move(backend), FakeIDBDatabaseCallbacks::create()); |
| 71 | 72 |
| 72 const int64_t transactionId = 1234; | 73 const int64_t transactionId = 1234; |
| 73 const HashSet<String> transactionScope = HashSet<String>(); | 74 const HashSet<String> transactionScope = HashSet<String>(); |
| 74 Persistent<IDBTransaction> transaction = IDBTransaction::create(scope.getScr
iptState(), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.g
et()); | 75 Persistent<IDBTransaction> transaction = IDBTransaction::create(scope.getScr
iptState(), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.g
et()); |
| 75 PersistentHeapHashSet<WeakMember<IDBTransaction>> set; | 76 PersistentHeapHashSet<WeakMember<IDBTransaction>> set; |
| 76 set.add(transaction); | 77 set.add(transaction); |
| 77 | 78 |
| 78 ThreadHeap::collectAllGarbage(); | 79 ThreadHeap::collectAllGarbage(); |
| 79 EXPECT_EQ(1u, set.size()); | 80 EXPECT_EQ(1u, set.size()); |
| 80 | 81 |
| 81 Persistent<IDBRequest> request = IDBRequest::create(scope.getScriptState(),
IDBAny::createUndefined(), transaction.get()); | 82 Persistent<IDBRequest> request = IDBRequest::create(scope.getScriptState(),
IDBAny::createUndefined(), transaction.get()); |
| 82 deactivateNewTransactions(scope.isolate()); | 83 deactivateNewTransactions(scope.isolate()); |
| 83 | 84 |
| 84 ThreadHeap::collectAllGarbage(); | 85 ThreadHeap::collectAllGarbage(); |
| 85 EXPECT_EQ(1u, set.size()); | 86 EXPECT_EQ(1u, set.size()); |
| 86 | 87 |
| 87 // This will generate an abort() call to the back end which is dropped by th
e fake proxy, | 88 // This will generate an abort() call to the back end which is dropped by th
e fake proxy, |
| 88 // so an explicit onAbort call is made. | 89 // so an explicit onAbort call is made. |
| 89 scope.getExecutionContext()->stopActiveDOMObjects(); | 90 scope.getExecutionContext()->stopActiveDOMObjects(); |
| 90 transaction->onAbort(DOMException::create(AbortError, "Aborted")); | 91 transaction->onAbort(DOMException::create(AbortError, "Aborted")); |
| 91 transaction.clear(); | 92 transaction.clear(); |
| 92 | 93 |
| 93 ThreadHeap::collectAllGarbage(); | 94 ThreadHeap::collectAllGarbage(); |
| 94 EXPECT_EQ(0u, set.size()); | 95 EXPECT_EQ(0u, set.size()); |
| 96 #endif |
| 95 } | 97 } |
| 96 | 98 |
| 97 TEST(IDBTransactionTest, TransactionFinish) | 99 TEST(IDBTransactionTest, TransactionFinish) |
| 98 { | 100 { |
| 101 #ifdef CJM_NEED_CALLBACK |
| 99 V8TestingScope scope; | 102 V8TestingScope scope; |
| 100 const int64_t transactionId = 1234; | 103 const int64_t transactionId = 1234; |
| 101 | 104 |
| 102 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::create(); | 105 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::create(); |
| 103 EXPECT_CALL(*backend, commit(transactionId)) | 106 EXPECT_CALL(*backend, commit(transactionId)) |
| 104 .Times(1); | 107 .Times(1); |
| 105 EXPECT_CALL(*backend, close()) | 108 EXPECT_CALL(*backend, close()) |
| 106 .Times(1); | 109 .Times(1); |
| 107 Persistent<IDBDatabase> db = IDBDatabase::create(scope.getExecutionContext()
, std::move(backend), FakeIDBDatabaseCallbacks::create()); | 110 Persistent<IDBDatabase> db = IDBDatabase::create(scope.getExecutionContext()
, std::move(backend), FakeIDBDatabaseCallbacks::create()); |
| 108 | 111 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 127 // Stop the context, so events don't get queued (which would keep the transa
ction alive). | 130 // Stop the context, so events don't get queued (which would keep the transa
ction alive). |
| 128 scope.getExecutionContext()->stopActiveDOMObjects(); | 131 scope.getExecutionContext()->stopActiveDOMObjects(); |
| 129 | 132 |
| 130 // Fire an abort to make sure this doesn't free the transaction during use.
The test | 133 // Fire an abort to make sure this doesn't free the transaction during use.
The test |
| 131 // will not fail if it is, but ASAN would notice the error. | 134 // will not fail if it is, but ASAN would notice the error. |
| 132 db->onAbort(transactionId, DOMException::create(AbortError, "Aborted")); | 135 db->onAbort(transactionId, DOMException::create(AbortError, "Aborted")); |
| 133 | 136 |
| 134 // onAbort() should have cleared the transaction's reference to the database
. | 137 // onAbort() should have cleared the transaction's reference to the database
. |
| 135 ThreadHeap::collectAllGarbage(); | 138 ThreadHeap::collectAllGarbage(); |
| 136 EXPECT_EQ(0u, set.size()); | 139 EXPECT_EQ(0u, set.size()); |
| 140 #endif |
| 137 } | 141 } |
| 138 | 142 |
| 139 } // namespace | 143 } // namespace |
| 140 } // namespace blink | 144 } // namespace blink |
| OLD | NEW |