OLD | NEW |
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 Loading... |
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 } |
OLD | NEW |