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

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

Issue 8873004: Fix safe-browsing sub parsing for download whitelist. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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 946 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 EXPECT_EQ(chunks[1].hosts[0].host, 0); 957 EXPECT_EQ(chunks[1].hosts[0].host, 0);
958 entry = chunks[1].hosts[0].entry; 958 entry = chunks[1].hosts[0].entry;
959 EXPECT_TRUE(entry->IsAdd()); 959 EXPECT_TRUE(entry->IsAdd());
960 EXPECT_FALSE(entry->IsPrefix()); 960 EXPECT_FALSE(entry->IsPrefix());
961 EXPECT_EQ(entry->prefix_count(), 2); 961 EXPECT_EQ(entry->prefix_count(), 2);
962 memcpy(full.full_hash, "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy", 32); 962 memcpy(full.full_hash, "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy", 32);
963 EXPECT_TRUE(entry->FullHashAt(0) == full); 963 EXPECT_TRUE(entry->FullHashAt(0) == full);
964 memcpy(full.full_hash, "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", 32); 964 memcpy(full.full_hash, "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", 32);
965 EXPECT_TRUE(entry->FullHashAt(1) == full); 965 EXPECT_TRUE(entry->FullHashAt(1) == full);
966 } 966 }
967
968 // Test parsing one sub chunk.
969 TEST(SafeBrowsingProtocolParsingTest, TestSubDownloadWhitelistChunk) {
970 std::string sub_chunk("s:1:32:36\n1111xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
971
972 // Run the parser.
973 SafeBrowsingProtocolParser parser;
974 bool re_key = false;
975 SBChunkList chunks;
976 bool result = parser.ParseChunk(
977 safe_browsing_util::kDownloadWhiteList,
978 sub_chunk.data(),
979 static_cast<int>(sub_chunk.length()),
980 "", "", &re_key, &chunks);
981 ASSERT_TRUE(result);
982 EXPECT_FALSE(re_key);
983 ASSERT_EQ(chunks.size(), 1U);
984 EXPECT_EQ(chunks[0].chunk_number, 1);
985 EXPECT_EQ(chunks[0].hosts.size(), 1U);
986
987 EXPECT_EQ(chunks[0].hosts[0].host, 0);
988 SBEntry* entry = chunks[0].hosts[0].entry;
989 EXPECT_TRUE(entry->IsSub());
990 ASSERT_FALSE(entry->IsPrefix());
991 ASSERT_EQ(entry->prefix_count(), 1);
992 EXPECT_EQ(entry->ChunkIdAtPrefix(0), 0x31313131);
993 SBFullHash full;
994 memcpy(full.full_hash, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 32);
995 EXPECT_TRUE(entry->FullHashAt(0) == full);
996 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698