| 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 <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/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/test/test_simple_task_runner.h" | 12 #include "base/test/test_simple_task_runner.h" |
| 13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 14 #include "content/browser/browser_thread_impl.h" | |
| 15 #include "content/browser/indexed_db/indexed_db_connection.h" | 14 #include "content/browser/indexed_db/indexed_db_connection.h" |
| 16 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 15 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 17 #include "content/browser/indexed_db/indexed_db_factory_impl.h" | 16 #include "content/browser/indexed_db/indexed_db_factory_impl.h" |
| 18 #include "content/browser/indexed_db/mock_indexed_db_callbacks.h" | 17 #include "content/browser/indexed_db/mock_indexed_db_callbacks.h" |
| 19 #include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h" | 18 #include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h" |
| 20 #include "content/browser/quota/mock_quota_manager_proxy.h" | 19 #include "content/browser/quota/mock_quota_manager_proxy.h" |
| 21 #include "content/public/browser/storage_partition.h" | 20 #include "content/public/browser/storage_partition.h" |
| 22 #include "content/public/common/url_constants.h" | 21 #include "content/public/common/url_constants.h" |
| 23 #include "content/public/test/mock_special_storage_policy.h" | 22 #include "content/public/test/mock_special_storage_policy.h" |
| 24 #include "content/public/test/test_browser_context.h" | 23 #include "content/public/test/test_browser_context.h" |
| 24 #include "content/public/test/test_browser_thread_bundle.h" |
| 25 #include "storage/browser/quota/quota_manager.h" | 25 #include "storage/browser/quota/quota_manager.h" |
| 26 #include "storage/browser/quota/special_storage_policy.h" | 26 #include "storage/browser/quota/special_storage_policy.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 28 #include "url/origin.h" | 28 #include "url/origin.h" |
| 29 | 29 |
| 30 using url::Origin; | 30 using url::Origin; |
| 31 | 31 |
| 32 namespace content { | 32 namespace content { |
| 33 | 33 |
| 34 class IndexedDBTest : public testing::Test { | 34 class IndexedDBTest : public testing::Test { |
| 35 public: | 35 public: |
| 36 const Origin kNormalOrigin; | 36 const Origin kNormalOrigin; |
| 37 const Origin kSessionOnlyOrigin; | 37 const Origin kSessionOnlyOrigin; |
| 38 | 38 |
| 39 IndexedDBTest() | 39 IndexedDBTest() |
| 40 : kNormalOrigin(GURL("http://normal/")), | 40 : kNormalOrigin(GURL("http://normal/")), |
| 41 kSessionOnlyOrigin(GURL("http://session-only/")), | 41 kSessionOnlyOrigin(GURL("http://session-only/")), |
| 42 task_runner_(new base::TestSimpleTaskRunner), | 42 task_runner_(new base::TestSimpleTaskRunner), |
| 43 special_storage_policy_(new MockSpecialStoragePolicy), | 43 special_storage_policy_(new MockSpecialStoragePolicy), |
| 44 quota_manager_proxy_(new MockQuotaManagerProxy(nullptr, nullptr)), | 44 quota_manager_proxy_(new MockQuotaManagerProxy(nullptr, nullptr)) { |
| 45 file_thread_(BrowserThread::FILE_USER_BLOCKING, &message_loop_), | |
| 46 io_thread_(BrowserThread::IO, &message_loop_) { | |
| 47 special_storage_policy_->AddSessionOnly(kSessionOnlyOrigin.GetURL()); | 45 special_storage_policy_->AddSessionOnly(kSessionOnlyOrigin.GetURL()); |
| 48 } | 46 } |
| 49 ~IndexedDBTest() override { | 47 ~IndexedDBTest() override { |
| 50 quota_manager_proxy_->SimulateQuotaManagerDestroyed(); | 48 quota_manager_proxy_->SimulateQuotaManagerDestroyed(); |
| 51 } | 49 } |
| 52 | 50 |
| 53 protected: | 51 protected: |
| 54 void FlushIndexedDBTaskRunner() { task_runner_->RunUntilIdle(); } | 52 void FlushIndexedDBTaskRunner() { task_runner_->RunUntilIdle(); } |
| 55 | 53 |
| 56 base::MessageLoopForIO message_loop_; | |
| 57 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | 54 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
| 58 scoped_refptr<MockSpecialStoragePolicy> special_storage_policy_; | 55 scoped_refptr<MockSpecialStoragePolicy> special_storage_policy_; |
| 59 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_; | 56 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_; |
| 60 | 57 |
| 61 private: | 58 private: |
| 62 BrowserThreadImpl file_thread_; | 59 TestBrowserThreadBundle thread_bundle_; |
| 63 BrowserThreadImpl io_thread_; | |
| 64 | 60 |
| 65 DISALLOW_COPY_AND_ASSIGN(IndexedDBTest); | 61 DISALLOW_COPY_AND_ASSIGN(IndexedDBTest); |
| 66 }; | 62 }; |
| 67 | 63 |
| 68 TEST_F(IndexedDBTest, ClearSessionOnlyDatabases) { | 64 TEST_F(IndexedDBTest, ClearSessionOnlyDatabases) { |
| 69 base::ScopedTempDir temp_dir; | 65 base::ScopedTempDir temp_dir; |
| 70 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 66 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 71 | 67 |
| 72 base::FilePath normal_path; | 68 base::FilePath normal_path; |
| 73 base::FilePath session_only_path; | 69 base::FilePath session_only_path; |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 | 280 |
| 285 // Simulate the write failure. | 281 // Simulate the write failure. |
| 286 leveldb::Status status = leveldb::Status::IOError("Simulated failure"); | 282 leveldb::Status status = leveldb::Status::IOError("Simulated failure"); |
| 287 callbacks->connection()->database()->TransactionCommitFailed(status); | 283 callbacks->connection()->database()->TransactionCommitFailed(status); |
| 288 | 284 |
| 289 EXPECT_TRUE(db_callbacks->forced_close_called()); | 285 EXPECT_TRUE(db_callbacks->forced_close_called()); |
| 290 EXPECT_FALSE(factory->IsBackingStoreOpen(kTestOrigin)); | 286 EXPECT_FALSE(factory->IsBackingStoreOpen(kTestOrigin)); |
| 291 } | 287 } |
| 292 | 288 |
| 293 } // namespace content | 289 } // namespace content |
| OLD | NEW |