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

Side by Side Diff: content/browser/indexed_db/indexed_db_database_unittest.cc

Issue 18147009: IndexedDB: Remove unnecessary scoped_refptr<T>::get() calls (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: clang-format Created 7 years, 5 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 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/indexed_db/indexed_db_database.h" 5 #include "content/browser/indexed_db/indexed_db_database.h"
6 6
7 #include <gtest/gtest.h> 7 #include <gtest/gtest.h>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 11 matching lines...) Expand all
22 #include "content/browser/indexed_db/indexed_db_transaction.h" 22 #include "content/browser/indexed_db/indexed_db_transaction.h"
23 23
24 namespace content { 24 namespace content {
25 25
26 TEST(IndexedDBDatabaseTest, BackingStoreRetention) { 26 TEST(IndexedDBDatabaseTest, BackingStoreRetention) {
27 scoped_refptr<IndexedDBFakeBackingStore> backing_store = 27 scoped_refptr<IndexedDBFakeBackingStore> backing_store =
28 new IndexedDBFakeBackingStore(); 28 new IndexedDBFakeBackingStore();
29 EXPECT_TRUE(backing_store->HasOneRef()); 29 EXPECT_TRUE(backing_store->HasOneRef());
30 30
31 IndexedDBFactory* factory = 0; 31 IndexedDBFactory* factory = 0;
32 scoped_refptr<IndexedDBDatabase> db = 32 scoped_refptr<IndexedDBDatabase> db = IndexedDBDatabase::Create(
33 IndexedDBDatabase::Create(ASCIIToUTF16("db"), 33 ASCIIToUTF16("db"), backing_store, factory, ASCIIToUTF16("uniqueid"));
34 backing_store.get(),
35 factory,
36 ASCIIToUTF16("uniqueid"));
37 EXPECT_FALSE(backing_store->HasOneRef()); // local and db 34 EXPECT_FALSE(backing_store->HasOneRef()); // local and db
38 db = NULL; 35 db = NULL;
39 EXPECT_TRUE(backing_store->HasOneRef()); // local 36 EXPECT_TRUE(backing_store->HasOneRef()); // local
40 } 37 }
41 38
42 class MockIDBCallbacks : public IndexedDBCallbacks { 39 class MockIDBCallbacks : public IndexedDBCallbacks {
43 public: 40 public:
44 static scoped_refptr<MockIDBCallbacks> Create() { 41 static scoped_refptr<MockIDBCallbacks> Create() {
45 return make_scoped_refptr(new MockIDBCallbacks()); 42 return make_scoped_refptr(new MockIDBCallbacks());
46 } 43 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 virtual ~FakeIDBDatabaseCallbacks() {} 90 virtual ~FakeIDBDatabaseCallbacks() {}
94 FakeIDBDatabaseCallbacks() : IndexedDBDatabaseCallbacks(NULL, 0, 0) {} 91 FakeIDBDatabaseCallbacks() : IndexedDBDatabaseCallbacks(NULL, 0, 0) {}
95 }; 92 };
96 93
97 TEST(IndexedDBDatabaseTest, ConnectionLifecycle) { 94 TEST(IndexedDBDatabaseTest, ConnectionLifecycle) {
98 scoped_refptr<IndexedDBFakeBackingStore> backing_store = 95 scoped_refptr<IndexedDBFakeBackingStore> backing_store =
99 new IndexedDBFakeBackingStore(); 96 new IndexedDBFakeBackingStore();
100 EXPECT_TRUE(backing_store->HasOneRef()); // local 97 EXPECT_TRUE(backing_store->HasOneRef()); // local
101 98
102 IndexedDBFactory* factory = 0; 99 IndexedDBFactory* factory = 0;
103 scoped_refptr<IndexedDBDatabase> db = 100 scoped_refptr<IndexedDBDatabase> db = IndexedDBDatabase::Create(
104 IndexedDBDatabase::Create(ASCIIToUTF16("db"), 101 ASCIIToUTF16("db"), backing_store, factory, ASCIIToUTF16("uniqueid"));
105 backing_store.get(),
106 factory,
107 ASCIIToUTF16("uniqueid"));
108 102
109 EXPECT_FALSE(backing_store->HasOneRef()); // local and db 103 EXPECT_FALSE(backing_store->HasOneRef()); // local and db
110 104
111 scoped_refptr<MockIDBCallbacks> request1 = MockIDBCallbacks::Create(); 105 scoped_refptr<MockIDBCallbacks> request1 = MockIDBCallbacks::Create();
112 scoped_refptr<FakeIDBDatabaseCallbacks> callbacks1 = 106 scoped_refptr<FakeIDBDatabaseCallbacks> callbacks1 =
113 FakeIDBDatabaseCallbacks::Create(); 107 FakeIDBDatabaseCallbacks::Create();
114 const int64 transaction_id1 = 1; 108 const int64 transaction_id1 = 1;
115 db->OpenConnection(request1, 109 db->OpenConnection(request1,
116 callbacks1, 110 callbacks1,
117 transaction_id1, 111 transaction_id1,
(...skipping 11 matching lines...) Expand all
129 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION); 123 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION);
130 124
131 EXPECT_FALSE(backing_store->HasOneRef()); // local and connection 125 EXPECT_FALSE(backing_store->HasOneRef()); // local and connection
132 126
133 db->Close(request1->connection()); 127 db->Close(request1->connection());
134 128
135 EXPECT_FALSE(backing_store->HasOneRef()); // local and connection 129 EXPECT_FALSE(backing_store->HasOneRef()); // local and connection
136 130
137 db->Close(request2->connection()); 131 db->Close(request2->connection());
138 EXPECT_TRUE(backing_store->HasOneRef()); 132 EXPECT_TRUE(backing_store->HasOneRef());
139 EXPECT_FALSE(db->BackingStore().get()); 133 EXPECT_FALSE(db->BackingStore());
140 134
141 db = NULL; 135 db = NULL;
142 } 136 }
143 137
144 class MockIDBDatabaseCallbacks : public IndexedDBDatabaseCallbacks { 138 class MockIDBDatabaseCallbacks : public IndexedDBDatabaseCallbacks {
145 public: 139 public:
146 static scoped_refptr<MockIDBDatabaseCallbacks> Create() { 140 static scoped_refptr<MockIDBDatabaseCallbacks> Create() {
147 return make_scoped_refptr(new MockIDBDatabaseCallbacks()); 141 return make_scoped_refptr(new MockIDBDatabaseCallbacks());
148 } 142 }
149 virtual void OnVersionChange(int64 old_version, int64 new_version) OVERRIDE {} 143 virtual void OnVersionChange(int64 old_version, int64 new_version) OVERRIDE {}
(...skipping 10 matching lines...) Expand all
160 virtual ~MockIDBDatabaseCallbacks() { EXPECT_TRUE(was_abort_called_); } 154 virtual ~MockIDBDatabaseCallbacks() { EXPECT_TRUE(was_abort_called_); }
161 bool was_abort_called_; 155 bool was_abort_called_;
162 }; 156 };
163 157
164 TEST(IndexedDBDatabaseTest, ForcedClose) { 158 TEST(IndexedDBDatabaseTest, ForcedClose) {
165 scoped_refptr<IndexedDBFakeBackingStore> backing_store = 159 scoped_refptr<IndexedDBFakeBackingStore> backing_store =
166 new IndexedDBFakeBackingStore(); 160 new IndexedDBFakeBackingStore();
167 EXPECT_TRUE(backing_store->HasOneRef()); 161 EXPECT_TRUE(backing_store->HasOneRef());
168 162
169 IndexedDBFactory* factory = 0; 163 IndexedDBFactory* factory = 0;
170 scoped_refptr<IndexedDBDatabase> backend = 164 scoped_refptr<IndexedDBDatabase> backend = IndexedDBDatabase::Create(
171 IndexedDBDatabase::Create(ASCIIToUTF16("db"), 165 ASCIIToUTF16("db"), backing_store, factory, ASCIIToUTF16("uniqueid"));
172 backing_store.get(),
173 factory,
174 ASCIIToUTF16("uniqueid"));
175 166
176 EXPECT_FALSE(backing_store->HasOneRef()); // local and db 167 EXPECT_FALSE(backing_store->HasOneRef()); // local and db
177 168
178 scoped_refptr<MockIDBDatabaseCallbacks> callbacks = 169 scoped_refptr<MockIDBDatabaseCallbacks> callbacks =
179 MockIDBDatabaseCallbacks::Create(); 170 MockIDBDatabaseCallbacks::Create();
180 171
181 scoped_refptr<MockIDBCallbacks> request = MockIDBCallbacks::Create(); 172 scoped_refptr<MockIDBCallbacks> request = MockIDBCallbacks::Create();
182 const int64 upgrade_transaction_id = 3; 173 const int64 upgrade_transaction_id = 3;
183 backend->OpenConnection(request, 174 backend->OpenConnection(request,
184 callbacks, 175 callbacks,
185 upgrade_transaction_id, 176 upgrade_transaction_id,
186 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION); 177 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION);
187 178
188 const int64 transaction_id = 123; 179 const int64 transaction_id = 123;
189 const std::vector<int64> scope; 180 const std::vector<int64> scope;
190 request->connection()->database()->CreateTransaction( 181 request->connection()->database()->CreateTransaction(
191 transaction_id, 182 transaction_id,
192 request->connection(), 183 request->connection(),
193 scope, 184 scope,
194 indexed_db::TRANSACTION_READ_ONLY); 185 indexed_db::TRANSACTION_READ_ONLY);
195 186
196 request->connection()->ForceClose(); 187 request->connection()->ForceClose();
197 188
198 EXPECT_TRUE(backing_store->HasOneRef()); // local 189 EXPECT_TRUE(backing_store->HasOneRef()); // local
199 } 190 }
200 191
201 } // namespace content 192 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_database.cc ('k') | content/browser/indexed_db/indexed_db_dispatcher_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698