| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 class IDBTransactionTest : public testing::Test { | 47 class IDBTransactionTest : public testing::Test { |
| 48 public: | 48 public: |
| 49 IDBTransactionTest() | 49 IDBTransactionTest() |
| 50 : m_scope(v8::Isolate::GetCurrent()) | 50 : m_scope(v8::Isolate::GetCurrent()) |
| 51 { | 51 { |
| 52 } | 52 } |
| 53 | 53 |
| 54 void SetUp() override | 54 void SetUp() override |
| 55 { | 55 { |
| 56 m_executionContext = Document::create(); | 56 m_executionContext = Document::create(); |
| 57 m_scope.scriptState()->setExecutionContext(m_executionContext.get()); | 57 m_scope.getScriptState()->setExecutionContext(m_executionContext.get()); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void TearDown() override | 60 void TearDown() override |
| 61 { | 61 { |
| 62 m_executionContext->notifyContextDestroyed(); | 62 m_executionContext->notifyContextDestroyed(); |
| 63 m_scope.scriptState()->setExecutionContext(nullptr); | 63 m_scope.getScriptState()->setExecutionContext(nullptr); |
| 64 } | 64 } |
| 65 | 65 |
| 66 v8::Isolate* isolate() const { return m_scope.isolate(); } | 66 v8::Isolate* isolate() const { return m_scope.isolate(); } |
| 67 ScriptState* scriptState() const { return m_scope.scriptState(); } | 67 ScriptState* getScriptState() const { return m_scope.getScriptState(); } |
| 68 ExecutionContext* executionContext() { return m_scope.scriptState()->executi
onContext(); } | 68 ExecutionContext* getExecutionContext() { return m_scope.getScriptState()->g
etExecutionContext(); } |
| 69 | 69 |
| 70 void deactivateNewTransactions() | 70 void deactivateNewTransactions() |
| 71 { | 71 { |
| 72 V8PerIsolateData::from(isolate())->runEndOfScopeTasks(); | 72 V8PerIsolateData::from(isolate())->runEndOfScopeTasks(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 private: | 75 private: |
| 76 V8TestingScope m_scope; | 76 V8TestingScope m_scope; |
| 77 RefPtrWillBePersistent<ExecutionContext> m_executionContext; | 77 RefPtrWillBePersistent<ExecutionContext> m_executionContext; |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 class FakeIDBDatabaseCallbacks final : public IDBDatabaseCallbacks { | 80 class FakeIDBDatabaseCallbacks final : public IDBDatabaseCallbacks { |
| 81 public: | 81 public: |
| 82 static FakeIDBDatabaseCallbacks* create() { return new FakeIDBDatabaseCallba
cks(); } | 82 static FakeIDBDatabaseCallbacks* create() { return new FakeIDBDatabaseCallba
cks(); } |
| 83 void onVersionChange(int64_t oldVersion, int64_t newVersion) override { } | 83 void onVersionChange(int64_t oldVersion, int64_t newVersion) override { } |
| 84 void onForcedClose() override { } | 84 void onForcedClose() override { } |
| 85 void onAbort(int64_t transactionId, DOMException* error) override { } | 85 void onAbort(int64_t transactionId, DOMException* error) override { } |
| 86 void onComplete(int64_t transactionId) override { } | 86 void onComplete(int64_t transactionId) override { } |
| 87 private: | 87 private: |
| 88 FakeIDBDatabaseCallbacks() { } | 88 FakeIDBDatabaseCallbacks() { } |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 TEST_F(IDBTransactionTest, EnsureLifetime) | 91 TEST_F(IDBTransactionTest, EnsureLifetime) |
| 92 { | 92 { |
| 93 OwnPtr<MockWebIDBDatabase> backend = MockWebIDBDatabase::create(); | 93 OwnPtr<MockWebIDBDatabase> backend = MockWebIDBDatabase::create(); |
| 94 EXPECT_CALL(*backend, close()) | 94 EXPECT_CALL(*backend, close()) |
| 95 .Times(1); | 95 .Times(1); |
| 96 Persistent<IDBDatabase> db = IDBDatabase::create(executionContext(), backend
.release(), FakeIDBDatabaseCallbacks::create()); | 96 Persistent<IDBDatabase> db = IDBDatabase::create(getExecutionContext(), back
end.release(), FakeIDBDatabaseCallbacks::create()); |
| 97 | 97 |
| 98 const int64_t transactionId = 1234; | 98 const int64_t transactionId = 1234; |
| 99 const HashSet<String> transactionScope = HashSet<String>(); | 99 const HashSet<String> transactionScope = HashSet<String>(); |
| 100 Persistent<IDBTransaction> transaction = IDBTransaction::create(scriptState(
), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.get()); | 100 Persistent<IDBTransaction> transaction = IDBTransaction::create(getScriptSta
te(), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.get()); |
| 101 PersistentHeapHashSet<WeakMember<IDBTransaction>> set; | 101 PersistentHeapHashSet<WeakMember<IDBTransaction>> set; |
| 102 set.add(transaction); | 102 set.add(transaction); |
| 103 | 103 |
| 104 Heap::collectAllGarbage(); | 104 Heap::collectAllGarbage(); |
| 105 EXPECT_EQ(1u, set.size()); | 105 EXPECT_EQ(1u, set.size()); |
| 106 | 106 |
| 107 Persistent<IDBRequest> request = IDBRequest::create(scriptState(), IDBAny::c
reateUndefined(), transaction.get()); | 107 Persistent<IDBRequest> request = IDBRequest::create(getScriptState(), IDBAny
::createUndefined(), transaction.get()); |
| 108 deactivateNewTransactions(); | 108 deactivateNewTransactions(); |
| 109 | 109 |
| 110 Heap::collectAllGarbage(); | 110 Heap::collectAllGarbage(); |
| 111 EXPECT_EQ(1u, set.size()); | 111 EXPECT_EQ(1u, set.size()); |
| 112 | 112 |
| 113 // This will generate an abort() call to the back end which is dropped by th
e fake proxy, | 113 // This will generate an abort() call to the back end which is dropped by th
e fake proxy, |
| 114 // so an explicit onAbort call is made. | 114 // so an explicit onAbort call is made. |
| 115 executionContext()->stopActiveDOMObjects(); | 115 getExecutionContext()->stopActiveDOMObjects(); |
| 116 transaction->onAbort(DOMException::create(AbortError, "Aborted")); | 116 transaction->onAbort(DOMException::create(AbortError, "Aborted")); |
| 117 transaction.clear(); | 117 transaction.clear(); |
| 118 | 118 |
| 119 Heap::collectAllGarbage(); | 119 Heap::collectAllGarbage(); |
| 120 EXPECT_EQ(0u, set.size()); | 120 EXPECT_EQ(0u, set.size()); |
| 121 } | 121 } |
| 122 | 122 |
| 123 TEST_F(IDBTransactionTest, TransactionFinish) | 123 TEST_F(IDBTransactionTest, TransactionFinish) |
| 124 { | 124 { |
| 125 const int64_t transactionId = 1234; | 125 const int64_t transactionId = 1234; |
| 126 | 126 |
| 127 OwnPtr<MockWebIDBDatabase> backend = MockWebIDBDatabase::create(); | 127 OwnPtr<MockWebIDBDatabase> backend = MockWebIDBDatabase::create(); |
| 128 EXPECT_CALL(*backend, commit(transactionId)) | 128 EXPECT_CALL(*backend, commit(transactionId)) |
| 129 .Times(1); | 129 .Times(1); |
| 130 EXPECT_CALL(*backend, close()) | 130 EXPECT_CALL(*backend, close()) |
| 131 .Times(1); | 131 .Times(1); |
| 132 Persistent<IDBDatabase> db = IDBDatabase::create(executionContext(), backend
.release(), FakeIDBDatabaseCallbacks::create()); | 132 Persistent<IDBDatabase> db = IDBDatabase::create(getExecutionContext(), back
end.release(), FakeIDBDatabaseCallbacks::create()); |
| 133 | 133 |
| 134 const HashSet<String> transactionScope = HashSet<String>(); | 134 const HashSet<String> transactionScope = HashSet<String>(); |
| 135 Persistent<IDBTransaction> transaction = IDBTransaction::create(scriptState(
), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.get()); | 135 Persistent<IDBTransaction> transaction = IDBTransaction::create(getScriptSta
te(), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.get()); |
| 136 PersistentHeapHashSet<WeakMember<IDBTransaction>> set; | 136 PersistentHeapHashSet<WeakMember<IDBTransaction>> set; |
| 137 set.add(transaction); | 137 set.add(transaction); |
| 138 | 138 |
| 139 Heap::collectAllGarbage(); | 139 Heap::collectAllGarbage(); |
| 140 EXPECT_EQ(1u, set.size()); | 140 EXPECT_EQ(1u, set.size()); |
| 141 | 141 |
| 142 deactivateNewTransactions(); | 142 deactivateNewTransactions(); |
| 143 | 143 |
| 144 Heap::collectAllGarbage(); | 144 Heap::collectAllGarbage(); |
| 145 EXPECT_EQ(1u, set.size()); | 145 EXPECT_EQ(1u, set.size()); |
| 146 | 146 |
| 147 transaction.clear(); | 147 transaction.clear(); |
| 148 | 148 |
| 149 Heap::collectAllGarbage(); | 149 Heap::collectAllGarbage(); |
| 150 EXPECT_EQ(1u, set.size()); | 150 EXPECT_EQ(1u, set.size()); |
| 151 | 151 |
| 152 // Stop the context, so events don't get queued (which would keep the transa
ction alive). | 152 // Stop the context, so events don't get queued (which would keep the transa
ction alive). |
| 153 executionContext()->stopActiveDOMObjects(); | 153 getExecutionContext()->stopActiveDOMObjects(); |
| 154 | 154 |
| 155 // Fire an abort to make sure this doesn't free the transaction during use.
The test | 155 // Fire an abort to make sure this doesn't free the transaction during use.
The test |
| 156 // will not fail if it is, but ASAN would notice the error. | 156 // will not fail if it is, but ASAN would notice the error. |
| 157 db->onAbort(transactionId, DOMException::create(AbortError, "Aborted")); | 157 db->onAbort(transactionId, DOMException::create(AbortError, "Aborted")); |
| 158 | 158 |
| 159 // onAbort() should have cleared the transaction's reference to the database
. | 159 // onAbort() should have cleared the transaction's reference to the database
. |
| 160 Heap::collectAllGarbage(); | 160 Heap::collectAllGarbage(); |
| 161 EXPECT_EQ(0u, set.size()); | 161 EXPECT_EQ(0u, set.size()); |
| 162 } | 162 } |
| 163 | 163 |
| 164 } // namespace | 164 } // namespace |
| 165 } // namespace blink | 165 } // namespace blink |
| OLD | NEW |