Chromium Code Reviews| Index: content/browser/loader/resource_loader_unittest.cc |
| diff --git a/content/browser/loader/resource_loader_unittest.cc b/content/browser/loader/resource_loader_unittest.cc |
| index 5ffd0294c518bde315a779d50b442c68be292590..d8889a2109a5f4e0cec16d006f69369e09735e93 100644 |
| --- a/content/browser/loader/resource_loader_unittest.cc |
| +++ b/content/browser/loader/resource_loader_unittest.cc |
| @@ -589,19 +589,24 @@ class ResourceLoaderTest : public testing::Test, |
| // Replaces loader_ with a new one for |request|. |
| void SetUpResourceLoader(std::unique_ptr<net::URLRequest> request, |
| - bool is_main_frame) { |
| + bool is_main_frame_request, |
| + bool belongs_to_main_frame) { |
| raw_ptr_to_request_ = request.get(); |
| + // A request marked as a main frame request must also belong to a main |
| + // frame. |
| + ASSERT_TRUE(!is_main_frame_request || belongs_to_main_frame); |
| + |
| ResourceType resource_type = |
|
RyanSturm
2016/08/08 18:13:37
nit: Would it be better to pass in ResourceType in
tbansal1
2016/08/08 18:35:25
Not sure. May be we can change in future if there
tbansal1
2016/08/08 18:45:14
Done.
|
| - is_main_frame ? RESOURCE_TYPE_MAIN_FRAME : RESOURCE_TYPE_SUB_FRAME; |
| + is_main_frame_request ? RESOURCE_TYPE_MAIN_FRAME : RESOURCE_TYPE_OBJECT; |
|
RyanSturm
2016/08/08 18:16:45
#include "content/public/common/resource_type.h"
tbansal1
2016/08/08 18:35:25
Done.
|
| RenderFrameHost* rfh = web_contents_->GetMainFrame(); |
| ResourceRequestInfo::AllocateForTesting( |
| request.get(), resource_type, &resource_context_, |
| rfh->GetProcess()->GetID(), rfh->GetRenderViewHost()->GetRoutingID(), |
| - rfh->GetRoutingID(), is_main_frame, false /* parent_is_main_frame */, |
| - true /* allow_download */, false /* is_async */, |
| - false /* is_using_lofi_ */); |
| + rfh->GetRoutingID(), belongs_to_main_frame, |
| + false /* parent_is_main_frame */, true /* allow_download */, |
| + false /* is_async */, false /* is_using_lofi_ */); |
| std::unique_ptr<ResourceHandlerStub> resource_handler( |
| new ResourceHandlerStub(request.get())); |
| raw_ptr_resource_handler_ = resource_handler.get(); |
| @@ -623,7 +628,7 @@ class ResourceLoaderTest : public testing::Test, |
| std::unique_ptr<net::URLRequest> request( |
| resource_context_.GetRequestContext()->CreateRequest( |
| test_url(), net::DEFAULT_PRIORITY, nullptr /* delegate */)); |
| - SetUpResourceLoader(std::move(request), true); |
| + SetUpResourceLoader(std::move(request), true, true); |
| } |
| void TearDown() override { |
| @@ -1112,7 +1117,7 @@ TEST_F(HTTPSSecurityInfoResourceLoaderTest, SecurityInfoOnHTTPSResource) { |
| std::unique_ptr<net::URLRequest> request( |
| resource_context_.GetRequestContext()->CreateRequest( |
| test_https_url(), net::DEFAULT_PRIORITY, nullptr /* delegate */)); |
| - SetUpResourceLoader(std::move(request), true); |
| + SetUpResourceLoader(std::move(request), true, true); |
| // Send the request and wait until it completes. |
| loader_->StartRequest(); |
| @@ -1151,7 +1156,7 @@ TEST_F(HTTPSSecurityInfoResourceLoaderTest, |
| resource_context_.GetRequestContext()->CreateRequest( |
| test_https_redirect_url(), net::DEFAULT_PRIORITY, |
| nullptr /* delegate */)); |
| - SetUpResourceLoader(std::move(request), true); |
| + SetUpResourceLoader(std::move(request), true, true); |
| // Send the request and wait until it completes. |
| loader_->StartRequest(); |
| @@ -1186,7 +1191,8 @@ TEST_F(HTTPSSecurityInfoResourceLoaderTest, |
| class EffectiveConnectionTypeResourceLoaderTest : public ResourceLoaderTest { |
| public: |
| void VerifyEffectiveConnectionType( |
| - bool is_main_frame, |
| + bool is_main_frame_request, |
| + bool belongs_to_main_frame, |
| net::EffectiveConnectionType set_type, |
| net::EffectiveConnectionType expected_type) { |
| network_quality_estimator()->set_effective_connection_type(set_type); |
| @@ -1195,7 +1201,8 @@ class EffectiveConnectionTypeResourceLoaderTest : public ResourceLoaderTest { |
| std::unique_ptr<net::URLRequest> request( |
| resource_context_.GetRequestContext()->CreateRequest( |
| test_url(), net::DEFAULT_PRIORITY, nullptr /* delegate */)); |
| - SetUpResourceLoader(std::move(request), is_main_frame); |
| + SetUpResourceLoader(std::move(request), is_main_frame_request, |
| + belongs_to_main_frame); |
| // Send the request and wait until it completes. |
| loader_->StartRequest(); |
| @@ -1210,20 +1217,28 @@ class EffectiveConnectionTypeResourceLoaderTest : public ResourceLoaderTest { |
| // Tests that the effective connection type is set on main frame requests. |
| TEST_F(EffectiveConnectionTypeResourceLoaderTest, Slow2G) { |
| - VerifyEffectiveConnectionType(true, net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G, |
| + VerifyEffectiveConnectionType(true, true, |
| + net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G, |
| net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G); |
| } |
| // Tests that the effective connection type is set on main frame requests. |
| TEST_F(EffectiveConnectionTypeResourceLoaderTest, 3G) { |
| - VerifyEffectiveConnectionType(true, net::EFFECTIVE_CONNECTION_TYPE_3G, |
| + VerifyEffectiveConnectionType(true, true, net::EFFECTIVE_CONNECTION_TYPE_3G, |
| net::EFFECTIVE_CONNECTION_TYPE_3G); |
| } |
| +// Tests that the effective connection type is not set on requests that belong |
| +// to main frame. |
| +TEST_F(EffectiveConnectionTypeResourceLoaderTest, BelongsToMainFrame) { |
| + VerifyEffectiveConnectionType(false, true, net::EFFECTIVE_CONNECTION_TYPE_3G, |
| + net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN); |
| +} |
| + |
| // Tests that the effective connection type is not set on non-main frame |
| // requests. |
| -TEST_F(EffectiveConnectionTypeResourceLoaderTest, NotAMainFrame) { |
| - VerifyEffectiveConnectionType(false, net::EFFECTIVE_CONNECTION_TYPE_3G, |
| +TEST_F(EffectiveConnectionTypeResourceLoaderTest, DoesNotBelongToMainFrame) { |
| + VerifyEffectiveConnectionType(false, false, net::EFFECTIVE_CONNECTION_TYPE_3G, |
| net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN); |
| } |