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

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

Issue 2164523002: PVer4: V4Store: Check whether a hash prefix exists for a full hash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/ContainsFullHash/GetMatchingHashPrefix 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
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 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 additions->mutable_raw_hashes()->set_raw_hashes("abcdef"); 523 additions->mutable_raw_hashes()->set_raw_hashes("abcdef");
524 EXPECT_EQ(WRITE_SUCCESS, 524 EXPECT_EQ(WRITE_SUCCESS,
525 V4Store(task_runner_, store_path_).WriteToDisk(std::move(lur))); 525 V4Store(task_runner_, store_path_).WriteToDisk(std::move(lur)));
526 526
527 V4Store read_store(task_runner_, store_path_); 527 V4Store read_store(task_runner_, store_path_);
528 EXPECT_EQ(HASH_PREFIX_MAP_GENERATION_FAILURE, read_store.ReadFromDisk()); 528 EXPECT_EQ(HASH_PREFIX_MAP_GENERATION_FAILURE, read_store.ReadFromDisk());
529 EXPECT_TRUE(read_store.state_.empty()); 529 EXPECT_TRUE(read_store.state_.empty());
530 EXPECT_TRUE(read_store.hash_prefix_map_.empty()); 530 EXPECT_TRUE(read_store.hash_prefix_map_.empty());
531 } 531 }
532 532
533 TEST_F(V4StoreTest, TestHashPrefixExistsAtTheBeginning) {
534 HashPrefixes hash_prefixes = "abcdebbbbbccccc";
535 HashPrefix hash_prefix = "abcde";
536 EXPECT_TRUE(V4Store::HashPrefixMatches(hash_prefix, std::begin(hash_prefixes),
Nathan Parker 2016/07/19 23:01:31 nit: These many-short-tests could fit well into on
vakh (use Gerrit instead) 2016/07/20 00:24:52 IIRC, during my Noogler orientation this came up a
537 std::end(hash_prefixes)));
538 }
539
540 TEST_F(V4StoreTest, TestHashPrefixExistsInTheMiddle) {
541 HashPrefixes hash_prefixes = "abcdebbbbbccccc";
542 HashPrefix hash_prefix = "bbbbb";
543 EXPECT_TRUE(V4Store::HashPrefixMatches(hash_prefix, std::begin(hash_prefixes),
544 std::end(hash_prefixes)));
545 }
546
547 TEST_F(V4StoreTest, TestHashPrefixExistsAtTheEnd) {
548 HashPrefixes hash_prefixes = "abcdebbbbbccccc";
549 HashPrefix hash_prefix = "ccccc";
550 EXPECT_TRUE(V4Store::HashPrefixMatches(hash_prefix, std::begin(hash_prefixes),
551 std::end(hash_prefixes)));
552 }
553
554 TEST_F(V4StoreTest, TestHashPrefixExistsAtTheBeginningOfEven) {
555 HashPrefixes hash_prefixes = "abcdebbbbb";
556 HashPrefix hash_prefix = "abcde";
557 EXPECT_TRUE(V4Store::HashPrefixMatches(hash_prefix, std::begin(hash_prefixes),
558 std::end(hash_prefixes)));
559 }
560
561 TEST_F(V4StoreTest, TestHashPrefixExistsAtTheEndOfEven) {
562 HashPrefixes hash_prefixes = "abcdebbbbb";
563 HashPrefix hash_prefix = "bbbbb";
564 EXPECT_TRUE(V4Store::HashPrefixMatches(hash_prefix, std::begin(hash_prefixes),
565 std::end(hash_prefixes)));
566 }
567
568 TEST_F(V4StoreTest, TestHashPrefixDoesNotExistInConcatenatedList) {
569 HashPrefixes hash_prefixes = "abcdebbbbb";
570 HashPrefix hash_prefix = "bbbbc";
571 EXPECT_FALSE(V4Store::HashPrefixMatches(
572 hash_prefix, std::begin(hash_prefixes), std::end(hash_prefixes)));
573 }
574
575 TEST_F(V4StoreTest, TestFullHashExistsInMapWithSingleSize) {
576 V4Store store(task_runner_, store_path_);
577 store.hash_prefix_map_[32] =
578 "0111222233334444555566667777888811112222333344445555666677778888";
579 FullHash full_hash = "11112222333344445555666677778888";
580 EXPECT_EQ("11112222333344445555666677778888",
581 store.GetMatchingHashPrefix(full_hash));
582 }
583
584 TEST_F(V4StoreTest, TestFullHashExistsInMapWithDifferentSizes) {
585 V4Store store(task_runner_, store_path_);
586 store.hash_prefix_map_[4] = "22223333aaaa";
587 store.hash_prefix_map_[32] = "11112222333344445555666677778888";
588 FullHash full_hash = "11112222333344445555666677778888";
589 EXPECT_EQ("11112222333344445555666677778888",
590 store.GetMatchingHashPrefix(full_hash));
591 }
592
593 TEST_F(V4StoreTest, TestHashPrefixExistsInMapWithSingleSize) {
594 V4Store store(task_runner_, store_path_);
595 store.hash_prefix_map_[4] = "22223333aaaa";
596 FullHash full_hash = "22222222222222222222222222222222";
597 EXPECT_EQ("2222", store.GetMatchingHashPrefix(full_hash));
598 }
599
600 TEST_F(V4StoreTest, TestHashPrefixExistsInMapWithDifferentSizes) {
601 V4Store store(task_runner_, store_path_);
602 store.hash_prefix_map_[4] = "22223333aaaa";
603 store.hash_prefix_map_[5] = "11111hhhhh";
604 FullHash full_hash = "22222222222222222222222222222222";
605 EXPECT_EQ("2222", store.GetMatchingHashPrefix(full_hash));
606 }
607
608 TEST_F(V4StoreTest, TestHashPrefixDoesNotExistInMapWithDifferentSizes) {
609 V4Store store(task_runner_, store_path_);
610 store.hash_prefix_map_[4] = "3333aaaa";
611 store.hash_prefix_map_[5] = "11111hhhhh";
612 FullHash full_hash = "22222222222222222222222222222222";
613 EXPECT_TRUE(store.GetMatchingHashPrefix(full_hash).empty());
Nathan Parker 2016/07/19 23:01:31 How about a test that has no matching prefix? Que
vakh (use Gerrit instead) 2016/07/20 00:24:52 This test. The name has "DoesNot" which may be har
Nathan Parker 2016/07/20 00:36:47 ok, maybe we could add a comment in the code that
vakh (use Gerrit instead) 2016/07/20 06:12:04 Done.
614 }
615
533 } // namespace safe_browsing 616 } // namespace safe_browsing
OLDNEW
« components/safe_browsing_db/v4_store.cc ('K') | « 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