Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(463)

Side by Side Diff: chrome/browser/policy/resource_cache_unittest.cc

Issue 12189011: Split up chrome/browser/policy subdirectory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, add chrome/browser/chromeos/policy/OWNERS Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/policy/resource_cache.h"
6
7 #include "base/basictypes.h"
8 #include "base/files/scoped_temp_dir.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace policy {
12
13 namespace {
14
15 const char kKey[] = "key";
16 const char kAnotherKey[] = "anotherkey";
17 const char kSubA[] = "a";
18 const char kSubB[] = "bb";
19 const char kSubC[] = "ccc";
20 const char kSubD[] = "dddd";
21 const char kSubE[] = "eeeee";
22
23 const char kData0[] = "{ \"key\": \"value\" }";
24 const char kData1[] = "{}";
25
26 } // namespace
27
28 TEST(ResourceCacheTest, StoreAndLoad) {
29 base::ScopedTempDir temp_dir;
30 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
31 ResourceCache cache(temp_dir.path().AppendASCII("db"));
32
33 // No data initially.
34 std::string data;
35 EXPECT_FALSE(cache.Load(kKey, kSubA, &data));
36
37 // Store some data and load it.
38 EXPECT_TRUE(cache.Store(kKey, kSubA, kData0));
39 EXPECT_TRUE(cache.Load(kKey, kSubA, &data));
40 EXPECT_EQ(kData0, data);
41
42 // Store more data in another subkey.
43 EXPECT_TRUE(cache.Store(kKey, kSubB, kData1));
44
45 // Write subkeys to another key.
46 EXPECT_TRUE(cache.Store(kAnotherKey, kSubA, kData0));
47 EXPECT_TRUE(cache.Store(kAnotherKey, kSubB, kData1));
48
49 // Enumerate all the keys.
50 std::map<std::string, std::string> contents;
51 cache.LoadAllSubkeys(kKey, &contents);
52 EXPECT_EQ(2u, contents.size());
53 EXPECT_EQ(kData0, contents[kSubA]);
54 EXPECT_EQ(kData1, contents[kSubB]);
55
56 // Store more keys.
57 EXPECT_TRUE(cache.Store(kKey, kSubC, kData1));
58 EXPECT_TRUE(cache.Store(kKey, kSubD, kData1));
59 EXPECT_TRUE(cache.Store(kKey, kSubE, kData1));
60
61 // Now purge some of them.
62 std::set<std::string> keep;
63 keep.insert(kSubB);
64 keep.insert(kSubD);
65 cache.PurgeOtherSubkeys(kKey, keep);
66
67 // Enumerate all the remaining keys.
68 cache.LoadAllSubkeys(kKey, &contents);
69 EXPECT_EQ(2u, contents.size());
70 EXPECT_EQ(kData1, contents[kSubB]);
71 EXPECT_EQ(kData1, contents[kSubD]);
72
73 // Delete keys directly.
74 cache.Delete(kKey, kSubB);
75 cache.Delete(kKey, kSubD);
76 cache.LoadAllSubkeys(kKey, &contents);
77 EXPECT_EQ(0u, contents.size());
78
79 // The other key was not affected.
80 cache.LoadAllSubkeys(kAnotherKey, &contents);
81 EXPECT_EQ(2u, contents.size());
82 EXPECT_EQ(kData0, contents[kSubA]);
83 EXPECT_EQ(kData1, contents[kSubB]);
84 }
85
86 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/resource_cache.cc ('k') | chrome/browser/policy/test/local_policy_test_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698