| 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 <limits.h> | 5 #include <limits.h> |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 //------------------------------------------------------------------------------ | 158 //------------------------------------------------------------------------------ |
| 159 | 159 |
| 160 TEST_F(SdchFilterTest, EmptyInputOk) { | 160 TEST_F(SdchFilterTest, EmptyInputOk) { |
| 161 std::vector<Filter::FilterType> filter_types; | 161 std::vector<Filter::FilterType> filter_types; |
| 162 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 162 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 163 char output_buffer[20]; | 163 char output_buffer[20]; |
| 164 std::string url_string("http://ignore.com"); | 164 std::string url_string("http://ignore.com"); |
| 165 filter_context()->SetURL(GURL(url_string)); | 165 filter_context()->SetURL(GURL(url_string)); |
| 166 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); | 166 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
| 167 | 167 |
| 168 // With no input data, try to read output. |
| 169 int output_bytes_or_buffer_size = sizeof(output_buffer); |
| 170 Filter::FilterStatus status = filter->ReadData(output_buffer, |
| 171 &output_bytes_or_buffer_size); |
| 172 |
| 173 EXPECT_EQ(0, output_bytes_or_buffer_size); |
| 174 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, status); |
| 175 } |
| 176 |
| 177 // Make sure that the filter context has everything that might be |
| 178 // nuked from it during URLRequest teardown before the SdchFilter |
| 179 // destructor. |
| 180 TEST_F(SdchFilterTest, SparseContextOk) { |
| 181 std::vector<Filter::FilterType> filter_types; |
| 182 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 183 char output_buffer[20]; |
| 184 std::string url_string("http://ignore.com"); |
| 185 filter_context()->SetURL(GURL(url_string)); |
| 186 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context())); |
| 168 | 187 |
| 169 // With no input data, try to read output. | 188 // With no input data, try to read output. |
| 170 int output_bytes_or_buffer_size = sizeof(output_buffer); | 189 int output_bytes_or_buffer_size = sizeof(output_buffer); |
| 171 Filter::FilterStatus status = filter->ReadData(output_buffer, | 190 Filter::FilterStatus status = filter->ReadData(output_buffer, |
| 172 &output_bytes_or_buffer_size); | 191 &output_bytes_or_buffer_size); |
| 173 | 192 |
| 174 EXPECT_EQ(0, output_bytes_or_buffer_size); | 193 EXPECT_EQ(0, output_bytes_or_buffer_size); |
| 175 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, status); | 194 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, status); |
| 195 |
| 196 // Partially tear down context. Anything that goes through request() |
| 197 // without checking it for null in the URLRequestJob::HttpFilterContext |
| 198 // implementation is suspect. Everything that does check it for null should |
| 199 // return null. This is to test for incorrectly relying on filter_context() |
| 200 // from the SdchFilter destructor. |
| 201 filter_context()->NukeUnstableInterfaces(); |
| 176 } | 202 } |
| 177 | 203 |
| 178 TEST_F(SdchFilterTest, PassThroughWhenTentative) { | 204 TEST_F(SdchFilterTest, PassThroughWhenTentative) { |
| 179 std::vector<Filter::FilterType> filter_types; | 205 std::vector<Filter::FilterType> filter_types; |
| 180 // Selective a tentative filter (which can fall back to pass through). | 206 // Selective a tentative filter (which can fall back to pass through). |
| 181 filter_types.push_back(Filter::FILTER_TYPE_GZIP_HELPING_SDCH); | 207 filter_types.push_back(Filter::FILTER_TYPE_GZIP_HELPING_SDCH); |
| 182 char output_buffer[20]; | 208 char output_buffer[20]; |
| 183 // Response code needs to be 200 to allow a pass through. | 209 // Response code needs to be 200 to allow a pass through. |
| 184 filter_context()->SetResponseCode(200); | 210 filter_context()->SetResponseCode(200); |
| 185 std::string url_string("http://ignore.com"); | 211 std::string url_string("http://ignore.com"); |
| (...skipping 947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1133 | 1159 |
| 1134 feed_block_size = 1; | 1160 feed_block_size = 1; |
| 1135 output_block_size = 1; | 1161 output_block_size = 1; |
| 1136 output.clear(); | 1162 output.clear(); |
| 1137 EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size, | 1163 EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size, |
| 1138 output_block_size, filter.get(), &output)); | 1164 output_block_size, filter.get(), &output)); |
| 1139 EXPECT_EQ(output, expanded_); | 1165 EXPECT_EQ(output, expanded_); |
| 1140 } | 1166 } |
| 1141 | 1167 |
| 1142 } // namespace net | 1168 } // namespace net |
| OLD | NEW |