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

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

Issue 8417040: Measure how often downloaded executables match the download whitelist. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Address Brian's comment. Created 9 years, 1 month 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
OLDNEW
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 // Program to test the SafeBrowsing protocol parsing v2.1. 5 // Program to test the SafeBrowsing protocol parsing v2.1.
6 6
7 #include "base/stringprintf.h" 7 #include "base/stringprintf.h"
8 #include "chrome/browser/safe_browsing/protocol_parser.h" 8 #include "chrome/browser/safe_browsing/protocol_parser.h"
9 #include "chrome/browser/safe_browsing/safe_browsing_util.h" 9 #include "chrome/browser/safe_browsing/safe_browsing_util.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 EXPECT_EQ(chunks[0].hosts[0].host, 0); 917 EXPECT_EQ(chunks[0].hosts[0].host, 0);
918 SBEntry* entry = chunks[0].hosts[0].entry; 918 SBEntry* entry = chunks[0].hosts[0].entry;
919 EXPECT_TRUE(entry->IsSub()); 919 EXPECT_TRUE(entry->IsSub());
920 EXPECT_TRUE(entry->IsPrefix()); 920 EXPECT_TRUE(entry->IsPrefix());
921 EXPECT_EQ(entry->prefix_count(), 2); 921 EXPECT_EQ(entry->prefix_count(), 2);
922 EXPECT_EQ(entry->ChunkIdAtPrefix(0), 0x31313131); 922 EXPECT_EQ(entry->ChunkIdAtPrefix(0), 0x31313131);
923 EXPECT_EQ(entry->PrefixAt(0), 0x6d6d6d6d); 923 EXPECT_EQ(entry->PrefixAt(0), 0x6d6d6d6d);
924 EXPECT_EQ(entry->ChunkIdAtPrefix(1), 0x32323232); 924 EXPECT_EQ(entry->ChunkIdAtPrefix(1), 0x32323232);
925 EXPECT_EQ(entry->PrefixAt(1), 0x6e6e6e6e); 925 EXPECT_EQ(entry->PrefixAt(1), 0x6e6e6e6e);
926 } 926 }
927
928 TEST(SafeBrowsingProtocolParsingTest, TestAddDownloadWhitelistChunk) {
929 std::string add_chunk("a:1:32:32\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
930 "a:2:32:64\nyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
931 "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz");
932 // Run the parse.
933 SafeBrowsingProtocolParser parser;
934 bool re_key = false;
935 SBChunkList chunks;
936 bool result = parser.ParseChunk(
937 safe_browsing_util::kDownloadWhiteList,
938 add_chunk.data(),
939 static_cast<int>(add_chunk.length()),
940 "", "", &re_key, &chunks);
941 EXPECT_TRUE(result);
942 EXPECT_FALSE(re_key);
943 EXPECT_EQ(chunks.size(), 2U);
944 EXPECT_EQ(chunks[0].chunk_number, 1);
945 EXPECT_EQ(chunks[0].hosts.size(), 1U);
946 EXPECT_EQ(chunks[0].hosts[0].host, 0);
947 SBEntry* entry = chunks[0].hosts[0].entry;
948 EXPECT_TRUE(entry->IsAdd());
949 EXPECT_FALSE(entry->IsPrefix());
950 EXPECT_EQ(entry->prefix_count(), 1);
951 SBFullHash full;
952 memcpy(full.full_hash, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 32);
953 EXPECT_TRUE(entry->FullHashAt(0) == full);
954
955 EXPECT_EQ(chunks[1].chunk_number, 2);
956 EXPECT_EQ(chunks[1].hosts.size(), 1U);
957 EXPECT_EQ(chunks[1].hosts[0].host, 0);
958 entry = chunks[1].hosts[0].entry;
959 EXPECT_TRUE(entry->IsAdd());
960 EXPECT_FALSE(entry->IsPrefix());
961 EXPECT_EQ(entry->prefix_count(), 2);
962 memcpy(full.full_hash, "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy", 32);
963 EXPECT_TRUE(entry->FullHashAt(0) == full);
964 memcpy(full.full_hash, "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", 32);
965 EXPECT_TRUE(entry->FullHashAt(1) == full);
966 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/protocol_parser.cc ('k') | chrome/browser/safe_browsing/safe_browsing_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698