OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/browser/policy/cloud/resource_cache.h" | 5 #include "chrome/browser/policy/cloud/resource_cache.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/test/test_simple_task_runner.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 | 11 |
11 namespace policy { | 12 namespace policy { |
12 | 13 |
13 namespace { | 14 namespace { |
14 | 15 |
15 const char kKey1[] = "key 1"; | 16 const char kKey1[] = "key 1"; |
16 const char kKey2[] = "key 2"; | 17 const char kKey2[] = "key 2"; |
17 const char kKey3[] = "key 3"; | 18 const char kKey3[] = "key 3"; |
18 const char kSubA[] = "a"; | 19 const char kSubA[] = "a"; |
19 const char kSubB[] = "bb"; | 20 const char kSubB[] = "bb"; |
20 const char kSubC[] = "ccc"; | 21 const char kSubC[] = "ccc"; |
21 const char kSubD[] = "dddd"; | 22 const char kSubD[] = "dddd"; |
22 const char kSubE[] = "eeeee"; | 23 const char kSubE[] = "eeeee"; |
23 | 24 |
24 const char kData0[] = "{ \"key\": \"value\" }"; | 25 const char kData0[] = "{ \"key\": \"value\" }"; |
25 const char kData1[] = "{}"; | 26 const char kData1[] = "{}"; |
26 | 27 |
27 } // namespace | 28 } // namespace |
28 | 29 |
29 TEST(ResourceCacheTest, StoreAndLoad) { | 30 TEST(ResourceCacheTest, StoreAndLoad) { |
30 base::ScopedTempDir temp_dir; | 31 base::ScopedTempDir temp_dir; |
31 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 32 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
32 ResourceCache cache(temp_dir.path()); | 33 ResourceCache cache(temp_dir.path(), |
| 34 make_scoped_refptr(new base::TestSimpleTaskRunner)); |
33 | 35 |
34 // No data initially. | 36 // No data initially. |
35 std::string data; | 37 std::string data; |
36 EXPECT_FALSE(cache.Load(kKey1, kSubA, &data)); | 38 EXPECT_FALSE(cache.Load(kKey1, kSubA, &data)); |
37 | 39 |
38 // Store some data and load it. | 40 // Store some data and load it. |
39 EXPECT_TRUE(cache.Store(kKey1, kSubA, kData0)); | 41 EXPECT_TRUE(cache.Store(kKey1, kSubA, kData0)); |
40 EXPECT_TRUE(cache.Load(kKey1, kSubA, &data)); | 42 EXPECT_TRUE(cache.Load(kKey1, kSubA, &data)); |
41 EXPECT_EQ(kData0, data); | 43 EXPECT_EQ(kData0, data); |
42 | 44 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 EXPECT_EQ(0u, contents.size()); | 103 EXPECT_EQ(0u, contents.size()); |
102 | 104 |
103 // The third key is unaffected. | 105 // The third key is unaffected. |
104 cache.LoadAllSubkeys(kKey3, &contents); | 106 cache.LoadAllSubkeys(kKey3, &contents); |
105 EXPECT_EQ(2u, contents.size()); | 107 EXPECT_EQ(2u, contents.size()); |
106 EXPECT_EQ(kData0, contents[kSubA]); | 108 EXPECT_EQ(kData0, contents[kSubA]); |
107 EXPECT_EQ(kData1, contents[kSubB]); | 109 EXPECT_EQ(kData1, contents[kSubB]); |
108 } | 110 } |
109 | 111 |
110 } // namespace policy | 112 } // namespace policy |
OLD | NEW |