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

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

Issue 501183003: Remove implicit conversions from scoped_refptr to T* in content/browser/indexed_db/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « content/browser/indexed_db/indexed_db_transaction_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/files/scoped_temp_dir.h" 6 #include "base/files/scoped_temp_dir.h"
7 #include "base/test/test_simple_task_runner.h" 7 #include "base/test/test_simple_task_runner.h"
8 #include "base/threading/thread.h" 8 #include "base/threading/thread.h"
9 #include "content/browser/browser_thread_impl.h" 9 #include "content/browser/browser_thread_impl.h"
10 #include "content/browser/indexed_db/indexed_db_connection.h" 10 #include "content/browser/indexed_db/indexed_db_connection.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 TEST_F(IndexedDBTest, ClearSessionOnlyDatabases) { 55 TEST_F(IndexedDBTest, ClearSessionOnlyDatabases) {
56 base::ScopedTempDir temp_dir; 56 base::ScopedTempDir temp_dir;
57 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 57 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
58 58
59 base::FilePath normal_path; 59 base::FilePath normal_path;
60 base::FilePath session_only_path; 60 base::FilePath session_only_path;
61 61
62 // Create the scope which will ensure we run the destructor of the context 62 // Create the scope which will ensure we run the destructor of the context
63 // which should trigger the clean up. 63 // which should trigger the clean up.
64 { 64 {
65 scoped_refptr<IndexedDBContextImpl> idb_context = new IndexedDBContextImpl( 65 scoped_refptr<IndexedDBContextImpl> idb_context =
66 temp_dir.path(), special_storage_policy_, NULL, task_runner_); 66 new IndexedDBContextImpl(temp_dir.path(),
67 special_storage_policy_.get(),
68 NULL,
69 task_runner_.get());
67 70
68 normal_path = idb_context->GetFilePathForTesting( 71 normal_path = idb_context->GetFilePathForTesting(
69 storage::GetIdentifierFromOrigin(kNormalOrigin)); 72 storage::GetIdentifierFromOrigin(kNormalOrigin));
70 session_only_path = idb_context->GetFilePathForTesting( 73 session_only_path = idb_context->GetFilePathForTesting(
71 storage::GetIdentifierFromOrigin(kSessionOnlyOrigin)); 74 storage::GetIdentifierFromOrigin(kSessionOnlyOrigin));
72 ASSERT_TRUE(base::CreateDirectory(normal_path)); 75 ASSERT_TRUE(base::CreateDirectory(normal_path));
73 ASSERT_TRUE(base::CreateDirectory(session_only_path)); 76 ASSERT_TRUE(base::CreateDirectory(session_only_path));
74 FlushIndexedDBTaskRunner(); 77 FlushIndexedDBTaskRunner();
75 message_loop_.RunUntilIdle(); 78 message_loop_.RunUntilIdle();
76 } 79 }
77 80
78 FlushIndexedDBTaskRunner(); 81 FlushIndexedDBTaskRunner();
79 message_loop_.RunUntilIdle(); 82 message_loop_.RunUntilIdle();
80 83
81 EXPECT_TRUE(base::DirectoryExists(normal_path)); 84 EXPECT_TRUE(base::DirectoryExists(normal_path));
82 EXPECT_FALSE(base::DirectoryExists(session_only_path)); 85 EXPECT_FALSE(base::DirectoryExists(session_only_path));
83 } 86 }
84 87
85 TEST_F(IndexedDBTest, SetForceKeepSessionState) { 88 TEST_F(IndexedDBTest, SetForceKeepSessionState) {
86 base::ScopedTempDir temp_dir; 89 base::ScopedTempDir temp_dir;
87 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 90 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
88 91
89 base::FilePath normal_path; 92 base::FilePath normal_path;
90 base::FilePath session_only_path; 93 base::FilePath session_only_path;
91 94
92 // Create the scope which will ensure we run the destructor of the context. 95 // Create the scope which will ensure we run the destructor of the context.
93 { 96 {
94 // Create some indexedDB paths. 97 // Create some indexedDB paths.
95 // With the levelDB backend, these are directories. 98 // With the levelDB backend, these are directories.
96 scoped_refptr<IndexedDBContextImpl> idb_context = new IndexedDBContextImpl( 99 scoped_refptr<IndexedDBContextImpl> idb_context =
97 temp_dir.path(), special_storage_policy_, NULL, task_runner_); 100 new IndexedDBContextImpl(temp_dir.path(),
101 special_storage_policy_.get(),
102 NULL,
103 task_runner_.get());
98 104
99 // Save session state. This should bypass the destruction-time deletion. 105 // Save session state. This should bypass the destruction-time deletion.
100 idb_context->SetForceKeepSessionState(); 106 idb_context->SetForceKeepSessionState();
101 107
102 normal_path = idb_context->GetFilePathForTesting( 108 normal_path = idb_context->GetFilePathForTesting(
103 storage::GetIdentifierFromOrigin(kNormalOrigin)); 109 storage::GetIdentifierFromOrigin(kNormalOrigin));
104 session_only_path = idb_context->GetFilePathForTesting( 110 session_only_path = idb_context->GetFilePathForTesting(
105 storage::GetIdentifierFromOrigin(kSessionOnlyOrigin)); 111 storage::GetIdentifierFromOrigin(kSessionOnlyOrigin));
106 ASSERT_TRUE(base::CreateDirectory(normal_path)); 112 ASSERT_TRUE(base::CreateDirectory(normal_path));
107 ASSERT_TRUE(base::CreateDirectory(session_only_path)); 113 ASSERT_TRUE(base::CreateDirectory(session_only_path));
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 new MockIndexedDBDatabaseCallbacks()); 160 new MockIndexedDBDatabaseCallbacks());
155 161
156 base::FilePath test_path; 162 base::FilePath test_path;
157 163
158 // Create the scope which will ensure we run the destructor of the context. 164 // Create the scope which will ensure we run the destructor of the context.
159 { 165 {
160 TestBrowserContext browser_context; 166 TestBrowserContext browser_context;
161 167
162 const GURL kTestOrigin("http://test/"); 168 const GURL kTestOrigin("http://test/");
163 169
164 scoped_refptr<IndexedDBContextImpl> idb_context = new IndexedDBContextImpl( 170 scoped_refptr<IndexedDBContextImpl> idb_context =
165 temp_dir.path(), special_storage_policy_, NULL, task_runner_); 171 new IndexedDBContextImpl(temp_dir.path(),
172 special_storage_policy_.get(),
173 NULL,
174 task_runner_.get());
166 175
167 scoped_refptr<ForceCloseDBCallbacks> open_callbacks = 176 scoped_refptr<ForceCloseDBCallbacks> open_callbacks =
168 new ForceCloseDBCallbacks(idb_context, kTestOrigin); 177 new ForceCloseDBCallbacks(idb_context, kTestOrigin);
169 178
170 scoped_refptr<ForceCloseDBCallbacks> closed_callbacks = 179 scoped_refptr<ForceCloseDBCallbacks> closed_callbacks =
171 new ForceCloseDBCallbacks(idb_context, kTestOrigin); 180 new ForceCloseDBCallbacks(idb_context, kTestOrigin);
172 181
173 IndexedDBFactory* factory = idb_context->GetIDBFactory(); 182 IndexedDBFactory* factory = idb_context->GetIDBFactory();
174 183
175 test_path = idb_context->GetFilePathForTesting( 184 test_path = idb_context->GetFilePathForTesting(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 EXPECT_FALSE(closed_db_callbacks->forced_close_called()); 222 EXPECT_FALSE(closed_db_callbacks->forced_close_called());
214 EXPECT_FALSE(base::DirectoryExists(test_path)); 223 EXPECT_FALSE(base::DirectoryExists(test_path));
215 } 224 }
216 225
217 TEST_F(IndexedDBTest, DeleteFailsIfDirectoryLocked) { 226 TEST_F(IndexedDBTest, DeleteFailsIfDirectoryLocked) {
218 base::ScopedTempDir temp_dir; 227 base::ScopedTempDir temp_dir;
219 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 228 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
220 const GURL kTestOrigin("http://test/"); 229 const GURL kTestOrigin("http://test/");
221 230
222 scoped_refptr<IndexedDBContextImpl> idb_context = new IndexedDBContextImpl( 231 scoped_refptr<IndexedDBContextImpl> idb_context = new IndexedDBContextImpl(
223 temp_dir.path(), special_storage_policy_, NULL, task_runner_); 232 temp_dir.path(), special_storage_policy_.get(), NULL, task_runner_.get());
224 233
225 base::FilePath test_path = idb_context->GetFilePathForTesting( 234 base::FilePath test_path = idb_context->GetFilePathForTesting(
226 storage::GetIdentifierFromOrigin(kTestOrigin)); 235 storage::GetIdentifierFromOrigin(kTestOrigin));
227 ASSERT_TRUE(base::CreateDirectory(test_path)); 236 ASSERT_TRUE(base::CreateDirectory(test_path));
228 237
229 scoped_ptr<LevelDBLock> lock = 238 scoped_ptr<LevelDBLock> lock =
230 LevelDBDatabase::LockForTesting(test_path); 239 LevelDBDatabase::LockForTesting(test_path);
231 ASSERT_TRUE(lock); 240 ASSERT_TRUE(lock);
232 241
233 idb_context->TaskRunner()->PostTask( 242 idb_context->TaskRunner()->PostTask(
234 FROM_HERE, 243 FROM_HERE,
235 base::Bind( 244 base::Bind(
236 &IndexedDBContextImpl::DeleteForOrigin, idb_context, kTestOrigin)); 245 &IndexedDBContextImpl::DeleteForOrigin, idb_context, kTestOrigin));
237 FlushIndexedDBTaskRunner(); 246 FlushIndexedDBTaskRunner();
238 247
239 EXPECT_TRUE(base::DirectoryExists(test_path)); 248 EXPECT_TRUE(base::DirectoryExists(test_path));
240 } 249 }
241 250
242 TEST_F(IndexedDBTest, ForceCloseOpenDatabasesOnCommitFailure) { 251 TEST_F(IndexedDBTest, ForceCloseOpenDatabasesOnCommitFailure) {
243 const GURL kTestOrigin("http://test/"); 252 const GURL kTestOrigin("http://test/");
244 253
245 base::ScopedTempDir temp_dir; 254 base::ScopedTempDir temp_dir;
246 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 255 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
247 256
248 scoped_refptr<IndexedDBContextImpl> context = new IndexedDBContextImpl( 257 scoped_refptr<IndexedDBContextImpl> context = new IndexedDBContextImpl(
249 temp_dir.path(), special_storage_policy_, NULL, task_runner_); 258 temp_dir.path(), special_storage_policy_.get(), NULL, task_runner_.get());
250 259
251 scoped_refptr<IndexedDBFactoryImpl> factory = 260 scoped_refptr<IndexedDBFactoryImpl> factory =
252 static_cast<IndexedDBFactoryImpl*>(context->GetIDBFactory()); 261 static_cast<IndexedDBFactoryImpl*>(context->GetIDBFactory());
253 262
254 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); 263 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks());
255 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( 264 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks(
256 new MockIndexedDBDatabaseCallbacks()); 265 new MockIndexedDBDatabaseCallbacks());
257 const int64 transaction_id = 1; 266 const int64 transaction_id = 1;
258 IndexedDBPendingConnection connection( 267 IndexedDBPendingConnection connection(
259 callbacks, 268 callbacks,
(...skipping 16 matching lines...) Expand all
276 285
277 // Simulate the write failure. 286 // Simulate the write failure.
278 leveldb::Status status = leveldb::Status::IOError("Simulated failure"); 287 leveldb::Status status = leveldb::Status::IOError("Simulated failure");
279 callbacks->connection()->database()->TransactionCommitFailed(status); 288 callbacks->connection()->database()->TransactionCommitFailed(status);
280 289
281 EXPECT_TRUE(db_callbacks->forced_close_called()); 290 EXPECT_TRUE(db_callbacks->forced_close_called());
282 EXPECT_FALSE(factory->IsBackingStoreOpen(kTestOrigin)); 291 EXPECT_FALSE(factory->IsBackingStoreOpen(kTestOrigin));
283 } 292 }
284 293
285 } // namespace content 294 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_transaction_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698