Commit 01b6a610 authored by Helen Li's avatar Helen Li Committed by Commit Bot

Make RenderViewHostTestHarness create a net::NetworkChangeNotifier

This makes RenderViewHostTestHarness own a NetworkChangeNotifier,
so Network Service can skip creating one (see
CreateNetworkChangeNotifierIfNeeded() in network_service.cc). The
in-process NetworkService is a leaky global singleton, which also
leaks a NetworkChangeNotifier that conflicts with subsequent unit
tests.

See: https://groups.google.com/a/chromium.org/d/msg/network-service-dev/IgNFrq1zFHI/FNCAplsCCQAJ

An alternative approach is to tear down the in-process singleton
NetworkService, but I ran into issues when doing that mostly because
the BrowserThreadDelegate::CleanUp hook is only implemented by
chrome/browser/io_thread.h and not by other content embedders.

Change-Id: I1fbfca32e582621c3cfcbb7af3a82a4243c5b44b
Reviewed-on: https://chromium-review.googlesource.com/1114924
Commit-Queue: Helen Li <xunjieli@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#571560}
parent e903f5e6
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "content/test/test_render_view_host_factory.h" #include "content/test/test_render_view_host_factory.h"
#include "content/test/test_render_widget_host_factory.h" #include "content/test/test_render_widget_host_factory.h"
#include "content/test/test_web_contents.h" #include "content/test/test_web_contents.h"
#include "net/base/network_change_notifier.h"
#include "ui/base/material_design/material_design_controller.h" #include "ui/base/material_design/material_design_controller.h"
#include "ui/base/test/material_design_controller_test_api.h" #include "ui/base/test/material_design_controller_test_api.h"
...@@ -247,6 +248,12 @@ void RenderViewHostTestHarness::NavigateAndCommit(const GURL& url) { ...@@ -247,6 +248,12 @@ void RenderViewHostTestHarness::NavigateAndCommit(const GURL& url) {
} }
void RenderViewHostTestHarness::SetUp() { void RenderViewHostTestHarness::SetUp() {
// Create and own a NetworkChangeNotifier so that it will not be created
// during the initialization of the global leaky singleton NetworkService. The
// global NetworkService's NetworkChangeNotifier can affect subsequent unit
// tests.
network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock());
// ContentTestSuiteBase might have already initialized // ContentTestSuiteBase might have already initialized
// MaterialDesignController in unit_tests suite. // MaterialDesignController in unit_tests suite.
ui::test::MaterialDesignControllerTestAPI::Uninitialize(); ui::test::MaterialDesignControllerTestAPI::Uninitialize();
......
...@@ -34,6 +34,10 @@ namespace display { ...@@ -34,6 +34,10 @@ namespace display {
class Screen; class Screen;
} }
namespace net {
class NetworkChangeNotifier;
}
namespace ui { namespace ui {
class ScopedOleInitializer; class ScopedOleInitializer;
} }
...@@ -265,6 +269,8 @@ class RenderViewHostTestHarness : public testing::Test { ...@@ -265,6 +269,8 @@ class RenderViewHostTestHarness : public testing::Test {
private: private:
std::unique_ptr<TestBrowserThreadBundle> thread_bundle_; std::unique_ptr<TestBrowserThreadBundle> thread_bundle_;
std::unique_ptr<net::NetworkChangeNotifier> network_change_notifier_;
std::unique_ptr<ContentBrowserSanityChecker> sanity_checker_; std::unique_ptr<ContentBrowserSanityChecker> sanity_checker_;
std::unique_ptr<BrowserContext> browser_context_; std::unique_ptr<BrowserContext> browser_context_;
......
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