diff --git a/Tests/AFHTTPRequestOperationTests.m b/Tests/AFHTTPRequestOperationTests.m index ebe3685..9c4582a 100644 --- a/Tests/AFHTTPRequestOperationTests.m +++ b/Tests/AFHTTPRequestOperationTests.m @@ -147,6 +147,8 @@ expect(numberOfRedirects).will.equal(5); } +#pragma mark - Pause + - (void)testThatOperationCanBePaused{ [Expecta setAsynchronousTestTimeout:3.0]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/delay/1" relativeToURL:self.baseURL]]; @@ -197,4 +199,38 @@ expect(blockResponseObject).willNot.beNil(); } +#pragma mark - Response String Encoding + +- (void) testThatTextStringEncodingIsISOLatin1WhenNoCharsetParameterIsProvided { + NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=text/plain" relativeToURL:self.baseURL]]; + AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; + [operation start]; + expect([operation isFinished]).will.beTruthy(); + expect(operation.responseStringEncoding).will.equal(NSISOLatin1StringEncoding); +} + +- (void) testThatTextStringEncodingIsShiftJISWhenShiftJISCharsetParameterIsProvided { + NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=text/plain;%20charset=%22Shift_JIS%22" relativeToURL:self.baseURL]]; + AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; + [operation start]; + expect([operation isFinished]).will.beTruthy(); + expect(operation.responseStringEncoding).will.equal(NSShiftJISStringEncoding); +} + +- (void) testThatTextStringEncodingIsUTF8WhenInvalidCharsetParameterIsProvided { + NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=text/plain;%20charset=%22invalid%22" relativeToURL:self.baseURL]]; + AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; + [operation start]; + expect([operation isFinished]).will.beTruthy(); + expect(operation.responseStringEncoding).will.equal(NSUTF8StringEncoding); +} + +- (void) testThatTextStringEncodingIsUTF8WhenUTF8CharsetParameterIsProvided { + NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=text/plain;%20charset=%22UTF-8%22" relativeToURL:self.baseURL]]; + AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; + [operation start]; + expect([operation isFinished]).will.beTruthy(); + expect(operation.responseStringEncoding).will.equal(NSUTF8StringEncoding); +} + @end