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

Side by Side Diff: chromeos/printing/ppd_cache_unittest.cc

Issue 2487343006: Add in-memory caching to PpdCache available printers. (Closed)
Patch Set: Address thestig@ comment Created 4 years, 1 month 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
« no previous file with comments | « chromeos/printing/ppd_cache.cc ('k') | chromeos/printing/ppd_provider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <utility>
6
5 #include "base/bind.h" 7 #include "base/bind.h"
6 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
7 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
8 #include "base/hash.h" 10 #include "base/hash.h"
9 #include "base/logging.h" 11 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h" 13 #include "base/run_loop.h"
12 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
13 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
14 #include "chromeos/printing/ppd_cache.h" 16 #include "chromeos/printing/ppd_cache.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 sizeof(kTestGZippedPpdContents)); 147 sizeof(kTestGZippedPpdContents));
146 EXPECT_EQ(".ppd.gz", cache->Store(ref, gzipped_contents).value().Extension()); 148 EXPECT_EQ(".ppd.gz", cache->Store(ref, gzipped_contents).value().Extension());
147 } 149 }
148 150
149 // Test that we get back what we stored when we store an available printers 151 // Test that we get back what we stored when we store an available printers
150 // list. 152 // list.
151 TEST_F(PpdCacheTest, StoreAndRetrieveAvailablePrinters) { 153 TEST_F(PpdCacheTest, StoreAndRetrieveAvailablePrinters) {
152 auto cache = CreateTestCache(); 154 auto cache = CreateTestCache();
153 155
154 // Nothing stored, so should miss in the cache. 156 // Nothing stored, so should miss in the cache.
155 base::Optional<PpdProvider::AvailablePrintersMap> result = 157 const PpdProvider::AvailablePrintersMap* result =
156 cache->FindAvailablePrinters(); 158 cache->FindAvailablePrinters();
157 EXPECT_FALSE(result); 159 EXPECT_EQ(nullptr, result);
158 160
159 // Create something to store. 161 // Create something to store.
160 PpdProvider::AvailablePrintersMap a; 162 auto a = base::MakeUnique<PpdProvider::AvailablePrintersMap>();
161 a["foo"] = {"bar", "baz", "sna"}; 163 (*a)["foo"] = {"bar", "baz", "sna"};
162 a["bar"] = {"c", "d", "e"}; 164 (*a)["bar"] = {"c", "d", "e"};
163 a["baz"] = {"f", "g", "h"}; 165 (*a)["baz"] = {"f", "g", "h"};
166 PpdProvider::AvailablePrintersMap original = *a;
164 167
165 // Store it, get it back. 168 // Store it, get it back.
166 cache->StoreAvailablePrinters(a); 169 cache->StoreAvailablePrinters(std::move(a));
167 result = cache->FindAvailablePrinters(); 170 result = cache->FindAvailablePrinters();
168 ASSERT_TRUE(result); 171 ASSERT_NE(nullptr, result);
169 172
170 EXPECT_EQ(a, result.value()); 173 EXPECT_EQ(original, *result);
171 } 174 }
172 175
173 // When an entry is too old, we shouldn't return it. 176 // When an entry is too old, we shouldn't return it.
174 TEST_F(PpdCacheTest, ExpireStaleAvailablePrinters) { 177 TEST_F(PpdCacheTest, ExpireStaleAvailablePrinters) {
175 PpdCache::Options options; 178 PpdCache::Options options;
176 // Expire stuff immediately by setting the staleness limit to 0. 179 // Expire stuff immediately by setting the staleness limit to 0.
177 options.max_available_list_staleness = base::TimeDelta(); 180 options.max_available_list_staleness = base::TimeDelta();
178 auto cache = CreateTestCache(options); 181 auto cache = CreateTestCache(options);
179 182
180 // Store an empty map. (Contents don't really matter for this test). 183 // Store an empty map. (Contents don't really matter for this test).
181 cache->StoreAvailablePrinters(PpdProvider::AvailablePrintersMap()); 184 cache->StoreAvailablePrinters(
185 base::MakeUnique<PpdProvider::AvailablePrintersMap>());
182 186
183 // Should *miss* in the cache because the entry is already expired. 187 // Should *miss* in the cache because the entry is already expired.
184 EXPECT_FALSE(cache->FindAvailablePrinters()); 188 EXPECT_EQ(nullptr, cache->FindAvailablePrinters());
185 } 189 }
186 190
187 } // namespace 191 } // namespace
188 } // namespace printing 192 } // namespace printing
189 } // namespace chromeos 193 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/printing/ppd_cache.cc ('k') | chromeos/printing/ppd_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698