Commit 19640abf authored by Marek Haranczyk's avatar Marek Haranczyk Committed by Commit Bot

Fix some of content_unittests crashes.

1. Add missing ContentClient initialization in ContentTestSuite
in death child process case. Repeater does not notify events to test
listeners in death child process by design.
2. Add proper appcache tests teardown to avoid leaking test setup
configuration to other test, potentially causing crashes if other tests
in batch created response without headers. The config enabled relevant
headers checking code, which expects headers to exist.

BUG=604078

Change-Id: I05adb10ce30a1324ba2a80054808bd0697feb4c9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2478603Reviewed-by: default avatarMarijn Kruisselbrink <mek@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819477}
parent a5119b72
......@@ -1202,6 +1202,7 @@ Mozilla Corporation <*@mozilla.com>
Neverware Inc. <*@neverware.com>
NIKE, Inc. <*@nike.com>
NVIDIA Corporation <*@nvidia.com>
OpenFin Inc. <*@openfin.co>
Opera Software ASA <*@opera.com>
Optical Tone Ltd <*@opticaltone.com>
Pengutronix e.K. <*@pengutronix.de>
......
......@@ -28,6 +28,9 @@ class AppCacheManifestParserTest : public testing::Test {
blink::TrialTokenValidator::SetOriginTrialPolicyGetter(base::BindRepeating(
[]() -> blink::OriginTrialPolicy* { return &g_origin_trial_policy; }));
}
void TearDown() override {
blink::TrialTokenValidator::ResetOriginTrialPolicyGetter();
}
};
TEST_F(AppCacheManifestParserTest, NoData) {
......
......@@ -791,6 +791,7 @@ class AppCacheUpdateJobTest : public testing::Test,
}
void TearDown() override {
blink::TrialTokenValidator::ResetOriginTrialPolicyGetter();
weak_partition_factory_.reset();
browser_context_.reset();
......
......@@ -184,8 +184,6 @@ void BluetoothBlocklist::PopulateWithDefaultValues() {
}
void BluetoothBlocklist::PopulateWithServerProvidedValues() {
// DCHECK to maybe help debug https://crbug.com/604078.
DCHECK(GetContentClient());
Add(GetContentClient()->browser()->GetWebBluetoothBlocklist());
}
......
......@@ -53,20 +53,31 @@ TEST_F(BluetoothBlocklistTest, ExcludeWritesUUID) {
}
TEST_F(BluetoothBlocklistTest, InvalidUUID) {
#ifdef OFFICIAL_BUILD
// The official build does not print the reason a CHECK failed.
const char kErrorRegex[] = "";
#else
const char kErrorRegex[] = "uuid.IsValid\\(\\)";
#endif
BluetoothUUID empty_string_uuid("");
EXPECT_DEATH_IF_SUPPORTED(
list_.Add(empty_string_uuid, BluetoothBlocklist::Value::EXCLUDE), "");
EXPECT_DEATH_IF_SUPPORTED(list_.IsExcluded(empty_string_uuid), "");
EXPECT_DEATH_IF_SUPPORTED(list_.IsExcludedFromReads(empty_string_uuid), "");
EXPECT_DEATH_IF_SUPPORTED(list_.IsExcludedFromWrites(empty_string_uuid), "");
list_.Add(empty_string_uuid, BluetoothBlocklist::Value::EXCLUDE),
kErrorRegex);
EXPECT_DEATH_IF_SUPPORTED(list_.IsExcluded(empty_string_uuid), kErrorRegex);
EXPECT_DEATH_IF_SUPPORTED(list_.IsExcludedFromReads(empty_string_uuid),
kErrorRegex);
EXPECT_DEATH_IF_SUPPORTED(list_.IsExcludedFromWrites(empty_string_uuid),
kErrorRegex);
BluetoothUUID invalid_string_uuid("Not a valid UUID string.");
EXPECT_DEATH_IF_SUPPORTED(
list_.Add(invalid_string_uuid, BluetoothBlocklist::Value::EXCLUDE), "");
EXPECT_DEATH_IF_SUPPORTED(list_.IsExcluded(invalid_string_uuid), "");
EXPECT_DEATH_IF_SUPPORTED(list_.IsExcludedFromReads(invalid_string_uuid), "");
list_.Add(invalid_string_uuid, BluetoothBlocklist::Value::EXCLUDE),
kErrorRegex);
EXPECT_DEATH_IF_SUPPORTED(list_.IsExcluded(invalid_string_uuid), kErrorRegex);
EXPECT_DEATH_IF_SUPPORTED(list_.IsExcludedFromReads(invalid_string_uuid),
kErrorRegex);
EXPECT_DEATH_IF_SUPPORTED(list_.IsExcludedFromWrites(invalid_string_uuid),
"");
kErrorRegex);
}
// Abreviated UUIDs used to create, or test against, the blocklist work
......
......@@ -90,9 +90,21 @@ void ContentTestSuite::Initialize() {
gpu_feature_info->disabled_extensions);
gl::init::InitializeExtensionSettingsOneOffPlatform();
}
testing::TestEventListeners& listeners =
testing::UnitTest::GetInstance()->listeners();
listeners.Append(new TestInitializationListener);
// TestEventListeners repeater event propagation is disabled in death test
// child process.
if (command_line->HasSwitch("gtest_internal_run_death_test")) {
test_content_client_initializer_ =
std::make_unique<TestContentClientInitializer>();
} else {
testing::TestEventListeners& listeners =
testing::UnitTest::GetInstance()->listeners();
listeners.Append(new TestInitializationListener);
}
}
void ContentTestSuite::Shutdown() {
test_content_client_initializer_.reset();
ContentTestSuiteBase::Shutdown();
}
} // namespace content
......@@ -19,6 +19,8 @@
namespace content {
class TestContentClientInitializer;
class ContentTestSuite : public ContentTestSuiteBase {
public:
ContentTestSuite(int argc, char** argv);
......@@ -26,8 +28,11 @@ class ContentTestSuite : public ContentTestSuiteBase {
protected:
void Initialize() override;
void Shutdown() override;
private:
std::unique_ptr<TestContentClientInitializer>
test_content_client_initializer_;
base::TestDiscardableMemoryAllocator discardable_memory_allocator_;
#if defined(OS_WIN)
......
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