| 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::Create(); | 141 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::Create(); |
| 142 EXPECT_CALL(*backend, Close()).Times(1); | 142 EXPECT_CALL(*backend, Close()).Times(1); |
| 143 BuildTransaction(scope, std::move(backend)); | 143 BuildTransaction(scope, std::move(backend)); |
| 144 | 144 |
| 145 PersistentHeapHashSet<WeakMember<IDBTransaction>> live_transactions; | 145 PersistentHeapHashSet<WeakMember<IDBTransaction>> live_transactions; |
| 146 live_transactions.insert(transaction_); | 146 live_transactions.insert(transaction_); |
| 147 | 147 |
| 148 ThreadState::Current()->CollectAllGarbage(); | 148 ThreadState::Current()->CollectAllGarbage(); |
| 149 EXPECT_EQ(1u, live_transactions.size()); | 149 EXPECT_EQ(1u, live_transactions.size()); |
| 150 | 150 |
| 151 Persistent<IDBRequest> request = IDBRequest::Create( | 151 Persistent<IDBRequest> request = |
| 152 scope.GetScriptState(), IDBAny::CreateUndefined(), transaction_.Get()); | 152 IDBRequest::Create(scope.GetScriptState(), IDBAny::CreateUndefined(), |
| 153 transaction_.Get(), IDBRequest::AsyncTraceState()); |
| 154 |
| 153 DeactivateNewTransactions(scope.GetIsolate()); | 155 DeactivateNewTransactions(scope.GetIsolate()); |
| 154 | 156 |
| 155 request.Clear(); // The transaction is holding onto the request. | 157 request.Clear(); // The transaction is holding onto the request. |
| 156 ThreadState::Current()->CollectAllGarbage(); | 158 ThreadState::Current()->CollectAllGarbage(); |
| 157 EXPECT_EQ(1u, live_transactions.size()); | 159 EXPECT_EQ(1u, live_transactions.size()); |
| 158 | 160 |
| 159 // This will generate an Abort() call to the back end which is dropped by the | 161 // This will generate an Abort() call to the back end which is dropped by the |
| 160 // fake proxy, so an explicit OnAbort call is made. | 162 // fake proxy, so an explicit OnAbort call is made. |
| 161 scope.GetExecutionContext()->NotifyContextDestroyed(); | 163 scope.GetExecutionContext()->NotifyContextDestroyed(); |
| 162 transaction_->OnAbort(DOMException::Create(kAbortError, "Aborted")); | 164 transaction_->OnAbort(DOMException::Create(kAbortError, "Aborted")); |
| 163 transaction_.Clear(); | 165 transaction_.Clear(); |
| 164 | 166 |
| 165 ThreadState::Current()->CollectAllGarbage(); | 167 ThreadState::Current()->CollectAllGarbage(); |
| 166 EXPECT_EQ(0U, live_transactions.size()); | 168 EXPECT_EQ(0U, live_transactions.size()); |
| 167 } | 169 } |
| 168 | 170 |
| 169 TEST_F(IDBTransactionTest, ContextDestroyedAfterDone) { | 171 TEST_F(IDBTransactionTest, ContextDestroyedAfterDone) { |
| 170 V8TestingScope scope; | 172 V8TestingScope scope; |
| 171 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::Create(); | 173 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::Create(); |
| 172 EXPECT_CALL(*backend, Close()).Times(1); | 174 EXPECT_CALL(*backend, Close()).Times(1); |
| 173 BuildTransaction(scope, std::move(backend)); | 175 BuildTransaction(scope, std::move(backend)); |
| 174 | 176 |
| 175 PersistentHeapHashSet<WeakMember<IDBTransaction>> live_transactions; | 177 PersistentHeapHashSet<WeakMember<IDBTransaction>> live_transactions; |
| 176 live_transactions.insert(transaction_); | 178 live_transactions.insert(transaction_); |
| 177 | 179 |
| 178 ThreadState::Current()->CollectAllGarbage(); | 180 ThreadState::Current()->CollectAllGarbage(); |
| 179 EXPECT_EQ(1U, live_transactions.size()); | 181 EXPECT_EQ(1U, live_transactions.size()); |
| 180 | 182 |
| 181 Persistent<IDBRequest> request = IDBRequest::Create( | 183 Persistent<IDBRequest> request = |
| 182 scope.GetScriptState(), IDBAny::CreateUndefined(), transaction_.Get()); | 184 IDBRequest::Create(scope.GetScriptState(), IDBAny::CreateUndefined(), |
| 185 transaction_.Get(), IDBRequest::AsyncTraceState()); |
| 183 DeactivateNewTransactions(scope.GetIsolate()); | 186 DeactivateNewTransactions(scope.GetIsolate()); |
| 184 | 187 |
| 185 // This response should result in an event being enqueued immediately. | 188 // This response should result in an event being enqueued immediately. |
| 186 request->HandleResponse(CreateIDBValue(scope.GetIsolate(), false)); | 189 request->HandleResponse(CreateIDBValue(scope.GetIsolate(), false)); |
| 187 | 190 |
| 188 request.Clear(); // The transaction is holding onto the request. | 191 request.Clear(); // The transaction is holding onto the request. |
| 189 ThreadState::Current()->CollectAllGarbage(); | 192 ThreadState::Current()->CollectAllGarbage(); |
| 190 EXPECT_EQ(1U, live_transactions.size()); | 193 EXPECT_EQ(1U, live_transactions.size()); |
| 191 | 194 |
| 192 // This will generate an Abort() call to the back end which is dropped by the | 195 // This will generate an Abort() call to the back end which is dropped by the |
| (...skipping 16 matching lines...) Expand all Loading... |
| 209 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::Create(); | 212 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::Create(); |
| 210 EXPECT_CALL(*backend, Close()).Times(1); | 213 EXPECT_CALL(*backend, Close()).Times(1); |
| 211 BuildTransaction(scope, std::move(backend)); | 214 BuildTransaction(scope, std::move(backend)); |
| 212 | 215 |
| 213 PersistentHeapHashSet<WeakMember<IDBTransaction>> live_transactions; | 216 PersistentHeapHashSet<WeakMember<IDBTransaction>> live_transactions; |
| 214 live_transactions.insert(transaction_); | 217 live_transactions.insert(transaction_); |
| 215 | 218 |
| 216 ThreadState::Current()->CollectAllGarbage(); | 219 ThreadState::Current()->CollectAllGarbage(); |
| 217 EXPECT_EQ(1U, live_transactions.size()); | 220 EXPECT_EQ(1U, live_transactions.size()); |
| 218 | 221 |
| 219 Persistent<IDBRequest> request = IDBRequest::Create( | 222 Persistent<IDBRequest> request = |
| 220 scope.GetScriptState(), IDBAny::CreateUndefined(), transaction_.Get()); | 223 IDBRequest::Create(scope.GetScriptState(), IDBAny::CreateUndefined(), |
| 224 transaction_.Get(), IDBRequest::AsyncTraceState()); |
| 221 DeactivateNewTransactions(scope.GetIsolate()); | 225 DeactivateNewTransactions(scope.GetIsolate()); |
| 222 | 226 |
| 223 request->HandleResponse(CreateIDBValue(scope.GetIsolate(), true)); | 227 request->HandleResponse(CreateIDBValue(scope.GetIsolate(), true)); |
| 224 | 228 |
| 225 request.Clear(); // The transaction is holding onto the request. | 229 request.Clear(); // The transaction is holding onto the request. |
| 226 ThreadState::Current()->CollectAllGarbage(); | 230 ThreadState::Current()->CollectAllGarbage(); |
| 227 EXPECT_EQ(1U, live_transactions.size()); | 231 EXPECT_EQ(1U, live_transactions.size()); |
| 228 | 232 |
| 229 // This will generate an Abort() call to the back end which is dropped by the | 233 // This will generate an Abort() call to the back end which is dropped by the |
| 230 // fake proxy, so an explicit OnAbort call is made. | 234 // fake proxy, so an explicit OnAbort call is made. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 243 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::Create(); | 247 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::Create(); |
| 244 EXPECT_CALL(*backend, Close()).Times(1); | 248 EXPECT_CALL(*backend, Close()).Times(1); |
| 245 BuildTransaction(scope, std::move(backend)); | 249 BuildTransaction(scope, std::move(backend)); |
| 246 | 250 |
| 247 PersistentHeapHashSet<WeakMember<IDBTransaction>> live_transactions; | 251 PersistentHeapHashSet<WeakMember<IDBTransaction>> live_transactions; |
| 248 live_transactions.insert(transaction_); | 252 live_transactions.insert(transaction_); |
| 249 | 253 |
| 250 ThreadState::Current()->CollectAllGarbage(); | 254 ThreadState::Current()->CollectAllGarbage(); |
| 251 EXPECT_EQ(1U, live_transactions.size()); | 255 EXPECT_EQ(1U, live_transactions.size()); |
| 252 | 256 |
| 253 Persistent<IDBRequest> request1 = IDBRequest::Create( | 257 Persistent<IDBRequest> request1 = |
| 254 scope.GetScriptState(), IDBAny::CreateUndefined(), transaction_.Get()); | 258 IDBRequest::Create(scope.GetScriptState(), IDBAny::CreateUndefined(), |
| 255 Persistent<IDBRequest> request2 = IDBRequest::Create( | 259 transaction_.Get(), IDBRequest::AsyncTraceState()); |
| 256 scope.GetScriptState(), IDBAny::CreateUndefined(), transaction_.Get()); | 260 Persistent<IDBRequest> request2 = |
| 261 IDBRequest::Create(scope.GetScriptState(), IDBAny::CreateUndefined(), |
| 262 transaction_.Get(), IDBRequest::AsyncTraceState()); |
| 257 DeactivateNewTransactions(scope.GetIsolate()); | 263 DeactivateNewTransactions(scope.GetIsolate()); |
| 258 | 264 |
| 259 request1->HandleResponse(CreateIDBValue(scope.GetIsolate(), true)); | 265 request1->HandleResponse(CreateIDBValue(scope.GetIsolate(), true)); |
| 260 request2->HandleResponse(CreateIDBValue(scope.GetIsolate(), true)); | 266 request2->HandleResponse(CreateIDBValue(scope.GetIsolate(), true)); |
| 261 | 267 |
| 262 request1.Clear(); // The transaction is holding onto the requests. | 268 request1.Clear(); // The transaction is holding onto the requests. |
| 263 request2.Clear(); | 269 request2.Clear(); |
| 264 ThreadState::Current()->CollectAllGarbage(); | 270 ThreadState::Current()->CollectAllGarbage(); |
| 265 EXPECT_EQ(1U, live_transactions.size()); | 271 EXPECT_EQ(1U, live_transactions.size()); |
| 266 | 272 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 // The test will not fail if it is, but ASAN would notice the error. | 313 // The test will not fail if it is, but ASAN would notice the error. |
| 308 db_->OnAbort(kTransactionId, DOMException::Create(kAbortError, "Aborted")); | 314 db_->OnAbort(kTransactionId, DOMException::Create(kAbortError, "Aborted")); |
| 309 | 315 |
| 310 // OnAbort() should have cleared the transaction's reference to the database. | 316 // OnAbort() should have cleared the transaction's reference to the database. |
| 311 ThreadState::Current()->CollectAllGarbage(); | 317 ThreadState::Current()->CollectAllGarbage(); |
| 312 EXPECT_EQ(0U, live_transactions.size()); | 318 EXPECT_EQ(0U, live_transactions.size()); |
| 313 } | 319 } |
| 314 | 320 |
| 315 } // namespace | 321 } // namespace |
| 316 } // namespace blink | 322 } // namespace blink |
| OLD | NEW |