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

Side by Side Diff: net/base/filter_unittest.cc

Issue 40319: Use filter context to track stats better in SDCH filtering (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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
« no previous file with comments | « net/base/filter_unittest.h ('k') | net/base/sdch_filter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "net/base/filter.h" 5 #include "net/base/filter.h"
6 #include "net/base/filter_unittest.h"
6 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
7 8
8 class FilterTest : public testing::Test { 9 class FilterTest : public testing::Test {
9 }; 10 };
10 11
11 TEST(FilterTest, ContentTypeId) { 12 TEST(FilterTest, ContentTypeId) {
12 // Check for basic translation of Content-Encoding, including case variations. 13 // Check for basic translation of Content-Encoding, including case variations.
13 EXPECT_EQ(Filter::FILTER_TYPE_DEFLATE, 14 EXPECT_EQ(Filter::FILTER_TYPE_DEFLATE,
14 Filter::ConvertEncodingToType("deflate")); 15 Filter::ConvertEncodingToType("deflate"));
15 EXPECT_EQ(Filter::FILTER_TYPE_DEFLATE, 16 EXPECT_EQ(Filter::FILTER_TYPE_DEFLATE,
(...skipping 19 matching lines...) Expand all
35 EXPECT_EQ(Filter::FILTER_TYPE_SDCH, 36 EXPECT_EQ(Filter::FILTER_TYPE_SDCH,
36 Filter::ConvertEncodingToType("sDcH")); 37 Filter::ConvertEncodingToType("sDcH"));
37 EXPECT_EQ(Filter::FILTER_TYPE_UNSUPPORTED, 38 EXPECT_EQ(Filter::FILTER_TYPE_UNSUPPORTED,
38 Filter::ConvertEncodingToType("weird")); 39 Filter::ConvertEncodingToType("weird"));
39 EXPECT_EQ(Filter::FILTER_TYPE_UNSUPPORTED, 40 EXPECT_EQ(Filter::FILTER_TYPE_UNSUPPORTED,
40 Filter::ConvertEncodingToType("strange")); 41 Filter::ConvertEncodingToType("strange"));
41 } 42 }
42 43
43 // Check various fixups that modify content encoding lists. 44 // Check various fixups that modify content encoding lists.
44 TEST(FilterTest, ApacheGzip) { 45 TEST(FilterTest, ApacheGzip) {
46 const int kInputBufferSize(100);
47 MockFilterContext filter_context(kInputBufferSize);
48 filter_context.SetSdchResponse(false);
49
45 // Check that redundant gzip mime type removes only solo gzip encoding. 50 // Check that redundant gzip mime type removes only solo gzip encoding.
46 const bool is_sdch_response = false;
47 const std::string kGzipMime1("application/x-gzip"); 51 const std::string kGzipMime1("application/x-gzip");
48 const std::string kGzipMime2("application/gzip"); 52 const std::string kGzipMime2("application/gzip");
49 const std::string kGzipMime3("application/x-gunzip"); 53 const std::string kGzipMime3("application/x-gunzip");
50 std::vector<Filter::FilterType> encoding_types; 54 std::vector<Filter::FilterType> encoding_types;
51 55
52 // First show it removes the gzip, given any gzip style mime type. 56 // First show it removes the gzip, given any gzip style mime type.
53 encoding_types.clear(); 57 encoding_types.clear();
54 encoding_types.push_back(Filter::FILTER_TYPE_GZIP); 58 encoding_types.push_back(Filter::FILTER_TYPE_GZIP);
55 Filter::FixupEncodingTypes(is_sdch_response, kGzipMime1, &encoding_types); 59 filter_context.SetMimeType(kGzipMime1);
60 Filter::FixupEncodingTypes(filter_context, &encoding_types);
56 EXPECT_TRUE(encoding_types.empty()); 61 EXPECT_TRUE(encoding_types.empty());
57 62
58 encoding_types.clear(); 63 encoding_types.clear();
59 encoding_types.push_back(Filter::FILTER_TYPE_GZIP); 64 encoding_types.push_back(Filter::FILTER_TYPE_GZIP);
60 Filter::FixupEncodingTypes(is_sdch_response, kGzipMime2, &encoding_types); 65 filter_context.SetMimeType(kGzipMime2);
66 Filter::FixupEncodingTypes(filter_context, &encoding_types);
61 EXPECT_TRUE(encoding_types.empty()); 67 EXPECT_TRUE(encoding_types.empty());
62 68
63 encoding_types.clear(); 69 encoding_types.clear();
64 encoding_types.push_back(Filter::FILTER_TYPE_GZIP); 70 encoding_types.push_back(Filter::FILTER_TYPE_GZIP);
65 Filter::FixupEncodingTypes(is_sdch_response, kGzipMime3, &encoding_types); 71 filter_context.SetMimeType(kGzipMime3);
72 Filter::FixupEncodingTypes(filter_context, &encoding_types);
66 EXPECT_TRUE(encoding_types.empty()); 73 EXPECT_TRUE(encoding_types.empty());
67 74
68 // Check to be sure it doesn't remove everything when it has such a type. 75 // Check to be sure it doesn't remove everything when it has such a type.
69 encoding_types.clear(); 76 encoding_types.clear();
70 encoding_types.push_back(Filter::FILTER_TYPE_SDCH); 77 encoding_types.push_back(Filter::FILTER_TYPE_SDCH);
71 Filter::FixupEncodingTypes(is_sdch_response, kGzipMime1, &encoding_types); 78 filter_context.SetMimeType(kGzipMime1);
79 Filter::FixupEncodingTypes(filter_context, &encoding_types);
72 EXPECT_EQ(1U, encoding_types.size()); 80 EXPECT_EQ(1U, encoding_types.size());
73 EXPECT_EQ(Filter::FILTER_TYPE_SDCH, encoding_types.front()); 81 EXPECT_EQ(Filter::FILTER_TYPE_SDCH, encoding_types.front());
74 82
75 // Check to be sure that gzip can survive with other mime types. 83 // Check to be sure that gzip can survive with other mime types.
76 encoding_types.clear(); 84 encoding_types.clear();
77 encoding_types.push_back(Filter::FILTER_TYPE_GZIP); 85 encoding_types.push_back(Filter::FILTER_TYPE_GZIP);
78 Filter::FixupEncodingTypes(is_sdch_response, "other/mime", &encoding_types); 86 filter_context.SetMimeType("other/mime");
87 Filter::FixupEncodingTypes(filter_context, &encoding_types);
79 EXPECT_EQ(1U, encoding_types.size()); 88 EXPECT_EQ(1U, encoding_types.size());
80 EXPECT_EQ(Filter::FILTER_TYPE_GZIP, encoding_types.front()); 89 EXPECT_EQ(Filter::FILTER_TYPE_GZIP, encoding_types.front());
81 } 90 }
82 91
83 TEST(FilterTest, SdchEncoding) { 92 TEST(FilterTest, SdchEncoding) {
84 // Handle content encodings including SDCH. 93 // Handle content encodings including SDCH.
85 const bool is_sdch_response = true;
86 const std::string kTextHtmlMime("text/html"); 94 const std::string kTextHtmlMime("text/html");
95 const int kInputBufferSize(100);
96 MockFilterContext filter_context(kInputBufferSize);
97 filter_context.SetSdchResponse(true);
98
87 std::vector<Filter::FilterType> encoding_types; 99 std::vector<Filter::FilterType> encoding_types;
88 100
89 // Check for most common encoding, and verify it survives unchanged. 101 // Check for most common encoding, and verify it survives unchanged.
90 encoding_types.clear(); 102 encoding_types.clear();
91 encoding_types.push_back(Filter::FILTER_TYPE_SDCH); 103 encoding_types.push_back(Filter::FILTER_TYPE_SDCH);
92 encoding_types.push_back(Filter::FILTER_TYPE_GZIP); 104 encoding_types.push_back(Filter::FILTER_TYPE_GZIP);
93 Filter::FixupEncodingTypes(is_sdch_response, kTextHtmlMime, &encoding_types); 105 filter_context.SetMimeType(kTextHtmlMime);
106 Filter::FixupEncodingTypes(filter_context, &encoding_types);
94 EXPECT_EQ(2U, encoding_types.size()); 107 EXPECT_EQ(2U, encoding_types.size());
95 EXPECT_EQ(Filter::FILTER_TYPE_SDCH, encoding_types[0]); 108 EXPECT_EQ(Filter::FILTER_TYPE_SDCH, encoding_types[0]);
96 EXPECT_EQ(Filter::FILTER_TYPE_GZIP, encoding_types[1]); 109 EXPECT_EQ(Filter::FILTER_TYPE_GZIP, encoding_types[1]);
97 110
98 // Unchanged even with other mime types. 111 // Unchanged even with other mime types.
99 encoding_types.clear(); 112 encoding_types.clear();
100 encoding_types.push_back(Filter::FILTER_TYPE_SDCH); 113 encoding_types.push_back(Filter::FILTER_TYPE_SDCH);
101 encoding_types.push_back(Filter::FILTER_TYPE_GZIP); 114 encoding_types.push_back(Filter::FILTER_TYPE_GZIP);
102 Filter::FixupEncodingTypes(is_sdch_response, "other/type", &encoding_types); 115 filter_context.SetMimeType("other/type");
116 Filter::FixupEncodingTypes(filter_context, &encoding_types);
103 EXPECT_EQ(2U, encoding_types.size()); 117 EXPECT_EQ(2U, encoding_types.size());
104 EXPECT_EQ(Filter::FILTER_TYPE_SDCH, encoding_types[0]); 118 EXPECT_EQ(Filter::FILTER_TYPE_SDCH, encoding_types[0]);
105 EXPECT_EQ(Filter::FILTER_TYPE_GZIP, encoding_types[1]); 119 EXPECT_EQ(Filter::FILTER_TYPE_GZIP, encoding_types[1]);
106 120
107 // Solo SDCH is extended to include optional gunzip. 121 // Solo SDCH is extended to include optional gunzip.
108 encoding_types.clear(); 122 encoding_types.clear();
109 encoding_types.push_back(Filter::FILTER_TYPE_SDCH); 123 encoding_types.push_back(Filter::FILTER_TYPE_SDCH);
110 Filter::FixupEncodingTypes(is_sdch_response, "other/type", &encoding_types); 124 Filter::FixupEncodingTypes(filter_context, &encoding_types);
111 EXPECT_EQ(2U, encoding_types.size()); 125 EXPECT_EQ(2U, encoding_types.size());
112 EXPECT_EQ(Filter::FILTER_TYPE_SDCH, encoding_types[0]); 126 EXPECT_EQ(Filter::FILTER_TYPE_SDCH, encoding_types[0]);
113 EXPECT_EQ(Filter::FILTER_TYPE_GZIP_HELPING_SDCH, encoding_types[1]); 127 EXPECT_EQ(Filter::FILTER_TYPE_GZIP_HELPING_SDCH, encoding_types[1]);
114 } 128 }
115 129
116 TEST(FilterTest, MissingSdchEncoding) { 130 TEST(FilterTest, MissingSdchEncoding) {
117 // Handle interesting case where entire SDCH encoding assertion "got lost." 131 // Handle interesting case where entire SDCH encoding assertion "got lost."
118 const bool is_sdch_response = true;
119 const std::string kTextHtmlMime("text/html"); 132 const std::string kTextHtmlMime("text/html");
133 const int kInputBufferSize(100);
134 MockFilterContext filter_context(kInputBufferSize);
135 filter_context.SetSdchResponse(true);
136
120 std::vector<Filter::FilterType> encoding_types; 137 std::vector<Filter::FilterType> encoding_types;
121 138
122 // Loss of encoding, but it was an SDCH response with html type. 139 // Loss of encoding, but it was an SDCH response with html type.
123 encoding_types.clear(); 140 encoding_types.clear();
124 Filter::FixupEncodingTypes(is_sdch_response, kTextHtmlMime, &encoding_types); 141 filter_context.SetMimeType(kTextHtmlMime);
142 Filter::FixupEncodingTypes(filter_context, &encoding_types);
125 EXPECT_EQ(2U, encoding_types.size()); 143 EXPECT_EQ(2U, encoding_types.size());
126 EXPECT_EQ(Filter::FILTER_TYPE_SDCH_POSSIBLE, encoding_types[0]); 144 EXPECT_EQ(Filter::FILTER_TYPE_SDCH_POSSIBLE, encoding_types[0]);
127 EXPECT_EQ(Filter::FILTER_TYPE_GZIP_HELPING_SDCH, encoding_types[1]); 145 EXPECT_EQ(Filter::FILTER_TYPE_GZIP_HELPING_SDCH, encoding_types[1]);
128 146
129 // Loss of encoding, but it was an SDCH response with a prefix that says it 147 // Loss of encoding, but it was an SDCH response with a prefix that says it
130 // was an html type. Note that it *should* be the case that a precise match 148 // was an html type. Note that it *should* be the case that a precise match
131 // with "text/html" we be collected by GetMimeType() and passed in, but we 149 // with "text/html" we be collected by GetMimeType() and passed in, but we
132 // coded the fixup defensively (scanning for a prefix of "text/html", so this 150 // coded the fixup defensively (scanning for a prefix of "text/html", so this
133 // is an example which could survive such confusion in the caller). 151 // is an example which could survive such confusion in the caller).
134 encoding_types.clear(); 152 encoding_types.clear();
135 Filter::FixupEncodingTypes(is_sdch_response, "text/html; charset=UTF-8", 153 filter_context.SetMimeType("text/html; charset=UTF-8");
136 &encoding_types); 154 Filter::FixupEncodingTypes(filter_context, &encoding_types);
137 EXPECT_EQ(2U, encoding_types.size()); 155 EXPECT_EQ(2U, encoding_types.size());
138 EXPECT_EQ(Filter::FILTER_TYPE_SDCH_POSSIBLE, encoding_types[0]); 156 EXPECT_EQ(Filter::FILTER_TYPE_SDCH_POSSIBLE, encoding_types[0]);
139 EXPECT_EQ(Filter::FILTER_TYPE_GZIP_HELPING_SDCH, encoding_types[1]); 157 EXPECT_EQ(Filter::FILTER_TYPE_GZIP_HELPING_SDCH, encoding_types[1]);
140 158
141 // No encoding, but it was an SDCH response with non-html type. 159 // No encoding, but it was an SDCH response with non-html type.
142 encoding_types.clear(); 160 encoding_types.clear();
143 Filter::FixupEncodingTypes(is_sdch_response, "other/mime", &encoding_types); 161 filter_context.SetMimeType("other/mime");
162 Filter::FixupEncodingTypes(filter_context, &encoding_types);
144 EXPECT_EQ(2U, encoding_types.size()); 163 EXPECT_EQ(2U, encoding_types.size());
145 EXPECT_EQ(Filter::FILTER_TYPE_SDCH_POSSIBLE, encoding_types[0]); 164 EXPECT_EQ(Filter::FILTER_TYPE_SDCH_POSSIBLE, encoding_types[0]);
146 EXPECT_EQ(Filter::FILTER_TYPE_GZIP_HELPING_SDCH, encoding_types[1]); 165 EXPECT_EQ(Filter::FILTER_TYPE_GZIP_HELPING_SDCH, encoding_types[1]);
147 } 166 }
OLDNEW
« no previous file with comments | « net/base/filter_unittest.h ('k') | net/base/sdch_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698