Commit 1439246c authored by Matt Menke's avatar Matt Menke Committed by Commit Bot

Add browser tests for HTTP auth and DNS stub resolver configuration.

These aren't full integration tests - they don't make sure that the
correct configuration is sent to the network service on start, or that
the configuration is updated as the prefs change. Instead, they just
check the code that maps prefs to NetworkService configuration structs.

Bug: 881168
Change-Id: I923d8536686ca3a10083c1b8ba0b76c5703e1f9d
Reviewed-on: https://chromium-review.googlesource.com/1210365Reviewed-by: default avatarAsanka Herath <asanka@chromium.org>
Commit-Queue: Matt Menke <mmenke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590481}
parent a66e0a3f
......@@ -5,10 +5,8 @@
#include "chrome/browser/net/system_network_context_manager.h"
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include "base/command_line.h"
#include "base/feature_list.h"
......@@ -97,10 +95,16 @@ void GetStubResolverConfig(
local_state->GetList(prefs::kDnsOverHttpsServers)->GetList();
const auto& doh_server_method_list =
local_state->GetList(prefs::kDnsOverHttpsServerMethods)->GetList();
DCHECK_EQ(doh_server_list.size(), doh_server_method_list.size());
for (size_t i = 0;
i < doh_server_list.size() && i < doh_server_method_list.size(); ++i) {
// The two lists may have mismatched lengths during a pref change. Just skip
// the DOH server list updates then, as the configuration may be incorrect.
//
// TODO(mmenke): May need to improve safety here when / if DNS over HTTPS is
// exposed via settings, as it's possible for the old and new lengths to be
// the same, but the servers not to match. Either a PostTask or merging the
// prefs would work around that.
if (doh_server_list.size() == doh_server_method_list.size()) {
for (size_t i = 0; i < doh_server_list.size(); ++i) {
if (!doh_server_list[i].is_string() ||
!doh_server_method_list[i].is_string()) {
continue;
......@@ -123,6 +127,7 @@ void GetStubResolverConfig(
(doh_server_method_list[i].GetString() == "POST");
(*dns_over_https_servers)->emplace_back(std::move(dns_over_https_server));
}
}
*stub_resolver_enabled =
dns_over_https_servers->has_value() ||
......@@ -624,6 +629,23 @@ void SystemNetworkContextManager::FlushNetworkInterfaceForTesting() {
url_loader_factory_.FlushForTesting();
}
void SystemNetworkContextManager::GetStubResolverConfigForTesting(
bool* stub_resolver_enabled,
base::Optional<std::vector<network::mojom::DnsOverHttpsServerPtr>>*
dns_over_https_servers) {
GetStubResolverConfig(stub_resolver_enabled, dns_over_https_servers);
}
network::mojom::HttpAuthStaticParamsPtr
SystemNetworkContextManager::GetHttpAuthStaticParamsForTesting() {
return CreateHttpAuthStaticParams();
}
network::mojom::HttpAuthDynamicParamsPtr
SystemNetworkContextManager::GetHttpAuthDynamicParamsForTesting() {
return CreateHttpAuthDynamicParams();
}
network::mojom::NetworkContextParamsPtr
SystemNetworkContextManager::CreateNetworkContextParams() {
// TODO(mmenke): Set up parameters here (in memory cookie store, etc).
......
......@@ -7,6 +7,7 @@
#include <memory>
#include <string>
#include <vector>
#include "base/macros.h"
#include "base/memory/ref_counted.h"
......@@ -124,6 +125,17 @@ class SystemNetworkContextManager {
// use only.
void FlushNetworkInterfaceForTesting();
// Returns configuration that would be sent to the stub DNS resolver.
static void GetStubResolverConfigForTesting(
bool* stub_resolver_enabled,
base::Optional<std::vector<network::mojom::DnsOverHttpsServerPtr>>*
dns_over_https_servers);
static network::mojom::HttpAuthStaticParamsPtr
GetHttpAuthStaticParamsForTesting();
static network::mojom::HttpAuthDynamicParamsPtr
GetHttpAuthDynamicParamsForTesting();
private:
class URLLoaderFactoryForSystem;
......
......@@ -673,6 +673,7 @@ test("browser_tests") {
"../browser/net/profile_network_context_service_browsertest.cc",
"../browser/net/proxy_browsertest.cc",
"../browser/net/reporting_browsertest.cc",
"../browser/net/system_network_context_manager_browsertest.cc",
"../browser/net/variations_http_headers_browsertest.cc",
"../browser/net/websocket_browsertest.cc",
"../browser/no_background_tasks_browsertest.cc",
......
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