OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/filter/filter.h" |
| 6 |
| 7 #include <utility> |
| 8 |
5 #include "base/macros.h" | 9 #include "base/macros.h" |
6 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
7 #include "net/filter/filter.h" | |
8 #include "net/filter/mock_filter_context.h" | 11 #include "net/filter/mock_filter_context.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
10 | 13 |
11 namespace net { | 14 namespace net { |
12 | 15 |
13 namespace { | 16 namespace { |
14 | 17 |
15 class PassThroughFilter : public Filter { | 18 class PassThroughFilter : public Filter { |
16 public: | 19 public: |
17 PassThroughFilter() : Filter(FILTER_TYPE_UNSUPPORTED) {} | 20 PassThroughFilter() : Filter(FILTER_TYPE_UNSUPPORTED) {} |
(...skipping 30 matching lines...) Expand all Loading... |
48 EXPECT_EQ(Filter::FILTER_TYPE_UNSUPPORTED, | 51 EXPECT_EQ(Filter::FILTER_TYPE_UNSUPPORTED, |
49 Filter::ConvertEncodingToType("strange")); | 52 Filter::ConvertEncodingToType("strange")); |
50 } | 53 } |
51 | 54 |
52 TEST(FilterTest, SdchEncoding) { | 55 TEST(FilterTest, SdchEncoding) { |
53 // Handle content encodings including SDCH. | 56 // Handle content encodings including SDCH. |
54 const std::string kTextHtmlMime("text/html"); | 57 const std::string kTextHtmlMime("text/html"); |
55 MockFilterContext filter_context; | 58 MockFilterContext filter_context; |
56 // Empty handle indicates to filter that SDCH is active. | 59 // Empty handle indicates to filter that SDCH is active. |
57 filter_context.SetSdchResponse( | 60 filter_context.SetSdchResponse( |
58 SdchManager::CreateEmptyDictionarySetForTesting().Pass()); | 61 SdchManager::CreateEmptyDictionarySetForTesting()); |
59 | 62 |
60 std::vector<Filter::FilterType> encoding_types; | 63 std::vector<Filter::FilterType> encoding_types; |
61 | 64 |
62 // Check for most common encoding, and verify it survives unchanged. | 65 // Check for most common encoding, and verify it survives unchanged. |
63 encoding_types.clear(); | 66 encoding_types.clear(); |
64 encoding_types.push_back(Filter::FILTER_TYPE_SDCH); | 67 encoding_types.push_back(Filter::FILTER_TYPE_SDCH); |
65 encoding_types.push_back(Filter::FILTER_TYPE_GZIP); | 68 encoding_types.push_back(Filter::FILTER_TYPE_GZIP); |
66 filter_context.SetMimeType(kTextHtmlMime); | 69 filter_context.SetMimeType(kTextHtmlMime); |
67 Filter::FixupEncodingTypes(filter_context, &encoding_types); | 70 Filter::FixupEncodingTypes(filter_context, &encoding_types); |
68 ASSERT_EQ(2U, encoding_types.size()); | 71 ASSERT_EQ(2U, encoding_types.size()); |
(...skipping 17 matching lines...) Expand all Loading... |
86 ASSERT_EQ(2U, encoding_types.size()); | 89 ASSERT_EQ(2U, encoding_types.size()); |
87 EXPECT_EQ(Filter::FILTER_TYPE_SDCH, encoding_types[0]); | 90 EXPECT_EQ(Filter::FILTER_TYPE_SDCH, encoding_types[0]); |
88 EXPECT_EQ(Filter::FILTER_TYPE_GZIP_HELPING_SDCH, encoding_types[1]); | 91 EXPECT_EQ(Filter::FILTER_TYPE_GZIP_HELPING_SDCH, encoding_types[1]); |
89 } | 92 } |
90 | 93 |
91 TEST(FilterTest, MissingSdchEncoding) { | 94 TEST(FilterTest, MissingSdchEncoding) { |
92 // Handle interesting case where entire SDCH encoding assertion "got lost." | 95 // Handle interesting case where entire SDCH encoding assertion "got lost." |
93 const std::string kTextHtmlMime("text/html"); | 96 const std::string kTextHtmlMime("text/html"); |
94 MockFilterContext filter_context; | 97 MockFilterContext filter_context; |
95 filter_context.SetSdchResponse( | 98 filter_context.SetSdchResponse( |
96 SdchManager::CreateEmptyDictionarySetForTesting().Pass()); | 99 SdchManager::CreateEmptyDictionarySetForTesting()); |
97 | 100 |
98 std::vector<Filter::FilterType> encoding_types; | 101 std::vector<Filter::FilterType> encoding_types; |
99 | 102 |
100 // Loss of encoding, but it was an SDCH response with html type. | 103 // Loss of encoding, but it was an SDCH response with html type. |
101 encoding_types.clear(); | 104 encoding_types.clear(); |
102 filter_context.SetMimeType(kTextHtmlMime); | 105 filter_context.SetMimeType(kTextHtmlMime); |
103 Filter::FixupEncodingTypes(filter_context, &encoding_types); | 106 Filter::FixupEncodingTypes(filter_context, &encoding_types); |
104 ASSERT_EQ(2U, encoding_types.size()); | 107 ASSERT_EQ(2U, encoding_types.size()); |
105 EXPECT_EQ(Filter::FILTER_TYPE_SDCH_POSSIBLE, encoding_types[0]); | 108 EXPECT_EQ(Filter::FILTER_TYPE_SDCH_POSSIBLE, encoding_types[0]); |
106 EXPECT_EQ(Filter::FILTER_TYPE_GZIP_HELPING_SDCH, encoding_types[1]); | 109 EXPECT_EQ(Filter::FILTER_TYPE_GZIP_HELPING_SDCH, encoding_types[1]); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 // Regression test for http://crbug.com/418975. | 150 // Regression test for http://crbug.com/418975. |
148 TEST(FilterTest, ThreeFilterChain) { | 151 TEST(FilterTest, ThreeFilterChain) { |
149 scoped_ptr<PassThroughFilter> filter1(new PassThroughFilter); | 152 scoped_ptr<PassThroughFilter> filter1(new PassThroughFilter); |
150 scoped_ptr<PassThroughFilter> filter2(new PassThroughFilter); | 153 scoped_ptr<PassThroughFilter> filter2(new PassThroughFilter); |
151 scoped_ptr<PassThroughFilter> filter3(new PassThroughFilter); | 154 scoped_ptr<PassThroughFilter> filter3(new PassThroughFilter); |
152 | 155 |
153 filter1->InitBuffer(32 * 1024); | 156 filter1->InitBuffer(32 * 1024); |
154 filter2->InitBuffer(32 * 1024); | 157 filter2->InitBuffer(32 * 1024); |
155 filter3->InitBuffer(32 * 1024); | 158 filter3->InitBuffer(32 * 1024); |
156 | 159 |
157 filter2->next_filter_ = filter3.Pass(); | 160 filter2->next_filter_ = std::move(filter3); |
158 filter1->next_filter_ = filter2.Pass(); | 161 filter1->next_filter_ = std::move(filter2); |
159 | 162 |
160 // Initialize the input array with a varying byte sequence. | 163 // Initialize the input array with a varying byte sequence. |
161 const size_t input_array_size = 64 * 1024; | 164 const size_t input_array_size = 64 * 1024; |
162 char input_array[input_array_size]; | 165 char input_array[input_array_size]; |
163 size_t read_array_index = 0; | 166 size_t read_array_index = 0; |
164 for (size_t i = 0; i < input_array_size; i++) { | 167 for (size_t i = 0; i < input_array_size; i++) { |
165 input_array[i] = i % 113; | 168 input_array[i] = i % 113; |
166 } | 169 } |
167 | 170 |
168 const size_t output_array_size = 4 * 1024; | 171 const size_t output_array_size = 4 * 1024; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 amount_to_copy); | 204 amount_to_copy); |
202 filter1->FlushStreamBuffer(amount_to_copy); | 205 filter1->FlushStreamBuffer(amount_to_copy); |
203 read_array_index += amount_to_copy; | 206 read_array_index += amount_to_copy; |
204 } while (true); | 207 } while (true); |
205 | 208 |
206 EXPECT_EQ(read_array_index, input_array_size); | 209 EXPECT_EQ(read_array_index, input_array_size); |
207 EXPECT_EQ(compare_array_index, input_array_size); | 210 EXPECT_EQ(compare_array_index, input_array_size); |
208 } | 211 } |
209 | 212 |
210 } // Namespace net | 213 } // Namespace net |
OLD | NEW |