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 "content/browser/storage_partition_impl_map.h" | 5 #include "content/browser/storage_partition_impl_map.h" |
| 6 |
| 7 #include "base/file_util.h" |
| 8 #include "base/run_loop.h" |
| 9 #include "content/public/test/test_browser_context.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
7 | 11 |
8 namespace content { | 12 namespace content { |
9 | 13 |
10 class StoragePartitionConfigTest : public testing::Test { | |
11 }; | |
12 | |
13 // Test that the Less comparison function is implemented properly to uniquely | 14 // Test that the Less comparison function is implemented properly to uniquely |
14 // identify storage partitions used as keys in a std::map. | 15 // identify storage partitions used as keys in a std::map. |
15 TEST_F(StoragePartitionConfigTest, OperatorLess) { | 16 TEST(StoragePartitionConfigTest, OperatorLess) { |
16 StoragePartitionImplMap::StoragePartitionConfig c1( | 17 StoragePartitionImplMap::StoragePartitionConfig c1( |
17 std::string(), std::string(), false); | 18 std::string(), std::string(), false); |
18 StoragePartitionImplMap::StoragePartitionConfig c2( | 19 StoragePartitionImplMap::StoragePartitionConfig c2( |
19 std::string(), std::string(), false); | 20 std::string(), std::string(), false); |
20 StoragePartitionImplMap::StoragePartitionConfig c3( | 21 StoragePartitionImplMap::StoragePartitionConfig c3( |
21 std::string(), std::string(), true); | 22 std::string(), std::string(), true); |
22 StoragePartitionImplMap::StoragePartitionConfig c4("a", std::string(), true); | 23 StoragePartitionImplMap::StoragePartitionConfig c4("a", std::string(), true); |
23 StoragePartitionImplMap::StoragePartitionConfig c5("b", std::string(), true); | 24 StoragePartitionImplMap::StoragePartitionConfig c5("b", std::string(), true); |
24 StoragePartitionImplMap::StoragePartitionConfig c6( | 25 StoragePartitionImplMap::StoragePartitionConfig c6( |
25 std::string(), "abc", false); | 26 std::string(), "abc", false); |
(...skipping 27 matching lines...) Expand all Loading... |
53 // Check for irreflexivity. | 54 // Check for irreflexivity. |
54 EXPECT_FALSE(less(c1, c1)); | 55 EXPECT_FALSE(less(c1, c1)); |
55 | 56 |
56 // Check for transitivity. | 57 // Check for transitivity. |
57 EXPECT_TRUE(less(c1, c4)); | 58 EXPECT_TRUE(less(c1, c4)); |
58 | 59 |
59 // Let's enforce that two identical elements obey strict weak ordering. | 60 // Let's enforce that two identical elements obey strict weak ordering. |
60 EXPECT_TRUE(!less(c1, c2) && !less(c2, c1)); | 61 EXPECT_TRUE(!less(c1, c2) && !less(c2, c1)); |
61 } | 62 } |
62 | 63 |
| 64 TEST(StoragePartitionImplMapTest, GarbageCollect) { |
| 65 base::MessageLoop message_loop; |
| 66 TestBrowserContext browser_context; |
| 67 StoragePartitionImplMap storage_partition_impl_map(&browser_context); |
| 68 |
| 69 scoped_ptr<base::hash_set<base::FilePath> > active_paths( |
| 70 new base::hash_set<base::FilePath>); |
| 71 |
| 72 base::FilePath active_path = browser_context.GetPath().Append( |
| 73 StoragePartitionImplMap::GetStoragePartitionPath( |
| 74 "active", std::string())); |
| 75 ASSERT_TRUE(base::CreateDirectory(active_path)); |
| 76 active_paths->insert(active_path); |
| 77 |
| 78 base::FilePath inactive_path = browser_context.GetPath().Append( |
| 79 StoragePartitionImplMap::GetStoragePartitionPath( |
| 80 "inactive", std::string())); |
| 81 ASSERT_TRUE(base::CreateDirectory(inactive_path)); |
| 82 |
| 83 base::RunLoop run_loop; |
| 84 storage_partition_impl_map.GarbageCollect( |
| 85 active_paths.Pass(), run_loop.QuitClosure()); |
| 86 run_loop.Run(); |
| 87 |
| 88 EXPECT_TRUE(base::PathExists(active_path)); |
| 89 EXPECT_FALSE(base::PathExists(inactive_path)); |
| 90 } |
| 91 |
63 } // namespace content | 92 } // namespace content |
OLD | NEW |