OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #import <Cronet/Cronet.h> | 5 #import <Cronet/Cronet.h> |
6 #import <Foundation/Foundation.h> | 6 #import <Foundation/Foundation.h> |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 | 189 |
190 TEST_F(HttpTest, SdchDisabledByDefault) { | 190 TEST_F(HttpTest, SdchDisabledByDefault) { |
191 NSURL* url = | 191 NSURL* url = |
192 net::NSURLWithGURL(GURL(TestServer::GetEchoHeaderURL("Accept-Encoding"))); | 192 net::NSURLWithGURL(GURL(TestServer::GetEchoHeaderURL("Accept-Encoding"))); |
193 NSURLSessionDataTask* task = [session_ dataTaskWithURL:url]; | 193 NSURLSessionDataTask* task = [session_ dataTaskWithURL:url]; |
194 StartDataTaskAndWaitForCompletion(task); | 194 StartDataTaskAndWaitForCompletion(task); |
195 EXPECT_EQ(nil, [delegate_ error]); | 195 EXPECT_EQ(nil, [delegate_ error]); |
196 EXPECT_FALSE([[delegate_ responseBody] containsString:@"sdch"]); | 196 EXPECT_FALSE([[delegate_ responseBody] containsString:@"sdch"]); |
197 } | 197 } |
198 | 198 |
| 199 // Verify that explictly setting Accept-Encoding request header to 'gzip,sdch" |
| 200 // is passed to the server and does not trigger any failures. This behavior may |
| 201 // In the future Cronet may not allow caller to set Accept-Encoding header and |
| 202 // could limit it to set of internally suported and enabled encodings, matching |
| 203 // behavior of Cronet on Android. |
| 204 TEST_F(HttpTest, AcceptEncodingSdchIsAllowed) { |
| 205 NSURL* url = |
| 206 net::NSURLWithGURL(GURL(TestServer::GetEchoHeaderURL("Accept-Encoding"))); |
| 207 NSMutableURLRequest* mutableRequest = |
| 208 [[NSURLRequest requestWithURL:url] mutableCopy]; |
| 209 [mutableRequest addValue:@"gzip,sdch" forHTTPHeaderField:@"Accept-Encoding"]; |
| 210 NSURLSessionDataTask* task = [session_ dataTaskWithRequest:mutableRequest]; |
| 211 StartDataTaskAndWaitForCompletion(task); |
| 212 EXPECT_EQ(nil, [delegate_ error]); |
| 213 EXPECT_TRUE([[delegate_ responseBody] containsString:@"gzip,sdch"]); |
| 214 } |
| 215 |
| 216 // Verify that explictly setting Accept-Encoding request header to 'foo,bar" |
| 217 // is passed to the server and does not trigger any failures. This behavior may |
| 218 // In the future Cronet may not allow caller to set Accept-Encoding header and |
| 219 // could limit it to set of internally suported and enabled encodings, matching |
| 220 // behavior of Cronet on Android. |
| 221 TEST_F(HttpTest, AcceptEncodingFooBarIsAllowed) { |
| 222 NSURL* url = |
| 223 net::NSURLWithGURL(GURL(TestServer::GetEchoHeaderURL("Accept-Encoding"))); |
| 224 NSMutableURLRequest* mutableRequest = |
| 225 [[NSURLRequest requestWithURL:url] mutableCopy]; |
| 226 [mutableRequest addValue:@"foo,bar" forHTTPHeaderField:@"Accept-Encoding"]; |
| 227 NSURLSessionDataTask* task = [session_ dataTaskWithRequest:mutableRequest]; |
| 228 StartDataTaskAndWaitForCompletion(task); |
| 229 EXPECT_EQ(nil, [delegate_ error]); |
| 230 EXPECT_TRUE([[delegate_ responseBody] containsString:@"foo,bar"]); |
| 231 } |
| 232 |
199 TEST_F(HttpTest, NSURLSessionAcceptLanguage) { | 233 TEST_F(HttpTest, NSURLSessionAcceptLanguage) { |
200 NSURL* url = | 234 NSURL* url = |
201 net::NSURLWithGURL(GURL(TestServer::GetEchoHeaderURL("Accept-Language"))); | 235 net::NSURLWithGURL(GURL(TestServer::GetEchoHeaderURL("Accept-Language"))); |
202 NSURLSessionDataTask* task = [session_ dataTaskWithURL:url]; | 236 NSURLSessionDataTask* task = [session_ dataTaskWithURL:url]; |
203 StartDataTaskAndWaitForCompletion(task); | 237 StartDataTaskAndWaitForCompletion(task); |
204 EXPECT_EQ(nil, [delegate_ error]); | 238 EXPECT_EQ(nil, [delegate_ error]); |
205 ASSERT_STREQ("en-US,en", [[delegate_ responseBody] UTF8String]); | 239 ASSERT_STREQ("en-US,en", [[delegate_ responseBody] UTF8String]); |
206 } | 240 } |
207 | 241 |
208 TEST_F(HttpTest, SetUserAgentIsExact) { | 242 TEST_F(HttpTest, SetUserAgentIsExact) { |
(...skipping 18 matching lines...) Expand all Loading... |
227 }]; | 261 }]; |
228 StartDataTaskAndWaitForCompletion(task); | 262 StartDataTaskAndWaitForCompletion(task); |
229 EXPECT_TRUE(block_used); | 263 EXPECT_TRUE(block_used); |
230 EXPECT_EQ(nil, [delegate_ error]); | 264 EXPECT_EQ(nil, [delegate_ error]); |
231 EXPECT_FALSE([[delegate_ responseBody] | 265 EXPECT_FALSE([[delegate_ responseBody] |
232 containsString:base::SysUTF8ToNSString(kUserAgent)]); | 266 containsString:base::SysUTF8ToNSString(kUserAgent)]); |
233 EXPECT_TRUE([[delegate_ responseBody] containsString:@"CFNetwork"]); | 267 EXPECT_TRUE([[delegate_ responseBody] containsString:@"CFNetwork"]); |
234 } | 268 } |
235 | 269 |
236 } // namespace cronet | 270 } // namespace cronet |
OLD | NEW |