| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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.h" | 5 #include "chrome/browser/safe_browsing/safe_browsing_store.h" |
| 6 #include "chrome/browser/safe_browsing/safe_browsing_store_unittest_helper.h" | 6 #include "chrome/browser/safe_browsing/safe_browsing_store_unittest_helper.h" |
| 7 | 7 |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 SBSubFullHash(9, 10, one))); | 105 SBSubFullHash(9, 10, one))); |
| 106 | 106 |
| 107 // Equal is not less-than. | 107 // Equal is not less-than. |
| 108 EXPECT_FALSE(SBAddPrefixHashLess(SBSubFullHash(12, 10, one), | 108 EXPECT_FALSE(SBAddPrefixHashLess(SBSubFullHash(12, 10, one), |
| 109 SBSubFullHash(9, 10, one))); | 109 SBSubFullHash(9, 10, one))); |
| 110 } | 110 } |
| 111 | 111 |
| 112 // SBProcessSubs does a lot of iteration, run through empty just to | 112 // SBProcessSubs does a lot of iteration, run through empty just to |
| 113 // make sure degenerate cases work. | 113 // make sure degenerate cases work. |
| 114 TEST(SafeBrowsingStoreTest, SBProcessSubsEmpty) { | 114 TEST(SafeBrowsingStoreTest, SBProcessSubsEmpty) { |
| 115 std::vector<SBAddPrefix> add_prefixes; | 115 SBAddPrefixes add_prefixes; |
| 116 std::vector<SBAddFullHash> add_hashes; | 116 std::vector<SBAddFullHash> add_hashes; |
| 117 std::vector<SBSubPrefix> sub_prefixes; | 117 std::vector<SBSubPrefix> sub_prefixes; |
| 118 std::vector<SBSubFullHash> sub_hashes; | 118 std::vector<SBSubFullHash> sub_hashes; |
| 119 | 119 |
| 120 const base::hash_set<int32> no_deletions; | 120 const base::hash_set<int32> no_deletions; |
| 121 SBProcessSubs(&add_prefixes, &sub_prefixes, &add_hashes, &sub_hashes, | 121 SBProcessSubs(&add_prefixes, &sub_prefixes, &add_hashes, &sub_hashes, |
| 122 no_deletions, no_deletions); | 122 no_deletions, no_deletions); |
| 123 EXPECT_TRUE(add_prefixes.empty()); | 123 EXPECT_TRUE(add_prefixes.empty()); |
| 124 EXPECT_TRUE(sub_prefixes.empty()); | 124 EXPECT_TRUE(sub_prefixes.empty()); |
| 125 EXPECT_TRUE(add_hashes.empty()); | 125 EXPECT_TRUE(add_hashes.empty()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 136 const int kSubChunk1 = 2; | 136 const int kSubChunk1 = 2; |
| 137 | 137 |
| 138 // Construct some full hashes which share prefix with another. | 138 // Construct some full hashes which share prefix with another. |
| 139 SBFullHash kHash1mod1 = kHash1; | 139 SBFullHash kHash1mod1 = kHash1; |
| 140 kHash1mod1.full_hash[sizeof(kHash1mod1.full_hash) - 1] ++; | 140 kHash1mod1.full_hash[sizeof(kHash1mod1.full_hash) - 1] ++; |
| 141 SBFullHash kHash1mod2 = kHash1mod1; | 141 SBFullHash kHash1mod2 = kHash1mod1; |
| 142 kHash1mod2.full_hash[sizeof(kHash1mod2.full_hash) - 1] ++; | 142 kHash1mod2.full_hash[sizeof(kHash1mod2.full_hash) - 1] ++; |
| 143 SBFullHash kHash1mod3 = kHash1mod2; | 143 SBFullHash kHash1mod3 = kHash1mod2; |
| 144 kHash1mod3.full_hash[sizeof(kHash1mod3.full_hash) - 1] ++; | 144 kHash1mod3.full_hash[sizeof(kHash1mod3.full_hash) - 1] ++; |
| 145 | 145 |
| 146 std::vector<SBAddPrefix> add_prefixes; | 146 SBAddPrefixes add_prefixes; |
| 147 std::vector<SBAddFullHash> add_hashes; | 147 std::vector<SBAddFullHash> add_hashes; |
| 148 std::vector<SBSubPrefix> sub_prefixes; | 148 std::vector<SBSubPrefix> sub_prefixes; |
| 149 std::vector<SBSubFullHash> sub_hashes; | 149 std::vector<SBSubFullHash> sub_hashes; |
| 150 | 150 |
| 151 // An add with prefix and a couple hashes, plus a sub for the prefix | 151 // An add with prefix and a couple hashes, plus a sub for the prefix |
| 152 // and a couple sub hashes. The sub should knock all of them out. | 152 // and a couple sub hashes. The sub should knock all of them out. |
| 153 add_prefixes.push_back(SBAddPrefix(kAddChunk1, kHash1.prefix)); | 153 add_prefixes.push_back(SBAddPrefix(kAddChunk1, kHash1.prefix)); |
| 154 add_hashes.push_back(SBAddFullHash(kAddChunk1, kNow, kHash1)); | 154 add_hashes.push_back(SBAddFullHash(kAddChunk1, kNow, kHash1)); |
| 155 add_hashes.push_back(SBAddFullHash(kAddChunk1, kNow, kHash1mod1)); | 155 add_hashes.push_back(SBAddFullHash(kAddChunk1, kNow, kHash1mod1)); |
| 156 sub_prefixes.push_back(SBSubPrefix(kSubChunk1, kAddChunk1, kHash1.prefix)); | 156 sub_prefixes.push_back(SBSubPrefix(kSubChunk1, kAddChunk1, kHash1.prefix)); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 const int kSubChunk1 = 2; | 199 const int kSubChunk1 = 2; |
| 200 | 200 |
| 201 // Construct some full hashes which share prefix with another. | 201 // Construct some full hashes which share prefix with another. |
| 202 SBFullHash kHash1mod1 = kHash1; | 202 SBFullHash kHash1mod1 = kHash1; |
| 203 kHash1mod1.full_hash[sizeof(kHash1mod1.full_hash) - 1] ++; | 203 kHash1mod1.full_hash[sizeof(kHash1mod1.full_hash) - 1] ++; |
| 204 SBFullHash kHash1mod2 = kHash1mod1; | 204 SBFullHash kHash1mod2 = kHash1mod1; |
| 205 kHash1mod2.full_hash[sizeof(kHash1mod2.full_hash) - 1] ++; | 205 kHash1mod2.full_hash[sizeof(kHash1mod2.full_hash) - 1] ++; |
| 206 SBFullHash kHash1mod3 = kHash1mod2; | 206 SBFullHash kHash1mod3 = kHash1mod2; |
| 207 kHash1mod3.full_hash[sizeof(kHash1mod3.full_hash) - 1] ++; | 207 kHash1mod3.full_hash[sizeof(kHash1mod3.full_hash) - 1] ++; |
| 208 | 208 |
| 209 std::vector<SBAddPrefix> add_prefixes; | 209 SBAddPrefixes add_prefixes; |
| 210 std::vector<SBAddFullHash> add_hashes; | 210 std::vector<SBAddFullHash> add_hashes; |
| 211 std::vector<SBSubPrefix> sub_prefixes; | 211 std::vector<SBSubPrefix> sub_prefixes; |
| 212 std::vector<SBSubFullHash> sub_hashes; | 212 std::vector<SBSubFullHash> sub_hashes; |
| 213 | 213 |
| 214 // An add with prefix and a couple hashes, plus a sub for the prefix | 214 // An add with prefix and a couple hashes, plus a sub for the prefix |
| 215 // and a couple sub hashes. The sub should knock all of them out. | 215 // and a couple sub hashes. The sub should knock all of them out. |
| 216 add_prefixes.push_back(SBAddPrefix(kAddChunk1, kHash1.prefix)); | 216 add_prefixes.push_back(SBAddPrefix(kAddChunk1, kHash1.prefix)); |
| 217 add_hashes.push_back(SBAddFullHash(kAddChunk1, kNow, kHash1)); | 217 add_hashes.push_back(SBAddFullHash(kAddChunk1, kNow, kHash1)); |
| 218 add_hashes.push_back(SBAddFullHash(kAddChunk1, kNow, kHash1mod1)); | 218 add_hashes.push_back(SBAddFullHash(kAddChunk1, kNow, kHash1mod1)); |
| 219 sub_prefixes.push_back(SBSubPrefix(kSubChunk1, kAddChunk1, kHash1.prefix)); | 219 sub_prefixes.push_back(SBSubPrefix(kSubChunk1, kAddChunk1, kHash1.prefix)); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 TEST(SafeBrowsingStoreTest, Y2K38) { | 261 TEST(SafeBrowsingStoreTest, Y2K38) { |
| 262 const base::Time now = base::Time::Now(); | 262 const base::Time now = base::Time::Now(); |
| 263 const base::Time future = now + base::TimeDelta::FromDays(3*365); | 263 const base::Time future = now + base::TimeDelta::FromDays(3*365); |
| 264 | 264 |
| 265 // TODO: Fix file format before 2035. | 265 // TODO: Fix file format before 2035. |
| 266 EXPECT_GT(static_cast<int32>(future.ToTimeT()), 0) | 266 EXPECT_GT(static_cast<int32>(future.ToTimeT()), 0) |
| 267 << " (int32)time_t is running out."; | 267 << " (int32)time_t is running out."; |
| 268 } | 268 } |
| 269 | 269 |
| 270 } // namespace | 270 } // namespace |
| OLD | NEW |