Commit 91b55a34 authored by Takashi Toyoshima's avatar Takashi Toyoshima Committed by Commit Bot

OOR-CORS: Make ResourceDispatcherHostTest pass

ResourceDispatcherHostTest was modified to run with TestMode, but
I forgot to setup features for each param.

This patch puts right configurations and makes failed tests
pass with some modification around how to manage RunLoops.

Bug: 870173
Change-Id: I2b61774668ca5dd7ca2f587b68a9a8671c18fe2d
Reviewed-on: https://chromium-review.googlesource.com/1249462
Commit-Queue: Takashi Toyoshima <toyoshim@chromium.org>
Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595394}
parent bc0d5d56
...@@ -78,12 +78,14 @@ ...@@ -78,12 +78,14 @@
#include "net/url_request/url_request_simple_job.h" #include "net/url_request/url_request_simple_job.h"
#include "net/url_request/url_request_test_job.h" #include "net/url_request/url_request_test_job.h"
#include "net/url_request/url_request_test_util.h" #include "net/url_request/url_request_test_util.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/resource_request.h" #include "services/network/public/cpp/resource_request.h"
#include "services/network/resource_scheduler.h" #include "services/network/resource_scheduler.h"
#include "services/network/resource_scheduler_params_manager.h" #include "services/network/resource_scheduler_params_manager.h"
#include "services/network/test/test_url_loader_client.h" #include "services/network/test/test_url_loader_client.h"
#include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/blob/shareable_file_reference.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/page/page_visibility_state.mojom.h" #include "third_party/blink/public/mojom/page/page_visibility_state.mojom.h"
// TODO(eroman): Write unit tests for SafeBrowsing that exercise // TODO(eroman): Write unit tests for SafeBrowsing that exercise
...@@ -632,9 +634,8 @@ class ShareableFileReleaseWaiter { ...@@ -632,9 +634,8 @@ class ShareableFileReleaseWaiter {
}; };
enum class TestMode { enum class TestMode {
kOutOfBlinkCorsWithServicification, kWithoutOutOfBlinkCors,
kOutOfBlinkCorsWithoutServicification, kWithOutOfBlinkCors,
kWithoutOutOfBlinkCorsAndServicification,
}; };
class ResourceDispatcherHostTest : public testing::TestWithParam<TestMode> { class ResourceDispatcherHostTest : public testing::TestWithParam<TestMode> {
...@@ -651,6 +652,23 @@ class ResourceDispatcherHostTest : public testing::TestWithParam<TestMode> { ...@@ -651,6 +652,23 @@ class ResourceDispatcherHostTest : public testing::TestWithParam<TestMode> {
use_test_ssl_certificate_(false), use_test_ssl_certificate_(false),
send_data_received_acks_(false), send_data_received_acks_(false),
auto_advance_(false) { auto_advance_(false) {
switch (GetParam()) {
case TestMode::kWithoutOutOfBlinkCors:
scoped_feature_list_.InitWithFeatures(
// Enabled features
{},
// Disabled features
{network::features::kOutOfBlinkCORS});
break;
case TestMode::kWithOutOfBlinkCors:
scoped_feature_list_.InitWithFeatures(
// Enabled features
{network::features::kOutOfBlinkCORS,
blink::features::kServiceWorkerServicification},
// Disabled features
{});
break;
}
host_.SetLoaderDelegate(&loader_delegate_); host_.SetLoaderDelegate(&loader_delegate_);
browser_context_.reset(new TestBrowserContext()); browser_context_.reset(new TestBrowserContext());
BrowserContext::EnsureResourceContextInitialized(browser_context_.get()); BrowserContext::EnsureResourceContextInitialized(browser_context_.get());
...@@ -890,6 +908,7 @@ class ResourceDispatcherHostTest : public testing::TestWithParam<TestMode> { ...@@ -890,6 +908,7 @@ class ResourceDispatcherHostTest : public testing::TestWithParam<TestMode> {
RenderViewHostTestEnabler render_view_host_test_enabler_; RenderViewHostTestEnabler render_view_host_test_enabler_;
bool auto_advance_; bool auto_advance_;
scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_;
base::test::ScopedFeatureList scoped_feature_list_;
}; };
void ResourceDispatcherHostTest::MakeTestRequest( void ResourceDispatcherHostTest::MakeTestRequest(
...@@ -1074,6 +1093,7 @@ TEST_P(ResourceDispatcherHostTest, DetachedResourceTimesOut) { ...@@ -1074,6 +1093,7 @@ TEST_P(ResourceDispatcherHostTest, DetachedResourceTimesOut) {
loader = nullptr; loader = nullptr;
// From the renderer's perspective, the request was cancelled. // From the renderer's perspective, the request was cancelled.
content::RunAllTasksUntilIdle();
client.RunUntilComplete(); client.RunUntilComplete();
EXPECT_EQ(net::ERR_ABORTED, client.completion_status().error_code); EXPECT_EQ(net::ERR_ABORTED, client.completion_status().error_code);
...@@ -1118,8 +1138,8 @@ TEST_P(ResourceDispatcherHostTest, DeletedFilterDetached) { ...@@ -1118,8 +1138,8 @@ TEST_P(ResourceDispatcherHostTest, DeletedFilterDetached) {
DCHECK_EQ(filter_.get(), info_prefetch->requester_info()->filter()); DCHECK_EQ(filter_.get(), info_prefetch->requester_info()->filter());
filter_->OnChannelClosing(); filter_->OnChannelClosing();
client1.RunUntilComplete(); content::RunAllTasksUntilIdle();
EXPECT_EQ(net::ERR_ABORTED, client1.completion_status().error_code); DCHECK(IsAborted(client1));
// But it continues detached. // But it continues detached.
EXPECT_EQ(1, host_.pending_requests()); EXPECT_EQ(1, host_.pending_requests());
...@@ -1167,8 +1187,8 @@ TEST_P(ResourceDispatcherHostTest, DeletedFilterDetachedRedirect) { ...@@ -1167,8 +1187,8 @@ TEST_P(ResourceDispatcherHostTest, DeletedFilterDetachedRedirect) {
EXPECT_EQ(1u, url_request->url_chain().size()); EXPECT_EQ(1u, url_request->url_chain().size());
// From the renderer's perspective, the request was cancelled. // From the renderer's perspective, the request was cancelled.
client.RunUntilComplete(); content::RunAllTasksUntilIdle();
EXPECT_EQ(net::ERR_ABORTED, client.completion_status().error_code); DCHECK(IsAborted(client));
content::RunAllTasksUntilIdle(); content::RunAllTasksUntilIdle();
// Verify that a redirect was followed. // Verify that a redirect was followed.
...@@ -2524,19 +2544,12 @@ net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptResponse( ...@@ -2524,19 +2544,12 @@ net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptResponse(
return nullptr; return nullptr;
} }
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(WithoutOutOfBlinkCors,
OutOfBlinkCorsWithServicification, ResourceDispatcherHostTest,
ResourceDispatcherHostTest, ::testing::Values(TestMode::kWithoutOutOfBlinkCors));
::testing::Values(TestMode::kOutOfBlinkCorsWithServicification));
INSTANTIATE_TEST_CASE_P(
OutOfBlinkCorsWithoutServicification,
ResourceDispatcherHostTest,
::testing::Values(TestMode::kOutOfBlinkCorsWithoutServicification));
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(WithOutOfBlinkCors,
WithoutOutOfBlinkCorsAndServicification, ResourceDispatcherHostTest,
ResourceDispatcherHostTest, ::testing::Values(TestMode::kWithOutOfBlinkCors));
::testing::Values(TestMode::kWithoutOutOfBlinkCorsAndServicification));
} // namespace content } // namespace content
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment