2016-01-19 21:09:01 +01:00
|
|
|
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2020-08-20 00:23:42 +02:00
|
|
|
#ifndef CEF_TESTS_CEFTESTS_THREAD_HELPER_H_
|
|
|
|
#define CEF_TESTS_CEFTESTS_THREAD_HELPER_H_
|
2016-01-19 21:09:01 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "include/base/cef_bind.h"
|
|
|
|
#include "include/cef_task.h"
|
2016-11-15 22:18:41 +01:00
|
|
|
#include "include/cef_waitable_event.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Helper for signaling |event|.
|
2016-11-15 22:18:41 +01:00
|
|
|
void SignalEvent(CefRefPtr<CefWaitableEvent> event);
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Post a task to the specified thread and wait for the task to execute as
|
|
|
|
// indication that all previously pending tasks on that thread have completed.
|
2016-11-15 18:56:02 +01:00
|
|
|
void WaitForThread(CefThreadId thread_id, int64 delay_ms = 0);
|
|
|
|
void WaitForThread(CefRefPtr<CefTaskRunner> task_runner, int64 delay_ms = 0);
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
#define WaitForIOThread() WaitForThread(TID_IO)
|
|
|
|
#define WaitForUIThread() WaitForThread(TID_UI)
|
2020-09-25 03:40:47 +02:00
|
|
|
#define WaitForFILEThread() WaitForThread(TID_FILE_USER_VISIBLE)
|
2016-11-15 18:56:02 +01:00
|
|
|
#define WaitForIOThreadWithDelay(delay_ms) WaitForThread(TID_IO, delay_ms)
|
|
|
|
#define WaitForUIThreadWithDelay(delay_ms) WaitForThread(TID_UI, delay_ms)
|
2020-09-25 03:40:47 +02:00
|
|
|
#define WaitForFILEThreadWithDelay(delay_ms) \
|
|
|
|
WaitForThread(TID_FILE_USER_VISIBLE, delay_ms)
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Assert that execution is occuring on the named thread.
|
2017-05-17 11:29:28 +02:00
|
|
|
#define EXPECT_UI_THREAD() EXPECT_TRUE(CefCurrentlyOn(TID_UI));
|
|
|
|
#define EXPECT_IO_THREAD() EXPECT_TRUE(CefCurrentlyOn(TID_IO));
|
2020-09-25 03:40:47 +02:00
|
|
|
#define EXPECT_FILE_THREAD() EXPECT_TRUE(CefCurrentlyOn(TID_FILE_USER_VISIBLE));
|
2016-01-19 21:09:01 +01:00
|
|
|
#define EXPECT_RENDERER_THREAD() EXPECT_TRUE(CefCurrentlyOn(TID_RENDERER));
|
|
|
|
|
|
|
|
// Executes |test_impl| on the specified |thread_id|. |event| will be signaled
|
|
|
|
// once execution is complete.
|
|
|
|
void RunOnThread(CefThreadId thread_id,
|
|
|
|
const base::Callback<void(void)>& test_impl,
|
2016-11-15 22:18:41 +01:00
|
|
|
CefRefPtr<CefWaitableEvent> event);
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
#define NAMED_THREAD_TEST(thread_id, test_case_name, test_name) \
|
|
|
|
TEST(test_case_name, test_name) { \
|
|
|
|
CefRefPtr<CefWaitableEvent> event = \
|
|
|
|
CefWaitableEvent::CreateWaitableEvent(true, false); \
|
|
|
|
RunOnThread(thread_id, base::Bind(test_name##Impl), event); \
|
|
|
|
event->Wait(); \
|
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Execute "test_case_name.test_name" test on the named thread. The test
|
|
|
|
// implementation is "void test_nameImpl()".
|
2017-05-17 11:29:28 +02:00
|
|
|
#define UI_THREAD_TEST(test_case_name, test_name) \
|
|
|
|
NAMED_THREAD_TEST(TID_UI, test_case_name, test_name)
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Like RunOnThread() but |test_impl| is responsible for signaling |event|.
|
|
|
|
void RunOnThreadAsync(
|
|
|
|
CefThreadId thread_id,
|
2016-11-15 22:18:41 +01:00
|
|
|
const base::Callback<void(CefRefPtr<CefWaitableEvent>)>& test_impl,
|
|
|
|
CefRefPtr<CefWaitableEvent>);
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
#define NAMED_THREAD_TEST_ASYNC(thread_id, test_case_name, test_name) \
|
|
|
|
TEST(test_case_name, test_name) { \
|
|
|
|
CefRefPtr<CefWaitableEvent> event = \
|
|
|
|
CefWaitableEvent::CreateWaitableEvent(true, false); \
|
|
|
|
RunOnThreadAsync(thread_id, base::Bind(test_name##Impl), event); \
|
|
|
|
event->Wait(); \
|
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Execute "test_case_name.test_name" test on the named thread. The test
|
2016-11-15 22:18:41 +01:00
|
|
|
// implementation is "void test_nameImpl(CefRefPtr<CefWaitableEvent> event)".
|
2017-05-17 11:29:28 +02:00
|
|
|
#define UI_THREAD_TEST_ASYNC(test_case_name, test_name) \
|
|
|
|
NAMED_THREAD_TEST_ASYNC(TID_UI, test_case_name, test_name)
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2020-08-20 00:23:42 +02:00
|
|
|
#endif // CEF_TESTS_CEFTESTS_THREAD_HELPER_H_
|