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" |
11 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 11 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
12 #include "content/browser/indexed_db/mock_indexed_db_callbacks.h" | 12 #include "content/browser/indexed_db/mock_indexed_db_callbacks.h" |
13 #include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h" | 13 #include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h" |
14 #include "content/public/browser/storage_partition.h" | 14 #include "content/public/browser/storage_partition.h" |
15 #include "content/public/common/url_constants.h" | 15 #include "content/public/common/url_constants.h" |
| 16 #include "content/public/test/mock_special_storage_policy.h" |
16 #include "content/public/test/test_browser_context.h" | 17 #include "content/public/test/test_browser_context.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "webkit/browser/quota/mock_special_storage_policy.h" | |
19 #include "webkit/browser/quota/quota_manager.h" | 19 #include "webkit/browser/quota/quota_manager.h" |
20 #include "webkit/browser/quota/special_storage_policy.h" | 20 #include "webkit/browser/quota/special_storage_policy.h" |
21 #include "webkit/common/database/database_identifier.h" | 21 #include "webkit/common/database/database_identifier.h" |
22 | 22 |
23 namespace content { | 23 namespace content { |
24 | 24 |
25 class IndexedDBTest : public testing::Test { | 25 class IndexedDBTest : public testing::Test { |
26 public: | 26 public: |
27 const GURL kNormalOrigin; | 27 const GURL kNormalOrigin; |
28 const GURL kSessionOnlyOrigin; | 28 const GURL kSessionOnlyOrigin; |
29 | 29 |
30 IndexedDBTest() | 30 IndexedDBTest() |
31 : kNormalOrigin("http://normal/"), | 31 : kNormalOrigin("http://normal/"), |
32 kSessionOnlyOrigin("http://session-only/"), | 32 kSessionOnlyOrigin("http://session-only/"), |
33 task_runner_(new base::TestSimpleTaskRunner), | 33 task_runner_(new base::TestSimpleTaskRunner), |
34 special_storage_policy_(new quota::MockSpecialStoragePolicy), | 34 special_storage_policy_(new MockSpecialStoragePolicy), |
35 file_thread_(BrowserThread::FILE_USER_BLOCKING, &message_loop_), | 35 file_thread_(BrowserThread::FILE_USER_BLOCKING, &message_loop_), |
36 io_thread_(BrowserThread::IO, &message_loop_) { | 36 io_thread_(BrowserThread::IO, &message_loop_) { |
37 special_storage_policy_->AddSessionOnly(kSessionOnlyOrigin); | 37 special_storage_policy_->AddSessionOnly(kSessionOnlyOrigin); |
38 } | 38 } |
39 | 39 |
40 protected: | 40 protected: |
41 void FlushIndexedDBTaskRunner() { task_runner_->RunUntilIdle(); } | 41 void FlushIndexedDBTaskRunner() { task_runner_->RunUntilIdle(); } |
42 | 42 |
43 base::MessageLoopForIO message_loop_; | 43 base::MessageLoopForIO message_loop_; |
44 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | 44 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
45 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy_; | 45 scoped_refptr<MockSpecialStoragePolicy> special_storage_policy_; |
46 | 46 |
47 private: | 47 private: |
48 BrowserThreadImpl file_thread_; | 48 BrowserThreadImpl file_thread_; |
49 BrowserThreadImpl io_thread_; | 49 BrowserThreadImpl io_thread_; |
50 | 50 |
51 DISALLOW_COPY_AND_ASSIGN(IndexedDBTest); | 51 DISALLOW_COPY_AND_ASSIGN(IndexedDBTest); |
52 }; | 52 }; |
53 | 53 |
54 TEST_F(IndexedDBTest, ClearSessionOnlyDatabases) { | 54 TEST_F(IndexedDBTest, ClearSessionOnlyDatabases) { |
55 base::ScopedTempDir temp_dir; | 55 base::ScopedTempDir temp_dir; |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 EXPECT_TRUE(factory->IsBackingStoreOpen(kTestOrigin)); | 273 EXPECT_TRUE(factory->IsBackingStoreOpen(kTestOrigin)); |
274 | 274 |
275 // Simulate the write failure. | 275 // Simulate the write failure. |
276 callbacks->connection()->database()->TransactionCommitFailed(); | 276 callbacks->connection()->database()->TransactionCommitFailed(); |
277 | 277 |
278 EXPECT_TRUE(db_callbacks->forced_close_called()); | 278 EXPECT_TRUE(db_callbacks->forced_close_called()); |
279 EXPECT_FALSE(factory->IsBackingStoreOpen(kTestOrigin)); | 279 EXPECT_FALSE(factory->IsBackingStoreOpen(kTestOrigin)); |
280 } | 280 } |
281 | 281 |
282 } // namespace content | 282 } // namespace content |
OLD | NEW |