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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 EXPECT_CALL(*backend, close()) | 68 EXPECT_CALL(*backend, close()) |
69 .Times(1); | 69 .Times(1); |
70 Persistent<IDBDatabase> db = IDBDatabase::create(scope.getExecutionContext()
, std::move(backend), FakeIDBDatabaseCallbacks::create()); | 70 Persistent<IDBDatabase> db = IDBDatabase::create(scope.getExecutionContext()
, std::move(backend), FakeIDBDatabaseCallbacks::create()); |
71 | 71 |
72 const int64_t transactionId = 1234; | 72 const int64_t transactionId = 1234; |
73 const HashSet<String> transactionScope = HashSet<String>(); | 73 const HashSet<String> transactionScope = HashSet<String>(); |
74 Persistent<IDBTransaction> transaction = IDBTransaction::create(scope.getScr
iptState(), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.g
et()); | 74 Persistent<IDBTransaction> transaction = IDBTransaction::create(scope.getScr
iptState(), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.g
et()); |
75 PersistentHeapHashSet<WeakMember<IDBTransaction>> set; | 75 PersistentHeapHashSet<WeakMember<IDBTransaction>> set; |
76 set.add(transaction); | 76 set.add(transaction); |
77 | 77 |
78 ThreadHeap::collectAllGarbage(); | 78 ThreadState::current()-> collectAllGarbage(); |
79 EXPECT_EQ(1u, set.size()); | 79 EXPECT_EQ(1u, set.size()); |
80 | 80 |
81 Persistent<IDBRequest> request = IDBRequest::create(scope.getScriptState(),
IDBAny::createUndefined(), transaction.get()); | 81 Persistent<IDBRequest> request = IDBRequest::create(scope.getScriptState(),
IDBAny::createUndefined(), transaction.get()); |
82 deactivateNewTransactions(scope.isolate()); | 82 deactivateNewTransactions(scope.isolate()); |
83 | 83 |
84 ThreadHeap::collectAllGarbage(); | 84 ThreadState::current()-> collectAllGarbage(); |
85 EXPECT_EQ(1u, set.size()); | 85 EXPECT_EQ(1u, set.size()); |
86 | 86 |
87 // This will generate an abort() call to the back end which is dropped by th
e fake proxy, | 87 // 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. | 88 // so an explicit onAbort call is made. |
89 scope.getExecutionContext()->stopActiveDOMObjects(); | 89 scope.getExecutionContext()->stopActiveDOMObjects(); |
90 transaction->onAbort(DOMException::create(AbortError, "Aborted")); | 90 transaction->onAbort(DOMException::create(AbortError, "Aborted")); |
91 transaction.clear(); | 91 transaction.clear(); |
92 | 92 |
93 ThreadHeap::collectAllGarbage(); | 93 ThreadState::current()-> collectAllGarbage(); |
94 EXPECT_EQ(0u, set.size()); | 94 EXPECT_EQ(0u, set.size()); |
95 } | 95 } |
96 | 96 |
97 TEST(IDBTransactionTest, TransactionFinish) | 97 TEST(IDBTransactionTest, TransactionFinish) |
98 { | 98 { |
99 V8TestingScope scope; | 99 V8TestingScope scope; |
100 const int64_t transactionId = 1234; | 100 const int64_t transactionId = 1234; |
101 | 101 |
102 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::create(); | 102 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::create(); |
103 EXPECT_CALL(*backend, commit(transactionId)) | 103 EXPECT_CALL(*backend, commit(transactionId)) |
104 .Times(1); | 104 .Times(1); |
105 EXPECT_CALL(*backend, close()) | 105 EXPECT_CALL(*backend, close()) |
106 .Times(1); | 106 .Times(1); |
107 Persistent<IDBDatabase> db = IDBDatabase::create(scope.getExecutionContext()
, std::move(backend), FakeIDBDatabaseCallbacks::create()); | 107 Persistent<IDBDatabase> db = IDBDatabase::create(scope.getExecutionContext()
, std::move(backend), FakeIDBDatabaseCallbacks::create()); |
108 | 108 |
109 const HashSet<String> transactionScope = HashSet<String>(); | 109 const HashSet<String> transactionScope = HashSet<String>(); |
110 Persistent<IDBTransaction> transaction = IDBTransaction::create(scope.getScr
iptState(), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.g
et()); | 110 Persistent<IDBTransaction> transaction = IDBTransaction::create(scope.getScr
iptState(), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.g
et()); |
111 PersistentHeapHashSet<WeakMember<IDBTransaction>> set; | 111 PersistentHeapHashSet<WeakMember<IDBTransaction>> set; |
112 set.add(transaction); | 112 set.add(transaction); |
113 | 113 |
114 ThreadHeap::collectAllGarbage(); | 114 ThreadState::current()-> collectAllGarbage(); |
115 EXPECT_EQ(1u, set.size()); | 115 EXPECT_EQ(1u, set.size()); |
116 | 116 |
117 deactivateNewTransactions(scope.isolate()); | 117 deactivateNewTransactions(scope.isolate()); |
118 | 118 |
119 ThreadHeap::collectAllGarbage(); | 119 ThreadState::current()-> collectAllGarbage(); |
120 EXPECT_EQ(1u, set.size()); | 120 EXPECT_EQ(1u, set.size()); |
121 | 121 |
122 transaction.clear(); | 122 transaction.clear(); |
123 | 123 |
124 ThreadHeap::collectAllGarbage(); | 124 ThreadState::current()-> collectAllGarbage(); |
125 EXPECT_EQ(1u, set.size()); | 125 EXPECT_EQ(1u, set.size()); |
126 | 126 |
127 // Stop the context, so events don't get queued (which would keep the transa
ction alive). | 127 // Stop the context, so events don't get queued (which would keep the transa
ction alive). |
128 scope.getExecutionContext()->stopActiveDOMObjects(); | 128 scope.getExecutionContext()->stopActiveDOMObjects(); |
129 | 129 |
130 // Fire an abort to make sure this doesn't free the transaction during use.
The test | 130 // 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. | 131 // will not fail if it is, but ASAN would notice the error. |
132 db->onAbort(transactionId, DOMException::create(AbortError, "Aborted")); | 132 db->onAbort(transactionId, DOMException::create(AbortError, "Aborted")); |
133 | 133 |
134 // onAbort() should have cleared the transaction's reference to the database
. | 134 // onAbort() should have cleared the transaction's reference to the database
. |
135 ThreadHeap::collectAllGarbage(); | 135 ThreadState::current()-> collectAllGarbage(); |
136 EXPECT_EQ(0u, set.size()); | 136 EXPECT_EQ(0u, set.size()); |
137 } | 137 } |
138 | 138 |
139 } // namespace | 139 } // namespace |
140 } // namespace blink | 140 } // namespace blink |
OLD | NEW |