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 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/message_loop/message_loop.h" | |
11 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
12 #include "content/public/browser/browser_thread.h" | 11 #include "base/test/scoped_task_environment.h" |
13 #include "content/public/test/test_browser_context.h" | 12 #include "content/public/test/test_browser_context.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
15 | 14 |
16 namespace content { | 15 namespace content { |
17 | 16 |
18 // Test that the Less comparison function is implemented properly to uniquely | 17 // Test that the Less comparison function is implemented properly to uniquely |
19 // identify storage partitions used as keys in a std::map. | 18 // identify storage partitions used as keys in a std::map. |
20 TEST(StoragePartitionConfigTest, OperatorLess) { | 19 TEST(StoragePartitionConfigTest, OperatorLess) { |
21 StoragePartitionImplMap::StoragePartitionConfig c1( | 20 StoragePartitionImplMap::StoragePartitionConfig c1( |
22 std::string(), std::string(), false); | 21 std::string(), std::string(), false); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 59 |
61 // Check for transitivity. | 60 // Check for transitivity. |
62 EXPECT_TRUE(less(c1, c4)); | 61 EXPECT_TRUE(less(c1, c4)); |
63 | 62 |
64 // Let's enforce that two identical elements obey strict weak ordering. | 63 // Let's enforce that two identical elements obey strict weak ordering. |
65 EXPECT_TRUE(!less(c1, c2) && !less(c2, c1)); | 64 EXPECT_TRUE(!less(c1, c2) && !less(c2, c1)); |
66 } | 65 } |
67 | 66 |
68 TEST(StoragePartitionImplMapTest, GarbageCollect) { | 67 TEST(StoragePartitionImplMapTest, GarbageCollect) { |
69 TestBrowserContext browser_context; | 68 TestBrowserContext browser_context; |
70 base::MessageLoop message_loop; | 69 base::test::ScopedTaskEnvironment scoped_task_environment; |
71 StoragePartitionImplMap storage_partition_impl_map(&browser_context); | 70 StoragePartitionImplMap storage_partition_impl_map(&browser_context); |
72 | 71 |
73 std::unique_ptr<base::hash_set<base::FilePath>> active_paths( | 72 std::unique_ptr<base::hash_set<base::FilePath>> active_paths( |
74 new base::hash_set<base::FilePath>); | 73 new base::hash_set<base::FilePath>); |
75 | 74 |
76 base::FilePath active_path = browser_context.GetPath().Append( | 75 base::FilePath active_path = browser_context.GetPath().Append( |
77 StoragePartitionImplMap::GetStoragePartitionPath( | 76 StoragePartitionImplMap::GetStoragePartitionPath( |
78 "active", std::string())); | 77 "active", std::string())); |
79 ASSERT_TRUE(base::CreateDirectory(active_path)); | 78 ASSERT_TRUE(base::CreateDirectory(active_path)); |
80 active_paths->insert(active_path); | 79 active_paths->insert(active_path); |
81 | 80 |
82 base::FilePath inactive_path = browser_context.GetPath().Append( | 81 base::FilePath inactive_path = browser_context.GetPath().Append( |
83 StoragePartitionImplMap::GetStoragePartitionPath( | 82 StoragePartitionImplMap::GetStoragePartitionPath( |
84 "inactive", std::string())); | 83 "inactive", std::string())); |
85 ASSERT_TRUE(base::CreateDirectory(inactive_path)); | 84 ASSERT_TRUE(base::CreateDirectory(inactive_path)); |
86 | 85 |
87 base::RunLoop run_loop; | 86 base::RunLoop run_loop; |
88 storage_partition_impl_map.GarbageCollect(std::move(active_paths), | 87 storage_partition_impl_map.GarbageCollect(std::move(active_paths), |
89 run_loop.QuitClosure()); | 88 run_loop.QuitClosure()); |
90 run_loop.Run(); | 89 run_loop.Run(); |
91 BrowserThread::GetBlockingPool()->FlushForTesting(); | 90 scoped_task_environment.RunUntilIdle(); |
92 | 91 |
93 EXPECT_TRUE(base::PathExists(active_path)); | 92 EXPECT_TRUE(base::PathExists(active_path)); |
94 EXPECT_FALSE(base::PathExists(inactive_path)); | 93 EXPECT_FALSE(base::PathExists(inactive_path)); |
95 } | 94 } |
96 | 95 |
97 } // namespace content | 96 } // namespace content |
OLD | NEW |