| 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_context_impl.h" | 11 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 11 #include "content/browser/indexed_db/webidbdatabase_impl.h" | |
| 12 #include "content/public/browser/storage_partition.h" | 12 #include "content/public/browser/storage_partition.h" |
| 13 #include "content/public/common/url_constants.h" | 13 #include "content/public/common/url_constants.h" |
| 14 #include "content/public/test/test_browser_context.h" | 14 #include "content/public/test/test_browser_context.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "webkit/browser/quota/mock_special_storage_policy.h" | 16 #include "webkit/browser/quota/mock_special_storage_policy.h" |
| 17 #include "webkit/browser/quota/quota_manager.h" | 17 #include "webkit/browser/quota/quota_manager.h" |
| 18 #include "webkit/browser/quota/special_storage_policy.h" | 18 #include "webkit/browser/quota/special_storage_policy.h" |
| 19 #include "webkit/common/database/database_identifier.h" | 19 #include "webkit/common/database/database_identifier.h" |
| 20 | 20 |
| 21 namespace content { | 21 namespace content { |
| 22 | 22 |
| 23 class IndexedDBTest : public testing::Test { | 23 class IndexedDBTest : public testing::Test { |
| 24 public: | 24 public: |
| 25 const GURL kNormalOrigin; | 25 const GURL kNormalOrigin; |
| 26 const GURL kSessionOnlyOrigin; | 26 const GURL kSessionOnlyOrigin; |
| 27 | 27 |
| 28 IndexedDBTest() | 28 IndexedDBTest() |
| 29 : kNormalOrigin("http://normal/"), | 29 : kNormalOrigin("http://normal/"), |
| 30 kSessionOnlyOrigin("http://session-only/"), | 30 kSessionOnlyOrigin("http://session-only/"), |
| 31 message_loop_(base::MessageLoop::TYPE_IO), | 31 message_loop_(base::MessageLoop::TYPE_IO), |
| 32 task_runner_(new base::TestSimpleTaskRunner), | 32 task_runner_(new base::TestSimpleTaskRunner), |
| 33 special_storage_policy_(new quota::MockSpecialStoragePolicy), | 33 special_storage_policy_(new quota::MockSpecialStoragePolicy), |
| 34 file_thread_(BrowserThread::FILE_USER_BLOCKING, &message_loop_), | 34 file_thread_(BrowserThread::FILE_USER_BLOCKING, &message_loop_), |
| 35 io_thread_(BrowserThread::IO, &message_loop_) { | 35 io_thread_(BrowserThread::IO, &message_loop_) { |
| 36 special_storage_policy_->AddSessionOnly(kSessionOnlyOrigin); | 36 special_storage_policy_->AddSessionOnly(kSessionOnlyOrigin); |
| 37 } | 37 } |
| 38 | 38 |
| 39 protected: | 39 protected: |
| 40 void FlushIndexedDBTaskRunner() { | 40 void FlushIndexedDBTaskRunner() { task_runner_->RunUntilIdle(); } |
| 41 task_runner_->RunUntilIdle(); | |
| 42 } | |
| 43 | 41 |
| 44 base::MessageLoop message_loop_; | 42 base::MessageLoop message_loop_; |
| 45 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | 43 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
| 46 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy_; | 44 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy_; |
| 47 | 45 |
| 48 private: | 46 private: |
| 49 BrowserThreadImpl file_thread_; | 47 BrowserThreadImpl file_thread_; |
| 50 BrowserThreadImpl io_thread_; | 48 BrowserThreadImpl io_thread_; |
| 51 }; | 49 }; |
| 52 | 50 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 } | 111 } |
| 114 | 112 |
| 115 // Make sure we wait until the destructor has run. | 113 // Make sure we wait until the destructor has run. |
| 116 message_loop_.RunUntilIdle(); | 114 message_loop_.RunUntilIdle(); |
| 117 | 115 |
| 118 // No data was cleared because of SetForceKeepSessionState. | 116 // No data was cleared because of SetForceKeepSessionState. |
| 119 EXPECT_TRUE(file_util::DirectoryExists(normal_path)); | 117 EXPECT_TRUE(file_util::DirectoryExists(normal_path)); |
| 120 EXPECT_TRUE(file_util::DirectoryExists(session_only_path)); | 118 EXPECT_TRUE(file_util::DirectoryExists(session_only_path)); |
| 121 } | 119 } |
| 122 | 120 |
| 123 class MockWebIDBDatabase : public WebIDBDatabaseImpl { | 121 class MockConnection : public IndexedDBConnection { |
| 124 public: | 122 public: |
| 125 explicit MockWebIDBDatabase(bool expect_force_close) | 123 explicit MockConnection(bool expect_force_close) |
| 126 : WebIDBDatabaseImpl(NULL, NULL), | 124 : IndexedDBConnection(NULL, NULL), |
| 127 expect_force_close_(expect_force_close), | 125 expect_force_close_(expect_force_close), |
| 128 force_close_called_(false) {} | 126 force_close_called_(false) {} |
| 129 | 127 |
| 130 virtual ~MockWebIDBDatabase() { | 128 virtual ~MockConnection() { |
| 131 EXPECT_TRUE(force_close_called_ == expect_force_close_); | 129 EXPECT_TRUE(force_close_called_ == expect_force_close_); |
| 132 } | 130 } |
| 133 | 131 |
| 134 virtual void forceClose() OVERRIDE { | 132 virtual void ForceClose() OVERRIDE { |
| 135 ASSERT_TRUE(expect_force_close_); | 133 ASSERT_TRUE(expect_force_close_); |
| 136 force_close_called_ = true; | 134 force_close_called_ = true; |
| 137 } | 135 } |
| 138 | 136 |
| 139 private: | 137 private: |
| 140 bool expect_force_close_; | 138 bool expect_force_close_; |
| 141 bool force_close_called_; | 139 bool force_close_called_; |
| 142 }; | 140 }; |
| 143 | 141 |
| 144 TEST_F(IndexedDBTest, ForceCloseOpenDatabasesOnDelete) { | 142 TEST_F(IndexedDBTest, ForceCloseOpenDatabasesOnDelete) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 158 special_storage_policy_.get(), | 156 special_storage_policy_.get(), |
| 159 NULL, | 157 NULL, |
| 160 task_runner_.get()); | 158 task_runner_.get()); |
| 161 | 159 |
| 162 test_path = idb_context->GetFilePathForTesting( | 160 test_path = idb_context->GetFilePathForTesting( |
| 163 webkit_database::GetIdentifierFromOrigin(kTestOrigin)); | 161 webkit_database::GetIdentifierFromOrigin(kTestOrigin)); |
| 164 ASSERT_TRUE(file_util::CreateDirectory(test_path)); | 162 ASSERT_TRUE(file_util::CreateDirectory(test_path)); |
| 165 | 163 |
| 166 const bool kExpectForceClose = true; | 164 const bool kExpectForceClose = true; |
| 167 | 165 |
| 168 MockWebIDBDatabase connection1(kExpectForceClose); | 166 MockConnection connection1(kExpectForceClose); |
| 169 idb_context->TaskRunner()->PostTask( | 167 idb_context->TaskRunner()->PostTask( |
| 170 FROM_HERE, | 168 FROM_HERE, |
| 171 base::Bind(&IndexedDBContextImpl::ConnectionOpened, | 169 base::Bind(&IndexedDBContextImpl::ConnectionOpened, |
| 172 idb_context, | 170 idb_context, |
| 173 kTestOrigin, | 171 kTestOrigin, |
| 174 &connection1)); | 172 &connection1)); |
| 175 | 173 |
| 176 MockWebIDBDatabase connection2(!kExpectForceClose); | 174 MockConnection connection2(!kExpectForceClose); |
| 177 idb_context->TaskRunner()->PostTask( | 175 idb_context->TaskRunner()->PostTask( |
| 178 FROM_HERE, | 176 FROM_HERE, |
| 179 base::Bind(&IndexedDBContextImpl::ConnectionOpened, | 177 base::Bind(&IndexedDBContextImpl::ConnectionOpened, |
| 180 idb_context, | 178 idb_context, |
| 181 kTestOrigin, | 179 kTestOrigin, |
| 182 &connection2)); | 180 &connection2)); |
| 183 idb_context->TaskRunner()->PostTask( | 181 idb_context->TaskRunner()->PostTask( |
| 184 FROM_HERE, | 182 FROM_HERE, |
| 185 base::Bind(&IndexedDBContextImpl::ConnectionClosed, | 183 base::Bind(&IndexedDBContextImpl::ConnectionClosed, |
| 186 idb_context, | 184 idb_context, |
| 187 kTestOrigin, | 185 kTestOrigin, |
| 188 &connection2)); | 186 &connection2)); |
| 189 | 187 |
| 190 idb_context->TaskRunner()->PostTask( | 188 idb_context->TaskRunner()->PostTask( |
| 191 FROM_HERE, | 189 FROM_HERE, |
| 192 base::Bind(&IndexedDBContextImpl::DeleteForOrigin, | 190 base::Bind(&IndexedDBContextImpl::DeleteForOrigin, |
| 193 idb_context, | 191 idb_context, |
| 194 kTestOrigin)); | 192 kTestOrigin)); |
| 195 FlushIndexedDBTaskRunner(); | 193 FlushIndexedDBTaskRunner(); |
| 196 message_loop_.RunUntilIdle(); | 194 message_loop_.RunUntilIdle(); |
| 197 } | 195 } |
| 198 | 196 |
| 199 // Make sure we wait until the destructor has run. | 197 // Make sure we wait until the destructor has run. |
| 200 message_loop_.RunUntilIdle(); | 198 message_loop_.RunUntilIdle(); |
| 201 | 199 |
| 202 EXPECT_FALSE(file_util::DirectoryExists(test_path)); | 200 EXPECT_FALSE(file_util::DirectoryExists(test_path)); |
| 203 } | 201 } |
| 204 | 202 |
| 205 } // namespace content | 203 } // namespace content |
| OLD | NEW |