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

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

Issue 8018: Clean up filter and content encoding handling ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month 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.cc ('k') | net/base/gzip_filter_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "net/base/filter.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7
8 class FilterTest : public testing::Test {
9 };
10
11 TEST(FilterTest, ContentTypeId) {
12 // Check for basic translation of Content-Encoding, including case variations.
13 EXPECT_EQ(Filter::FILTER_TYPE_DEFLATE,
14 Filter::ConvertEncodingToType("deflate"));
15 EXPECT_EQ(Filter::FILTER_TYPE_DEFLATE,
16 Filter::ConvertEncodingToType("deflAte"));
17 EXPECT_EQ(Filter::FILTER_TYPE_GZIP,
18 Filter::ConvertEncodingToType("gzip"));
19 EXPECT_EQ(Filter::FILTER_TYPE_GZIP,
20 Filter::ConvertEncodingToType("GzIp"));
21 EXPECT_EQ(Filter::FILTER_TYPE_GZIP,
22 Filter::ConvertEncodingToType("x-gzip"));
23 EXPECT_EQ(Filter::FILTER_TYPE_GZIP,
24 Filter::ConvertEncodingToType("X-GzIp"));
25 EXPECT_EQ(Filter::FILTER_TYPE_BZIP2,
26 Filter::ConvertEncodingToType("bzip2"));
27 EXPECT_EQ(Filter::FILTER_TYPE_BZIP2,
28 Filter::ConvertEncodingToType("BZiP2"));
29 EXPECT_EQ(Filter::FILTER_TYPE_BZIP2,
30 Filter::ConvertEncodingToType("x-bzip2"));
31 EXPECT_EQ(Filter::FILTER_TYPE_BZIP2,
32 Filter::ConvertEncodingToType("X-BZiP2"));
33 EXPECT_EQ(Filter::FILTER_TYPE_SDCH,
34 Filter::ConvertEncodingToType("sdch"));
35 EXPECT_EQ(Filter::FILTER_TYPE_SDCH,
36 Filter::ConvertEncodingToType("sDcH"));
37 EXPECT_EQ(Filter::FILTER_TYPE_UNSUPPORTED,
38 Filter::ConvertEncodingToType("weird"));
39 EXPECT_EQ(Filter::FILTER_TYPE_UNSUPPORTED,
40 Filter::ConvertEncodingToType("strange"));
41 }
42
43 // Check various fixups that modify content encoding lists.
44 TEST(FilterTest, ApacheGzip) {
45 // 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");
48 const std::string kGzipMime2("application/gzip");
49 const std::string kGzipMime3("application/x-gunzip");
50 std::vector<Filter::FilterType> encoding_types;
51
52 // First show it removes the gzip, given any gzip style mime type.
53 encoding_types.clear();
54 encoding_types.push_back(Filter::FILTER_TYPE_GZIP);
55 Filter::FixupEncodingTypes(is_sdch_response, kGzipMime1, &encoding_types);
56 EXPECT_TRUE(encoding_types.empty());
57
58 encoding_types.clear();
59 encoding_types.push_back(Filter::FILTER_TYPE_GZIP);
60 Filter::FixupEncodingTypes(is_sdch_response, kGzipMime2, &encoding_types);
61 EXPECT_TRUE(encoding_types.empty());
62
63 encoding_types.clear();
64 encoding_types.push_back(Filter::FILTER_TYPE_GZIP);
65 Filter::FixupEncodingTypes(is_sdch_response, kGzipMime3, &encoding_types);
66 EXPECT_TRUE(encoding_types.empty());
67
68 // Check to be sure it doesn't remove everything when it has such a type.
69 encoding_types.clear();
70 encoding_types.push_back(Filter::FILTER_TYPE_SDCH);
71 Filter::FixupEncodingTypes(is_sdch_response, kGzipMime1, &encoding_types);
72 EXPECT_EQ(1, encoding_types.size());
73 EXPECT_EQ(Filter::FILTER_TYPE_SDCH, encoding_types.front());
74
75 // Check to be sure that gzip can survive with other mime types.
76 encoding_types.clear();
77 encoding_types.push_back(Filter::FILTER_TYPE_GZIP);
78 Filter::FixupEncodingTypes(is_sdch_response, "other/mime", &encoding_types);
79 EXPECT_EQ(1, encoding_types.size());
80 EXPECT_EQ(Filter::FILTER_TYPE_GZIP, encoding_types.front());
81 }
82
83 TEST(FilterTest, SdchEncoding) {
84 // Handle content encodings including SDCH.
85 const bool is_sdch_response = true;
86 const std::string kTextHtmlMime("text/html");
87 std::vector<Filter::FilterType> encoding_types;
88
89 // Check for most common encoding, and verify it survives unchanged.
90 encoding_types.clear();
91 encoding_types.push_back(Filter::FILTER_TYPE_SDCH);
92 encoding_types.push_back(Filter::FILTER_TYPE_GZIP);
93 Filter::FixupEncodingTypes(is_sdch_response, kTextHtmlMime, &encoding_types);
94 EXPECT_EQ(2, encoding_types.size());
95 EXPECT_EQ(Filter::FILTER_TYPE_SDCH, encoding_types[0]);
96 EXPECT_EQ(Filter::FILTER_TYPE_GZIP, encoding_types[1]);
97
98 // Unchanged even with other mime types.
99 encoding_types.clear();
100 encoding_types.push_back(Filter::FILTER_TYPE_SDCH);
101 encoding_types.push_back(Filter::FILTER_TYPE_GZIP);
102 Filter::FixupEncodingTypes(is_sdch_response, "other/type", &encoding_types);
103 EXPECT_EQ(2, encoding_types.size());
104 EXPECT_EQ(Filter::FILTER_TYPE_SDCH, encoding_types[0]);
105 EXPECT_EQ(Filter::FILTER_TYPE_GZIP, encoding_types[1]);
106
107 // Solo SDCH is extended to include optional gunzip.
108 encoding_types.clear();
109 encoding_types.push_back(Filter::FILTER_TYPE_SDCH);
110 Filter::FixupEncodingTypes(is_sdch_response, "other/type", &encoding_types);
111 EXPECT_EQ(2, encoding_types.size());
112 EXPECT_EQ(Filter::FILTER_TYPE_SDCH, encoding_types[0]);
113 EXPECT_EQ(Filter::FILTER_TYPE_GZIP_HELPING_SDCH, encoding_types[1]);
114 }
115
116 TEST(FilterTest, MissingSdchEncoding) {
117 // Handle interesting case where entire SDCH encoding assertion "got lost."
118 const bool is_sdch_response = true;
119 const std::string kTextHtmlMime("text/html");
120 std::vector<Filter::FilterType> encoding_types;
121
122 // Loss of encoding, but it was an SDCH response with html type.
123 encoding_types.clear();
124 Filter::FixupEncodingTypes(is_sdch_response, kTextHtmlMime, &encoding_types);
125 EXPECT_EQ(2, encoding_types.size());
126 EXPECT_EQ(Filter::FILTER_TYPE_SDCH, encoding_types[0]);
127 EXPECT_EQ(Filter::FILTER_TYPE_GZIP_HELPING_SDCH, encoding_types[1]);
128
129 // No encoding, but it was an SDCH response with non-html type.
130 encoding_types.clear();
131 Filter::FixupEncodingTypes(is_sdch_response, "other/mime", &encoding_types);
132 EXPECT_TRUE(encoding_types.empty());
133 }
OLDNEW
« no previous file with comments | « net/base/filter.cc ('k') | net/base/gzip_filter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698