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

Unified Diff: components/subresource_filter/core/common/unindexed_ruleset_unittest.cc

Issue 2279803002: Fix UnindexedRulesetWriter finishing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add regression test. Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: components/subresource_filter/core/common/unindexed_ruleset_unittest.cc
diff --git a/components/subresource_filter/core/common/unindexed_ruleset_unittest.cc b/components/subresource_filter/core/common/unindexed_ruleset_unittest.cc
index 5c093b3aa25609c902a6cff839192c75ec88bd3c..89eb989b06d6b79cb98d47e6f066f50ec6b79f9e 100644
--- a/components/subresource_filter/core/common/unindexed_ruleset_unittest.cc
+++ b/components/subresource_filter/core/common/unindexed_ruleset_unittest.cc
@@ -140,6 +140,24 @@ TEST(UnindexedRulesetTest, EmptyRuleset) {
EXPECT_TRUE(IsRulesetValid(builder.ruleset_contents(), builder.url_rules()));
}
+// The following test addresses a bug, that the UnindexedRulesetWriter didn't
engedy 2016/08/26 15:43:17 Let's just call a spade a spade + phrasing suggest
pkalinnikov1 2016/08/26 16:29:47 Done.
+// trim the output coded stream on Finish, causing the output had some extra
+// uninitialized bytes at the end.
+TEST(UnindexedRulesetTest, EmptyRulesetRegression) {
+ size_t contents_size_after_finish = 0;
+ std::string contents;
+
+ {
+ google::protobuf::io::StringOutputStream output(&contents);
+ UnindexedRulesetWriter ruleset_writer(&output);
+ EXPECT_TRUE(ruleset_writer.Finish());
engedy 2016/08/26 15:43:17 Hang on, is this going to allocate a single byte o
pkalinnikov1 2016/08/26 16:29:47 No, the size of the contents will be 0. I could ad
+ contents_size_after_finish = contents.size();
+ }
+
+ // The |contents| shouldn't be resized after writer/stream destruction.
+ EXPECT_EQ(contents_size_after_finish, contents.size());
+}
+
TEST(UnindexedRulesetTest, OneUrlRule) {
UnindexedRulesetTestBuilder builder;
EXPECT_TRUE(builder.AddUrlRule(UrlPattern("example.com"),

Powered by Google App Engine
This is Rietveld 408576698