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

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

Issue 1726403006: Switch Safe Browsing's metadata from string to struct. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix ParseJson in test Created 4 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 kDefaultMalwareList, 444 kDefaultMalwareList,
445 kDefaultPhishList)); 445 kDefaultPhishList));
446 EXPECT_TRUE(ParseGetHash(get_hash3.data(), get_hash3.length(), 446 EXPECT_TRUE(ParseGetHash(get_hash3.data(), get_hash3.length(),
447 &cache_lifetime, &full_hashes)); 447 &cache_lifetime, &full_hashes));
448 448
449 ASSERT_EQ(3U, full_hashes.size()); 449 ASSERT_EQ(3U, full_hashes.size());
450 EXPECT_EQ(memcmp(&full_hashes[0].hash, 450 EXPECT_EQ(memcmp(&full_hashes[0].hash,
451 "zzzzyyyyxxxxwwwwvvvvuuuuttttssss", 451 "zzzzyyyyxxxxwwwwvvvvuuuuttttssss",
452 sizeof(SBFullHash)), 0); 452 sizeof(SBFullHash)), 0);
453 EXPECT_EQ(MALWARE, full_hashes[0].list_id); 453 EXPECT_EQ(MALWARE, full_hashes[0].list_id);
454 EXPECT_EQ(std::string("ab"), full_hashes[0].metadata); 454 EXPECT_EQ(std::string("ab"), full_hashes[0].metadata.raw_metadata);
455 EXPECT_EQ(memcmp(&full_hashes[1].hash, 455 EXPECT_EQ(memcmp(&full_hashes[1].hash,
456 "00112233445566778899aabbccddeeff", 456 "00112233445566778899aabbccddeeff",
457 sizeof(SBFullHash)), 0); 457 sizeof(SBFullHash)), 0);
458 EXPECT_EQ(MALWARE, full_hashes[1].list_id); 458 EXPECT_EQ(MALWARE, full_hashes[1].list_id);
459 EXPECT_EQ(std::string("xy"), full_hashes[1].metadata); 459 EXPECT_EQ(std::string("xy"), full_hashes[1].metadata.raw_metadata);
460 EXPECT_EQ(memcmp(&full_hashes[2].hash, 460 EXPECT_EQ(memcmp(&full_hashes[2].hash,
461 "cafebeefcafebeefdeaddeaddeaddead", 461 "cafebeefcafebeefdeaddeaddeaddead",
462 sizeof(SBFullHash)), 0); 462 sizeof(SBFullHash)), 0);
463 EXPECT_EQ(PHISH, full_hashes[2].list_id); 463 EXPECT_EQ(PHISH, full_hashes[2].list_id);
464 EXPECT_EQ(std::string(), full_hashes[2].metadata); 464 EXPECT_EQ(std::string(), full_hashes[2].metadata.raw_metadata);
465 } 465 }
466 466
467 TEST(SafeBrowsingProtocolParsingTest, TestGetHashWithUnknownList) { 467 TEST(SafeBrowsingProtocolParsingTest, TestGetHashWithUnknownList) {
468 std::string hash_response(base::StringPrintf( 468 std::string hash_response(base::StringPrintf(
469 "45\n" 469 "45\n"
470 "%s:32:1\n" 470 "%s:32:1\n"
471 "12345678901234567890123456789012" 471 "12345678901234567890123456789012"
472 "googpub-phish-shavar:32:1\n" 472 "googpub-phish-shavar:32:1\n"
473 "09876543210987654321098765432109", 473 "09876543210987654321098765432109",
474 kDefaultPhishList)); 474 kDefaultPhishList));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 "%s:32:1\n" 512 "%s:32:1\n"
513 "0123456789hashhashhashhashhashha", 513 "0123456789hashhashhashhashhashha",
514 kDefaultMalwareList)); 514 kDefaultMalwareList));
515 EXPECT_TRUE(ParseGetHash(get_hash3.data(), get_hash3.length(), 515 EXPECT_TRUE(ParseGetHash(get_hash3.data(), get_hash3.length(),
516 &cache_lifetime, &full_hashes)); 516 &cache_lifetime, &full_hashes));
517 ASSERT_EQ(1U, full_hashes.size()); 517 ASSERT_EQ(1U, full_hashes.size());
518 EXPECT_EQ(memcmp(&full_hashes[0].hash, 518 EXPECT_EQ(memcmp(&full_hashes[0].hash,
519 "0123456789hashhashhashhashhashha", 519 "0123456789hashhashhashhashhashha",
520 sizeof(SBFullHash)), 0); 520 sizeof(SBFullHash)), 0);
521 EXPECT_EQ(MALWARE, full_hashes[0].list_id); 521 EXPECT_EQ(MALWARE, full_hashes[0].list_id);
522 EXPECT_EQ(std::string(), full_hashes[0].metadata); 522 EXPECT_EQ(std::string(), full_hashes[0].metadata.raw_metadata);
523 } 523 }
524 524
525 TEST(SafeBrowsingProtocolParsingTest, TestFormatHash) { 525 TEST(SafeBrowsingProtocolParsingTest, TestFormatHash) {
526 std::vector<SBPrefix> prefixes; 526 std::vector<SBPrefix> prefixes;
527 prefixes.push_back(0x34333231); 527 prefixes.push_back(0x34333231);
528 prefixes.push_back(0x64636261); 528 prefixes.push_back(0x64636261);
529 prefixes.push_back(0x73727170); 529 prefixes.push_back(0x73727170);
530 530
531 EXPECT_EQ("4:12\n1234abcdpqrs", FormatGetHash(prefixes)); 531 EXPECT_EQ("4:12\n1234abcdpqrs", FormatGetHash(prefixes));
532 } 532 }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 EXPECT_FALSE(chunks[0]->IsAdd()); 695 EXPECT_FALSE(chunks[0]->IsAdd());
696 EXPECT_TRUE(chunks[0]->IsSub()); 696 EXPECT_TRUE(chunks[0]->IsSub());
697 EXPECT_TRUE(chunks[2]->IsPrefix()); 697 EXPECT_TRUE(chunks[2]->IsPrefix());
698 EXPECT_FALSE(chunks[2]->IsFullHash()); 698 EXPECT_FALSE(chunks[2]->IsFullHash());
699 ASSERT_EQ(1U, chunks[2]->PrefixCount()); 699 ASSERT_EQ(1U, chunks[2]->PrefixCount());
700 EXPECT_EQ(0x70707070U, chunks[2]->PrefixAt(0)); // pppp 700 EXPECT_EQ(0x70707070U, chunks[2]->PrefixAt(0)); // pppp
701 EXPECT_EQ(11, chunks[2]->AddChunkNumberAt(0)); 701 EXPECT_EQ(11, chunks[2]->AddChunkNumberAt(0));
702 } 702 }
703 703
704 } // namespace safe_browsing 704 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/protocol_parser.cc ('k') | chrome/browser/safe_browsing/safe_browsing_service_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698