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

Side by Side Diff: components/safe_browsing_db/v4_store_unittest.cc

Issue 2145163003: PVer4: Keep track of the smallest hashes not their sizes. Replace counters with iterators. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@01_read_map_from_disk
Patch Set: Update comment about iterator initialization Created 4 years, 5 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
« no previous file with comments | « components/safe_browsing_db/v4_store.cc ('k') | no next file » | 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 "base/files/file_util.h" 5 #include "base/files/file_util.h"
6 #include "base/files/scoped_temp_dir.h" 6 #include "base/files/scoped_temp_dir.h"
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/test/test_simple_task_runner.h" 9 #include "base/test/test_simple_task_runner.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 prefix_size = 4; 170 prefix_size = 4;
171 EXPECT_EQ(APPLY_UPDATE_SUCCESS, 171 EXPECT_EQ(APPLY_UPDATE_SUCCESS,
172 V4Store::AddUnlumpedHashes(prefix_size, "abcde5432100000-----", 172 V4Store::AddUnlumpedHashes(prefix_size, "abcde5432100000-----",
173 &prefix_map)); 173 &prefix_map));
174 EXPECT_EQ(2u, prefix_map.size()); 174 EXPECT_EQ(2u, prefix_map.size());
175 hash_prefixes = prefix_map.at(prefix_size); 175 hash_prefixes = prefix_map.at(prefix_size);
176 EXPECT_EQ(5 * prefix_size, hash_prefixes.size()); 176 EXPECT_EQ(5 * prefix_size, hash_prefixes.size());
177 EXPECT_EQ("abcde5432100000-----", hash_prefixes); 177 EXPECT_EQ("abcde5432100000-----", hash_prefixes);
178 } 178 }
179 179
180 TEST_F(V4StoreTest, TestGetNextSmallestPrefixSizeWithEmptyPrefixMap) { 180 TEST_F(V4StoreTest, TestGetNextSmallestUnmergedPrefixWithEmptyPrefixMap) {
181 HashPrefixMap prefix_map; 181 HashPrefixMap prefix_map;
182 CounterMap counter_map; 182 IteratorMap iterator_map;
183 V4Store::InitializeCounterMap(prefix_map, &counter_map); 183 V4Store::InitializeIteratorMap(prefix_map, &iterator_map);
184 184
185 PrefixSize prefix_size; 185 HashPrefix prefix;
186 EXPECT_FALSE(V4Store::GetNextSmallestPrefixSize(prefix_map, counter_map, 186 EXPECT_FALSE(V4Store::GetNextSmallestUnmergedPrefix(prefix_map, iterator_map,
187 &prefix_size)); 187 &prefix));
188 } 188 }
189 189
190 TEST_F(V4StoreTest, TestGetNextSmallestPrefixSize) { 190 TEST_F(V4StoreTest, TestGetNextSmallestUnmergedPrefix) {
191 HashPrefixMap prefix_map; 191 HashPrefixMap prefix_map;
192 EXPECT_EQ(APPLY_UPDATE_SUCCESS, 192 EXPECT_EQ(APPLY_UPDATE_SUCCESS,
193 V4Store::AddUnlumpedHashes(5, "-----0000054321abcde", &prefix_map)); 193 V4Store::AddUnlumpedHashes(5, "-----0000054321abcde", &prefix_map));
194 EXPECT_EQ(APPLY_UPDATE_SUCCESS, 194 EXPECT_EQ(APPLY_UPDATE_SUCCESS,
195 V4Store::AddUnlumpedHashes(4, "-----0000054321abcde", &prefix_map)); 195 V4Store::AddUnlumpedHashes(4, "*****0000054321abcde", &prefix_map));
196 CounterMap counter_map; 196 IteratorMap iterator_map;
197 V4Store::InitializeCounterMap(prefix_map, &counter_map); 197 V4Store::InitializeIteratorMap(prefix_map, &iterator_map);
198 198
199 PrefixSize prefix_size; 199 HashPrefix prefix;
200 EXPECT_TRUE(V4Store::GetNextSmallestPrefixSize(prefix_map, counter_map, 200 EXPECT_TRUE(V4Store::GetNextSmallestUnmergedPrefix(prefix_map, iterator_map,
201 &prefix_size)); 201 &prefix));
202 EXPECT_EQ(4u, prefix_size); 202 EXPECT_EQ("****", prefix);
203 }
204
205 TEST_F(V4StoreTest, TestGetNextUnmergedPrefix) {
206 HashPrefixMap prefix_map;
207 EXPECT_EQ(APPLY_UPDATE_SUCCESS,
208 V4Store::AddUnlumpedHashes(5, "-----0000054321abcde", &prefix_map));
209 EXPECT_EQ(APPLY_UPDATE_SUCCESS,
210 V4Store::AddUnlumpedHashes(4, "-----0000054321abcde", &prefix_map));
211 CounterMap counter_map;
212 V4Store::InitializeCounterMap(prefix_map, &counter_map);
213
214 PrefixSize prefix_size;
215 EXPECT_TRUE(V4Store::GetNextSmallestPrefixSize(prefix_map, counter_map,
216 &prefix_size));
217 const HashPrefix& prefix = V4Store::GetNextUnmergedPrefixForSize(
218 prefix_size, prefix_map, counter_map);
219 EXPECT_EQ("----", prefix);
220 } 203 }
221 204
222 TEST_F(V4StoreTest, TestMergeUpdatesWithSameSizesInEachMap) { 205 TEST_F(V4StoreTest, TestMergeUpdatesWithSameSizesInEachMap) {
223 HashPrefixMap prefix_map_old; 206 HashPrefixMap prefix_map_old;
224 EXPECT_EQ(APPLY_UPDATE_SUCCESS, 207 EXPECT_EQ(APPLY_UPDATE_SUCCESS,
225 V4Store::AddUnlumpedHashes(4, "abcdefgh", &prefix_map_old)); 208 V4Store::AddUnlumpedHashes(4, "abcdefgh", &prefix_map_old));
226 EXPECT_EQ(APPLY_UPDATE_SUCCESS, 209 EXPECT_EQ(APPLY_UPDATE_SUCCESS,
227 V4Store::AddUnlumpedHashes(5, "54321abcde", &prefix_map_old)); 210 V4Store::AddUnlumpedHashes(5, "54321abcde", &prefix_map_old));
228 HashPrefixMap prefix_map_additions; 211 HashPrefixMap prefix_map_additions;
229 EXPECT_EQ( 212 EXPECT_EQ(
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 EXPECT_EQ(WRITE_SUCCESS, 365 EXPECT_EQ(WRITE_SUCCESS,
383 V4Store(task_runner_, store_path_).WriteToDisk(std::move(lur))); 366 V4Store(task_runner_, store_path_).WriteToDisk(std::move(lur)));
384 367
385 V4Store read_store(task_runner_, store_path_); 368 V4Store read_store(task_runner_, store_path_);
386 EXPECT_EQ(HASH_PREFIX_MAP_GENERATION_FAILURE, read_store.ReadFromDisk()); 369 EXPECT_EQ(HASH_PREFIX_MAP_GENERATION_FAILURE, read_store.ReadFromDisk());
387 EXPECT_TRUE(read_store.state_.empty()); 370 EXPECT_TRUE(read_store.state_.empty());
388 EXPECT_TRUE(read_store.hash_prefix_map_.empty()); 371 EXPECT_TRUE(read_store.hash_prefix_map_.empty());
389 } 372 }
390 373
391 } // namespace safe_browsing 374 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « components/safe_browsing_db/v4_store.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698