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

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

Issue 454353002: Cleanup namespace usage in modules/. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 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 23 matching lines...) Expand all
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" 38 #include "modules/indexeddb/IDBPendingTransactionMonitor.h"
39 #include "platform/SharedBuffer.h" 39 #include "platform/SharedBuffer.h"
40 #include "public/platform/WebIDBDatabase.h" 40 #include "public/platform/WebIDBDatabase.h"
41 #include <gtest/gtest.h> 41 #include <gtest/gtest.h>
42 #include <v8.h> 42 #include <v8.h>
43 43
44 using namespace blink; 44 namespace blink {
45
46 using blink::WebIDBDatabase;
47
48 namespace { 45 namespace {
49 46
50 class IDBTransactionTest : public testing::Test { 47 class IDBTransactionTest : public testing::Test {
51 public: 48 public:
52 IDBTransactionTest() 49 IDBTransactionTest()
53 : m_scope(v8::Isolate::GetCurrent()) 50 : m_scope(v8::Isolate::GetCurrent())
54 , m_executionContext(Document::create()) 51 , m_executionContext(Document::create())
55 { 52 {
56 m_scope.scriptState()->setExecutionContext(m_executionContext.get()); 53 m_scope.scriptState()->setExecutionContext(m_executionContext.get());
57 } 54 }
58 55
59 ~IDBTransactionTest() 56 ~IDBTransactionTest()
60 { 57 {
61 m_scope.scriptState()->setExecutionContext(0); 58 m_scope.scriptState()->setExecutionContext(0);
62 } 59 }
63 60
64 v8::Isolate* isolate() const { return m_scope.isolate(); } 61 v8::Isolate* isolate() const { return m_scope.isolate(); }
65 ScriptState* scriptState() const { return m_scope.scriptState(); } 62 ScriptState* scriptState() const { return m_scope.scriptState(); }
66 ExecutionContext* executionContext() { return m_scope.scriptState()->executi onContext(); } 63 ExecutionContext* executionContext() { return m_scope.scriptState()->executi onContext(); }
67 64
68 private: 65 private:
69 V8TestingScope m_scope; 66 V8TestingScope m_scope;
70 RefPtrWillBePersistent<ExecutionContext> m_executionContext; 67 RefPtrWillBePersistent<ExecutionContext> m_executionContext;
71 }; 68 };
72 69
73 class FakeWebIDBDatabase FINAL : public blink::WebIDBDatabase { 70 class FakeWebIDBDatabase FINAL : public WebIDBDatabase {
74 public: 71 public:
75 static PassOwnPtr<FakeWebIDBDatabase> create() { return adoptPtr(new FakeWeb IDBDatabase()); } 72 static PassOwnPtr<FakeWebIDBDatabase> create() { return adoptPtr(new FakeWeb IDBDatabase()); }
76 73
77 virtual void commit(long long transactionId) OVERRIDE { } 74 virtual void commit(long long transactionId) OVERRIDE { }
78 virtual void abort(long long transactionId) OVERRIDE { } 75 virtual void abort(long long transactionId) OVERRIDE { }
79 virtual void close() OVERRIDE { } 76 virtual void close() OVERRIDE { }
80 77
81 private: 78 private:
82 FakeWebIDBDatabase() { } 79 FakeWebIDBDatabase() { }
83 }; 80 };
84 81
85 class FakeIDBDatabaseCallbacks FINAL : public IDBDatabaseCallbacks { 82 class FakeIDBDatabaseCallbacks FINAL : public IDBDatabaseCallbacks {
86 public: 83 public:
87 static FakeIDBDatabaseCallbacks* create() { return new FakeIDBDatabaseCallba cks(); } 84 static FakeIDBDatabaseCallbacks* create() { return new FakeIDBDatabaseCallba cks(); }
88 virtual void onVersionChange(int64_t oldVersion, int64_t newVersion) OVERRID E { } 85 virtual void onVersionChange(int64_t oldVersion, int64_t newVersion) OVERRID E { }
89 virtual void onForcedClose() OVERRIDE { } 86 virtual void onForcedClose() OVERRIDE { }
90 virtual void onAbort(int64_t transactionId, PassRefPtrWillBeRawPtr<DOMError> error) OVERRIDE { } 87 virtual void onAbort(int64_t transactionId, PassRefPtrWillBeRawPtr<DOMError> error) OVERRIDE { }
91 virtual void onComplete(int64_t transactionId) OVERRIDE { } 88 virtual void onComplete(int64_t transactionId) OVERRIDE { }
92 private: 89 private:
93 FakeIDBDatabaseCallbacks() { } 90 FakeIDBDatabaseCallbacks() { }
94 }; 91 };
95 92
96 TEST_F(IDBTransactionTest, EnsureLifetime) 93 TEST_F(IDBTransactionTest, EnsureLifetime)
97 { 94 {
98 OwnPtr<FakeWebIDBDatabase> backend = FakeWebIDBDatabase::create(); 95 OwnPtr<FakeWebIDBDatabase> backend = FakeWebIDBDatabase::create();
99 Persistent<IDBDatabase> db = IDBDatabase::create(executionContext(), backend .release(), FakeIDBDatabaseCallbacks::create()); 96 Persistent<IDBDatabase> db = IDBDatabase::create(executionContext(), backend .release(), FakeIDBDatabaseCallbacks::create());
100 97
101 const int64_t transactionId = 1234; 98 const int64_t transactionId = 1234;
102 const Vector<String> transactionScope; 99 const Vector<String> transactionScope;
103 Persistent<IDBTransaction> transaction = IDBTransaction::create(executionCon text(), transactionId, transactionScope, blink::WebIDBTransactionModeReadOnly, d b.get()); 100 Persistent<IDBTransaction> transaction = IDBTransaction::create(executionCon text(), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.get() );
104 PersistentHeapHashSet<WeakMember<IDBTransaction> > set; 101 PersistentHeapHashSet<WeakMember<IDBTransaction> > set;
105 set.add(transaction); 102 set.add(transaction);
106 103
107 Heap::collectAllGarbage(); 104 Heap::collectAllGarbage();
108 EXPECT_EQ(1u, set.size()); 105 EXPECT_EQ(1u, set.size());
109 106
110 Persistent<IDBRequest> request = IDBRequest::create(scriptState(), IDBAny::c reateUndefined(), transaction.get()); 107 Persistent<IDBRequest> request = IDBRequest::create(scriptState(), IDBAny::c reateUndefined(), transaction.get());
111 IDBPendingTransactionMonitor::from(*executionContext()).deactivateNewTransac tions(); 108 IDBPendingTransactionMonitor::from(*executionContext()).deactivateNewTransac tions();
112 109
113 Heap::collectAllGarbage(); 110 Heap::collectAllGarbage();
114 EXPECT_EQ(1u, set.size()); 111 EXPECT_EQ(1u, set.size());
115 112
116 // 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,
117 // so an explicit onAbort call is made. 114 // so an explicit onAbort call is made.
118 executionContext()->stopActiveDOMObjects(); 115 executionContext()->stopActiveDOMObjects();
119 transaction->onAbort(DOMError::create(AbortError, "Aborted")); 116 transaction->onAbort(DOMError::create(AbortError, "Aborted"));
120 transaction.clear(); 117 transaction.clear();
121 118
122 Heap::collectAllGarbage(); 119 Heap::collectAllGarbage();
123 EXPECT_EQ(0u, set.size()); 120 EXPECT_EQ(0u, set.size());
124 } 121 }
125 122
126 TEST_F(IDBTransactionTest, TransactionFinish) 123 TEST_F(IDBTransactionTest, TransactionFinish)
127 { 124 {
128 OwnPtr<FakeWebIDBDatabase> backend = FakeWebIDBDatabase::create(); 125 OwnPtr<FakeWebIDBDatabase> backend = FakeWebIDBDatabase::create();
129 Persistent<IDBDatabase> db = IDBDatabase::create(executionContext(), backend .release(), FakeIDBDatabaseCallbacks::create()); 126 Persistent<IDBDatabase> db = IDBDatabase::create(executionContext(), backend .release(), FakeIDBDatabaseCallbacks::create());
130 127
131 const int64_t transactionId = 1234; 128 const int64_t transactionId = 1234;
132 const Vector<String> transactionScope; 129 const Vector<String> transactionScope;
133 Persistent<IDBTransaction> transaction = IDBTransaction::create(executionCon text(), transactionId, transactionScope, blink::WebIDBTransactionModeReadOnly, d b.get()); 130 Persistent<IDBTransaction> transaction = IDBTransaction::create(executionCon text(), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.get() );
134 PersistentHeapHashSet<WeakMember<IDBTransaction> > set; 131 PersistentHeapHashSet<WeakMember<IDBTransaction> > set;
135 set.add(transaction); 132 set.add(transaction);
136 133
137 Heap::collectAllGarbage(); 134 Heap::collectAllGarbage();
138 EXPECT_EQ(1u, set.size()); 135 EXPECT_EQ(1u, set.size());
139 136
140 IDBPendingTransactionMonitor::from(*executionContext()).deactivateNewTransac tions(); 137 IDBPendingTransactionMonitor::from(*executionContext()).deactivateNewTransac tions();
141 138
142 Heap::collectAllGarbage(); 139 Heap::collectAllGarbage();
143 EXPECT_EQ(1u, set.size()); 140 EXPECT_EQ(1u, set.size());
144 141
145 transaction.clear(); 142 transaction.clear();
146 143
147 Heap::collectAllGarbage(); 144 Heap::collectAllGarbage();
148 EXPECT_EQ(1u, set.size()); 145 EXPECT_EQ(1u, set.size());
149 146
150 // Stop the context, so events don't get queued (which would keep the transa ction alive). 147 // Stop the context, so events don't get queued (which would keep the transa ction alive).
151 executionContext()->stopActiveDOMObjects(); 148 executionContext()->stopActiveDOMObjects();
152 149
153 // Fire an abort to make sure this doesn't free the transaction during use. The test 150 // 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. 151 // will not fail if it is, but ASAN would notice the error.
155 db->onAbort(transactionId, DOMError::create(AbortError, "Aborted")); 152 db->onAbort(transactionId, DOMError::create(AbortError, "Aborted"));
156 153
157 // onAbort() should have cleared the transaction's reference to the database . 154 // onAbort() should have cleared the transaction's reference to the database .
158 Heap::collectAllGarbage(); 155 Heap::collectAllGarbage();
159 EXPECT_EQ(0u, set.size()); 156 EXPECT_EQ(0u, set.size());
160 } 157 }
161 158
162 } // namespace 159 } // namespace
160 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/indexeddb/IDBRequestTest.cpp ('k') | Source/modules/serviceworkers/ServiceWorkerContainerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698