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

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

Issue 7004007: iwyu: Include stringprintf.h where appropriate, part 2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix 2. Created 9 years, 7 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
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/string_util.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"
11 11
12 // Test parsing one add chunk. 12 // Test parsing one add chunk.
13 TEST(SafeBrowsingProtocolParsingTest, TestAddChunk) { 13 TEST(SafeBrowsingProtocolParsingTest, TestAddChunk) {
14 std::string add_chunk("a:1:4:35\naaaax1111\0032222333344447777\00288889999"); 14 std::string add_chunk("a:1:4:35\naaaax1111\0032222333344447777\00288889999");
15 add_chunk[13] = '\0'; 15 add_chunk[13] = '\0';
16 16
17 // Run the parse. 17 // Run the parse.
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 EXPECT_EQ(entry->prefix_count(), 2); 147 EXPECT_EQ(entry->prefix_count(), 2);
148 EXPECT_EQ(entry->PrefixAt(0), 0x70707070); 148 EXPECT_EQ(entry->PrefixAt(0), 0x70707070);
149 EXPECT_EQ(entry->PrefixAt(1), 0x67676767); 149 EXPECT_EQ(entry->PrefixAt(1), 0x67676767);
150 } 150 }
151 151
152 // Test parsing one add chunk where a hostkey spans several entries. 152 // Test parsing one add chunk where a hostkey spans several entries.
153 TEST(SafeBrowsingProtocolParsingTest, TestAddBigChunk) { 153 TEST(SafeBrowsingProtocolParsingTest, TestAddBigChunk) {
154 std::string add_chunk("a:1:4:1050\naaaaX"); 154 std::string add_chunk("a:1:4:1050\naaaaX");
155 add_chunk[add_chunk.size() - 1] |= 0xFF; 155 add_chunk[add_chunk.size() - 1] |= 0xFF;
156 for (int i = 0; i < 255; ++i) 156 for (int i = 0; i < 255; ++i)
157 add_chunk.append(StringPrintf("%04d", i)); 157 add_chunk.append(base::StringPrintf("%04d", i));
158 158
159 add_chunk.append("aaaa"); 159 add_chunk.append("aaaa");
160 add_chunk.push_back(5); 160 add_chunk.push_back(5);
161 for (int i = 0; i < 5; ++i) 161 for (int i = 0; i < 5; ++i)
162 add_chunk.append(StringPrintf("001%d", i)); 162 add_chunk.append(base::StringPrintf("001%d", i));
163 163
164 SafeBrowsingProtocolParser parser; 164 SafeBrowsingProtocolParser parser;
165 bool re_key = false; 165 bool re_key = false;
166 SBChunkList chunks; 166 SBChunkList chunks;
167 bool result = parser.ParseChunk( 167 bool result = parser.ParseChunk(
168 safe_browsing_util::kMalwareList, 168 safe_browsing_util::kMalwareList,
169 add_chunk.data(), 169 add_chunk.data(),
170 static_cast<int>(add_chunk.length()), 170 static_cast<int>(add_chunk.length()),
171 "", "", &re_key, &chunks); 171 "", "", &re_key, &chunks);
172 EXPECT_TRUE(result); 172 EXPECT_TRUE(result);
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 EXPECT_TRUE(entry->IsPrefix()); 866 EXPECT_TRUE(entry->IsPrefix());
867 EXPECT_EQ(entry->prefix_count(), 2); 867 EXPECT_EQ(entry->prefix_count(), 2);
868 EXPECT_EQ(entry->PrefixAt(0), 0x31313131); 868 EXPECT_EQ(entry->PrefixAt(0), 0x31313131);
869 EXPECT_EQ(entry->PrefixAt(1), 0x32323232); 869 EXPECT_EQ(entry->PrefixAt(1), 0x32323232);
870 } 870 }
871 871
872 // Test parsing one add chunk where a hostkey spans several entries. 872 // Test parsing one add chunk where a hostkey spans several entries.
873 TEST(SafeBrowsingProtocolParsingTest, TestAddBigBinHashChunk) { 873 TEST(SafeBrowsingProtocolParsingTest, TestAddBigBinHashChunk) {
874 std::string add_chunk("a:1:4:1028\n"); 874 std::string add_chunk("a:1:4:1028\n");
875 for (int i = 0; i < 257; ++i) 875 for (int i = 0; i < 257; ++i)
876 add_chunk.append(StringPrintf("%04d", i)); 876 add_chunk.append(base::StringPrintf("%04d", i));
877 877
878 SafeBrowsingProtocolParser parser; 878 SafeBrowsingProtocolParser parser;
879 bool re_key = false; 879 bool re_key = false;
880 SBChunkList chunks; 880 SBChunkList chunks;
881 bool result = parser.ParseChunk( 881 bool result = parser.ParseChunk(
882 safe_browsing_util::kBinHashList, 882 safe_browsing_util::kBinHashList,
883 add_chunk.data(), 883 add_chunk.data(),
884 static_cast<int>(add_chunk.length()), 884 static_cast<int>(add_chunk.length()),
885 "", "", &re_key, &chunks); 885 "", "", &re_key, &chunks);
886 EXPECT_TRUE(result); 886 EXPECT_TRUE(result);
(...skipping 30 matching lines...) Expand all
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 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/protocol_parser.cc ('k') | chrome/browser/safe_browsing/safe_browsing_blocking_page.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698