Chromium Code Reviews| 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 "ios/web/net/clients/crw_js_injection_network_client.h" | 5 #include "ios/web/net/clients/crw_js_injection_network_client.h" |
| 6 | 6 |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 test_data_.reset([[NSData dataWithContentsOfFile: | 104 test_data_.reset([[NSData dataWithContentsOfFile: |
| 105 base::SysUTF8ToNSString(file_path.value())] retain]); | 105 base::SysUTF8ToNSString(file_path.value())] retain]); |
| 106 ASSERT_TRUE(test_data_); | 106 ASSERT_TRUE(test_data_); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void TearDown() override { EXPECT_OCMOCK_VERIFY(mock_web_proxy_); } | 109 void TearDown() override { EXPECT_OCMOCK_VERIFY(mock_web_proxy_); } |
| 110 | 110 |
| 111 protected: | 111 protected: |
| 112 // Returns a CRNHTTPURLResponse. If |include_content_length|, header includes | 112 // Returns a CRNHTTPURLResponse. If |include_content_length|, header includes |
| 113 // Content-Length set to the length of test_data_. | 113 // Content-Length set to the length of test_data_. |
| 114 CRNHTTPURLResponse* CreateTestResponse(BOOL include_content_length); | 114 CRNHTTPURLResponse* CreateTestResponse(BOOL include_content_length) |
| 115 NS_RETURNS_RETAINED; | |
| 115 | 116 |
| 116 // Returns number of times an injected cr_web script tag is found in the | 117 // Returns number of times an injected cr_web script tag is found in the |
| 117 // underlying client's loaded data. Script tag should immediately follow | 118 // underlying client's loaded data. Script tag should immediately follow |
| 118 // the html start tag, if it exists, or should be injected before any header, | 119 // the html start tag, if it exists, or should be injected before any header, |
| 119 // if the first tag is something other than an html start tag. | 120 // if the first tag is something other than an html start tag. |
| 120 NSUInteger GetScriptTagCount() const; | 121 NSUInteger GetScriptTagCount() const; |
| 121 | 122 |
| 122 // Checks that if response forwarded to the underlying client has header field | 123 // Checks that if response forwarded to the underlying client has header field |
| 123 // Content-Length, the value matches the length of the data. | 124 // Content-Length, the value matches the length of the data. |
| 124 void ExpectConsistentContentLength(); | 125 void ExpectConsistentContentLength(); |
| 125 | 126 |
| 126 base::scoped_nsobject<CRWJSInjectionNetworkClient> js_injection_client_; | 127 base::scoped_nsobject<CRWJSInjectionNetworkClient> js_injection_client_; |
| 127 base::scoped_nsobject<UnderlyingClient> underlying_client_; | 128 base::scoped_nsobject<UnderlyingClient> underlying_client_; |
| 128 base::scoped_nsobject<OCMockObject> mock_web_proxy_; | 129 base::scoped_nsobject<OCMockObject> mock_web_proxy_; |
| 129 base::scoped_nsobject<NSData> test_data_; | 130 base::scoped_nsobject<NSData> test_data_; |
| 130 }; | 131 }; |
| 131 | 132 |
| 132 CRNHTTPURLResponse* CRWJSInjectionNetworkClientTest::CreateTestResponse( | 133 CRNHTTPURLResponse* CRWJSInjectionNetworkClientTest::CreateTestResponse( |
| 133 BOOL include_content_length) { | 134 BOOL include_content_length) NS_RETURNS_RETAINED { |
|
Eugene But (OOO till 7-30)
2016/08/16 16:45:48
Is it necessary to annotate in both interface and
stkhapugin
2016/08/16 16:51:49
Actually this annotation only makes a difference i
Eugene But (OOO till 7-30)
2016/08/16 17:02:31
If |NS_RETURNS_RETAINED| in implementation does no
| |
| 134 NSMutableDictionary *headers = [NSMutableDictionary | 135 NSMutableDictionary *headers = [NSMutableDictionary |
| 135 dictionaryWithDictionary:@{ @"Content-Type" : @"text/html" }]; | 136 dictionaryWithDictionary:@{ @"Content-Type" : @"text/html" }]; |
| 136 if (include_content_length) { | 137 if (include_content_length) { |
| 137 headers[@"Content-Length"] = @([test_data_ length]).stringValue; | 138 headers[@"Content-Length"] = @([test_data_ length]).stringValue; |
| 138 } | 139 } |
| 139 return [[CRNHTTPURLResponse alloc] | 140 return [[CRNHTTPURLResponse alloc] |
| 140 initWithURL:[NSURL URLWithString:@"http://testjsinjection.html"] | 141 initWithURL:[NSURL URLWithString:@"http://testjsinjection.html"] |
| 141 statusCode:200 | 142 statusCode:200 |
| 142 HTTPVersion:@"HTTP/1.1" | 143 HTTPVersion:@"HTTP/1.1" |
| 143 headerFields:headers]; | 144 headerFields:headers]; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 // Load data one byte at a time. | 280 // Load data one byte at a time. |
| 280 for (NSUInteger i = 0; i < [test_data_ length]; i++) { | 281 for (NSUInteger i = 0; i < [test_data_ length]; i++) { |
| 281 [js_injection_client_ didLoadData: | 282 [js_injection_client_ didLoadData: |
| 282 [test_data_ subdataWithRange:NSMakeRange(i, 1u)]]; | 283 [test_data_ subdataWithRange:NSMakeRange(i, 1u)]]; |
| 283 } | 284 } |
| 284 [js_injection_client_ didFinishLoading]; | 285 [js_injection_client_ didFinishLoading]; |
| 285 | 286 |
| 286 EXPECT_EQ(1u, GetScriptTagCount()); | 287 EXPECT_EQ(1u, GetScriptTagCount()); |
| 287 ExpectConsistentContentLength(); | 288 ExpectConsistentContentLength(); |
| 288 } | 289 } |
| OLD | NEW |