Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Side by Side Diff: content/browser/loader/resource_loader_unittest.cc

Issue 2315443003: Stop sending serialized SSLStatus to the renderer. (Closed)
Patch Set: self review fix and merge fix Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "content/browser/loader/resource_loader.h" 5 #include "content/browser/loader/resource_loader.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/files/file.h" 13 #include "base/files/file.h"
14 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
15 #include "base/location.h" 15 #include "base/location.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
18 #include "base/memory/weak_ptr.h" 18 #include "base/memory/weak_ptr.h"
19 #include "base/run_loop.h" 19 #include "base/run_loop.h"
20 #include "base/single_thread_task_runner.h" 20 #include "base/single_thread_task_runner.h"
21 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
22 #include "content/browser/browser_thread_impl.h" 22 #include "content/browser/browser_thread_impl.h"
23 #include "content/browser/loader/redirect_to_file_resource_handler.h" 23 #include "content/browser/loader/redirect_to_file_resource_handler.h"
24 #include "content/browser/loader/resource_loader_delegate.h" 24 #include "content/browser/loader/resource_loader_delegate.h"
25 #include "content/common/ssl_status_serialization.h"
26 #include "content/public/browser/cert_store.h" 25 #include "content/public/browser/cert_store.h"
27 #include "content/public/browser/client_certificate_delegate.h" 26 #include "content/public/browser/client_certificate_delegate.h"
28 #include "content/public/browser/resource_request_info.h" 27 #include "content/public/browser/resource_request_info.h"
29 #include "content/public/common/content_paths.h" 28 #include "content/public/common/content_paths.h"
30 #include "content/public/common/resource_response.h" 29 #include "content/public/common/resource_response.h"
31 #include "content/public/common/resource_type.h" 30 #include "content/public/common/resource_type.h"
32 #include "content/public/test/mock_resource_context.h" 31 #include "content/public/test/mock_resource_context.h"
33 #include "content/public/test/test_browser_context.h" 32 #include "content/public/test/test_browser_context.h"
34 #include "content/public/test/test_browser_thread_bundle.h" 33 #include "content/public/test/test_browser_thread_bundle.h"
35 #include "content/public/test/test_renderer_host.h" 34 #include "content/public/test/test_renderer_host.h"
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 } 380 }
382 } 381 }
383 382
384 // Need another OnWillRead() call before seeing an OnReadCompleted(). 383 // Need another OnWillRead() call before seeing an OnReadCompleted().
385 received_on_will_read_ = false; 384 received_on_will_read_ = false;
386 385
387 return !cancel_on_read_completed_; 386 return !cancel_on_read_completed_;
388 } 387 }
389 388
390 void OnResponseCompleted(const net::URLRequestStatus& status, 389 void OnResponseCompleted(const net::URLRequestStatus& status,
391 const std::string& security_info,
392 bool* defer) override { 390 bool* defer) override {
393 EXPECT_FALSE(received_response_completed_); 391 EXPECT_FALSE(received_response_completed_);
394 if (status.is_success() && expect_reads_) 392 if (status.is_success() && expect_reads_)
395 EXPECT_TRUE(received_eof_); 393 EXPECT_TRUE(received_eof_);
396 394
397 received_response_completed_ = true; 395 received_response_completed_ = true;
398 status_ = status; 396 status_ = status;
399 response_completed_run_loop_.Quit(); 397 response_completed_run_loop_.Quit();
400 } 398 }
401 399
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 raw_ptr_resource_handler_->status().status()); 1102 raw_ptr_resource_handler_->status().status());
1105 EXPECT_EQ(test_data().size(), static_cast<size_t>( 1103 EXPECT_EQ(test_data().size(), static_cast<size_t>(
1106 raw_ptr_resource_handler_->total_bytes_downloaded())); 1104 raw_ptr_resource_handler_->total_bytes_downloaded()));
1107 1105
1108 // Check that the data was written to the file. 1106 // Check that the data was written to the file.
1109 std::string contents; 1107 std::string contents;
1110 ASSERT_TRUE(base::ReadFileToString(temp_path(), &contents)); 1108 ASSERT_TRUE(base::ReadFileToString(temp_path(), &contents));
1111 EXPECT_EQ(test_data(), contents); 1109 EXPECT_EQ(test_data(), contents);
1112 } 1110 }
1113 1111
1114 // Test that an HTTPS resource has the expected security info attached
1115 // to it.
1116 TEST_F(HTTPSSecurityInfoResourceLoaderTest, SecurityInfoOnHTTPSResource) {
1117 // Start the request and wait for it to finish.
1118 std::unique_ptr<net::URLRequest> request(
1119 resource_context_.GetRequestContext()->CreateRequest(
1120 test_https_url(), net::DEFAULT_PRIORITY, nullptr /* delegate */));
1121 SetUpResourceLoader(std::move(request), RESOURCE_TYPE_MAIN_FRAME, true);
1122
1123 // Send the request and wait until it completes.
1124 loader_->StartRequest();
1125 raw_ptr_resource_handler_->WaitForResponseComplete();
1126 ASSERT_EQ(net::URLRequestStatus::SUCCESS,
1127 raw_ptr_to_request_->status().status());
1128
1129 ResourceResponse* response = raw_ptr_resource_handler_->response();
1130 ASSERT_TRUE(response);
1131
1132 // Deserialize the security info from the response and check that it
1133 // is as expected.
1134 SSLStatus deserialized;
1135 ASSERT_TRUE(
1136 DeserializeSecurityInfo(response->head.security_info, &deserialized));
1137
1138 // Expect a BROKEN security style because the cert status has errors.
1139 EXPECT_EQ(content::SECURITY_STYLE_AUTHENTICATION_BROKEN,
1140 deserialized.security_style);
1141 scoped_refptr<net::X509Certificate> cert;
1142 ASSERT_TRUE(
1143 CertStore::GetInstance()->RetrieveCert(deserialized.cert_id, &cert));
1144 EXPECT_TRUE(cert->Equals(GetTestCert().get()));
1145
1146 EXPECT_EQ(kTestCertError, deserialized.cert_status);
1147 EXPECT_EQ(kTestConnectionStatus, deserialized.connection_status);
1148 EXPECT_EQ(kTestSecurityBits, deserialized.security_bits);
1149 }
1150
1151 // Test that an HTTPS redirect response has the expected security info
1152 // attached to it.
1153 TEST_F(HTTPSSecurityInfoResourceLoaderTest,
1154 SecurityInfoOnHTTPSRedirectResource) {
1155 // Start the request and wait for it to finish.
1156 std::unique_ptr<net::URLRequest> request(
1157 resource_context_.GetRequestContext()->CreateRequest(
1158 test_https_redirect_url(), net::DEFAULT_PRIORITY,
1159 nullptr /* delegate */));
1160 SetUpResourceLoader(std::move(request), RESOURCE_TYPE_MAIN_FRAME, true);
1161
1162 // Send the request and wait until it completes.
1163 loader_->StartRequest();
1164 raw_ptr_resource_handler_->WaitForResponseComplete();
1165 ASSERT_EQ(net::URLRequestStatus::SUCCESS,
1166 raw_ptr_to_request_->status().status());
1167 ASSERT_TRUE(raw_ptr_resource_handler_->received_request_redirected());
1168
1169 ResourceResponse* redirect_response =
1170 raw_ptr_resource_handler_->redirect_response();
1171 ASSERT_TRUE(redirect_response);
1172
1173 // Deserialize the security info from the redirect response and check
1174 // that it is as expected.
1175 SSLStatus deserialized;
1176 ASSERT_TRUE(DeserializeSecurityInfo(redirect_response->head.security_info,
1177 &deserialized));
1178
1179 // Expect a BROKEN security style because the cert status has errors.
1180 EXPECT_EQ(content::SECURITY_STYLE_AUTHENTICATION_BROKEN,
1181 deserialized.security_style);
1182 scoped_refptr<net::X509Certificate> cert;
1183 ASSERT_TRUE(
1184 CertStore::GetInstance()->RetrieveCert(deserialized.cert_id, &cert));
1185 EXPECT_TRUE(cert->Equals(GetTestCert().get()));
1186
1187 EXPECT_EQ(kTestCertError, deserialized.cert_status);
1188 EXPECT_EQ(kTestConnectionStatus, deserialized.connection_status);
1189 EXPECT_EQ(kTestSecurityBits, deserialized.security_bits);
1190 }
1191
1192 class EffectiveConnectionTypeResourceLoaderTest : public ResourceLoaderTest { 1112 class EffectiveConnectionTypeResourceLoaderTest : public ResourceLoaderTest {
1193 public: 1113 public:
1194 void VerifyEffectiveConnectionType( 1114 void VerifyEffectiveConnectionType(
1195 ResourceType resource_type, 1115 ResourceType resource_type,
1196 bool belongs_to_main_frame, 1116 bool belongs_to_main_frame,
1197 net::EffectiveConnectionType set_type, 1117 net::EffectiveConnectionType set_type,
1198 net::EffectiveConnectionType expected_type) { 1118 net::EffectiveConnectionType expected_type) {
1199 network_quality_estimator()->set_effective_connection_type(set_type); 1119 network_quality_estimator()->set_effective_connection_type(set_type);
1200 1120
1201 // Start the request and wait for it to finish. 1121 // Start the request and wait for it to finish.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 1160
1241 // Tests that the effective connection type is not set on non-main frame 1161 // Tests that the effective connection type is not set on non-main frame
1242 // requests. 1162 // requests.
1243 TEST_F(EffectiveConnectionTypeResourceLoaderTest, DoesNotBelongToMainFrame) { 1163 TEST_F(EffectiveConnectionTypeResourceLoaderTest, DoesNotBelongToMainFrame) {
1244 VerifyEffectiveConnectionType(RESOURCE_TYPE_OBJECT, false, 1164 VerifyEffectiveConnectionType(RESOURCE_TYPE_OBJECT, false,
1245 net::EFFECTIVE_CONNECTION_TYPE_3G, 1165 net::EFFECTIVE_CONNECTION_TYPE_3G,
1246 net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN); 1166 net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN);
1247 } 1167 }
1248 1168
1249 } // namespace content 1169 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/resource_loader.cc ('k') | content/browser/loader/stream_resource_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698