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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 FakeIDBDatabaseCallbacks() { } | 93 FakeIDBDatabaseCallbacks() { } |
94 }; | 94 }; |
95 | 95 |
96 TEST_F(IDBTransactionTest, EnsureLifetime) | 96 TEST_F(IDBTransactionTest, EnsureLifetime) |
97 { | 97 { |
98 OwnPtr<FakeWebIDBDatabase> backend = FakeWebIDBDatabase::create(); | 98 OwnPtr<FakeWebIDBDatabase> backend = FakeWebIDBDatabase::create(); |
99 Persistent<IDBDatabase> db = IDBDatabase::create(executionContext(), backend
.release(), FakeIDBDatabaseCallbacks::create()); | 99 Persistent<IDBDatabase> db = IDBDatabase::create(executionContext(), backend
.release(), FakeIDBDatabaseCallbacks::create()); |
100 | 100 |
101 const int64_t transactionId = 1234; | 101 const int64_t transactionId = 1234; |
102 const Vector<String> transactionScope; | 102 const Vector<String> transactionScope; |
103 Persistent<IDBTransaction> transaction = IDBTransaction::create(executionCon
text(), transactionId, transactionScope, blink::WebIDBDatabase::TransactionReadO
nly, db.get()); | 103 Persistent<IDBTransaction> transaction = IDBTransaction::create(executionCon
text(), transactionId, transactionScope, blink::TransactionReadOnly, db.get()); |
104 PersistentHeapHashSet<WeakMember<IDBTransaction> > set; | 104 PersistentHeapHashSet<WeakMember<IDBTransaction> > set; |
105 set.add(transaction); | 105 set.add(transaction); |
106 | 106 |
107 Heap::collectAllGarbage(); | 107 Heap::collectAllGarbage(); |
108 EXPECT_EQ(1u, set.size()); | 108 EXPECT_EQ(1u, set.size()); |
109 | 109 |
110 Persistent<IDBRequest> request = IDBRequest::create(scriptState(), IDBAny::c
reateUndefined(), transaction.get()); | 110 Persistent<IDBRequest> request = IDBRequest::create(scriptState(), IDBAny::c
reateUndefined(), transaction.get()); |
111 IDBPendingTransactionMonitor::from(*executionContext()).deactivateNewTransac
tions(); | 111 IDBPendingTransactionMonitor::from(*executionContext()).deactivateNewTransac
tions(); |
112 | 112 |
113 Heap::collectAllGarbage(); | 113 Heap::collectAllGarbage(); |
114 EXPECT_EQ(1u, set.size()); | 114 EXPECT_EQ(1u, set.size()); |
115 | 115 |
116 // This will generate an abort() call to the back end which is dropped by th
e fake proxy, | 116 // This will generate an abort() call to the back end which is dropped by th
e fake proxy, |
117 // so an explicit onAbort call is made. | 117 // so an explicit onAbort call is made. |
118 executionContext()->stopActiveDOMObjects(); | 118 executionContext()->stopActiveDOMObjects(); |
119 transaction->onAbort(DOMError::create(AbortError, "Aborted")); | 119 transaction->onAbort(DOMError::create(AbortError, "Aborted")); |
120 transaction.clear(); | 120 transaction.clear(); |
121 | 121 |
122 Heap::collectAllGarbage(); | 122 Heap::collectAllGarbage(); |
123 EXPECT_EQ(0u, set.size()); | 123 EXPECT_EQ(0u, set.size()); |
124 } | 124 } |
125 | 125 |
126 TEST_F(IDBTransactionTest, TransactionFinish) | 126 TEST_F(IDBTransactionTest, TransactionFinish) |
127 { | 127 { |
128 OwnPtr<FakeWebIDBDatabase> backend = FakeWebIDBDatabase::create(); | 128 OwnPtr<FakeWebIDBDatabase> backend = FakeWebIDBDatabase::create(); |
129 Persistent<IDBDatabase> db = IDBDatabase::create(executionContext(), backend
.release(), FakeIDBDatabaseCallbacks::create()); | 129 Persistent<IDBDatabase> db = IDBDatabase::create(executionContext(), backend
.release(), FakeIDBDatabaseCallbacks::create()); |
130 | 130 |
131 const int64_t transactionId = 1234; | 131 const int64_t transactionId = 1234; |
132 const Vector<String> transactionScope; | 132 const Vector<String> transactionScope; |
133 Persistent<IDBTransaction> transaction = IDBTransaction::create(executionCon
text(), transactionId, transactionScope, blink::WebIDBDatabase::TransactionReadO
nly, db.get()); | 133 Persistent<IDBTransaction> transaction = IDBTransaction::create(executionCon
text(), transactionId, transactionScope, blink::TransactionReadOnly, db.get()); |
134 PersistentHeapHashSet<WeakMember<IDBTransaction> > set; | 134 PersistentHeapHashSet<WeakMember<IDBTransaction> > set; |
135 set.add(transaction); | 135 set.add(transaction); |
136 | 136 |
137 Heap::collectAllGarbage(); | 137 Heap::collectAllGarbage(); |
138 EXPECT_EQ(1u, set.size()); | 138 EXPECT_EQ(1u, set.size()); |
139 | 139 |
140 IDBPendingTransactionMonitor::from(*executionContext()).deactivateNewTransac
tions(); | 140 IDBPendingTransactionMonitor::from(*executionContext()).deactivateNewTransac
tions(); |
141 | 141 |
142 Heap::collectAllGarbage(); | 142 Heap::collectAllGarbage(); |
143 EXPECT_EQ(1u, set.size()); | 143 EXPECT_EQ(1u, set.size()); |
144 | 144 |
145 transaction.clear(); | 145 transaction.clear(); |
146 | 146 |
147 Heap::collectAllGarbage(); | 147 Heap::collectAllGarbage(); |
148 EXPECT_EQ(1u, set.size()); | 148 EXPECT_EQ(1u, set.size()); |
149 | 149 |
150 // Stop the context, so events don't get queued (which would keep the transa
ction alive). | 150 // Stop the context, so events don't get queued (which would keep the transa
ction alive). |
151 executionContext()->stopActiveDOMObjects(); | 151 executionContext()->stopActiveDOMObjects(); |
152 | 152 |
153 // Fire an abort to make sure this doesn't free the transaction during use.
The test | 153 // Fire an abort to make sure this doesn't free the transaction during use.
The test |
154 // will not fail if it is, but ASAN would notice the error. | 154 // will not fail if it is, but ASAN would notice the error. |
155 db->onAbort(transactionId, DOMError::create(AbortError, "Aborted")); | 155 db->onAbort(transactionId, DOMError::create(AbortError, "Aborted")); |
156 | 156 |
157 // onAbort() should have cleared the transaction's reference to the database
. | 157 // onAbort() should have cleared the transaction's reference to the database
. |
158 Heap::collectAllGarbage(); | 158 Heap::collectAllGarbage(); |
159 EXPECT_EQ(0u, set.size()); | 159 EXPECT_EQ(0u, set.size()); |
160 } | 160 } |
161 | 161 |
162 } // namespace | 162 } // namespace |
OLD | NEW |