| Index: chrome/browser/safe_browsing/safe_browsing_store_file_unittest.cc
|
| diff --git a/chrome/browser/safe_browsing/safe_browsing_store_file_unittest.cc b/chrome/browser/safe_browsing/safe_browsing_store_file_unittest.cc
|
| index c29fa60617421bec67c374b7872ecf0ebec16133..e56b97420a195e6ee40da4d19041cbcb93c21cd4 100644
|
| --- a/chrome/browser/safe_browsing/safe_browsing_store_file_unittest.cc
|
| +++ b/chrome/browser/safe_browsing/safe_browsing_store_file_unittest.cc
|
| @@ -9,6 +9,8 @@
|
| #include "base/files/scoped_file.h"
|
| #include "base/files/scoped_temp_dir.h"
|
| #include "base/md5.h"
|
| +#include "base/path_service.h"
|
| +#include "chrome/common/chrome_paths.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "testing/platform_test.h"
|
|
|
| @@ -759,4 +761,83 @@ TEST_F(SafeBrowsingStoreFileTest, Resharding) {
|
| EXPECT_EQ(0u, shard_stride);
|
| }
|
|
|
| +// Test that a golden v7 file can be read by the current code. All platforms
|
| +// generating v7 files are little-endian, so there is no point to testing this
|
| +// transition if/when a big-endian port is added.
|
| +#if defined(ARCH_CPU_LITTLE_ENDIAN)
|
| +TEST_F(SafeBrowsingStoreFileTest, Version7) {
|
| + store_.reset();
|
| +
|
| + // Copy the golden file into temporary storage. The golden file contains:
|
| + // - Add chunk kAddChunk1 containing kHash1.prefix and kHash2.
|
| + // - Sub chunk kSubChunk1 containing kHash3.
|
| + const char kBasename[] = "FileStoreVersion7";
|
| + base::FilePath golden_path;
|
| + ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &golden_path));
|
| + golden_path = golden_path.AppendASCII("SafeBrowsing");
|
| + golden_path = golden_path.AppendASCII(kBasename);
|
| + ASSERT_TRUE(base::CopyFile(golden_path, filename_));
|
| +
|
| + // Reset the store to make sure it re-reads the file.
|
| + store_.reset(new SafeBrowsingStoreFile());
|
| + store_->Init(filename_,
|
| + base::Bind(&SafeBrowsingStoreFileTest::OnCorruptionDetected,
|
| + base::Unretained(this)));
|
| +
|
| + // Check that the expected prefixes and hashes are in place.
|
| + SBAddPrefixes add_prefixes;
|
| + EXPECT_TRUE(store_->GetAddPrefixes(&add_prefixes));
|
| + ASSERT_EQ(2U, add_prefixes.size());
|
| + EXPECT_EQ(kAddChunk1, add_prefixes[0].chunk_id);
|
| + EXPECT_EQ(kHash1.prefix, add_prefixes[0].prefix);
|
| + EXPECT_EQ(kAddChunk1, add_prefixes[1].chunk_id);
|
| + EXPECT_EQ(kHash2.prefix, add_prefixes[1].prefix);
|
| +
|
| + std::vector<SBAddFullHash> add_hashes;
|
| + EXPECT_TRUE(store_->GetAddFullHashes(&add_hashes));
|
| + ASSERT_EQ(1U, add_hashes.size());
|
| + EXPECT_EQ(kAddChunk1, add_hashes[0].chunk_id);
|
| + EXPECT_TRUE(SBFullHashEqual(kHash2, add_hashes[0].full_hash));
|
| +
|
| + // Attempt an update to make sure things work end-to-end.
|
| + EXPECT_TRUE(store_->BeginUpdate());
|
| +
|
| + // Still has the chunks expected in the next update.
|
| + std::vector<int> chunks;
|
| + store_->GetAddChunks(&chunks);
|
| + ASSERT_EQ(1U, chunks.size());
|
| + EXPECT_EQ(kAddChunk1, chunks[0]);
|
| +
|
| + store_->GetSubChunks(&chunks);
|
| + ASSERT_EQ(1U, chunks.size());
|
| + EXPECT_EQ(kSubChunk1, chunks[0]);
|
| +
|
| + EXPECT_TRUE(store_->CheckAddChunk(kAddChunk1));
|
| + EXPECT_TRUE(store_->CheckSubChunk(kSubChunk1));
|
| +
|
| + // Sub chunk kAddChunk1 hash kHash2.
|
| + store_->SetSubChunk(kSubChunk2);
|
| + EXPECT_TRUE(store_->CheckSubChunk(kSubChunk1));
|
| + EXPECT_TRUE(store_->WriteSubPrefix(kSubChunk1, kAddChunk1, kHash2.prefix));
|
| + EXPECT_TRUE(store_->WriteSubHash(kSubChunk1, kAddChunk1, kHash2));
|
| + EXPECT_TRUE(store_->FinishChunk());
|
| +
|
| + {
|
| + std::vector<SBAddFullHash> pending_adds;
|
| + safe_browsing::PrefixSetBuilder builder;
|
| + std::vector<SBAddFullHash> add_full_hashes_result;
|
| + EXPECT_TRUE(store_->FinishUpdate(pending_adds,
|
| + &builder,
|
| + &add_full_hashes_result));
|
| +
|
| + // The sub'ed prefix and hash are gone.
|
| + std::vector<SBPrefix> prefixes_result;
|
| + builder.GetPrefixSet()->GetPrefixes(&prefixes_result);
|
| + ASSERT_EQ(1U, prefixes_result.size());
|
| + EXPECT_EQ(kHash1.prefix, prefixes_result[0]);
|
| + EXPECT_TRUE(add_full_hashes_result.empty());
|
| + }
|
| +}
|
| +#endif
|
| +
|
| } // namespace
|
|
|