| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/request_tracker_impl.h" | 5 #include "ios/web/net/request_tracker_impl.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
| 9 #include "base/macros.h" |
| 9 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| 10 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 11 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
| 12 #include "ios/web/public/cert_policy.h" | 13 #include "ios/web/public/cert_policy.h" |
| 13 #include "ios/web/public/certificate_policy_cache.h" | 14 #include "ios/web/public/certificate_policy_cache.h" |
| 14 #include "ios/web/public/ssl_status.h" | 15 #include "ios/web/public/ssl_status.h" |
| 15 #include "ios/web/public/test/test_browser_state.h" | 16 #include "ios/web/public/test/test_browser_state.h" |
| 16 #include "ios/web/public/test/test_web_thread.h" | 17 #include "ios/web/public/test/test_web_thread.h" |
| 17 #include "net/cert/x509_certificate.h" | 18 #include "net/cert/x509_certificate.h" |
| 18 #include "net/http/http_response_headers.h" | 19 #include "net/http/http_response_headers.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 // Nothing yet. | 115 // Nothing yet. |
| 115 } | 116 } |
| 116 | 117 |
| 117 @end | 118 @end |
| 118 | 119 |
| 119 namespace { | 120 namespace { |
| 120 | 121 |
| 121 // Used and incremented each time a tabId is created. | 122 // Used and incremented each time a tabId is created. |
| 122 int g_count = 0; | 123 int g_count = 0; |
| 123 | 124 |
| 125 // URLRequest::Delegate that does nothing. |
| 126 class DummyURLRequestDelegate : public net::URLRequest::Delegate { |
| 127 public: |
| 128 DummyURLRequestDelegate() {} |
| 129 ~DummyURLRequestDelegate() override {} |
| 130 |
| 131 void OnResponseStarted(net::URLRequest* request) override {} |
| 132 void OnReadCompleted(net::URLRequest* request, int bytes_read) override {} |
| 133 |
| 134 private: |
| 135 DISALLOW_COPY_AND_ASSIGN(DummyURLRequestDelegate); |
| 136 }; |
| 137 |
| 124 class RequestTrackerTest : public PlatformTest { | 138 class RequestTrackerTest : public PlatformTest { |
| 125 public: | 139 public: |
| 126 RequestTrackerTest() | 140 RequestTrackerTest() |
| 127 : loop_(base::MessageLoop::TYPE_IO), | 141 : loop_(base::MessageLoop::TYPE_IO), |
| 128 ui_thread_(web::WebThread::UI, &loop_), | 142 ui_thread_(web::WebThread::UI, &loop_), |
| 129 io_thread_(web::WebThread::IO, &loop_){}; | 143 io_thread_(web::WebThread::IO, &loop_){}; |
| 130 | 144 |
| 131 ~RequestTrackerTest() override {} | 145 ~RequestTrackerTest() override {} |
| 132 | 146 |
| 133 void SetUp() override { | 147 void SetUp() override { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 private: | 246 private: |
| 233 net::URLRequest* GetInternalRequest(size_t i, bool secure) { | 247 net::URLRequest* GetInternalRequest(size_t i, bool secure) { |
| 234 GURL url; | 248 GURL url; |
| 235 if (secure) | 249 if (secure) |
| 236 url = GetSecureURL(requests_.size()); | 250 url = GetSecureURL(requests_.size()); |
| 237 else | 251 else |
| 238 url = GetURL(requests_.size()); | 252 url = GetURL(requests_.size()); |
| 239 | 253 |
| 240 while (i >= requests_.size()) { | 254 while (i >= requests_.size()) { |
| 241 contexts_.push_back(new net::URLRequestContext()); | 255 contexts_.push_back(new net::URLRequestContext()); |
| 242 requests_.push_back(contexts_[i]->CreateRequest(url, | 256 requests_.push_back( |
| 243 net::DEFAULT_PRIORITY, | 257 contexts_[i] |
| 244 NULL).release()); | 258 ->CreateRequest(url, net::DEFAULT_PRIORITY, &request_delegate_) |
| 259 .release()); |
| 245 | 260 |
| 246 if (secure) { | 261 if (secure) { |
| 247 // Put a valid SSLInfo inside | 262 // Put a valid SSLInfo inside |
| 248 net::HttpResponseInfo* response = | 263 net::HttpResponseInfo* response = |
| 249 const_cast<net::HttpResponseInfo*>(&requests_[i]->response_info()); | 264 const_cast<net::HttpResponseInfo*>(&requests_[i]->response_info()); |
| 250 | 265 |
| 251 response->ssl_info.cert = new net::X509Certificate( | 266 response->ssl_info.cert = new net::X509Certificate( |
| 252 "subject", "issuer", | 267 "subject", "issuer", |
| 253 base::Time::Now() - base::TimeDelta::FromDays(2), | 268 base::Time::Now() - base::TimeDelta::FromDays(2), |
| 254 base::Time::Now() + base::TimeDelta::FromDays(2)); | 269 base::Time::Now() + base::TimeDelta::FromDays(2)); |
| 255 response->ssl_info.cert_status = 0; // No errors. | 270 response->ssl_info.cert_status = 0; // No errors. |
| 256 response->ssl_info.security_bits = 128; | 271 response->ssl_info.security_bits = 128; |
| 257 | 272 |
| 258 EXPECT_TRUE(requests_[i]->ssl_info().is_valid()); | 273 EXPECT_TRUE(requests_[i]->ssl_info().is_valid()); |
| 259 } | 274 } |
| 260 } | 275 } |
| 261 EXPECT_TRUE(!secure == !requests_[i]->url().SchemeIsCryptographic()); | 276 EXPECT_TRUE(!secure == !requests_[i]->url().SchemeIsCryptographic()); |
| 262 return requests_[i]; | 277 return requests_[i]; |
| 263 } | 278 } |
| 264 | 279 |
| 280 DummyURLRequestDelegate request_delegate_; |
| 281 |
| 265 DISALLOW_COPY_AND_ASSIGN(RequestTrackerTest); | 282 DISALLOW_COPY_AND_ASSIGN(RequestTrackerTest); |
| 266 }; | 283 }; |
| 267 | 284 |
| 268 TEST_F(RequestTrackerTest, OnePage) { | 285 TEST_F(RequestTrackerTest, OnePage) { |
| 269 // Start a request. | 286 // Start a request. |
| 270 tracker_->StartRequest(GetRequest(0)); | 287 tracker_->StartRequest(GetRequest(0)); |
| 271 // Start page load. | 288 // Start page load. |
| 272 TrimRequest(request_group_id_, GetURL(0)); | 289 TrimRequest(request_group_id_, GetURL(0)); |
| 273 EXPECT_NSEQ(nil, CheckActive()); | 290 EXPECT_NSEQ(nil, CheckActive()); |
| 274 | 291 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 base::Bind(&TwoStartsSSLCallback, | 506 base::Bind(&TwoStartsSSLCallback, |
| 490 &request_0_called)); | 507 &request_0_called)); |
| 491 tracker_->OnSSLCertificateError(GetSecureRequest(1), ssl_info, true, | 508 tracker_->OnSSLCertificateError(GetSecureRequest(1), ssl_info, true, |
| 492 base::Bind(&TwoStartsSSLCallback, | 509 base::Bind(&TwoStartsSSLCallback, |
| 493 &request_1_called)); | 510 &request_1_called)); |
| 494 EXPECT_TRUE(request_0_called); | 511 EXPECT_TRUE(request_0_called); |
| 495 EXPECT_TRUE(request_1_called); | 512 EXPECT_TRUE(request_1_called); |
| 496 } | 513 } |
| 497 | 514 |
| 498 } // namespace | 515 } // namespace |
| OLD | NEW |