Commit 8e3170c0 authored by Eric Roman's avatar Eric Roman Committed by Commit Bot

Fix the reporting-api and network-error-logging Web Platform Tests when Network Service is enabled.

The reason they failed was they rely on the following behaviors from "content_shell --run-web-tests":

  (1) Sending reports is allowed for all origins, irrespective of the BACKGROUND_SYNC permission.
  (2) The timeout for sending reports is 100ms instead of the default (1 minute)

This CL makes "content_shell --run-web-tests" with Network Service enabled behave the same way.

Bug: 910212
Change-Id: I0756a9605b2aa37647d2c049eb2868499f07e65e
Reviewed-on: https://chromium-review.googlesource.com/c/1387449
Commit-Queue: Eric Roman <eroman@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#619826}
parent 025aa11e
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "content/public/browser/client_certificate_delegate.h" #include "content/public/browser/client_certificate_delegate.h"
#include "content/public/browser/login_delegate.h" #include "content/public/browser/login_delegate.h"
#include "content/public/browser/network_service_instance.h"
#include "content/public/browser/page_navigator.h" #include "content/public/browser/page_navigator.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/browser/resource_dispatcher_host.h" #include "content/public/browser/resource_dispatcher_host.h"
...@@ -41,11 +42,14 @@ ...@@ -41,11 +42,14 @@
#include "content/shell/browser/shell_web_contents_view_delegate_creator.h" #include "content/shell/browser/shell_web_contents_view_delegate_creator.h"
#include "content/shell/common/shell_messages.h" #include "content/shell/common/shell_messages.h"
#include "content/shell/common/shell_switches.h" #include "content/shell/common/shell_switches.h"
#include "content/shell/common/web_test/web_test_switches.h"
#include "content/shell/grit/shell_resources.h" #include "content/shell/grit/shell_resources.h"
#include "media/mojo/buildflags.h" #include "media/mojo/buildflags.h"
#include "net/ssl/client_cert_identity.h" #include "net/ssl/client_cert_identity.h"
#include "net/url_request/url_request.h" #include "net/url_request/url_request.h"
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/mojom/network_service.mojom.h"
#include "services/test/echo/public/mojom/echo.mojom.h" #include "services/test/echo/public/mojom/echo.mojom.h"
#include "storage/browser/quota/quota_settings.h" #include "storage/browser/quota/quota_settings.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
...@@ -451,6 +455,41 @@ bool ShellContentBrowserClient::PreSpawnRenderer( ...@@ -451,6 +455,41 @@ bool ShellContentBrowserClient::PreSpawnRenderer(
} }
#endif // OS_WIN #endif // OS_WIN
network::mojom::NetworkContextPtr
ShellContentBrowserClient::CreateNetworkContext(
BrowserContext* context,
bool in_memory,
const base::FilePath& relative_partition_path) {
DCHECK(context);
if (!base::FeatureList::IsEnabled(network::features::kNetworkService))
return nullptr;
network::mojom::NetworkContextPtr network_context;
network::mojom::NetworkContextParamsPtr context_params =
network::mojom::NetworkContextParams::New();
context_params->user_agent = GetUserAgent();
context_params->accept_language = "en-us,en";
context_params->enable_data_url_support = true;
#if BUILDFLAG(ENABLE_REPORTING)
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kRunWebTests)) {
// Configure the Reporting service in a manner expected by certain Web
// Platform Tests (network-error-logging and reporting-api).
//
// (1) Always send reports (irrespective of BACKGROUND_SYNC permission)
// (2) Lower the timeout for sending reports.
context_params->reporting_delivery_interval =
kReportingDeliveryIntervalTimeForWebTests;
context_params->skip_reporting_send_permission_check = true;
}
#endif
GetNetworkService()->CreateNetworkContext(MakeRequest(&network_context),
std::move(context_params));
return network_context;
}
ShellBrowserContext* ShellContentBrowserClient::browser_context() { ShellBrowserContext* ShellContentBrowserClient::browser_context() {
return shell_browser_main_parts_->browser_context(); return shell_browser_main_parts_->browser_context();
} }
......
...@@ -100,6 +100,11 @@ class ShellContentBrowserClient : public ContentBrowserClient { ...@@ -100,6 +100,11 @@ class ShellContentBrowserClient : public ContentBrowserClient {
bool PreSpawnRenderer(sandbox::TargetPolicy* policy) override; bool PreSpawnRenderer(sandbox::TargetPolicy* policy) override;
#endif #endif
network::mojom::NetworkContextPtr CreateNetworkContext(
BrowserContext* context,
bool in_memory,
const base::FilePath& relative_partition_path) override;
ShellBrowserContext* browser_context(); ShellBrowserContext* browser_context();
ShellBrowserContext* off_the_record_browser_context(); ShellBrowserContext* off_the_record_browser_context();
ResourceDispatcherHostDelegate* resource_dispatcher_host_delegate() { ResourceDispatcherHostDelegate* resource_dispatcher_host_delegate() {
...@@ -149,6 +154,10 @@ class ShellContentBrowserClient : public ContentBrowserClient { ...@@ -149,6 +154,10 @@ class ShellContentBrowserClient : public ContentBrowserClient {
ShellBrowserMainParts* shell_browser_main_parts_; ShellBrowserMainParts* shell_browser_main_parts_;
}; };
// The delay for sending reports when running with --run-web-tests
constexpr base::TimeDelta kReportingDeliveryIntervalTimeForWebTests =
base::TimeDelta::FromMilliseconds(100);
} // namespace content } // namespace content
#endif // CONTENT_SHELL_BROWSER_SHELL_CONTENT_BROWSER_CLIENT_H_ #endif // CONTENT_SHELL_BROWSER_SHELL_CONTENT_BROWSER_CLIENT_H_
...@@ -231,7 +231,7 @@ net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { ...@@ -231,7 +231,7 @@ net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() {
net::ReportingPolicy::Create(); net::ReportingPolicy::Create();
if (command_line.HasSwitch(switches::kRunWebTests)) if (command_line.HasSwitch(switches::kRunWebTests))
reporting_policy->delivery_interval = reporting_policy->delivery_interval =
base::TimeDelta::FromMilliseconds(100); kReportingDeliveryIntervalTimeForWebTests;
builder.set_reporting_policy(std::move(reporting_policy)); builder.set_reporting_policy(std::move(reporting_policy));
} }
......
...@@ -746,6 +746,10 @@ size_t NetworkContext::GetNumOutstandingResolveHostRequestsForTesting() const { ...@@ -746,6 +746,10 @@ size_t NetworkContext::GetNumOutstandingResolveHostRequestsForTesting() const {
return sum; return sum;
} }
bool NetworkContext::SkipReportingPermissionCheck() const {
return params_ && params_->skip_reporting_send_permission_check;
}
void NetworkContext::ClearNetworkingHistorySince( void NetworkContext::ClearNetworkingHistorySince(
base::Time time, base::Time time,
base::OnceClosure completion_callback) { base::OnceClosure completion_callback) {
...@@ -1809,10 +1813,16 @@ URLRequestContextOwner NetworkContext::ApplyContextParamsToBuilder( ...@@ -1809,10 +1813,16 @@ URLRequestContextOwner NetworkContext::ApplyContextParamsToBuilder(
#endif #endif
#if BUILDFLAG(ENABLE_REPORTING) #if BUILDFLAG(ENABLE_REPORTING)
if (base::FeatureList::IsEnabled(features::kReporting)) if (base::FeatureList::IsEnabled(features::kReporting)) {
builder->set_reporting_policy(net::ReportingPolicy::Create()); auto reporting_policy = net::ReportingPolicy::Create();
else if (params_->reporting_delivery_interval) {
reporting_policy->delivery_interval =
*params_->reporting_delivery_interval;
}
builder->set_reporting_policy(std::move(reporting_policy));
} else {
builder->set_reporting_policy(nullptr); builder->set_reporting_policy(nullptr);
}
builder->set_network_error_logging_enabled( builder->set_network_error_logging_enabled(
base::FeatureList::IsEnabled(features::kNetworkErrorLogging)); base::FeatureList::IsEnabled(features::kNetworkErrorLogging));
......
...@@ -375,6 +375,10 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkContext ...@@ -375,6 +375,10 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkContext
return &cors_preflight_controller_; return &cors_preflight_controller_;
} }
// Returns true if reports should unconditionally be sent without first
// consulting NetworkContextClient.OnCanSendReportingReports()
bool SkipReportingPermissionCheck() const;
private: private:
class ContextNetworkDelegate; class ContextNetworkDelegate;
......
...@@ -129,6 +129,11 @@ void NetworkServiceNetworkDelegate::OnCanSendReportingReports( ...@@ -129,6 +129,11 @@ void NetworkServiceNetworkDelegate::OnCanSendReportingReports(
return; return;
} }
if (network_context_->SkipReportingPermissionCheck()) {
std::move(result_callback).Run(std::move(origins));
return;
}
std::vector<url::Origin> origin_vector; std::vector<url::Origin> origin_vector;
std::copy(origins.begin(), origins.end(), std::back_inserter(origin_vector)); std::copy(origins.begin(), origins.end(), std::back_inserter(origin_vector));
client->OnCanSendReportingReports( client->OnCanSendReportingReports(
......
...@@ -290,6 +290,15 @@ struct NetworkContextParams { ...@@ -290,6 +290,15 @@ struct NetworkContextParams {
// Whether to discard Domain Reliability uploads. // Whether to discard Domain Reliability uploads.
bool discard_domain_reliablity_uploads = false; bool discard_domain_reliablity_uploads = false;
// When reporting is enabled, this sets the delay between sending reports.
// When omitted a default value is used.
mojo_base.mojom.TimeDelta? reporting_delivery_interval;
// Whether to bypass the ordinary permission checks for sending reports,
// rather than calling NetworkContextClient.OnCanSendReportingReports() to
// decide. This should only be used by tests.
bool skip_reporting_send_permission_check = false;
// Sets whether the NetworkContext should be used for globally scoped tasks // Sets whether the NetworkContext should be used for globally scoped tasks
// that need to make network requests. Currently this includes DNS over HTTPS // that need to make network requests. Currently this includes DNS over HTTPS
// requests and certain cert validation requests (OCSP, AIA, etc) on some // requests and certain cert validation requests (OCSP, AIA, etc) on some
......
...@@ -19,17 +19,6 @@ crbug.com/917284 external/wpt/service-workers/service-worker/claim-fetch-with-ap ...@@ -19,17 +19,6 @@ crbug.com/917284 external/wpt/service-workers/service-worker/claim-fetch-with-ap
# enabled this fails in both content_shell and chrome. # enabled this fails in both content_shell and chrome.
Bug(none) http/tests/misc/redirect-to-about-blank.html [ Timeout ] Bug(none) http/tests/misc/redirect-to-about-blank.html [ Timeout ]
# Reports aren't allowed under content_shell NS
crbug.com/910212 virtual/network-error-logging/external/wpt/network-error-logging/sends-report-on-404.https.html [ Failure ]
crbug.com/910212 virtual/network-error-logging/external/wpt/network-error-logging/sends-report-on-cache-validation.https.html [ Failure ]
crbug.com/910212 virtual/network-error-logging/external/wpt/network-error-logging/sends-report-on-redirect.https.html [ Failure ]
crbug.com/910212 virtual/network-error-logging/external/wpt/network-error-logging/sends-report-on-subdomain-dns-failure.https.html [ Failure ]
crbug.com/910212 virtual/network-error-logging/external/wpt/network-error-logging/sends-report-on-success-with-subdomain-policy.https.html [ Failure ]
crbug.com/910212 virtual/network-error-logging/external/wpt/network-error-logging/sends-report-on-success.https.html [ Failure ]
crbug.com/910212 virtual/reporting-api/external/wpt/content-security-policy/reporting-api/reporting-api-report-only-sends-reports-on-violation.https.sub.html [ Failure ]
crbug.com/910212 virtual/reporting-api/external/wpt/content-security-policy/reporting-api/reporting-api-sends-reports-on-violation.https.sub.html [ Failure ]
crbug.com/910212 virtual/reporting-api/external/wpt/content-security-policy/reporting-api/reporting-api-works-on-frame-src.https.sub.html [ Failure ]
# Skip virtual/outofblink-cors when NetworkService is on, since it's only # Skip virtual/outofblink-cors when NetworkService is on, since it's only
# intended to be run with NetworkService off. # intended to be run with NetworkService off.
Bug(none) virtual/outofblink-cors [ Skip ] Bug(none) virtual/outofblink-cors [ Skip ]
......
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