Commit de0b6f6c authored by Robbie McElrath's avatar Robbie McElrath Committed by Commit Bot

Disable any existing NetworkChangeNotifier before all unit tests.

This is a quick fix for crbug.com/888215. crbug.com/901092 will track
the longer term fix, which will likely require quite a bit more work.

Bug: 888215
Change-Id: I071ea0a1508e486211789073c43050f4cd56accb
Reviewed-on: https://chromium-review.googlesource.com/c/1313414
Commit-Queue: Robbie McElrath <rmcelrath@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604797}
parent 4214a73b
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "content/public/common/content_client.h" #include "content/public/common/content_client.h"
#include "content/renderer/in_process_renderer_thread.h" #include "content/renderer/in_process_renderer_thread.h"
#include "content/utility/in_process_utility_thread.h" #include "content/utility/in_process_utility_thread.h"
#include "net/base/network_change_notifier.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/material_design/material_design_controller.h" #include "ui/base/material_design/material_design_controller.h"
#include "ui/base/ui_base_paths.h" #include "ui/base/ui_base_paths.h"
...@@ -41,7 +42,33 @@ constexpr gin::V8Initializer::V8SnapshotFileType kSnapshotType = ...@@ -41,7 +42,33 @@ constexpr gin::V8Initializer::V8SnapshotFileType kSnapshotType =
gin::V8Initializer::V8SnapshotFileType::kDefault; gin::V8Initializer::V8SnapshotFileType::kDefault;
#endif #endif
#endif #endif
}
// Disables any leaked NetworkChangeNotifier before each test.
// TODO(crbug.com/901092): Delete once the network service cleans itself up.
class NetworkChangeNotifierDisabler : public testing::EmptyTestEventListener {
public:
NetworkChangeNotifierDisabler() {}
~NetworkChangeNotifierDisabler() override {}
void OnTestCaseStart(const testing::TestCase& test_case) override {
if (net::NetworkChangeNotifier::HasNetworkChangeNotifier()) {
network_change_notifier_disabler_ =
std::make_unique<net::NetworkChangeNotifier::DisableForTest>();
}
}
void OnTestCaseEnd(const testing::TestCase& test_case) override {
network_change_notifier_disabler_ = nullptr;
}
private:
std::unique_ptr<net::NetworkChangeNotifier::DisableForTest>
network_change_notifier_disabler_;
DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierDisabler);
};
} // namespace
ContentTestSuiteBase::ContentTestSuiteBase(int argc, char** argv) ContentTestSuiteBase::ContentTestSuiteBase(int argc, char** argv)
: base::TestSuite(argc, argv) { : base::TestSuite(argc, argv) {
...@@ -50,6 +77,10 @@ ContentTestSuiteBase::ContentTestSuiteBase(int argc, char** argv) ...@@ -50,6 +77,10 @@ ContentTestSuiteBase::ContentTestSuiteBase(int argc, char** argv)
void ContentTestSuiteBase::Initialize() { void ContentTestSuiteBase::Initialize() {
base::TestSuite::Initialize(); base::TestSuite::Initialize();
testing::TestEventListeners& listeners =
testing::UnitTest::GetInstance()->listeners();
listeners.Append(new NetworkChangeNotifierDisabler());
#if defined(V8_USE_EXTERNAL_STARTUP_DATA) #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
gin::V8Initializer::LoadV8Snapshot(kSnapshotType); gin::V8Initializer::LoadV8Snapshot(kSnapshotType);
gin::V8Initializer::LoadV8Natives(); gin::V8Initializer::LoadV8Natives();
......
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