ceftests: Don't use base::Bind in object constructor (see issue #3140)

Fixes the following error:
[FATAL:cef_bind_internal.h(868)] Check failed: receiver->HasAtLeastOneRef().
base::Bind{Once,Repeating}() refuses to create the first reference to ref-counted
objects. That typically happens around PostTask() in their constructor, and such
objects can be destroyed before `new` returns if the task resolves fast enough.
This commit is contained in:
Marshall Greenblatt
2021-06-18 09:41:17 -07:00
parent 6a1c641f75
commit 3545e20b01
2 changed files with 9 additions and 5 deletions

View File

@@ -1553,7 +1553,9 @@ class RequestTestRunner : public base::RefCountedThreadSafe<RequestTestRunner> {
owner_task_runner_ = CefTaskRunner::GetForCurrentThread();
EXPECT_TRUE(owner_task_runner_.get());
EXPECT_TRUE(owner_task_runner_->BelongsToCurrentThread());
}
void Initialize() {
// Helper macro for registering test callbacks.
#define REGISTER_TEST(test_mode, setup_method, run_method) \
RegisterTest(test_mode, base::Bind(&RequestTestRunner::setup_method, this), \
@@ -2744,6 +2746,7 @@ class RequestRendererTest : public ClientAppRenderer::Delegate {
test_runner_ = new RequestTestRunner(
false, args->GetBool(1), use_frame_method, false,
base::Bind(&RequestRendererTest::OnIncompleteRequest, this));
test_runner_->Initialize();
// Setup the test. This will create the objects that we test against but
// not register any backend (because we're in the render process).
@@ -2879,6 +2882,7 @@ class RequestTestHandler : public TestHandler {
test_runner_ = new RequestTestRunner(
true, test_server_backend_, test_frame_method_, test_in_browser_,
base::Bind(&RequestTestHandler::OnIncompleteRequest, this));
test_runner_->Initialize();
// Get or create the request context.
if (context_mode_ == CONTEXT_GLOBAL) {