mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
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:
@@ -495,11 +495,7 @@ class HttpTestRunner : public base::RefCountedThreadSafe<HttpTestRunner> {
|
|||||||
HttpTestRunner(bool parallel_requests)
|
HttpTestRunner(bool parallel_requests)
|
||||||
: parallel_requests_(parallel_requests),
|
: parallel_requests_(parallel_requests),
|
||||||
initialized_(false),
|
initialized_(false),
|
||||||
next_request_id_(0) {
|
next_request_id_(0) {}
|
||||||
handler_ = new TestServerHandler(
|
|
||||||
base::Bind(&HttpTestRunner::OnServerStarted, this),
|
|
||||||
base::Bind(&HttpTestRunner::OnServerDestroyed, this));
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~HttpTestRunner() {
|
virtual ~HttpTestRunner() {
|
||||||
if (destroy_event_)
|
if (destroy_event_)
|
||||||
@@ -516,6 +512,10 @@ class HttpTestRunner : public base::RefCountedThreadSafe<HttpTestRunner> {
|
|||||||
void ExecuteTest() {
|
void ExecuteTest() {
|
||||||
EXPECT_FALSE(CefCurrentlyOn(TID_UI));
|
EXPECT_FALSE(CefCurrentlyOn(TID_UI));
|
||||||
|
|
||||||
|
handler_ = new TestServerHandler(
|
||||||
|
base::Bind(&HttpTestRunner::OnServerStarted, this),
|
||||||
|
base::Bind(&HttpTestRunner::OnServerDestroyed, this));
|
||||||
|
|
||||||
run_event_ = CefWaitableEvent::CreateWaitableEvent(false, false);
|
run_event_ = CefWaitableEvent::CreateWaitableEvent(false, false);
|
||||||
|
|
||||||
CefPostTask(TID_UI, base::Bind(&HttpTestRunner::RunTest, this));
|
CefPostTask(TID_UI, base::Bind(&HttpTestRunner::RunTest, this));
|
||||||
|
@@ -1553,7 +1553,9 @@ class RequestTestRunner : public base::RefCountedThreadSafe<RequestTestRunner> {
|
|||||||
owner_task_runner_ = CefTaskRunner::GetForCurrentThread();
|
owner_task_runner_ = CefTaskRunner::GetForCurrentThread();
|
||||||
EXPECT_TRUE(owner_task_runner_.get());
|
EXPECT_TRUE(owner_task_runner_.get());
|
||||||
EXPECT_TRUE(owner_task_runner_->BelongsToCurrentThread());
|
EXPECT_TRUE(owner_task_runner_->BelongsToCurrentThread());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Initialize() {
|
||||||
// Helper macro for registering test callbacks.
|
// Helper macro for registering test callbacks.
|
||||||
#define REGISTER_TEST(test_mode, setup_method, run_method) \
|
#define REGISTER_TEST(test_mode, setup_method, run_method) \
|
||||||
RegisterTest(test_mode, base::Bind(&RequestTestRunner::setup_method, this), \
|
RegisterTest(test_mode, base::Bind(&RequestTestRunner::setup_method, this), \
|
||||||
@@ -2744,6 +2746,7 @@ class RequestRendererTest : public ClientAppRenderer::Delegate {
|
|||||||
test_runner_ = new RequestTestRunner(
|
test_runner_ = new RequestTestRunner(
|
||||||
false, args->GetBool(1), use_frame_method, false,
|
false, args->GetBool(1), use_frame_method, false,
|
||||||
base::Bind(&RequestRendererTest::OnIncompleteRequest, this));
|
base::Bind(&RequestRendererTest::OnIncompleteRequest, this));
|
||||||
|
test_runner_->Initialize();
|
||||||
|
|
||||||
// Setup the test. This will create the objects that we test against but
|
// Setup the test. This will create the objects that we test against but
|
||||||
// not register any backend (because we're in the render process).
|
// not register any backend (because we're in the render process).
|
||||||
@@ -2879,6 +2882,7 @@ class RequestTestHandler : public TestHandler {
|
|||||||
test_runner_ = new RequestTestRunner(
|
test_runner_ = new RequestTestRunner(
|
||||||
true, test_server_backend_, test_frame_method_, test_in_browser_,
|
true, test_server_backend_, test_frame_method_, test_in_browser_,
|
||||||
base::Bind(&RequestTestHandler::OnIncompleteRequest, this));
|
base::Bind(&RequestTestHandler::OnIncompleteRequest, this));
|
||||||
|
test_runner_->Initialize();
|
||||||
|
|
||||||
// Get or create the request context.
|
// Get or create the request context.
|
||||||
if (context_mode_ == CONTEXT_GLOBAL) {
|
if (context_mode_ == CONTEXT_GLOBAL) {
|
||||||
|
Reference in New Issue
Block a user