summaryrefslogtreecommitdiffstats
path: root/chrome/browser/safe_browsing/protocol_parser_unittest.cc
diff options
context:
space:
mode:
authorpaulg@google.com <paulg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-09 21:31:57 +0000
committerpaulg@google.com <paulg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-09 21:31:57 +0000
commit445d4cc80e88320e4bd86068c100520c9025fc63 (patch)
tree3d4fc71e16627dbd23be957651d5bb412b4440cc /chrome/browser/safe_browsing/protocol_parser_unittest.cc
parent28f180ecca4fda508a0f7b6c512051012d2036df (diff)
downloadchromium_src-445d4cc80e88320e4bd86068c100520c9025fc63.zip
chromium_src-445d4cc80e88320e4bd86068c100520c9025fc63.tar.gz
chromium_src-445d4cc80e88320e4bd86068c100520c9025fc63.tar.bz2
Support zero size chunks in the current implementation.
This allows the SafeBrowsing servers to send us Add and Sub chunks with no content so that when we report our update status, the request size is decreased. Our update status request contains a list of all chunks that we have received from the service, and this can get fragmented over time. For example, the part of the request containing our phishing chunks might look like this: goog-phish-shavar:a:1,3,5,7,9,11,13,15,17 By sending zero size chunks for the chunk numbers missing from the above example, the report will now look like: goog-phish-shavar:a:1-17 Given the large number of chunks and the rate of chunk expiry, this change will reduce the client request size. BUG= http://code.google.com/p/chromium/issues/detail?id=3262 Review URL: http://codereview.chromium.org/6369 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3131 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/safe_browsing/protocol_parser_unittest.cc')
-rw-r--r--chrome/browser/safe_browsing/protocol_parser_unittest.cc100
1 files changed, 100 insertions, 0 deletions
diff --git a/chrome/browser/safe_browsing/protocol_parser_unittest.cc b/chrome/browser/safe_browsing/protocol_parser_unittest.cc
index f371b6b..b5799cd 100644
--- a/chrome/browser/safe_browsing/protocol_parser_unittest.cc
+++ b/chrome/browser/safe_browsing/protocol_parser_unittest.cc
@@ -551,6 +551,106 @@ TEST(SafeBrowsingProtocolParsingTest, TestReset) {
EXPECT_TRUE(reset);
}
+// The SafeBrowsing service will occasionally send zero length chunks so that
+// client requests will have longer contiguous chunk number ranges, and thus
+// reduce the request size.
+TEST(SafeBrowsingProtocolParsingTest, TestZeroSizeAddChunk) {
+ std::string add_chunk("a:1:4:0\n");
+ SafeBrowsingProtocolParser parser;
+ bool re_key = false;
+ std::deque<SBChunk> chunks;
+
+ bool result = parser.ParseChunk(add_chunk.data(),
+ static_cast<int>(add_chunk.length()),
+ "", "", &re_key, &chunks);
+ EXPECT_TRUE(result);
+ EXPECT_EQ(chunks.size(), static_cast<size_t>(1));
+ EXPECT_EQ(chunks[0].chunk_number, 1);
+ EXPECT_EQ(chunks[0].hosts.size(), static_cast<size_t>(0));
+
+ safe_browsing_util::FreeChunks(&chunks);
+
+ // Now test a zero size chunk in between normal chunks.
+ chunks.clear();
+ std::string add_chunks("a:1:4:18\n1234\001abcd5678\001wxyz"
+ "a:2:4:0\n"
+ "a:3:4:9\ncafe\001beef");
+ result = parser.ParseChunk(add_chunks.data(),
+ static_cast<int>(add_chunks.length()),
+ "", "", &re_key, &chunks);
+ EXPECT_TRUE(result);
+ EXPECT_EQ(chunks.size(), static_cast<size_t>(3));
+
+ // See that each chunk has the right content.
+ EXPECT_EQ(chunks[0].chunk_number, 1);
+ EXPECT_EQ(chunks[0].hosts.size(), static_cast<size_t>(2));
+ EXPECT_EQ(chunks[0].hosts[0].host, 0x34333231);
+ EXPECT_EQ(chunks[0].hosts[0].entry->PrefixAt(0), 0x64636261);
+ EXPECT_EQ(chunks[0].hosts[1].host, 0x38373635);
+ EXPECT_EQ(chunks[0].hosts[1].entry->PrefixAt(0), 0x7a797877);
+
+ EXPECT_EQ(chunks[1].chunk_number, 2);
+ EXPECT_EQ(chunks[1].hosts.size(), static_cast<size_t>(0));
+
+ EXPECT_EQ(chunks[2].chunk_number, 3);
+ EXPECT_EQ(chunks[2].hosts.size(), static_cast<size_t>(1));
+ EXPECT_EQ(chunks[2].hosts[0].host, 0x65666163);
+ EXPECT_EQ(chunks[2].hosts[0].entry->PrefixAt(0), 0x66656562);
+
+ safe_browsing_util::FreeChunks(&chunks);
+}
+
+// Test parsing a zero sized sub chunk.
+TEST(SafeBrowsingProtocolParsingTest, TestZeroSizeSubChunk) {
+ std::string sub_chunk("s:9:4:0\n");
+ SafeBrowsingProtocolParser parser;
+ bool re_key = false;
+ std::deque<SBChunk> chunks;
+
+ bool result = parser.ParseChunk(sub_chunk.data(),
+ static_cast<int>(sub_chunk.length()),
+ "", "", &re_key, &chunks);
+ EXPECT_TRUE(result);
+ EXPECT_EQ(chunks.size(), static_cast<size_t>(1));
+ EXPECT_EQ(chunks[0].chunk_number, 9);
+ EXPECT_EQ(chunks[0].hosts.size(), static_cast<size_t>(0));
+
+ safe_browsing_util::FreeChunks(&chunks);
+ chunks.clear();
+
+ // Test parsing a zero sized sub chunk mixed in with content carrying chunks.
+ std::string sub_chunks("s:1:4:9\nabcdxwxyz"
+ "s:2:4:0\n"
+ "s:3:4:26\nefgh\0011234pqrscafe\0015678lmno");
+ sub_chunks[12] = '\0';
+
+ result = parser.ParseChunk(sub_chunks.data(),
+ static_cast<int>(sub_chunks.length()),
+ "", "", &re_key, &chunks);
+ EXPECT_TRUE(result);
+
+ EXPECT_EQ(chunks[0].chunk_number, 1);
+ EXPECT_EQ(chunks[0].hosts.size(), static_cast<size_t>(1));
+ EXPECT_EQ(chunks[0].hosts[0].host, 0x64636261);
+ EXPECT_EQ(chunks[0].hosts[0].entry->prefix_count(), 0);
+
+ EXPECT_EQ(chunks[1].chunk_number, 2);
+ EXPECT_EQ(chunks[1].hosts.size(), static_cast<size_t>(0));
+
+ EXPECT_EQ(chunks[2].chunk_number, 3);
+ EXPECT_EQ(chunks[2].hosts.size(), static_cast<size_t>(2));
+ EXPECT_EQ(chunks[2].hosts[0].host, 0x68676665);
+ EXPECT_EQ(chunks[2].hosts[0].entry->prefix_count(), 1);
+ EXPECT_EQ(chunks[2].hosts[0].entry->PrefixAt(0), 0x73727170);
+ EXPECT_EQ(chunks[2].hosts[0].entry->ChunkIdAtPrefix(0), 0x31323334);
+ EXPECT_EQ(chunks[2].hosts[1].host, 0x65666163);
+ EXPECT_EQ(chunks[2].hosts[1].entry->prefix_count(), 1);
+ EXPECT_EQ(chunks[2].hosts[1].entry->PrefixAt(0), 0x6f6e6d6c);
+ EXPECT_EQ(chunks[2].hosts[1].entry->ChunkIdAtPrefix(0), 0x35363738);
+
+ safe_browsing_util::FreeChunks(&chunks);
+}
+
TEST(SafeBrowsingProtocolParsingTest, TestVerifyUpdateMac) {
SafeBrowsingProtocolParser parser;