summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-28 16:32:54 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-28 16:32:54 +0000
commita40e094fd17f39843beda15e3bc0a5efd1e815bd (patch)
treed321426d8009e362cfa271f0289d87ef1e4a41f5
parent0cec0d02b141debddef8ecdf7ea26233f7c7f4d2 (diff)
downloadchromium_src-a40e094fd17f39843beda15e3bc0a5efd1e815bd.zip
chromium_src-a40e094fd17f39843beda15e3bc0a5efd1e815bd.tar.gz
chromium_src-a40e094fd17f39843beda15e3bc0a5efd1e815bd.tar.bz2
Test for golden version-7 safe-browsing file.
Test that a golden version 7 file can be read and updated, in preparation for version 8. BUG=351448 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/211363005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260159 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_store_file_unittest.cc81
1 files changed, 81 insertions, 0 deletions
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 c29fa60..e56b974 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