OLD | NEW |
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 = new IndexedDBContextImpl( |
66 temp_dir.path(), special_storage_policy_, NULL, task_runner_); | 66 temp_dir.path(), special_storage_policy_, NULL, task_runner_); |
67 | 67 |
68 normal_path = idb_context->GetFilePathForTesting( | 68 normal_path = idb_context->GetFilePathForTesting( |
69 webkit_database::GetIdentifierFromOrigin(kNormalOrigin)); | 69 webkit_database::GetIdentifierFromOrigin(kNormalOrigin)); |
70 session_only_path = idb_context->GetFilePathForTesting( | 70 session_only_path = idb_context->GetFilePathForTesting( |
71 webkit_database::GetIdentifierFromOrigin(kSessionOnlyOrigin)); | 71 webkit_database::GetIdentifierFromOrigin(kSessionOnlyOrigin)); |
72 ASSERT_TRUE(file_util::CreateDirectory(normal_path)); | 72 ASSERT_TRUE(base::CreateDirectory(normal_path)); |
73 ASSERT_TRUE(file_util::CreateDirectory(session_only_path)); | 73 ASSERT_TRUE(base::CreateDirectory(session_only_path)); |
74 FlushIndexedDBTaskRunner(); | 74 FlushIndexedDBTaskRunner(); |
75 message_loop_.RunUntilIdle(); | 75 message_loop_.RunUntilIdle(); |
76 } | 76 } |
77 | 77 |
78 FlushIndexedDBTaskRunner(); | 78 FlushIndexedDBTaskRunner(); |
79 message_loop_.RunUntilIdle(); | 79 message_loop_.RunUntilIdle(); |
80 | 80 |
81 EXPECT_TRUE(base::DirectoryExists(normal_path)); | 81 EXPECT_TRUE(base::DirectoryExists(normal_path)); |
82 EXPECT_FALSE(base::DirectoryExists(session_only_path)); | 82 EXPECT_FALSE(base::DirectoryExists(session_only_path)); |
83 } | 83 } |
(...skipping 12 matching lines...) Expand all Loading... |
96 scoped_refptr<IndexedDBContextImpl> idb_context = new IndexedDBContextImpl( | 96 scoped_refptr<IndexedDBContextImpl> idb_context = new IndexedDBContextImpl( |
97 temp_dir.path(), special_storage_policy_, NULL, task_runner_); | 97 temp_dir.path(), special_storage_policy_, NULL, task_runner_); |
98 | 98 |
99 // Save session state. This should bypass the destruction-time deletion. | 99 // Save session state. This should bypass the destruction-time deletion. |
100 idb_context->SetForceKeepSessionState(); | 100 idb_context->SetForceKeepSessionState(); |
101 | 101 |
102 normal_path = idb_context->GetFilePathForTesting( | 102 normal_path = idb_context->GetFilePathForTesting( |
103 webkit_database::GetIdentifierFromOrigin(kNormalOrigin)); | 103 webkit_database::GetIdentifierFromOrigin(kNormalOrigin)); |
104 session_only_path = idb_context->GetFilePathForTesting( | 104 session_only_path = idb_context->GetFilePathForTesting( |
105 webkit_database::GetIdentifierFromOrigin(kSessionOnlyOrigin)); | 105 webkit_database::GetIdentifierFromOrigin(kSessionOnlyOrigin)); |
106 ASSERT_TRUE(file_util::CreateDirectory(normal_path)); | 106 ASSERT_TRUE(base::CreateDirectory(normal_path)); |
107 ASSERT_TRUE(file_util::CreateDirectory(session_only_path)); | 107 ASSERT_TRUE(base::CreateDirectory(session_only_path)); |
108 message_loop_.RunUntilIdle(); | 108 message_loop_.RunUntilIdle(); |
109 } | 109 } |
110 | 110 |
111 // Make sure we wait until the destructor has run. | 111 // Make sure we wait until the destructor has run. |
112 message_loop_.RunUntilIdle(); | 112 message_loop_.RunUntilIdle(); |
113 | 113 |
114 // No data was cleared because of SetForceKeepSessionState. | 114 // No data was cleared because of SetForceKeepSessionState. |
115 EXPECT_TRUE(base::DirectoryExists(normal_path)); | 115 EXPECT_TRUE(base::DirectoryExists(normal_path)); |
116 EXPECT_TRUE(base::DirectoryExists(session_only_path)); | 116 EXPECT_TRUE(base::DirectoryExists(session_only_path)); |
117 } | 117 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 { | 151 { |
152 TestBrowserContext browser_context; | 152 TestBrowserContext browser_context; |
153 | 153 |
154 const GURL kTestOrigin("http://test/"); | 154 const GURL kTestOrigin("http://test/"); |
155 | 155 |
156 scoped_refptr<IndexedDBContextImpl> idb_context = new IndexedDBContextImpl( | 156 scoped_refptr<IndexedDBContextImpl> idb_context = new IndexedDBContextImpl( |
157 temp_dir.path(), special_storage_policy_, NULL, task_runner_); | 157 temp_dir.path(), special_storage_policy_, NULL, task_runner_); |
158 | 158 |
159 test_path = idb_context->GetFilePathForTesting( | 159 test_path = idb_context->GetFilePathForTesting( |
160 webkit_database::GetIdentifierFromOrigin(kTestOrigin)); | 160 webkit_database::GetIdentifierFromOrigin(kTestOrigin)); |
161 ASSERT_TRUE(file_util::CreateDirectory(test_path)); | 161 ASSERT_TRUE(base::CreateDirectory(test_path)); |
162 | 162 |
163 const bool kExpectForceClose = true; | 163 const bool kExpectForceClose = true; |
164 | 164 |
165 MockConnection connection1(kExpectForceClose); | 165 MockConnection connection1(kExpectForceClose); |
166 idb_context->TaskRunner()->PostTask( | 166 idb_context->TaskRunner()->PostTask( |
167 FROM_HERE, | 167 FROM_HERE, |
168 base::Bind(&IndexedDBContextImpl::ConnectionOpened, | 168 base::Bind(&IndexedDBContextImpl::ConnectionOpened, |
169 idb_context, | 169 idb_context, |
170 kTestOrigin, | 170 kTestOrigin, |
171 &connection1)); | 171 &connection1)); |
(...skipping 29 matching lines...) Expand all Loading... |
201 TEST_F(IndexedDBTest, DeleteFailsIfDirectoryLocked) { | 201 TEST_F(IndexedDBTest, DeleteFailsIfDirectoryLocked) { |
202 base::ScopedTempDir temp_dir; | 202 base::ScopedTempDir temp_dir; |
203 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 203 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
204 const GURL kTestOrigin("http://test/"); | 204 const GURL kTestOrigin("http://test/"); |
205 | 205 |
206 scoped_refptr<IndexedDBContextImpl> idb_context = new IndexedDBContextImpl( | 206 scoped_refptr<IndexedDBContextImpl> idb_context = new IndexedDBContextImpl( |
207 temp_dir.path(), special_storage_policy_, NULL, task_runner_); | 207 temp_dir.path(), special_storage_policy_, NULL, task_runner_); |
208 | 208 |
209 base::FilePath test_path = idb_context->GetFilePathForTesting( | 209 base::FilePath test_path = idb_context->GetFilePathForTesting( |
210 webkit_database::GetIdentifierFromOrigin(kTestOrigin)); | 210 webkit_database::GetIdentifierFromOrigin(kTestOrigin)); |
211 ASSERT_TRUE(file_util::CreateDirectory(test_path)); | 211 ASSERT_TRUE(base::CreateDirectory(test_path)); |
212 | 212 |
213 scoped_ptr<LevelDBLock> lock = | 213 scoped_ptr<LevelDBLock> lock = |
214 LevelDBDatabase::LockForTesting(test_path); | 214 LevelDBDatabase::LockForTesting(test_path); |
215 ASSERT_TRUE(lock); | 215 ASSERT_TRUE(lock); |
216 | 216 |
217 idb_context->TaskRunner()->PostTask( | 217 idb_context->TaskRunner()->PostTask( |
218 FROM_HERE, | 218 FROM_HERE, |
219 base::Bind( | 219 base::Bind( |
220 &IndexedDBContextImpl::DeleteForOrigin, idb_context, kTestOrigin)); | 220 &IndexedDBContextImpl::DeleteForOrigin, idb_context, kTestOrigin)); |
221 FlushIndexedDBTaskRunner(); | 221 FlushIndexedDBTaskRunner(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 EXPECT_TRUE(factory->IsBackingStoreOpenForTesting(kTestOrigin)); | 254 EXPECT_TRUE(factory->IsBackingStoreOpenForTesting(kTestOrigin)); |
255 | 255 |
256 // Simulate the write failure. | 256 // Simulate the write failure. |
257 callbacks->connection()->database()->TransactionCommitFailed(); | 257 callbacks->connection()->database()->TransactionCommitFailed(); |
258 | 258 |
259 EXPECT_TRUE(db_callbacks->forced_close_called()); | 259 EXPECT_TRUE(db_callbacks->forced_close_called()); |
260 EXPECT_FALSE(factory->IsBackingStoreOpenForTesting(kTestOrigin)); | 260 EXPECT_FALSE(factory->IsBackingStoreOpenForTesting(kTestOrigin)); |
261 } | 261 } |
262 | 262 |
263 } // namespace content | 263 } // namespace content |
OLD | NEW |