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

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

Issue 1757693002: Reduce use of DatabaseIdentifier in Indexed DB entry points. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert change for ZIP file naming Created 4 years, 9 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
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 <stdint.h> 5 #include <stdint.h>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/test/test_simple_task_runner.h" 11 #include "base/test/test_simple_task_runner.h"
12 #include "base/threading/thread.h" 12 #include "base/threading/thread.h"
13 #include "content/browser/browser_thread_impl.h" 13 #include "content/browser/browser_thread_impl.h"
14 #include "content/browser/indexed_db/indexed_db_connection.h" 14 #include "content/browser/indexed_db/indexed_db_connection.h"
15 #include "content/browser/indexed_db/indexed_db_context_impl.h" 15 #include "content/browser/indexed_db/indexed_db_context_impl.h"
16 #include "content/browser/indexed_db/indexed_db_factory_impl.h" 16 #include "content/browser/indexed_db/indexed_db_factory_impl.h"
17 #include "content/browser/indexed_db/mock_indexed_db_callbacks.h" 17 #include "content/browser/indexed_db/mock_indexed_db_callbacks.h"
18 #include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h" 18 #include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h"
19 #include "content/browser/quota/mock_quota_manager_proxy.h" 19 #include "content/browser/quota/mock_quota_manager_proxy.h"
20 #include "content/public/browser/storage_partition.h" 20 #include "content/public/browser/storage_partition.h"
21 #include "content/public/common/url_constants.h" 21 #include "content/public/common/url_constants.h"
22 #include "content/public/test/mock_special_storage_policy.h" 22 #include "content/public/test/mock_special_storage_policy.h"
23 #include "content/public/test/test_browser_context.h" 23 #include "content/public/test/test_browser_context.h"
24 #include "storage/browser/quota/quota_manager.h" 24 #include "storage/browser/quota/quota_manager.h"
25 #include "storage/browser/quota/special_storage_policy.h" 25 #include "storage/browser/quota/special_storage_policy.h"
26 #include "storage/common/database/database_identifier.h"
27 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
28 27
29 namespace content { 28 namespace content {
30 29
31 class IndexedDBTest : public testing::Test { 30 class IndexedDBTest : public testing::Test {
32 public: 31 public:
33 const GURL kNormalOrigin; 32 const GURL kNormalOrigin;
34 const GURL kSessionOnlyOrigin; 33 const GURL kSessionOnlyOrigin;
35 34
36 IndexedDBTest() 35 IndexedDBTest()
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 70
72 // Create the scope which will ensure we run the destructor of the context 71 // Create the scope which will ensure we run the destructor of the context
73 // which should trigger the clean up. 72 // which should trigger the clean up.
74 { 73 {
75 scoped_refptr<IndexedDBContextImpl> idb_context = 74 scoped_refptr<IndexedDBContextImpl> idb_context =
76 new IndexedDBContextImpl(temp_dir.path(), 75 new IndexedDBContextImpl(temp_dir.path(),
77 special_storage_policy_.get(), 76 special_storage_policy_.get(),
78 quota_manager_proxy_.get(), 77 quota_manager_proxy_.get(),
79 task_runner_.get()); 78 task_runner_.get());
80 79
81 normal_path = idb_context->GetFilePathForTesting( 80 normal_path = idb_context->GetFilePathForTesting(kNormalOrigin);
82 storage::GetIdentifierFromOrigin(kNormalOrigin)); 81 session_only_path = idb_context->GetFilePathForTesting(kSessionOnlyOrigin);
83 session_only_path = idb_context->GetFilePathForTesting(
84 storage::GetIdentifierFromOrigin(kSessionOnlyOrigin));
85 ASSERT_TRUE(base::CreateDirectory(normal_path)); 82 ASSERT_TRUE(base::CreateDirectory(normal_path));
86 ASSERT_TRUE(base::CreateDirectory(session_only_path)); 83 ASSERT_TRUE(base::CreateDirectory(session_only_path));
87 FlushIndexedDBTaskRunner(); 84 FlushIndexedDBTaskRunner();
88 message_loop_.RunUntilIdle(); 85 message_loop_.RunUntilIdle();
89 quota_manager_proxy_->SimulateQuotaManagerDestroyed(); 86 quota_manager_proxy_->SimulateQuotaManagerDestroyed();
90 } 87 }
91 88
92 FlushIndexedDBTaskRunner(); 89 FlushIndexedDBTaskRunner();
93 message_loop_.RunUntilIdle(); 90 message_loop_.RunUntilIdle();
94 91
(...skipping 14 matching lines...) Expand all
109 // With the levelDB backend, these are directories. 106 // With the levelDB backend, these are directories.
110 scoped_refptr<IndexedDBContextImpl> idb_context = 107 scoped_refptr<IndexedDBContextImpl> idb_context =
111 new IndexedDBContextImpl(temp_dir.path(), 108 new IndexedDBContextImpl(temp_dir.path(),
112 special_storage_policy_.get(), 109 special_storage_policy_.get(),
113 quota_manager_proxy_.get(), 110 quota_manager_proxy_.get(),
114 task_runner_.get()); 111 task_runner_.get());
115 112
116 // Save session state. This should bypass the destruction-time deletion. 113 // Save session state. This should bypass the destruction-time deletion.
117 idb_context->SetForceKeepSessionState(); 114 idb_context->SetForceKeepSessionState();
118 115
119 normal_path = idb_context->GetFilePathForTesting( 116 normal_path = idb_context->GetFilePathForTesting(kNormalOrigin);
120 storage::GetIdentifierFromOrigin(kNormalOrigin)); 117 session_only_path = idb_context->GetFilePathForTesting(kSessionOnlyOrigin);
121 session_only_path = idb_context->GetFilePathForTesting(
122 storage::GetIdentifierFromOrigin(kSessionOnlyOrigin));
123 ASSERT_TRUE(base::CreateDirectory(normal_path)); 118 ASSERT_TRUE(base::CreateDirectory(normal_path));
124 ASSERT_TRUE(base::CreateDirectory(session_only_path)); 119 ASSERT_TRUE(base::CreateDirectory(session_only_path));
125 message_loop_.RunUntilIdle(); 120 message_loop_.RunUntilIdle();
126 } 121 }
127 122
128 // Make sure we wait until the destructor has run. 123 // Make sure we wait until the destructor has run.
129 message_loop_.RunUntilIdle(); 124 message_loop_.RunUntilIdle();
130 125
131 // No data was cleared because of SetForceKeepSessionState. 126 // No data was cleared because of SetForceKeepSessionState.
132 EXPECT_TRUE(base::DirectoryExists(normal_path)); 127 EXPECT_TRUE(base::DirectoryExists(normal_path));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 task_runner_.get()); 180 task_runner_.get());
186 181
187 scoped_refptr<ForceCloseDBCallbacks> open_callbacks = 182 scoped_refptr<ForceCloseDBCallbacks> open_callbacks =
188 new ForceCloseDBCallbacks(idb_context, kTestOrigin); 183 new ForceCloseDBCallbacks(idb_context, kTestOrigin);
189 184
190 scoped_refptr<ForceCloseDBCallbacks> closed_callbacks = 185 scoped_refptr<ForceCloseDBCallbacks> closed_callbacks =
191 new ForceCloseDBCallbacks(idb_context, kTestOrigin); 186 new ForceCloseDBCallbacks(idb_context, kTestOrigin);
192 187
193 IndexedDBFactory* factory = idb_context->GetIDBFactory(); 188 IndexedDBFactory* factory = idb_context->GetIDBFactory();
194 189
195 test_path = idb_context->GetFilePathForTesting( 190 test_path = idb_context->GetFilePathForTesting(kTestOrigin);
196 storage::GetIdentifierFromOrigin(kTestOrigin));
197 191
198 IndexedDBPendingConnection open_connection(open_callbacks, 192 IndexedDBPendingConnection open_connection(open_callbacks,
199 open_db_callbacks, 193 open_db_callbacks,
200 0 /* child_process_id */, 194 0 /* child_process_id */,
201 0 /* host_transaction_id */, 195 0 /* host_transaction_id */,
202 0 /* version */); 196 0 /* version */);
203 factory->Open(base::ASCIIToUTF16("opendb"), 197 factory->Open(base::ASCIIToUTF16("opendb"),
204 open_connection, 198 open_connection,
205 NULL /* request_context */, 199 NULL /* request_context */,
206 kTestOrigin, 200 kTestOrigin,
(...skipping 29 matching lines...) Expand all
236 230
237 TEST_F(IndexedDBTest, DeleteFailsIfDirectoryLocked) { 231 TEST_F(IndexedDBTest, DeleteFailsIfDirectoryLocked) {
238 base::ScopedTempDir temp_dir; 232 base::ScopedTempDir temp_dir;
239 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 233 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
240 const GURL kTestOrigin("http://test/"); 234 const GURL kTestOrigin("http://test/");
241 235
242 scoped_refptr<IndexedDBContextImpl> idb_context = new IndexedDBContextImpl( 236 scoped_refptr<IndexedDBContextImpl> idb_context = new IndexedDBContextImpl(
243 temp_dir.path(), special_storage_policy_.get(), 237 temp_dir.path(), special_storage_policy_.get(),
244 quota_manager_proxy_.get(), task_runner_.get()); 238 quota_manager_proxy_.get(), task_runner_.get());
245 239
246 base::FilePath test_path = idb_context->GetFilePathForTesting( 240 base::FilePath test_path = idb_context->GetFilePathForTesting(kTestOrigin);
247 storage::GetIdentifierFromOrigin(kTestOrigin));
248 ASSERT_TRUE(base::CreateDirectory(test_path)); 241 ASSERT_TRUE(base::CreateDirectory(test_path));
249 242
250 scoped_ptr<LevelDBLock> lock = 243 scoped_ptr<LevelDBLock> lock =
251 LevelDBDatabase::LockForTesting(test_path); 244 LevelDBDatabase::LockForTesting(test_path);
252 ASSERT_TRUE(lock); 245 ASSERT_TRUE(lock);
253 246
254 idb_context->TaskRunner()->PostTask( 247 idb_context->TaskRunner()->PostTask(
255 FROM_HERE, 248 FROM_HERE,
256 base::Bind( 249 base::Bind(
257 &IndexedDBContextImpl::DeleteForOrigin, idb_context, kTestOrigin)); 250 &IndexedDBContextImpl::DeleteForOrigin, idb_context, kTestOrigin));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 288
296 // Simulate the write failure. 289 // Simulate the write failure.
297 leveldb::Status status = leveldb::Status::IOError("Simulated failure"); 290 leveldb::Status status = leveldb::Status::IOError("Simulated failure");
298 callbacks->connection()->database()->TransactionCommitFailed(status); 291 callbacks->connection()->database()->TransactionCommitFailed(status);
299 292
300 EXPECT_TRUE(db_callbacks->forced_close_called()); 293 EXPECT_TRUE(db_callbacks->forced_close_called());
301 EXPECT_FALSE(factory->IsBackingStoreOpen(kTestOrigin)); 294 EXPECT_FALSE(factory->IsBackingStoreOpen(kTestOrigin));
302 } 295 }
303 296
304 } // namespace content 297 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698