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

Unified Diff: content/shell/utility/shell_content_utility_client.cc

Issue 2837813004: Sync the browser test host resolver with the network process before a test runs. (Closed)
Patch Set: review comments Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/shell/utility/shell_content_utility_client.h ('k') | content/test/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/shell/utility/shell_content_utility_client.cc
diff --git a/content/shell/utility/shell_content_utility_client.cc b/content/shell/utility/shell_content_utility_client.cc
index b9b5fb7aeeffdeb0af9093c7e18ffffdb55eb2ad..1ac9f8d57320a446f034d48b445b83080a207e66 100644
--- a/content/shell/utility/shell_content_utility_client.cc
+++ b/content/shell/utility/shell_content_utility_client.cc
@@ -14,10 +14,14 @@
#include "content/public/child/child_thread.h"
#include "content/public/common/service_manager_connection.h"
#include "content/public/common/simple_connection_filter.h"
+#include "content/public/test/test_host_resolver.h"
#include "content/public/test/test_service.h"
#include "content/public/test/test_service.mojom.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/system/buffer.h"
+#include "net/base/net_errors.h"
+#include "net/base/network_interfaces.h"
+#include "net/dns/mock_host_resolver.h"
#include "services/service_manager/public/cpp/binder_registry.h"
namespace content {
@@ -74,8 +78,36 @@ std::unique_ptr<service_manager::Service> CreateTestService() {
return std::unique_ptr<service_manager::Service>(new TestService);
}
+class NetworkServiceTestImpl : public mojom::NetworkServiceTest {
+ public:
+ static void Create(mojom::NetworkServiceTestRequest request) {
+ // Leak this.
+ new NetworkServiceTestImpl(std::move(request));
+ }
+ explicit NetworkServiceTestImpl(mojom::NetworkServiceTestRequest request)
+ : binding_(this, std::move(request)) {}
+ ~NetworkServiceTestImpl() override = default;
+
+ // mojom::NetworkServiceTest implementation.
+ void AddRules(std::vector<mojom::RulePtr> rules) override {
+ for (const auto& rule : rules) {
+ test_host_resolver_.host_resolver()->AddRule(rule->host_pattern,
+ rule->replacement);
+ }
+ }
+
+ private:
+ mojo::Binding<mojom::NetworkServiceTest> binding_;
+
+ TestHostResolver test_host_resolver_;
+
+ DISALLOW_COPY_AND_ASSIGN(NetworkServiceTestImpl);
+};
+
} // namespace
+ShellContentUtilityClient::ShellContentUtilityClient() {}
+
ShellContentUtilityClient::~ShellContentUtilityClient() {
}
@@ -95,4 +127,17 @@ void ShellContentUtilityClient::RegisterServices(StaticServiceMap* services) {
services->insert(std::make_pair(kTestServiceUrl, info));
}
+void ShellContentUtilityClient::RegisterNetworkBinders(
+ service_manager::BinderRegistry* registry) {
+ registry->AddInterface<mojom::NetworkServiceTest>(
+ base::Bind(&ShellContentUtilityClient::Create, base::Unretained(this)));
+}
+
+void ShellContentUtilityClient::Create(
+ mojom::NetworkServiceTestRequest request) {
+ DCHECK(!network_service_test_);
+ network_service_test_ =
+ base::MakeUnique<NetworkServiceTestImpl>(std::move(request));
+}
+
} // namespace content
« no previous file with comments | « content/shell/utility/shell_content_utility_client.h ('k') | content/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698