Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: Source/modules/indexeddb/IDBTransactionTest.cpp

Issue 429453010: Drop V8RecursionScope dependency on ExecutionContext (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Reorder cleanup methods per haraken Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 "config.h" 31 #include "config.h"
32 #include "modules/indexeddb/IDBTransaction.h" 32 #include "modules/indexeddb/IDBTransaction.h"
33 33
34 #include "core/dom/DOMError.h" 34 #include "core/dom/DOMError.h"
35 #include "core/dom/Document.h" 35 #include "core/dom/Document.h"
36 #include "modules/indexeddb/IDBDatabase.h" 36 #include "modules/indexeddb/IDBDatabase.h"
37 #include "modules/indexeddb/IDBDatabaseCallbacks.h" 37 #include "modules/indexeddb/IDBDatabaseCallbacks.h"
38 #include "modules/indexeddb/IDBPendingTransactionMonitor.h"
39 #include "platform/SharedBuffer.h" 38 #include "platform/SharedBuffer.h"
40 #include "public/platform/WebIDBDatabase.h" 39 #include "public/platform/WebIDBDatabase.h"
41 #include <gtest/gtest.h> 40 #include <gtest/gtest.h>
42 #include <v8.h> 41 #include <v8.h>
43 42
44 namespace blink { 43 namespace blink {
45 namespace { 44 namespace {
46 45
47 class IDBTransactionTest : public testing::Test { 46 class IDBTransactionTest : public testing::Test {
48 public: 47 public:
49 IDBTransactionTest() 48 IDBTransactionTest()
50 : m_scope(v8::Isolate::GetCurrent()) 49 : m_scope(v8::Isolate::GetCurrent())
51 , m_executionContext(Document::create()) 50 , m_executionContext(Document::create())
52 { 51 {
53 m_scope.scriptState()->setExecutionContext(m_executionContext.get()); 52 m_scope.scriptState()->setExecutionContext(m_executionContext.get());
54 } 53 }
55 54
56 ~IDBTransactionTest() 55 ~IDBTransactionTest()
57 { 56 {
58 m_scope.scriptState()->setExecutionContext(0); 57 m_scope.scriptState()->setExecutionContext(0);
59 } 58 }
60 59
61 v8::Isolate* isolate() const { return m_scope.isolate(); } 60 v8::Isolate* isolate() const { return m_scope.isolate(); }
62 ScriptState* scriptState() const { return m_scope.scriptState(); } 61 ScriptState* scriptState() const { return m_scope.scriptState(); }
63 ExecutionContext* executionContext() { return m_scope.scriptState()->executi onContext(); } 62 ExecutionContext* executionContext() { return m_scope.scriptState()->executi onContext(); }
64 63
64 void deactivateNewTransactions()
65 {
66 V8PerIsolateData::from(isolate())->ensureIDBPendingTransactionMonitor()- >deactivateNewTransactions();
67 }
68
65 private: 69 private:
66 V8TestingScope m_scope; 70 V8TestingScope m_scope;
67 RefPtrWillBePersistent<ExecutionContext> m_executionContext; 71 RefPtrWillBePersistent<ExecutionContext> m_executionContext;
68 }; 72 };
69 73
70 class FakeWebIDBDatabase FINAL : public WebIDBDatabase { 74 class FakeWebIDBDatabase FINAL : public WebIDBDatabase {
71 public: 75 public:
72 static PassOwnPtr<FakeWebIDBDatabase> create() { return adoptPtr(new FakeWeb IDBDatabase()); } 76 static PassOwnPtr<FakeWebIDBDatabase> create() { return adoptPtr(new FakeWeb IDBDatabase()); }
73 77
74 virtual void commit(long long transactionId) OVERRIDE { } 78 virtual void commit(long long transactionId) OVERRIDE { }
(...skipping 23 matching lines...) Expand all
98 const int64_t transactionId = 1234; 102 const int64_t transactionId = 1234;
99 const Vector<String> transactionScope; 103 const Vector<String> transactionScope;
100 Persistent<IDBTransaction> transaction = IDBTransaction::create(scriptState( ), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.get()); 104 Persistent<IDBTransaction> transaction = IDBTransaction::create(scriptState( ), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.get());
101 PersistentHeapHashSet<WeakMember<IDBTransaction> > set; 105 PersistentHeapHashSet<WeakMember<IDBTransaction> > set;
102 set.add(transaction); 106 set.add(transaction);
103 107
104 Heap::collectAllGarbage(); 108 Heap::collectAllGarbage();
105 EXPECT_EQ(1u, set.size()); 109 EXPECT_EQ(1u, set.size());
106 110
107 Persistent<IDBRequest> request = IDBRequest::create(scriptState(), IDBAny::c reateUndefined(), transaction.get()); 111 Persistent<IDBRequest> request = IDBRequest::create(scriptState(), IDBAny::c reateUndefined(), transaction.get());
108 IDBPendingTransactionMonitor::from(*executionContext()).deactivateNewTransac tions(); 112 deactivateNewTransactions();
109 113
110 Heap::collectAllGarbage(); 114 Heap::collectAllGarbage();
111 EXPECT_EQ(1u, set.size()); 115 EXPECT_EQ(1u, set.size());
112 116
113 // This will generate an abort() call to the back end which is dropped by th e fake proxy, 117 // 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. 118 // so an explicit onAbort call is made.
115 executionContext()->stopActiveDOMObjects(); 119 executionContext()->stopActiveDOMObjects();
116 transaction->onAbort(DOMError::create(AbortError, "Aborted")); 120 transaction->onAbort(DOMError::create(AbortError, "Aborted"));
117 transaction.clear(); 121 transaction.clear();
118 122
119 Heap::collectAllGarbage(); 123 Heap::collectAllGarbage();
120 EXPECT_EQ(0u, set.size()); 124 EXPECT_EQ(0u, set.size());
121 } 125 }
122 126
123 TEST_F(IDBTransactionTest, TransactionFinish) 127 TEST_F(IDBTransactionTest, TransactionFinish)
124 { 128 {
125 OwnPtr<FakeWebIDBDatabase> backend = FakeWebIDBDatabase::create(); 129 OwnPtr<FakeWebIDBDatabase> backend = FakeWebIDBDatabase::create();
126 Persistent<IDBDatabase> db = IDBDatabase::create(executionContext(), backend .release(), FakeIDBDatabaseCallbacks::create()); 130 Persistent<IDBDatabase> db = IDBDatabase::create(executionContext(), backend .release(), FakeIDBDatabaseCallbacks::create());
127 131
128 const int64_t transactionId = 1234; 132 const int64_t transactionId = 1234;
129 const Vector<String> transactionScope; 133 const Vector<String> transactionScope;
130 Persistent<IDBTransaction> transaction = IDBTransaction::create(scriptState( ), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.get()); 134 Persistent<IDBTransaction> transaction = IDBTransaction::create(scriptState( ), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.get());
131 PersistentHeapHashSet<WeakMember<IDBTransaction> > set; 135 PersistentHeapHashSet<WeakMember<IDBTransaction> > set;
132 set.add(transaction); 136 set.add(transaction);
133 137
134 Heap::collectAllGarbage(); 138 Heap::collectAllGarbage();
135 EXPECT_EQ(1u, set.size()); 139 EXPECT_EQ(1u, set.size());
136 140
137 IDBPendingTransactionMonitor::from(*executionContext()).deactivateNewTransac tions(); 141 deactivateNewTransactions();
138 142
139 Heap::collectAllGarbage(); 143 Heap::collectAllGarbage();
140 EXPECT_EQ(1u, set.size()); 144 EXPECT_EQ(1u, set.size());
141 145
142 transaction.clear(); 146 transaction.clear();
143 147
144 Heap::collectAllGarbage(); 148 Heap::collectAllGarbage();
145 EXPECT_EQ(1u, set.size()); 149 EXPECT_EQ(1u, set.size());
146 150
147 // Stop the context, so events don't get queued (which would keep the transa ction alive). 151 // Stop the context, so events don't get queued (which would keep the transa ction alive).
148 executionContext()->stopActiveDOMObjects(); 152 executionContext()->stopActiveDOMObjects();
149 153
150 // Fire an abort to make sure this doesn't free the transaction during use. The test 154 // Fire an abort to make sure this doesn't free the transaction during use. The test
151 // will not fail if it is, but ASAN would notice the error. 155 // will not fail if it is, but ASAN would notice the error.
152 db->onAbort(transactionId, DOMError::create(AbortError, "Aborted")); 156 db->onAbort(transactionId, DOMError::create(AbortError, "Aborted"));
153 157
154 // onAbort() should have cleared the transaction's reference to the database . 158 // onAbort() should have cleared the transaction's reference to the database .
155 Heap::collectAllGarbage(); 159 Heap::collectAllGarbage();
156 EXPECT_EQ(0u, set.size()); 160 EXPECT_EQ(0u, set.size());
157 } 161 }
158 162
159 } // namespace 163 } // namespace
160 } // namespace blink 164 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/indexeddb/IDBTransaction.cpp ('k') | Source/modules/indexeddb/InspectorIndexedDBAgent.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698