Add ICU message format support
[chromium-blink-merge.git] / content / browser / storage_partition_impl_map_unittest.cc
blobc88fb53876489c8ec02679342b9ab2becee9760a
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
3 // found in the LICENSE file.
5 #include "content/browser/storage_partition_impl_map.h"
7 #include "base/files/file_util.h"
8 #include "base/run_loop.h"
9 #include "content/public/test/test_browser_context.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace content {
14 // Test that the Less comparison function is implemented properly to uniquely
15 // identify storage partitions used as keys in a std::map.
16 TEST(StoragePartitionConfigTest, OperatorLess) {
17 StoragePartitionImplMap::StoragePartitionConfig c1(
18 std::string(), std::string(), false);
19 StoragePartitionImplMap::StoragePartitionConfig c2(
20 std::string(), std::string(), false);
21 StoragePartitionImplMap::StoragePartitionConfig c3(
22 std::string(), std::string(), true);
23 StoragePartitionImplMap::StoragePartitionConfig c4("a", std::string(), true);
24 StoragePartitionImplMap::StoragePartitionConfig c5("b", std::string(), true);
25 StoragePartitionImplMap::StoragePartitionConfig c6(
26 std::string(), "abc", false);
27 StoragePartitionImplMap::StoragePartitionConfig c7(
28 std::string(), "abc", true);
29 StoragePartitionImplMap::StoragePartitionConfig c8("a", "abc", false);
30 StoragePartitionImplMap::StoragePartitionConfig c9("a", "abc", true);
32 StoragePartitionImplMap::StoragePartitionConfigLess less;
34 // Let's ensure basic comparison works.
35 EXPECT_TRUE(less(c1, c3));
36 EXPECT_TRUE(less(c1, c4));
37 EXPECT_TRUE(less(c3, c4));
38 EXPECT_TRUE(less(c4, c5));
39 EXPECT_TRUE(less(c4, c8));
40 EXPECT_TRUE(less(c6, c4));
41 EXPECT_TRUE(less(c6, c7));
42 EXPECT_TRUE(less(c8, c9));
44 // Now, ensure antisymmetry for each pair we've tested.
45 EXPECT_FALSE(less(c3, c1));
46 EXPECT_FALSE(less(c4, c1));
47 EXPECT_FALSE(less(c4, c3));
48 EXPECT_FALSE(less(c5, c4));
49 EXPECT_FALSE(less(c8, c4));
50 EXPECT_FALSE(less(c4, c6));
51 EXPECT_FALSE(less(c7, c6));
52 EXPECT_FALSE(less(c9, c8));
54 // Check for irreflexivity.
55 EXPECT_FALSE(less(c1, c1));
57 // Check for transitivity.
58 EXPECT_TRUE(less(c1, c4));
60 // Let's enforce that two identical elements obey strict weak ordering.
61 EXPECT_TRUE(!less(c1, c2) && !less(c2, c1));
64 TEST(StoragePartitionImplMapTest, GarbageCollect) {
65 base::MessageLoop message_loop;
66 TestBrowserContext browser_context;
67 StoragePartitionImplMap storage_partition_impl_map(&browser_context);
69 scoped_ptr<base::hash_set<base::FilePath> > active_paths(
70 new base::hash_set<base::FilePath>);
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);
78 base::FilePath inactive_path = browser_context.GetPath().Append(
79 StoragePartitionImplMap::GetStoragePartitionPath(
80 "inactive", std::string()));
81 ASSERT_TRUE(base::CreateDirectory(inactive_path));
83 base::RunLoop run_loop;
84 storage_partition_impl_map.GarbageCollect(
85 active_paths.Pass(), run_loop.QuitClosure());
86 run_loop.Run();
88 EXPECT_TRUE(base::PathExists(active_path));
89 EXPECT_FALSE(base::PathExists(inactive_path));
92 } // namespace content