Remove global kFeatureAndParams vector in hang_watcher_unittest.cc
The Google C++ style guide forbids the use of complex (non-POD) global
variables [1]. kFeatureAndParams should therefore not be declared in the
global scope.
kFeatureAndParams was doing two things: it was enabling the feature
kEnableHangWatcher and it was setting ui_thread_log_level=2. This now
the default log level when InitializeOnMainThread is called with
emit_crashes=true. Thus, we don't need to set ui_thread_log_level in the
unit test. We can now simply enable the feature from the test fixtures.
[1] https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables
Change-Id: I0b91e1f7b374a31aa0476bc59b2db5ab2c1f539d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6587071
Commit-Queue: Jean-Philippe Gravel <jpgravel@chromium.org>
Reviewed-by: Olivier Li <olivierli@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1466640}
diff --git a/base/threading/hang_watcher_unittest.cc b/base/threading/hang_watcher_unittest.cc
index 5b755a3..2f97d22 100644
--- a/base/threading/hang_watcher_unittest.cc
+++ b/base/threading/hang_watcher_unittest.cc
@@ -42,11 +42,6 @@
namespace base {
namespace {
-// Use with a FeatureList to activate crash dumping for threads marked as
-// threadpool threads.
-const std::vector<base::test::FeatureRefAndParams> kFeatureAndParams{
- {base::kEnableHangWatcher, {{"ui_thread_log_level", "2"}}}};
-
// Use this value to mark things very far off in the future. Adding this
// to TimeTicks::Now() gives a point that will never be reached during the
// normal execution of a test.
@@ -186,12 +181,8 @@
const base::TimeDelta kTimeout = base::Seconds(10);
const base::TimeDelta kHangTime = kTimeout + base::Seconds(1);
- HangWatcherTest() {
- feature_list_.InitWithFeaturesAndParameters(kFeatureAndParams, {});
- }
-
protected:
- base::test::ScopedFeatureList feature_list_;
+ base::test::ScopedFeatureList feature_list_{base::kEnableHangWatcher};
// Used exclusively for MOCK_TIME. No tasks will be run on the environment.
// Single threaded to avoid ThreadPool WorkerThreads registering.
@@ -571,11 +562,6 @@
namespace {
class HangWatcherSnapshotTest : public testing::Test {
- public:
- void SetUp() override {
- feature_list_.InitWithFeaturesAndParameters(kFeatureAndParams, {});
- }
-
protected:
// Verify that a capture takes place and that at the time of the capture the
// list of hung thread ids is correct.
@@ -618,7 +604,7 @@
// actually took place.
int reference_capture_count_ = 0;
- base::test::ScopedFeatureList feature_list_;
+ base::test::ScopedFeatureList feature_list_{base::kEnableHangWatcher};
// Used exclusively for MOCK_TIME.
test::SingleThreadTaskEnvironment task_environment_{
@@ -939,7 +925,6 @@
class WatchHangsInScopeBlockingTest : public testing::Test {
public:
WatchHangsInScopeBlockingTest() {
- feature_list_.InitWithFeaturesAndParameters(kFeatureAndParams, {});
HangWatcher::InitializeOnMainThread(
HangWatcher::ProcessType::kBrowserProcess, /*emit_crashes=*/true);
@@ -1006,7 +991,7 @@
base::WaitableEvent continue_capture_;
bool completed_capture_{false};
- base::test::ScopedFeatureList feature_list_;
+ base::test::ScopedFeatureList feature_list_{base::kEnableHangWatcher};
HangWatcher hang_watcher_;
base::ScopedClosureRunner unregister_thread_closure_;
};