| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 TEST_F(IndexedDBTest, ClearSessionOnlyDatabases) { | 51 TEST_F(IndexedDBTest, ClearSessionOnlyDatabases) { |
| 52 base::ScopedTempDir temp_dir; | 52 base::ScopedTempDir temp_dir; |
| 53 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 53 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 54 | 54 |
| 55 base::FilePath normal_path; | 55 base::FilePath normal_path; |
| 56 base::FilePath session_only_path; | 56 base::FilePath session_only_path; |
| 57 | 57 |
| 58 // Create the scope which will ensure we run the destructor of the context | 58 // Create the scope which will ensure we run the destructor of the context |
| 59 // which should trigger the clean up. | 59 // which should trigger the clean up. |
| 60 { | 60 { |
| 61 scoped_refptr<IndexedDBContextImpl> idb_context = | 61 scoped_refptr<IndexedDBContextImpl> idb_context = new IndexedDBContextImpl( |
| 62 new IndexedDBContextImpl(temp_dir.path(), | 62 temp_dir.path(), special_storage_policy_, NULL, task_runner_); |
| 63 special_storage_policy_.get(), | |
| 64 NULL, | |
| 65 task_runner_.get()); | |
| 66 | 63 |
| 67 normal_path = idb_context->GetFilePathForTesting( | 64 normal_path = idb_context->GetFilePathForTesting( |
| 68 webkit_database::GetIdentifierFromOrigin(kNormalOrigin)); | 65 webkit_database::GetIdentifierFromOrigin(kNormalOrigin)); |
| 69 session_only_path = idb_context->GetFilePathForTesting( | 66 session_only_path = idb_context->GetFilePathForTesting( |
| 70 webkit_database::GetIdentifierFromOrigin(kSessionOnlyOrigin)); | 67 webkit_database::GetIdentifierFromOrigin(kSessionOnlyOrigin)); |
| 71 ASSERT_TRUE(file_util::CreateDirectory(normal_path)); | 68 ASSERT_TRUE(file_util::CreateDirectory(normal_path)); |
| 72 ASSERT_TRUE(file_util::CreateDirectory(session_only_path)); | 69 ASSERT_TRUE(file_util::CreateDirectory(session_only_path)); |
| 73 FlushIndexedDBTaskRunner(); | 70 FlushIndexedDBTaskRunner(); |
| 74 message_loop_.RunUntilIdle(); | 71 message_loop_.RunUntilIdle(); |
| 75 } | 72 } |
| 76 | 73 |
| 77 FlushIndexedDBTaskRunner(); | 74 FlushIndexedDBTaskRunner(); |
| 78 message_loop_.RunUntilIdle(); | 75 message_loop_.RunUntilIdle(); |
| 79 | 76 |
| 80 EXPECT_TRUE(file_util::DirectoryExists(normal_path)); | 77 EXPECT_TRUE(file_util::DirectoryExists(normal_path)); |
| 81 EXPECT_FALSE(file_util::DirectoryExists(session_only_path)); | 78 EXPECT_FALSE(file_util::DirectoryExists(session_only_path)); |
| 82 } | 79 } |
| 83 | 80 |
| 84 TEST_F(IndexedDBTest, SetForceKeepSessionState) { | 81 TEST_F(IndexedDBTest, SetForceKeepSessionState) { |
| 85 base::ScopedTempDir temp_dir; | 82 base::ScopedTempDir temp_dir; |
| 86 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 83 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 87 | 84 |
| 88 base::FilePath normal_path; | 85 base::FilePath normal_path; |
| 89 base::FilePath session_only_path; | 86 base::FilePath session_only_path; |
| 90 | 87 |
| 91 // Create the scope which will ensure we run the destructor of the context. | 88 // Create the scope which will ensure we run the destructor of the context. |
| 92 { | 89 { |
| 93 // Create some indexedDB paths. | 90 // Create some indexedDB paths. |
| 94 // With the levelDB backend, these are directories. | 91 // With the levelDB backend, these are directories. |
| 95 scoped_refptr<IndexedDBContextImpl> idb_context = | 92 scoped_refptr<IndexedDBContextImpl> idb_context = new IndexedDBContextImpl( |
| 96 new IndexedDBContextImpl(temp_dir.path(), | 93 temp_dir.path(), special_storage_policy_, NULL, task_runner_); |
| 97 special_storage_policy_.get(), | |
| 98 NULL, | |
| 99 task_runner_.get()); | |
| 100 | 94 |
| 101 // Save session state. This should bypass the destruction-time deletion. | 95 // Save session state. This should bypass the destruction-time deletion. |
| 102 idb_context->SetForceKeepSessionState(); | 96 idb_context->SetForceKeepSessionState(); |
| 103 | 97 |
| 104 normal_path = idb_context->GetFilePathForTesting( | 98 normal_path = idb_context->GetFilePathForTesting( |
| 105 webkit_database::GetIdentifierFromOrigin(kNormalOrigin)); | 99 webkit_database::GetIdentifierFromOrigin(kNormalOrigin)); |
| 106 session_only_path = idb_context->GetFilePathForTesting( | 100 session_only_path = idb_context->GetFilePathForTesting( |
| 107 webkit_database::GetIdentifierFromOrigin(kSessionOnlyOrigin)); | 101 webkit_database::GetIdentifierFromOrigin(kSessionOnlyOrigin)); |
| 108 ASSERT_TRUE(file_util::CreateDirectory(normal_path)); | 102 ASSERT_TRUE(file_util::CreateDirectory(normal_path)); |
| 109 ASSERT_TRUE(file_util::CreateDirectory(session_only_path)); | 103 ASSERT_TRUE(file_util::CreateDirectory(session_only_path)); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 138 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 145 | 139 |
| 146 base::FilePath test_path; | 140 base::FilePath test_path; |
| 147 | 141 |
| 148 // Create the scope which will ensure we run the destructor of the context. | 142 // Create the scope which will ensure we run the destructor of the context. |
| 149 { | 143 { |
| 150 TestBrowserContext browser_context; | 144 TestBrowserContext browser_context; |
| 151 | 145 |
| 152 const GURL kTestOrigin("http://test/"); | 146 const GURL kTestOrigin("http://test/"); |
| 153 | 147 |
| 154 scoped_refptr<IndexedDBContextImpl> idb_context = | 148 scoped_refptr<IndexedDBContextImpl> idb_context = new IndexedDBContextImpl( |
| 155 new IndexedDBContextImpl(temp_dir.path(), | 149 temp_dir.path(), special_storage_policy_, NULL, task_runner_); |
| 156 special_storage_policy_.get(), | |
| 157 NULL, | |
| 158 task_runner_.get()); | |
| 159 | 150 |
| 160 test_path = idb_context->GetFilePathForTesting( | 151 test_path = idb_context->GetFilePathForTesting( |
| 161 webkit_database::GetIdentifierFromOrigin(kTestOrigin)); | 152 webkit_database::GetIdentifierFromOrigin(kTestOrigin)); |
| 162 ASSERT_TRUE(file_util::CreateDirectory(test_path)); | 153 ASSERT_TRUE(file_util::CreateDirectory(test_path)); |
| 163 | 154 |
| 164 const bool kExpectForceClose = true; | 155 const bool kExpectForceClose = true; |
| 165 | 156 |
| 166 MockConnection connection1(kExpectForceClose); | 157 MockConnection connection1(kExpectForceClose); |
| 167 idb_context->TaskRunner()->PostTask( | 158 idb_context->TaskRunner()->PostTask( |
| 168 FROM_HERE, | 159 FROM_HERE, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 180 &connection2)); | 171 &connection2)); |
| 181 idb_context->TaskRunner()->PostTask( | 172 idb_context->TaskRunner()->PostTask( |
| 182 FROM_HERE, | 173 FROM_HERE, |
| 183 base::Bind(&IndexedDBContextImpl::ConnectionClosed, | 174 base::Bind(&IndexedDBContextImpl::ConnectionClosed, |
| 184 idb_context, | 175 idb_context, |
| 185 kTestOrigin, | 176 kTestOrigin, |
| 186 &connection2)); | 177 &connection2)); |
| 187 | 178 |
| 188 idb_context->TaskRunner()->PostTask( | 179 idb_context->TaskRunner()->PostTask( |
| 189 FROM_HERE, | 180 FROM_HERE, |
| 190 base::Bind(&IndexedDBContextImpl::DeleteForOrigin, | 181 base::Bind( |
| 191 idb_context, | 182 &IndexedDBContextImpl::DeleteForOrigin, idb_context, kTestOrigin)); |
| 192 kTestOrigin)); | |
| 193 FlushIndexedDBTaskRunner(); | 183 FlushIndexedDBTaskRunner(); |
| 194 message_loop_.RunUntilIdle(); | 184 message_loop_.RunUntilIdle(); |
| 195 } | 185 } |
| 196 | 186 |
| 197 // Make sure we wait until the destructor has run. | 187 // Make sure we wait until the destructor has run. |
| 198 message_loop_.RunUntilIdle(); | 188 message_loop_.RunUntilIdle(); |
| 199 | 189 |
| 200 EXPECT_FALSE(file_util::DirectoryExists(test_path)); | 190 EXPECT_FALSE(file_util::DirectoryExists(test_path)); |
| 201 } | 191 } |
| 202 | 192 |
| 203 } // namespace content | 193 } // namespace content |
| OLD | NEW |