Commit 28afe34f authored by Ilia Samsonov's avatar Ilia Samsonov Committed by Commit Bot

Skip manual tests using TestEventListener.

Moving this logic to TestEventListener will avoid executing
overriding SetUp and TearDown methods.

Change-Id: I98f625dc86280c2f2f590a0cac55d46e46a4fa99
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1804070
Commit-Queue: Ilia Samsonov <isamsonov@google.com>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707877}
parent 8cf3df27
...@@ -320,11 +320,6 @@ void InProcessBrowserTest::TearDown() { ...@@ -320,11 +320,6 @@ void InProcessBrowserTest::TearDown() {
#if defined(OS_WIN) #if defined(OS_WIN)
com_initializer_.reset(); com_initializer_.reset();
#endif #endif
if (::testing::UnitTest::GetInstance()
->current_test_info()
->result()
->Skipped())
return;
BrowserTestBase::TearDown(); BrowserTestBase::TearDown();
#if defined(OS_MACOSX) || defined(OS_LINUX) #if defined(OS_MACOSX) || defined(OS_LINUX)
OSCryptMocker::TearDown(); OSCryptMocker::TearDown();
......
...@@ -39,8 +39,6 @@ MediaRouterBaseBrowserTest::~MediaRouterBaseBrowserTest() { ...@@ -39,8 +39,6 @@ MediaRouterBaseBrowserTest::~MediaRouterBaseBrowserTest() {
} }
void MediaRouterBaseBrowserTest::SetUp() { void MediaRouterBaseBrowserTest::SetUp() {
if (BrowserTestBase::ShouldSkipManualTests())
GTEST_SKIP();
ParseCommandLine(); ParseCommandLine();
ExtensionBrowserTest::SetUp(); ExtensionBrowserTest::SetUp();
} }
......
...@@ -66,8 +66,6 @@ RemoteDesktopBrowserTest::RemoteDesktopBrowserTest() ...@@ -66,8 +66,6 @@ RemoteDesktopBrowserTest::RemoteDesktopBrowserTest()
RemoteDesktopBrowserTest::~RemoteDesktopBrowserTest() {} RemoteDesktopBrowserTest::~RemoteDesktopBrowserTest() {}
void RemoteDesktopBrowserTest::SetUp() { void RemoteDesktopBrowserTest::SetUp() {
if (BrowserTestBase::ShouldSkipManualTests())
GTEST_SKIP();
ParseCommandLine(); ParseCommandLine();
PlatformAppBrowserTest::SetUp(); PlatformAppBrowserTest::SetUp();
} }
......
...@@ -109,9 +109,6 @@ ...@@ -109,9 +109,6 @@
namespace content { namespace content {
namespace { namespace {
// See kRunManualTestsFlag in "content_switches.cc".
const char kManualTestPrefix[] = "MANUAL_";
#if defined(OS_POSIX) #if defined(OS_POSIX)
// On SIGSEGV or SIGTERM (sent by the runner on timeouts), dump a stack trace // On SIGSEGV or SIGTERM (sent by the runner on timeouts), dump a stack trace
// (to make debugging easier) and also exit with a known error code (so that // (to make debugging easier) and also exit with a known error code (so that
...@@ -212,9 +209,6 @@ BrowserTestBase::~BrowserTestBase() { ...@@ -212,9 +209,6 @@ BrowserTestBase::~BrowserTestBase() {
void BrowserTestBase::SetUp() { void BrowserTestBase::SetUp() {
set_up_called_ = true; set_up_called_ = true;
if (BrowserTestBase::ShouldSkipManualTests())
GTEST_SKIP();
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
// Features that depend on external factors (e.g. memory pressure monitor) can // Features that depend on external factors (e.g. memory pressure monitor) can
...@@ -541,14 +535,6 @@ void BrowserTestBase::SimulateNetworkServiceCrash() { ...@@ -541,14 +535,6 @@ void BrowserTestBase::SimulateNetworkServiceCrash() {
InitializeNetworkProcess(); InitializeNetworkProcess();
} }
bool BrowserTestBase::ShouldSkipManualTests() {
return (base::StartsWith(
::testing::UnitTest::GetInstance()->current_test_info()->name(),
kManualTestPrefix, base::CompareCase::SENSITIVE) &&
!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kRunManualTestsFlag));
}
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
void BrowserTestBase::WaitUntilJavaIsReady(base::OnceClosure quit_closure) { void BrowserTestBase::WaitUntilJavaIsReady(base::OnceClosure quit_closure) {
if (testing::android::JavaAsyncStartupTasksCompleteForBrowserTests()) { if (testing::android::JavaAsyncStartupTasksCompleteForBrowserTests()) {
......
...@@ -102,13 +102,6 @@ class BrowserTestBase : public testing::Test { ...@@ -102,13 +102,6 @@ class BrowserTestBase : public testing::Test {
// This is meant to be inherited only by the test harness. // This is meant to be inherited only by the test harness.
virtual void PostRunTestOnMainThread() = 0; virtual void PostRunTestOnMainThread() = 0;
// Returns true if this test should be skipped. Tests starting with 'MANUAL_'
// are skipped unless the command line flag "--run-manual" is supplied.
// In case overriding SetUp() breaks, add:
// if (ShouldSkipManualTest())
// GTEST_SKIP();
bool ShouldSkipManualTests();
// Sets expected browser exit code, in case it's different than 0 (success). // Sets expected browser exit code, in case it's different than 0 (success).
void set_expected_exit_code(int code) { expected_exit_code_ = code; } void set_expected_exit_code(int code) { expected_exit_code_ = code; }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "content/common/url_schemes.h" #include "content/common/url_schemes.h"
#include "content/gpu/in_process_gpu_thread.h" #include "content/gpu/in_process_gpu_thread.h"
#include "content/public/common/content_client.h" #include "content/public/common/content_client.h"
#include "content/public/common/content_switches.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 "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -38,6 +39,23 @@ constexpr gin::V8Initializer::V8SnapshotFileType kSnapshotType = ...@@ -38,6 +39,23 @@ constexpr gin::V8Initializer::V8SnapshotFileType kSnapshotType =
#endif #endif
#endif #endif
// See kRunManualTestsFlag in "content_switches.cc".
const char kManualTestPrefix[] = "MANUAL_";
// Tests starting with 'MANUAL_' are skipped unless the
// command line flag "--run-manual" is supplied.
class SkipManualTests : public testing::EmptyTestEventListener {
public:
void OnTestStart(const testing::TestInfo& test_info) override {
if (base::StartsWith(test_info.name(), kManualTestPrefix,
base::CompareCase::SENSITIVE) &&
!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kRunManualTestsFlag)) {
GTEST_SKIP();
}
}
};
} // namespace } // namespace
ContentTestSuiteBase::ContentTestSuiteBase(int argc, char** argv) ContentTestSuiteBase::ContentTestSuiteBase(int argc, char** argv)
...@@ -46,6 +64,8 @@ ContentTestSuiteBase::ContentTestSuiteBase(int argc, char** argv) ...@@ -46,6 +64,8 @@ ContentTestSuiteBase::ContentTestSuiteBase(int argc, char** argv)
void ContentTestSuiteBase::Initialize() { void ContentTestSuiteBase::Initialize() {
base::TestSuite::Initialize(); base::TestSuite::Initialize();
testing::UnitTest::GetInstance()->listeners().Append(
std::make_unique<SkipManualTests>().release());
#if defined(V8_USE_EXTERNAL_STARTUP_DATA) #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
gin::V8Initializer::LoadV8Snapshot(kSnapshotType); gin::V8Initializer::LoadV8Snapshot(kSnapshotType);
......
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