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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_util_unittest.cc

Issue 6805019: Move crypto files out of base, to a top level directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fixes comments by eroman Created 9 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_util.cc ('k') | chrome/browser/sync/util/nigori.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 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/sha2.h"
8 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "crypto/sha2.h"
9 #include "chrome/browser/safe_browsing/safe_browsing_util.h" 9 #include "chrome/browser/safe_browsing/safe_browsing_util.h"
10 #include "googleurl/src/gurl.h" 10 #include "googleurl/src/gurl.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace { 13 namespace {
14 14
15 bool VectorContains(const std::vector<std::string>& data, 15 bool VectorContains(const std::vector<std::string>& data,
16 const std::string& str) { 16 const std::string& str) {
17 return std::find(data.begin(), data.end(), str) != data.end(); 17 return std::find(data.begin(), data.end(), str) != data.end();
18 } 18 }
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 EXPECT_EQ(tests[i].expected_canonicalized_path, 276 EXPECT_EQ(tests[i].expected_canonicalized_path,
277 canonicalized_path); 277 canonicalized_path);
278 EXPECT_EQ(tests[i].expected_canonicalized_query, 278 EXPECT_EQ(tests[i].expected_canonicalized_query,
279 canonicalized_query); 279 canonicalized_query);
280 } 280 }
281 } 281 }
282 282
283 TEST(SafeBrowsingUtilTest, GetUrlHashIndex) { 283 TEST(SafeBrowsingUtilTest, GetUrlHashIndex) {
284 GURL url("http://www.evil.com/phish.html"); 284 GURL url("http://www.evil.com/phish.html");
285 SBFullHashResult full_hash; 285 SBFullHashResult full_hash;
286 base::SHA256HashString(url.host() + url.path(), 286 crypto::SHA256HashString(url.host() + url.path(),
287 &full_hash.hash, 287 &full_hash.hash,
288 sizeof(SBFullHash)); 288 sizeof(SBFullHash));
289 std::vector<SBFullHashResult> full_hashes; 289 std::vector<SBFullHashResult> full_hashes;
290 full_hashes.push_back(full_hash); 290 full_hashes.push_back(full_hash);
291 291
292 EXPECT_EQ(safe_browsing_util::GetUrlHashIndex(url, full_hashes), 0); 292 EXPECT_EQ(safe_browsing_util::GetUrlHashIndex(url, full_hashes), 0);
293 293
294 url = GURL("http://www.evil.com/okay_path.html"); 294 url = GURL("http://www.evil.com/okay_path.html");
295 EXPECT_EQ(safe_browsing_util::GetUrlHashIndex(url, full_hashes), -1); 295 EXPECT_EQ(safe_browsing_util::GetUrlHashIndex(url, full_hashes), -1);
296 } 296 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 // 31 chars plus the last \0 as full_hash. 339 // 31 chars plus the last \0 as full_hash.
340 const std::string hash_in = "12345678902234567890323456789012"; 340 const std::string hash_in = "12345678902234567890323456789012";
341 SBFullHash hash_out; 341 SBFullHash hash_out;
342 safe_browsing_util::StringToSBFullHash(hash_in, &hash_out); 342 safe_browsing_util::StringToSBFullHash(hash_in, &hash_out);
343 EXPECT_EQ(0x34333231, hash_out.prefix); 343 EXPECT_EQ(0x34333231, hash_out.prefix);
344 EXPECT_EQ(0, memcmp(hash_in.data(), hash_out.full_hash, sizeof(SBFullHash))); 344 EXPECT_EQ(0, memcmp(hash_in.data(), hash_out.full_hash, sizeof(SBFullHash)));
345 345
346 std::string hash_final = safe_browsing_util::SBFullHashToString(hash_out); 346 std::string hash_final = safe_browsing_util::SBFullHashToString(hash_out);
347 EXPECT_EQ(hash_in, hash_final); 347 EXPECT_EQ(hash_in, hash_final);
348 } 348 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_util.cc ('k') | chrome/browser/sync/util/nigori.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698