OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 8 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
9 #include "crypto/sha2.h" | 9 #include "crypto/sha2.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 &list_name)); | 309 &list_name)); |
310 EXPECT_EQ(list_name, std::string(safe_browsing_util::kPhishingList)); | 310 EXPECT_EQ(list_name, std::string(safe_browsing_util::kPhishingList)); |
311 EXPECT_EQ(safe_browsing_util::PHISH, | 311 EXPECT_EQ(safe_browsing_util::PHISH, |
312 safe_browsing_util::GetListId(list_name)); | 312 safe_browsing_util::GetListId(list_name)); |
313 | 313 |
314 EXPECT_TRUE(safe_browsing_util::GetListName(safe_browsing_util::BINURL, | 314 EXPECT_TRUE(safe_browsing_util::GetListName(safe_browsing_util::BINURL, |
315 &list_name)); | 315 &list_name)); |
316 EXPECT_EQ(list_name, std::string(safe_browsing_util::kBinUrlList)); | 316 EXPECT_EQ(list_name, std::string(safe_browsing_util::kBinUrlList)); |
317 EXPECT_EQ(safe_browsing_util::BINURL, | 317 EXPECT_EQ(safe_browsing_util::BINURL, |
318 safe_browsing_util::GetListId(list_name)); | 318 safe_browsing_util::GetListId(list_name)); |
319 | |
320 | |
321 EXPECT_TRUE(safe_browsing_util::GetListName(safe_browsing_util::BINHASH, | |
322 &list_name)); | |
323 EXPECT_EQ(list_name, std::string(safe_browsing_util::kBinHashList)); | |
324 EXPECT_EQ(safe_browsing_util::BINHASH, | |
325 safe_browsing_util::GetListId(list_name)); | |
326 } | 319 } |
327 | 320 |
328 // Since the ids are saved in file, we need to make sure they don't change. | 321 // Since the ids are saved in file, we need to make sure they don't change. |
329 // Since only the last bit of each id is saved in file together with | 322 // Since only the last bit of each id is saved in file together with |
330 // chunkids, this checks only last bit. | 323 // chunkids, this checks only last bit. |
331 TEST(SafeBrowsingUtilTest, ListIdVerification) { | 324 TEST(SafeBrowsingUtilTest, ListIdVerification) { |
332 EXPECT_EQ(0, safe_browsing_util::MALWARE % 2); | 325 EXPECT_EQ(0, safe_browsing_util::MALWARE % 2); |
333 EXPECT_EQ(1, safe_browsing_util::PHISH % 2); | 326 EXPECT_EQ(1, safe_browsing_util::PHISH % 2); |
334 EXPECT_EQ(0, safe_browsing_util::BINURL %2); | 327 EXPECT_EQ(0, safe_browsing_util::BINURL %2); |
335 EXPECT_EQ(1, safe_browsing_util::BINHASH % 2); | |
336 } | 328 } |
337 | 329 |
338 TEST(SafeBrowsingUtilTest, StringToSBFullHashAndSBFullHashToString) { | 330 TEST(SafeBrowsingUtilTest, StringToSBFullHashAndSBFullHashToString) { |
339 // 31 chars plus the last \0 as full_hash. | 331 // 31 chars plus the last \0 as full_hash. |
340 const std::string hash_in = "12345678902234567890323456789012"; | 332 const std::string hash_in = "12345678902234567890323456789012"; |
341 SBFullHash hash_out = safe_browsing_util::StringToSBFullHash(hash_in); | 333 SBFullHash hash_out = safe_browsing_util::StringToSBFullHash(hash_in); |
342 EXPECT_EQ(0x34333231, hash_out.prefix); | 334 EXPECT_EQ(0x34333231, hash_out.prefix); |
343 EXPECT_EQ(0, memcmp(hash_in.data(), hash_out.full_hash, sizeof(SBFullHash))); | 335 EXPECT_EQ(0, memcmp(hash_in.data(), hash_out.full_hash, sizeof(SBFullHash))); |
344 | 336 |
345 std::string hash_final = safe_browsing_util::SBFullHashToString(hash_out); | 337 std::string hash_final = safe_browsing_util::SBFullHashToString(hash_out); |
346 EXPECT_EQ(hash_in, hash_final); | 338 EXPECT_EQ(hash_in, hash_final); |
347 } | 339 } |
OLD | NEW |