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/safe_browsing/safe_browsing_store_file.h" | 5 #include "chrome/browser/safe_browsing/safe_browsing_store_file.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/scoped_file.h" | 9 #include "base/files/scoped_file.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 // The sub'ed prefix and hash are gone. | 889 // The sub'ed prefix and hash are gone. |
890 std::vector<SBPrefix> prefixes_result; | 890 std::vector<SBPrefix> prefixes_result; |
891 builder.GetPrefixSetNoHashes()->GetPrefixes(&prefixes_result); | 891 builder.GetPrefixSetNoHashes()->GetPrefixes(&prefixes_result); |
892 ASSERT_EQ(1U, prefixes_result.size()); | 892 ASSERT_EQ(1U, prefixes_result.size()); |
893 EXPECT_EQ(kHash1.prefix, prefixes_result[0]); | 893 EXPECT_EQ(kHash1.prefix, prefixes_result[0]); |
894 EXPECT_TRUE(add_full_hashes_result.empty()); | 894 EXPECT_TRUE(add_full_hashes_result.empty()); |
895 } | 895 } |
896 } | 896 } |
897 #endif | 897 #endif |
898 | 898 |
| 899 // Test that when the v8 golden file is updated, the add prefix injected from |
| 900 // the full hash is removed. All platforms generating v8 files are |
| 901 // little-endian, so there is no point to testing this transition if/when a |
| 902 // big-endian port is added. |
| 903 #if defined(ARCH_CPU_LITTLE_ENDIAN) |
| 904 TEST_F(SafeBrowsingStoreFileTest, KnockoutPrefixVolunteers) { |
| 905 store_.reset(); |
| 906 |
| 907 // Copy the golden file into temporary storage. The golden file contains: |
| 908 // - Add chunk kAddChunk1 containing kHash1.prefix and kHash2. |
| 909 // - Sub chunk kSubChunk1 containing kHash3. |
| 910 const char kBasename[] = "FileStoreVersion8"; |
| 911 base::FilePath golden_path; |
| 912 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &golden_path)); |
| 913 golden_path = golden_path.AppendASCII("SafeBrowsing"); |
| 914 golden_path = golden_path.AppendASCII(kBasename); |
| 915 ASSERT_TRUE(base::CopyFile(golden_path, filename_)); |
| 916 |
| 917 // Reset the store to make sure it re-reads the file. |
| 918 store_.reset(new SafeBrowsingStoreFile()); |
| 919 store_->Init(filename_, |
| 920 base::Bind(&SafeBrowsingStoreFileTest::OnCorruptionDetected, |
| 921 base::Unretained(this))); |
| 922 |
| 923 // Check that the expected prefixes and hashes are in place. |
| 924 { |
| 925 SBAddPrefixes add_prefixes; |
| 926 EXPECT_TRUE(store_->GetAddPrefixes(&add_prefixes)); |
| 927 ASSERT_EQ(2U, add_prefixes.size()); |
| 928 EXPECT_EQ(kAddChunk1, add_prefixes[0].chunk_id); |
| 929 EXPECT_EQ(kHash1.prefix, add_prefixes[0].prefix); |
| 930 EXPECT_EQ(kAddChunk1, add_prefixes[1].chunk_id); |
| 931 EXPECT_EQ(kHash2.prefix, add_prefixes[1].prefix); |
| 932 |
| 933 std::vector<SBAddFullHash> add_hashes; |
| 934 EXPECT_TRUE(store_->GetAddFullHashes(&add_hashes)); |
| 935 ASSERT_EQ(1U, add_hashes.size()); |
| 936 EXPECT_EQ(kAddChunk1, add_hashes[0].chunk_id); |
| 937 EXPECT_TRUE(SBFullHashEqual(kHash2, add_hashes[0].full_hash)); |
| 938 } |
| 939 |
| 940 // Update the store. |
| 941 { |
| 942 EXPECT_TRUE(store_->BeginUpdate()); |
| 943 |
| 944 safe_browsing::PrefixSetBuilder builder; |
| 945 std::vector<SBAddFullHash> add_full_hashes_result; |
| 946 ASSERT_TRUE(store_->FinishUpdate(&builder, &add_full_hashes_result)); |
| 947 } |
| 948 |
| 949 // Reset the store to make sure it re-reads the file. |
| 950 store_.reset(new SafeBrowsingStoreFile()); |
| 951 store_->Init(filename_, |
| 952 base::Bind(&SafeBrowsingStoreFileTest::OnCorruptionDetected, |
| 953 base::Unretained(this))); |
| 954 |
| 955 // |kHash2.prefix| should have dropped. |
| 956 { |
| 957 SBAddPrefixes add_prefixes; |
| 958 EXPECT_TRUE(store_->GetAddPrefixes(&add_prefixes)); |
| 959 ASSERT_EQ(1U, add_prefixes.size()); |
| 960 EXPECT_EQ(kAddChunk1, add_prefixes[0].chunk_id); |
| 961 EXPECT_EQ(kHash1.prefix, add_prefixes[0].prefix); |
| 962 |
| 963 std::vector<SBAddFullHash> add_hashes; |
| 964 EXPECT_TRUE(store_->GetAddFullHashes(&add_hashes)); |
| 965 ASSERT_EQ(1U, add_hashes.size()); |
| 966 EXPECT_EQ(kAddChunk1, add_hashes[0].chunk_id); |
| 967 EXPECT_TRUE(SBFullHashEqual(kHash2, add_hashes[0].full_hash)); |
| 968 } |
| 969 } |
| 970 #endif |
| 971 |
899 } // namespace safe_browsing | 972 } // namespace safe_browsing |
OLD | NEW |