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

Unified Diff: chrome/browser/safe_browsing/prefix_set_unittest.cc

Issue 6591087: Additional validation code for PrefixSet. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Back out testing chg. Created 9 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/safe_browsing/prefix_set.cc ('k') | chrome/browser/safe_browsing/safe_browsing_database.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/safe_browsing/prefix_set_unittest.cc
diff --git a/chrome/browser/safe_browsing/prefix_set_unittest.cc b/chrome/browser/safe_browsing/prefix_set_unittest.cc
index 9328b77ef2dca54dd4604a3f128f2c21ce0a2f40..f7be5dad77b8307ac91797802484fe6ed159c59b 100644
--- a/chrome/browser/safe_browsing/prefix_set_unittest.cc
+++ b/chrome/browser/safe_browsing/prefix_set_unittest.cc
@@ -26,11 +26,19 @@ TEST(PrefixSetTest, Baseline) {
prefixes.push_back(GenPrefix());
}
+ std::sort(prefixes.begin(), prefixes.end());
safe_browsing::PrefixSet prefix_set(prefixes);
+ // Check that |GetPrefixes()| returns exactly the same set of
+ // prefixes as was passed in.
+ std::set<SBPrefix> check(prefixes.begin(), prefixes.end());
+ std::vector<SBPrefix> prefixes_copy;
+ prefix_set.GetPrefixes(&prefixes_copy);
+ EXPECT_EQ(prefixes_copy.size(), check.size());
+ EXPECT_TRUE(std::equal(check.begin(), check.end(), prefixes_copy.begin()));
+
// Check that the set flags all of the inputs, and also check items
// just above and below the inputs to make sure they aren't there.
- std::set<SBPrefix> check(prefixes.begin(), prefixes.end());
for (size_t i = 0; i < prefixes.size(); ++i) {
EXPECT_TRUE(prefix_set.Exists(prefixes[i]));
@@ -45,7 +53,7 @@ TEST(PrefixSetTest, Baseline) {
}
// Test that the empty set doesn't appear to have anything in it.
-TEST(PrefixSetTest, xEmpty) {
+TEST(PrefixSetTest, Empty) {
std::vector<SBPrefix> prefixes;
safe_browsing::PrefixSet prefix_set(prefixes);
for (size_t i = 0; i < 500; ++i) {
@@ -97,11 +105,18 @@ TEST(PrefixSetTest, EdgeCases) {
delta--;
}
- // Shuffle things up for giggles.
- std::random_shuffle(prefixes.begin(), prefixes.end());
-
+ std::sort(prefixes.begin(), prefixes.end());
safe_browsing::PrefixSet prefix_set(prefixes);
+ // Check that |GetPrefixes()| returns the same set of prefixes as
+ // was passed in.
+ std::vector<SBPrefix> prefixes_copy;
+ prefix_set.GetPrefixes(&prefixes_copy);
+ prefixes.erase(std::unique(prefixes.begin(), prefixes.end()), prefixes.end());
+ EXPECT_EQ(prefixes_copy.size(), prefixes.size());
+ EXPECT_TRUE(std::equal(prefixes.begin(), prefixes.end(),
+ prefixes_copy.begin()));
+
// Items before and after the set are not present, and don't crash.
EXPECT_FALSE(prefix_set.Exists(kVeryNegative - 100));
EXPECT_FALSE(prefix_set.Exists(kVeryPositive + 100));
« no previous file with comments | « chrome/browser/safe_browsing/prefix_set.cc ('k') | chrome/browser/safe_browsing/safe_browsing_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698