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 "chrome/browser/chromeos/gdata/gdata_cache.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_cache.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/scoped_temp_dir.h" | 12 #include "base/scoped_temp_dir.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace gdata { | 15 namespace gdata { |
16 namespace { | 16 namespace { |
17 | 17 |
| 18 const char kTestCacheRootPath[] = "/"; |
| 19 |
18 // Helper function to insert an item with key |resource_id| into |cache_map|. | 20 // Helper function to insert an item with key |resource_id| into |cache_map|. |
19 // |md5|, |sub_dir_type|, |cache_state| are used to create the value CacheEntry. | 21 // |md5|, |sub_dir_type|, |cache_state| are used to create the value CacheEntry. |
20 void InsertIntoMap(GDataCache::CacheMap* cache_map, | 22 void InsertIntoMap(GDataCache::CacheMap* cache_map, |
21 const std::string& resource_id, const std::string& md5, | 23 const std::string& resource_id, const std::string& md5, |
22 GDataCache::CacheSubDirectoryType sub_dir_type, int cache_state) { | 24 GDataCache::CacheSubDirectoryType sub_dir_type, int cache_state) { |
23 cache_map->insert(std::make_pair(resource_id, | 25 cache_map->insert(std::make_pair(resource_id, |
24 GDataCache::CacheEntry(md5, sub_dir_type, cache_state))); | 26 GDataCache::CacheEntry(md5, sub_dir_type, cache_state))); |
25 } | 27 } |
26 | 28 |
27 } // namespace | 29 } // namespace |
28 | 30 |
29 // Test all the api methods of GDataCache except for RemoveTemporaryFiles. | 31 // Test all the api methods of GDataCache except for RemoveTemporaryFiles. |
30 TEST(GDataCacheTest, CacheTest) { | 32 TEST(GDataCacheTest, CacheTest) { |
31 scoped_ptr<GDataCache> cache(GDataCache::CreateGDataCache()); | 33 scoped_ptr<GDataCache> cache(GDataCache::CreateGDataCache( |
| 34 FilePath(kTestCacheRootPath))); |
32 | 35 |
33 // Save an initial entry. | 36 // Save an initial entry. |
34 std::string test_resource_id("test_resource_id"); | 37 std::string test_resource_id("test_resource_id"); |
35 std::string test_file_md5("test_file_md5"); | 38 std::string test_file_md5("test_file_md5"); |
36 GDataCache::CacheSubDirectoryType test_sub_dir_type( | 39 GDataCache::CacheSubDirectoryType test_sub_dir_type( |
37 GDataCache::CACHE_TYPE_PERSISTENT); | 40 GDataCache::CACHE_TYPE_PERSISTENT); |
38 int test_cache_state(GDataCache::CACHE_STATE_PRESENT); | 41 int test_cache_state(GDataCache::CACHE_STATE_PRESENT); |
39 cache->UpdateCache(test_resource_id, test_file_md5, | 42 cache->UpdateCache(test_resource_id, test_file_md5, |
40 test_sub_dir_type, test_cache_state); | 43 test_sub_dir_type, test_cache_state); |
41 | 44 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 "<resource_id_3>", | 155 "<resource_id_3>", |
153 "<md5>", | 156 "<md5>", |
154 GDataCache::CACHE_TYPE_OUTGOING, | 157 GDataCache::CACHE_TYPE_OUTGOING, |
155 GDataCache::CACHE_STATE_PRESENT); | 158 GDataCache::CACHE_STATE_PRESENT); |
156 InsertIntoMap(&cache_map, | 159 InsertIntoMap(&cache_map, |
157 "<resource_id_4>", | 160 "<resource_id_4>", |
158 "<md5>", | 161 "<md5>", |
159 GDataCache::CACHE_TYPE_TMP, | 162 GDataCache::CACHE_TYPE_TMP, |
160 GDataCache::CACHE_STATE_PRESENT); | 163 GDataCache::CACHE_STATE_PRESENT); |
161 | 164 |
162 scoped_ptr<GDataCache> cache(GDataCache::CreateGDataCache()); | 165 scoped_ptr<GDataCache> cache(GDataCache::CreateGDataCache( |
| 166 FilePath(kTestCacheRootPath))); |
163 cache->SetCacheMap(cache_map); | 167 cache->SetCacheMap(cache_map); |
164 cache->RemoveTemporaryFiles(); | 168 cache->RemoveTemporaryFiles(); |
165 // resource 1 and 4 should be gone, as these are CACHE_TYPE_TMP. | 169 // resource 1 and 4 should be gone, as these are CACHE_TYPE_TMP. |
166 EXPECT_FALSE(cache->GetCacheEntry("<resource_id_1>", "").get()); | 170 EXPECT_FALSE(cache->GetCacheEntry("<resource_id_1>", "").get()); |
167 EXPECT_TRUE(cache->GetCacheEntry("<resource_id_2>", "").get()); | 171 EXPECT_TRUE(cache->GetCacheEntry("<resource_id_2>", "").get()); |
168 EXPECT_TRUE(cache->GetCacheEntry("<resource_id_3>", "").get()); | 172 EXPECT_TRUE(cache->GetCacheEntry("<resource_id_3>", "").get()); |
169 EXPECT_FALSE(cache->GetCacheEntry("<resource_id_4>", "").get()); | 173 EXPECT_FALSE(cache->GetCacheEntry("<resource_id_4>", "").get()); |
170 } | 174 } |
171 | 175 |
172 } // namespace gdata | 176 } // namespace gdata |
OLD | NEW |