Commit cb130794 authored by Gabriel Charette's avatar Gabriel Charette Committed by Commit Bot

[MessageLoop tests] Remove obsolete WITH_TASK_SCHEDULER variant

That variant was useful in the early days of TaskScheduler to ensure
compatibility. It is now in the way as other variants of MessageLoop
are being considered. MessageLoop is independent from TaskScheduler
and the integration is now well-covered implicitly by the vast majority
of tests in the codebase.

R=fdoray@chromium.org

Bug: 708584
Change-Id: Id93d8eb4f970e0aa0e1915ffcbc7471190e3d312
Reviewed-on: https://chromium-review.googlesource.com/1232573Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Commit-Queue: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592528}
parent 65181316
...@@ -259,53 +259,7 @@ void PostNTasks(int posts_remaining) { ...@@ -259,53 +259,7 @@ void PostNTasks(int posts_remaining) {
} }
} }
enum class TaskSchedulerAvailability { class MessageLoopTest : public ::testing::Test {};
NO_TASK_SCHEDULER,
WITH_TASK_SCHEDULER,
};
std::string TaskSchedulerAvailabilityToString(
TaskSchedulerAvailability availability) {
switch (availability) {
case TaskSchedulerAvailability::NO_TASK_SCHEDULER:
return "NoTaskScheduler";
case TaskSchedulerAvailability::WITH_TASK_SCHEDULER:
return "WithTaskScheduler";
}
NOTREACHED();
return "Unknown";
}
class MessageLoopTest
: public ::testing::TestWithParam<TaskSchedulerAvailability> {
public:
MessageLoopTest() = default;
~MessageLoopTest() override = default;
void SetUp() override {
if (GetParam() == TaskSchedulerAvailability::WITH_TASK_SCHEDULER)
TaskScheduler::CreateAndStartWithDefaultParams("MessageLoopTest");
}
void TearDown() override {
if (GetParam() == TaskSchedulerAvailability::WITH_TASK_SCHEDULER) {
// Failure to call FlushForTesting() could result in task leaks as tasks
// are skipped on shutdown.
base::TaskScheduler::GetInstance()->FlushForTesting();
base::TaskScheduler::GetInstance()->Shutdown();
base::TaskScheduler::GetInstance()->JoinForTesting();
base::TaskScheduler::SetInstance(nullptr);
}
}
static std::string ParamInfoToString(
::testing::TestParamInfo<TaskSchedulerAvailability> param_info) {
return TaskSchedulerAvailabilityToString(param_info.param);
}
private:
DISALLOW_COPY_AND_ASSIGN(MessageLoopTest);
};
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
void DoNotRun() { void DoNotRun() {
...@@ -345,23 +299,23 @@ void RunTest_AbortDontRunMoreTasks(bool delayed, bool init_java_first) { ...@@ -345,23 +299,23 @@ void RunTest_AbortDontRunMoreTasks(bool delayed, bool init_java_first) {
android::JavaHandlerThreadHelpers::IsExceptionTestException(exception)); android::JavaHandlerThreadHelpers::IsExceptionTestException(exception));
} }
TEST_P(MessageLoopTest, JavaExceptionAbort) { TEST_F(MessageLoopTest, JavaExceptionAbort) {
constexpr bool delayed = false; constexpr bool delayed = false;
constexpr bool init_java_first = false; constexpr bool init_java_first = false;
RunTest_AbortDontRunMoreTasks(delayed, init_java_first); RunTest_AbortDontRunMoreTasks(delayed, init_java_first);
} }
TEST_P(MessageLoopTest, DelayedJavaExceptionAbort) { TEST_F(MessageLoopTest, DelayedJavaExceptionAbort) {
constexpr bool delayed = true; constexpr bool delayed = true;
constexpr bool init_java_first = false; constexpr bool init_java_first = false;
RunTest_AbortDontRunMoreTasks(delayed, init_java_first); RunTest_AbortDontRunMoreTasks(delayed, init_java_first);
} }
TEST_P(MessageLoopTest, JavaExceptionAbortInitJavaFirst) { TEST_F(MessageLoopTest, JavaExceptionAbortInitJavaFirst) {
constexpr bool delayed = false; constexpr bool delayed = false;
constexpr bool init_java_first = true; constexpr bool init_java_first = true;
RunTest_AbortDontRunMoreTasks(delayed, init_java_first); RunTest_AbortDontRunMoreTasks(delayed, init_java_first);
} }
TEST_P(MessageLoopTest, RunTasksWhileShuttingDownJavaThread) { TEST_F(MessageLoopTest, RunTasksWhileShuttingDownJavaThread) {
const int kNumPosts = 6; const int kNumPosts = 6;
DummyTaskObserver observer(kNumPosts, 1); DummyTaskObserver observer(kNumPosts, 1);
...@@ -758,56 +712,15 @@ void RunTest_WaitForIO() { ...@@ -758,56 +712,15 @@ void RunTest_WaitForIO() {
namespace { namespace {
struct MessageLoopTypedTestParams {
MessageLoopTypedTestParams(
MessageLoop::Type type_in,
TaskSchedulerAvailability task_scheduler_availability_in) {
type = type_in;
task_scheduler_availability = task_scheduler_availability_in;
}
MessageLoop::Type type;
TaskSchedulerAvailability task_scheduler_availability;
};
class MessageLoopTypedTest class MessageLoopTypedTest
: public ::testing::TestWithParam<MessageLoopTypedTestParams> { : public ::testing::TestWithParam<MessageLoop::Type> {
public: public:
MessageLoopTypedTest() = default; MessageLoopTypedTest() = default;
~MessageLoopTypedTest() = default; ~MessageLoopTypedTest() = default;
void SetUp() override {
if (GetTaskSchedulerAvailability() ==
TaskSchedulerAvailability::WITH_TASK_SCHEDULER) {
TaskScheduler::CreateAndStartWithDefaultParams("MessageLoopTypedTest");
}
}
void TearDown() override {
if (GetTaskSchedulerAvailability() ==
TaskSchedulerAvailability::WITH_TASK_SCHEDULER) {
// Failure to call FlushForTesting() could result in task leaks as tasks
// are skipped on shutdown.
base::TaskScheduler::GetInstance()->FlushForTesting();
base::TaskScheduler::GetInstance()->Shutdown();
base::TaskScheduler::GetInstance()->JoinForTesting();
base::TaskScheduler::SetInstance(nullptr);
}
}
static std::string ParamInfoToString( static std::string ParamInfoToString(
::testing::TestParamInfo<MessageLoopTypedTestParams> param_info) { ::testing::TestParamInfo<MessageLoop::Type> param_info) {
return MessageLoopTypeToString(param_info.param.type) + "_" + switch (param_info.param) {
TaskSchedulerAvailabilityToString(
param_info.param.task_scheduler_availability);
}
protected:
MessageLoop::Type GetMessageLoopType() { return GetParam().type; }
private:
static std::string MessageLoopTypeToString(MessageLoop::Type type) {
switch (type) {
case MessageLoop::TYPE_DEFAULT: case MessageLoop::TYPE_DEFAULT:
return "Default"; return "Default";
case MessageLoop::TYPE_IO: case MessageLoop::TYPE_IO:
...@@ -821,20 +734,17 @@ class MessageLoopTypedTest ...@@ -821,20 +734,17 @@ class MessageLoopTypedTest
break; break;
} }
NOTREACHED(); NOTREACHED();
return "NotSupported"; return "";
}
TaskSchedulerAvailability GetTaskSchedulerAvailability() {
return GetParam().task_scheduler_availability;
} }
private:
DISALLOW_COPY_AND_ASSIGN(MessageLoopTypedTest); DISALLOW_COPY_AND_ASSIGN(MessageLoopTypedTest);
}; };
} // namespace } // namespace
TEST_P(MessageLoopTypedTest, PostTask) { TEST_P(MessageLoopTypedTest, PostTask) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
// Add tests to message loop // Add tests to message loop
scoped_refptr<Foo> foo(new Foo()); scoped_refptr<Foo> foo(new Foo());
std::string a("a"), b("b"), c("c"), d("d"); std::string a("a"), b("b"), c("c"), d("d");
...@@ -862,7 +772,7 @@ TEST_P(MessageLoopTypedTest, PostTask) { ...@@ -862,7 +772,7 @@ TEST_P(MessageLoopTypedTest, PostTask) {
} }
TEST_P(MessageLoopTypedTest, PostDelayedTask_Basic) { TEST_P(MessageLoopTypedTest, PostDelayedTask_Basic) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
// Test that PostDelayedTask results in a delayed task. // Test that PostDelayedTask results in a delayed task.
...@@ -882,7 +792,7 @@ TEST_P(MessageLoopTypedTest, PostDelayedTask_Basic) { ...@@ -882,7 +792,7 @@ TEST_P(MessageLoopTypedTest, PostDelayedTask_Basic) {
} }
TEST_P(MessageLoopTypedTest, PostDelayedTask_InDelayOrder) { TEST_P(MessageLoopTypedTest, PostDelayedTask_InDelayOrder) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
// Test that two tasks with different delays run in the right order. // Test that two tasks with different delays run in the right order.
int num_tasks = 2; int num_tasks = 2;
...@@ -904,7 +814,7 @@ TEST_P(MessageLoopTypedTest, PostDelayedTask_InDelayOrder) { ...@@ -904,7 +814,7 @@ TEST_P(MessageLoopTypedTest, PostDelayedTask_InDelayOrder) {
} }
TEST_P(MessageLoopTypedTest, PostDelayedTask_InPostOrder) { TEST_P(MessageLoopTypedTest, PostDelayedTask_InPostOrder) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
// Test that two tasks with the same delay run in the order in which they // Test that two tasks with the same delay run in the order in which they
// were posted. // were posted.
...@@ -931,7 +841,7 @@ TEST_P(MessageLoopTypedTest, PostDelayedTask_InPostOrder) { ...@@ -931,7 +841,7 @@ TEST_P(MessageLoopTypedTest, PostDelayedTask_InPostOrder) {
} }
TEST_P(MessageLoopTypedTest, PostDelayedTask_InPostOrder_2) { TEST_P(MessageLoopTypedTest, PostDelayedTask_InPostOrder_2) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
// Test that a delayed task still runs after a normal tasks even if the // Test that a delayed task still runs after a normal tasks even if the
// normal tasks take a long time to run. // normal tasks take a long time to run.
...@@ -957,7 +867,7 @@ TEST_P(MessageLoopTypedTest, PostDelayedTask_InPostOrder_2) { ...@@ -957,7 +867,7 @@ TEST_P(MessageLoopTypedTest, PostDelayedTask_InPostOrder_2) {
} }
TEST_P(MessageLoopTypedTest, PostDelayedTask_InPostOrder_3) { TEST_P(MessageLoopTypedTest, PostDelayedTask_InPostOrder_3) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
// Test that a delayed task still runs after a pile of normal tasks. The key // Test that a delayed task still runs after a pile of normal tasks. The key
// difference between this test and the previous one is that here we return // difference between this test and the previous one is that here we return
...@@ -984,7 +894,7 @@ TEST_P(MessageLoopTypedTest, PostDelayedTask_InPostOrder_3) { ...@@ -984,7 +894,7 @@ TEST_P(MessageLoopTypedTest, PostDelayedTask_InPostOrder_3) {
} }
TEST_P(MessageLoopTypedTest, PostDelayedTask_SharedTimer) { TEST_P(MessageLoopTypedTest, PostDelayedTask_SharedTimer) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
// Test that the interval of the timer, used to run the next delayed task, is // Test that the interval of the timer, used to run the next delayed task, is
// set to a value corresponding to when the next delayed task should run. // set to a value corresponding to when the next delayed task should run.
...@@ -1054,7 +964,7 @@ TEST_P(MessageLoopTypedTest, DISABLED_EnsureDeletion) { ...@@ -1054,7 +964,7 @@ TEST_P(MessageLoopTypedTest, DISABLED_EnsureDeletion) {
bool a_was_deleted = false; bool a_was_deleted = false;
bool b_was_deleted = false; bool b_was_deleted = false;
{ {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
loop.task_runner()->PostTask( loop.task_runner()->PostTask(
FROM_HERE, BindOnce(&RecordDeletionProbe::Run, FROM_HERE, BindOnce(&RecordDeletionProbe::Run,
new RecordDeletionProbe(nullptr, &a_was_deleted))); new RecordDeletionProbe(nullptr, &a_was_deleted)));
...@@ -1077,7 +987,7 @@ TEST_P(MessageLoopTypedTest, DISABLED_EnsureDeletion_Chain) { ...@@ -1077,7 +987,7 @@ TEST_P(MessageLoopTypedTest, DISABLED_EnsureDeletion_Chain) {
bool b_was_deleted = false; bool b_was_deleted = false;
bool c_was_deleted = false; bool c_was_deleted = false;
{ {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
// The scoped_refptr for each of the below is held either by the chained // The scoped_refptr for each of the below is held either by the chained
// RecordDeletionProbe, or the bound RecordDeletionProbe::Run() callback. // RecordDeletionProbe, or the bound RecordDeletionProbe::Run() callback.
RecordDeletionProbe* a = new RecordDeletionProbe(nullptr, &a_was_deleted); RecordDeletionProbe* a = new RecordDeletionProbe(nullptr, &a_was_deleted);
...@@ -1108,7 +1018,7 @@ void NestingFunc(int* depth) { ...@@ -1108,7 +1018,7 @@ void NestingFunc(int* depth) {
} // namespace } // namespace
TEST_P(MessageLoopTypedTest, Nesting) { TEST_P(MessageLoopTypedTest, Nesting) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
int depth = 50; int depth = 50;
ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
...@@ -1118,7 +1028,7 @@ TEST_P(MessageLoopTypedTest, Nesting) { ...@@ -1118,7 +1028,7 @@ TEST_P(MessageLoopTypedTest, Nesting) {
} }
TEST_P(MessageLoopTypedTest, RecursiveDenial1) { TEST_P(MessageLoopTypedTest, RecursiveDenial1) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
EXPECT_TRUE(MessageLoopCurrent::Get()->NestableTasksAllowed()); EXPECT_TRUE(MessageLoopCurrent::Get()->NestableTasksAllowed());
TaskList order; TaskList order;
...@@ -1167,7 +1077,7 @@ void OrderedFunc(TaskList* order, int cookie) { ...@@ -1167,7 +1077,7 @@ void OrderedFunc(TaskList* order, int cookie) {
} // namespace } // namespace
TEST_P(MessageLoopTypedTest, RecursiveDenial3) { TEST_P(MessageLoopTypedTest, RecursiveDenial3) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
EXPECT_TRUE(MessageLoopCurrent::Get()->NestableTasksAllowed()); EXPECT_TRUE(MessageLoopCurrent::Get()->NestableTasksAllowed());
TaskList order; TaskList order;
...@@ -1205,7 +1115,7 @@ TEST_P(MessageLoopTypedTest, RecursiveDenial3) { ...@@ -1205,7 +1115,7 @@ TEST_P(MessageLoopTypedTest, RecursiveDenial3) {
} }
TEST_P(MessageLoopTypedTest, RecursiveSupport1) { TEST_P(MessageLoopTypedTest, RecursiveSupport1) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
TaskList order; TaskList order;
ThreadTaskRunnerHandle::Get()->PostTask( ThreadTaskRunnerHandle::Get()->PostTask(
...@@ -1237,7 +1147,7 @@ TEST_P(MessageLoopTypedTest, RecursiveSupport1) { ...@@ -1237,7 +1147,7 @@ TEST_P(MessageLoopTypedTest, RecursiveSupport1) {
// Tests that non nestable tasks run in FIFO if there are no nested loops. // Tests that non nestable tasks run in FIFO if there are no nested loops.
TEST_P(MessageLoopTypedTest, NonNestableWithNoNesting) { TEST_P(MessageLoopTypedTest, NonNestableWithNoNesting) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
TaskList order; TaskList order;
...@@ -1277,7 +1187,7 @@ void SleepFunc(TaskList* order, int cookie, TimeDelta delay) { ...@@ -1277,7 +1187,7 @@ void SleepFunc(TaskList* order, int cookie, TimeDelta delay) {
// Tests that non nestable tasks don't run when there's code in the call stack. // Tests that non nestable tasks don't run when there's code in the call stack.
TEST_P(MessageLoopTypedTest, NonNestableDelayedInNestedLoop) { TEST_P(MessageLoopTypedTest, NonNestableDelayedInNestedLoop) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
TaskList order; TaskList order;
...@@ -1332,7 +1242,7 @@ void FuncThatQuitsNow() { ...@@ -1332,7 +1242,7 @@ void FuncThatQuitsNow() {
// Tests RunLoopQuit only quits the corresponding MessageLoop::Run. // Tests RunLoopQuit only quits the corresponding MessageLoop::Run.
TEST_P(MessageLoopTypedTest, QuitNow) { TEST_P(MessageLoopTypedTest, QuitNow) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
TaskList order; TaskList order;
...@@ -1366,7 +1276,7 @@ TEST_P(MessageLoopTypedTest, QuitNow) { ...@@ -1366,7 +1276,7 @@ TEST_P(MessageLoopTypedTest, QuitNow) {
// Tests RunLoopQuit only quits the corresponding MessageLoop::Run. // Tests RunLoopQuit only quits the corresponding MessageLoop::Run.
TEST_P(MessageLoopTypedTest, RunLoopQuitTop) { TEST_P(MessageLoopTypedTest, RunLoopQuitTop) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
TaskList order; TaskList order;
...@@ -1396,7 +1306,7 @@ TEST_P(MessageLoopTypedTest, RunLoopQuitTop) { ...@@ -1396,7 +1306,7 @@ TEST_P(MessageLoopTypedTest, RunLoopQuitTop) {
// Tests RunLoopQuit only quits the corresponding MessageLoop::Run. // Tests RunLoopQuit only quits the corresponding MessageLoop::Run.
TEST_P(MessageLoopTypedTest, RunLoopQuitNested) { TEST_P(MessageLoopTypedTest, RunLoopQuitNested) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
TaskList order; TaskList order;
...@@ -1437,7 +1347,7 @@ void QuitAndRunNestedLoop(TaskList* order, ...@@ -1437,7 +1347,7 @@ void QuitAndRunNestedLoop(TaskList* order,
// Test that we can run nested loop after quitting the current one. // Test that we can run nested loop after quitting the current one.
TEST_P(MessageLoopTypedTest, RunLoopNestedAfterQuit) { TEST_P(MessageLoopTypedTest, RunLoopNestedAfterQuit) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
TaskList order; TaskList order;
...@@ -1461,7 +1371,7 @@ TEST_P(MessageLoopTypedTest, RunLoopNestedAfterQuit) { ...@@ -1461,7 +1371,7 @@ TEST_P(MessageLoopTypedTest, RunLoopNestedAfterQuit) {
// Tests RunLoopQuit only quits the corresponding MessageLoop::Run. // Tests RunLoopQuit only quits the corresponding MessageLoop::Run.
TEST_P(MessageLoopTypedTest, RunLoopQuitBogus) { TEST_P(MessageLoopTypedTest, RunLoopQuitBogus) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
TaskList order; TaskList order;
...@@ -1494,7 +1404,7 @@ TEST_P(MessageLoopTypedTest, RunLoopQuitBogus) { ...@@ -1494,7 +1404,7 @@ TEST_P(MessageLoopTypedTest, RunLoopQuitBogus) {
// Tests RunLoopQuit only quits the corresponding MessageLoop::Run. // Tests RunLoopQuit only quits the corresponding MessageLoop::Run.
TEST_P(MessageLoopTypedTest, RunLoopQuitDeep) { TEST_P(MessageLoopTypedTest, RunLoopQuitDeep) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
TaskList order; TaskList order;
...@@ -1562,7 +1472,7 @@ TEST_P(MessageLoopTypedTest, RunLoopQuitDeep) { ...@@ -1562,7 +1472,7 @@ TEST_P(MessageLoopTypedTest, RunLoopQuitDeep) {
// Tests RunLoopQuit works before RunWithID. // Tests RunLoopQuit works before RunWithID.
TEST_P(MessageLoopTypedTest, RunLoopQuitOrderBefore) { TEST_P(MessageLoopTypedTest, RunLoopQuitOrderBefore) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
TaskList order; TaskList order;
...@@ -1582,7 +1492,7 @@ TEST_P(MessageLoopTypedTest, RunLoopQuitOrderBefore) { ...@@ -1582,7 +1492,7 @@ TEST_P(MessageLoopTypedTest, RunLoopQuitOrderBefore) {
// Tests RunLoopQuit works during RunWithID. // Tests RunLoopQuit works during RunWithID.
TEST_P(MessageLoopTypedTest, RunLoopQuitOrderDuring) { TEST_P(MessageLoopTypedTest, RunLoopQuitOrderDuring) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
TaskList order; TaskList order;
...@@ -1607,7 +1517,7 @@ TEST_P(MessageLoopTypedTest, RunLoopQuitOrderDuring) { ...@@ -1607,7 +1517,7 @@ TEST_P(MessageLoopTypedTest, RunLoopQuitOrderDuring) {
// Tests RunLoopQuit works after RunWithID. // Tests RunLoopQuit works after RunWithID.
TEST_P(MessageLoopTypedTest, RunLoopQuitOrderAfter) { TEST_P(MessageLoopTypedTest, RunLoopQuitOrderAfter) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
TaskList order; TaskList order;
...@@ -1662,21 +1572,21 @@ TEST_P(MessageLoopTypedTest, RunLoopQuitOrderAfter) { ...@@ -1662,21 +1572,21 @@ TEST_P(MessageLoopTypedTest, RunLoopQuitOrderAfter) {
#endif #endif
TEST_P(MessageLoopTypedTest, MAYBE_RecursivePosts) { TEST_P(MessageLoopTypedTest, MAYBE_RecursivePosts) {
const int kNumTimes = 1 << 17; const int kNumTimes = 1 << 17;
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
loop.task_runner()->PostTask(FROM_HERE, loop.task_runner()->PostTask(FROM_HERE,
BindOnce(&PostNTasksThenQuit, kNumTimes)); BindOnce(&PostNTasksThenQuit, kNumTimes));
RunLoop().Run(); RunLoop().Run();
} }
TEST_P(MessageLoopTypedTest, NestableTasksAllowedAtTopLevel) { TEST_P(MessageLoopTypedTest, NestableTasksAllowedAtTopLevel) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
EXPECT_TRUE(MessageLoopCurrent::Get()->NestableTasksAllowed()); EXPECT_TRUE(MessageLoopCurrent::Get()->NestableTasksAllowed());
} }
// Nestable tasks shouldn't be allowed to run reentrantly by default (regression // Nestable tasks shouldn't be allowed to run reentrantly by default (regression
// test for https://crbug.com/754112). // test for https://crbug.com/754112).
TEST_P(MessageLoopTypedTest, NestableTasksDisallowedByDefault) { TEST_P(MessageLoopTypedTest, NestableTasksDisallowedByDefault) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
RunLoop run_loop; RunLoop run_loop;
loop.task_runner()->PostTask( loop.task_runner()->PostTask(
FROM_HERE, FROM_HERE,
...@@ -1690,7 +1600,7 @@ TEST_P(MessageLoopTypedTest, NestableTasksDisallowedByDefault) { ...@@ -1690,7 +1600,7 @@ TEST_P(MessageLoopTypedTest, NestableTasksDisallowedByDefault) {
} }
TEST_P(MessageLoopTypedTest, NestableTasksProcessedWhenRunLoopAllows) { TEST_P(MessageLoopTypedTest, NestableTasksProcessedWhenRunLoopAllows) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
RunLoop run_loop; RunLoop run_loop;
loop.task_runner()->PostTask( loop.task_runner()->PostTask(
FROM_HERE, FROM_HERE,
...@@ -1723,7 +1633,7 @@ TEST_P(MessageLoopTypedTest, NestableTasksProcessedWhenRunLoopAllows) { ...@@ -1723,7 +1633,7 @@ TEST_P(MessageLoopTypedTest, NestableTasksProcessedWhenRunLoopAllows) {
} }
TEST_P(MessageLoopTypedTest, NestableTasksAllowedExplicitlyInScope) { TEST_P(MessageLoopTypedTest, NestableTasksAllowedExplicitlyInScope) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
RunLoop run_loop; RunLoop run_loop;
loop.task_runner()->PostTask( loop.task_runner()->PostTask(
FROM_HERE, FROM_HERE,
...@@ -1742,7 +1652,7 @@ TEST_P(MessageLoopTypedTest, NestableTasksAllowedExplicitlyInScope) { ...@@ -1742,7 +1652,7 @@ TEST_P(MessageLoopTypedTest, NestableTasksAllowedExplicitlyInScope) {
} }
TEST_P(MessageLoopTypedTest, NestableTasksAllowedManually) { TEST_P(MessageLoopTypedTest, NestableTasksAllowedManually) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
RunLoop run_loop; RunLoop run_loop;
loop.task_runner()->PostTask( loop.task_runner()->PostTask(
FROM_HERE, FROM_HERE,
...@@ -1769,9 +1679,9 @@ TEST_P(MessageLoopTypedTest, NestableTasksAllowedManually) { ...@@ -1769,9 +1679,9 @@ TEST_P(MessageLoopTypedTest, NestableTasksAllowedManually) {
#endif #endif
TEST_P(MessageLoopTypedTest, MAYBE_MetricsOnlyFromUILoops) { TEST_P(MessageLoopTypedTest, MAYBE_MetricsOnlyFromUILoops) {
MessageLoop loop(GetMessageLoopType()); MessageLoop loop(GetParam());
const bool histograms_expected = GetMessageLoopType() == MessageLoop::TYPE_UI; const bool histograms_expected = GetParam() == MessageLoop::TYPE_UI;
HistogramTester histogram_tester; HistogramTester histogram_tester;
...@@ -1816,34 +1726,18 @@ TEST_P(MessageLoopTypedTest, MAYBE_MetricsOnlyFromUILoops) { ...@@ -1816,34 +1726,18 @@ TEST_P(MessageLoopTypedTest, MAYBE_MetricsOnlyFromUILoops) {
} }
} }
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(,
,
MessageLoopTypedTest, MessageLoopTypedTest,
::testing::Values(MessageLoopTypedTestParams( ::testing::Values(MessageLoop::TYPE_DEFAULT,
MessageLoop::TYPE_DEFAULT,
TaskSchedulerAvailability::NO_TASK_SCHEDULER),
MessageLoopTypedTestParams(
MessageLoop::TYPE_IO, MessageLoop::TYPE_IO,
TaskSchedulerAvailability::NO_TASK_SCHEDULER), MessageLoop::TYPE_UI),
MessageLoopTypedTestParams(
MessageLoop::TYPE_UI,
TaskSchedulerAvailability::NO_TASK_SCHEDULER),
MessageLoopTypedTestParams(
MessageLoop::TYPE_DEFAULT,
TaskSchedulerAvailability::WITH_TASK_SCHEDULER),
MessageLoopTypedTestParams(
MessageLoop::TYPE_IO,
TaskSchedulerAvailability::WITH_TASK_SCHEDULER),
MessageLoopTypedTestParams(
MessageLoop::TYPE_UI,
TaskSchedulerAvailability::WITH_TASK_SCHEDULER)),
MessageLoopTypedTest::ParamInfoToString); MessageLoopTypedTest::ParamInfoToString);
#if defined(OS_WIN) #if defined(OS_WIN)
// Verifies that the MessageLoop ignores WM_QUIT, rather than quitting. // Verifies that the MessageLoop ignores WM_QUIT, rather than quitting.
// Users of MessageLoop typically expect to control when their RunLoops stop // Users of MessageLoop typically expect to control when their RunLoops stop
// Run()ning explicitly, via QuitClosure() etc (see https://crbug.com/720078) // Run()ning explicitly, via QuitClosure() etc (see https://crbug.com/720078)
TEST_P(MessageLoopTest, WmQuitIsIgnored) { TEST_F(MessageLoopTest, WmQuitIsIgnored) {
MessageLoop loop(MessageLoop::TYPE_UI); MessageLoop loop(MessageLoop::TYPE_UI);
// Post a WM_QUIT message to the current thread. // Post a WM_QUIT message to the current thread.
...@@ -1868,7 +1762,7 @@ TEST_P(MessageLoopTest, WmQuitIsIgnored) { ...@@ -1868,7 +1762,7 @@ TEST_P(MessageLoopTest, WmQuitIsIgnored) {
EXPECT_TRUE(task_was_run); EXPECT_TRUE(task_was_run);
} }
TEST_P(MessageLoopTest, WmQuitIsNotIgnoredWithEnableWmQuit) { TEST_F(MessageLoopTest, WmQuitIsNotIgnoredWithEnableWmQuit) {
MessageLoop loop(MessageLoop::TYPE_UI); MessageLoop loop(MessageLoop::TYPE_UI);
static_cast<MessageLoopForUI*>(&loop)->EnableWmQuit(); static_cast<MessageLoopForUI*>(&loop)->EnableWmQuit();
...@@ -1891,24 +1785,24 @@ TEST_P(MessageLoopTest, WmQuitIsNotIgnoredWithEnableWmQuit) { ...@@ -1891,24 +1785,24 @@ TEST_P(MessageLoopTest, WmQuitIsNotIgnoredWithEnableWmQuit) {
run_loop.Run(); run_loop.Run();
} }
TEST_P(MessageLoopTest, PostDelayedTask_SharedTimer_SubPump) { TEST_F(MessageLoopTest, PostDelayedTask_SharedTimer_SubPump) {
RunTest_PostDelayedTask_SharedTimer_SubPump(); RunTest_PostDelayedTask_SharedTimer_SubPump();
} }
// This test occasionally hangs. See http://crbug.com/44567. // This test occasionally hangs. See http://crbug.com/44567.
TEST_P(MessageLoopTest, DISABLED_RecursiveDenial2) { TEST_F(MessageLoopTest, DISABLED_RecursiveDenial2) {
RunTest_RecursiveDenial2(MessageLoop::TYPE_DEFAULT); RunTest_RecursiveDenial2(MessageLoop::TYPE_DEFAULT);
RunTest_RecursiveDenial2(MessageLoop::TYPE_UI); RunTest_RecursiveDenial2(MessageLoop::TYPE_UI);
RunTest_RecursiveDenial2(MessageLoop::TYPE_IO); RunTest_RecursiveDenial2(MessageLoop::TYPE_IO);
} }
TEST_P(MessageLoopTest, RecursiveSupport2) { TEST_F(MessageLoopTest, RecursiveSupport2) {
// This test requires a UI loop. // This test requires a UI loop.
RunTest_RecursiveSupport2(MessageLoop::TYPE_UI); RunTest_RecursiveSupport2(MessageLoop::TYPE_UI);
} }
#endif // defined(OS_WIN) #endif // defined(OS_WIN)
TEST_P(MessageLoopTest, TaskObserver) { TEST_F(MessageLoopTest, TaskObserver) {
const int kNumPosts = 6; const int kNumPosts = 6;
DummyTaskObserver observer(kNumPosts); DummyTaskObserver observer(kNumPosts);
...@@ -1924,15 +1818,15 @@ TEST_P(MessageLoopTest, TaskObserver) { ...@@ -1924,15 +1818,15 @@ TEST_P(MessageLoopTest, TaskObserver) {
} }
#if defined(OS_WIN) #if defined(OS_WIN)
TEST_P(MessageLoopTest, IOHandler) { TEST_F(MessageLoopTest, IOHandler) {
RunTest_IOHandler(); RunTest_IOHandler();
} }
TEST_P(MessageLoopTest, WaitForIO) { TEST_F(MessageLoopTest, WaitForIO) {
RunTest_WaitForIO(); RunTest_WaitForIO();
} }
TEST_P(MessageLoopTest, HighResolutionTimer) { TEST_F(MessageLoopTest, HighResolutionTimer) {
MessageLoop message_loop; MessageLoop message_loop;
Time::EnableHighResolutionTimer(true); Time::EnableHighResolutionTimer(true);
...@@ -2024,7 +1918,7 @@ class MLDestructionObserver : public MessageLoopCurrent::DestructionObserver { ...@@ -2024,7 +1918,7 @@ class MLDestructionObserver : public MessageLoopCurrent::DestructionObserver {
} // namespace } // namespace
TEST_P(MessageLoopTest, DestructionObserverTest) { TEST_F(MessageLoopTest, DestructionObserverTest) {
// Verify that the destruction observer gets called at the very end (after // Verify that the destruction observer gets called at the very end (after
// all the pending tasks have been destroyed). // all the pending tasks have been destroyed).
MessageLoop* loop = new MessageLoop; MessageLoop* loop = new MessageLoop;
...@@ -2051,7 +1945,7 @@ TEST_P(MessageLoopTest, DestructionObserverTest) { ...@@ -2051,7 +1945,7 @@ TEST_P(MessageLoopTest, DestructionObserverTest) {
// Verify that MessageLoop sets ThreadMainTaskRunner::current() and it // Verify that MessageLoop sets ThreadMainTaskRunner::current() and it
// posts tasks on that message loop. // posts tasks on that message loop.
TEST_P(MessageLoopTest, ThreadMainTaskRunner) { TEST_F(MessageLoopTest, ThreadMainTaskRunner) {
MessageLoop loop; MessageLoop loop;
scoped_refptr<Foo> foo(new Foo()); scoped_refptr<Foo> foo(new Foo());
...@@ -2070,7 +1964,7 @@ TEST_P(MessageLoopTest, ThreadMainTaskRunner) { ...@@ -2070,7 +1964,7 @@ TEST_P(MessageLoopTest, ThreadMainTaskRunner) {
EXPECT_EQ(foo->result(), "a"); EXPECT_EQ(foo->result(), "a");
} }
TEST_P(MessageLoopTest, IsType) { TEST_F(MessageLoopTest, IsType) {
MessageLoop loop(MessageLoop::TYPE_UI); MessageLoop loop(MessageLoop::TYPE_UI);
EXPECT_TRUE(loop.IsType(MessageLoop::TYPE_UI)); EXPECT_TRUE(loop.IsType(MessageLoop::TYPE_UI));
EXPECT_FALSE(loop.IsType(MessageLoop::TYPE_IO)); EXPECT_FALSE(loop.IsType(MessageLoop::TYPE_IO));
...@@ -2145,7 +2039,7 @@ LRESULT CALLBACK TestWndProcThunk(HWND hwnd, UINT message, ...@@ -2145,7 +2039,7 @@ LRESULT CALLBACK TestWndProcThunk(HWND hwnd, UINT message,
return 0; return 0;
} }
TEST_P(MessageLoopTest, AlwaysHaveUserMessageWhenNesting) { TEST_F(MessageLoopTest, AlwaysHaveUserMessageWhenNesting) {
MessageLoop loop(MessageLoop::TYPE_UI); MessageLoop loop(MessageLoop::TYPE_UI);
HINSTANCE instance = CURRENT_MODULE(); HINSTANCE instance = CURRENT_MODULE();
WNDCLASSEX wc = {0}; WNDCLASSEX wc = {0};
...@@ -2168,7 +2062,7 @@ TEST_P(MessageLoopTest, AlwaysHaveUserMessageWhenNesting) { ...@@ -2168,7 +2062,7 @@ TEST_P(MessageLoopTest, AlwaysHaveUserMessageWhenNesting) {
} }
#endif // defined(OS_WIN) #endif // defined(OS_WIN)
TEST_P(MessageLoopTest, SetTaskRunner) { TEST_F(MessageLoopTest, SetTaskRunner) {
MessageLoop loop; MessageLoop loop;
scoped_refptr<SingleThreadTaskRunner> new_runner(new TestSimpleTaskRunner()); scoped_refptr<SingleThreadTaskRunner> new_runner(new TestSimpleTaskRunner());
...@@ -2177,7 +2071,7 @@ TEST_P(MessageLoopTest, SetTaskRunner) { ...@@ -2177,7 +2071,7 @@ TEST_P(MessageLoopTest, SetTaskRunner) {
EXPECT_EQ(new_runner, ThreadTaskRunnerHandle::Get()); EXPECT_EQ(new_runner, ThreadTaskRunnerHandle::Get());
} }
TEST_P(MessageLoopTest, OriginalRunnerWorks) { TEST_F(MessageLoopTest, OriginalRunnerWorks) {
MessageLoop loop; MessageLoop loop;
scoped_refptr<SingleThreadTaskRunner> new_runner(new TestSimpleTaskRunner()); scoped_refptr<SingleThreadTaskRunner> new_runner(new TestSimpleTaskRunner());
scoped_refptr<SingleThreadTaskRunner> original_runner(loop.task_runner()); scoped_refptr<SingleThreadTaskRunner> original_runner(loop.task_runner());
...@@ -2189,7 +2083,7 @@ TEST_P(MessageLoopTest, OriginalRunnerWorks) { ...@@ -2189,7 +2083,7 @@ TEST_P(MessageLoopTest, OriginalRunnerWorks) {
EXPECT_EQ(1, foo->test_count()); EXPECT_EQ(1, foo->test_count());
} }
TEST_P(MessageLoopTest, DeleteUnboundLoop) { TEST_F(MessageLoopTest, DeleteUnboundLoop) {
// It should be possible to delete an unbound message loop on a thread which // It should be possible to delete an unbound message loop on a thread which
// already has another active loop. This happens when thread creation fails. // already has another active loop. This happens when thread creation fails.
MessageLoop loop; MessageLoop loop;
...@@ -2200,7 +2094,7 @@ TEST_P(MessageLoopTest, DeleteUnboundLoop) { ...@@ -2200,7 +2094,7 @@ TEST_P(MessageLoopTest, DeleteUnboundLoop) {
EXPECT_EQ(loop.task_runner(), ThreadTaskRunnerHandle::Get()); EXPECT_EQ(loop.task_runner(), ThreadTaskRunnerHandle::Get());
} }
TEST_P(MessageLoopTest, ThreadName) { TEST_F(MessageLoopTest, ThreadName) {
{ {
std::string kThreadName("foo"); std::string kThreadName("foo");
MessageLoop loop; MessageLoop loop;
...@@ -2218,7 +2112,7 @@ TEST_P(MessageLoopTest, ThreadName) { ...@@ -2218,7 +2112,7 @@ TEST_P(MessageLoopTest, ThreadName) {
// Verify that tasks posted to and code running in the scope of the same // Verify that tasks posted to and code running in the scope of the same
// MessageLoop access the same SequenceLocalStorage values. // MessageLoop access the same SequenceLocalStorage values.
TEST_P(MessageLoopTest, SequenceLocalStorageSetGet) { TEST_F(MessageLoopTest, SequenceLocalStorageSetGet) {
MessageLoop loop; MessageLoop loop;
SequenceLocalStorageSlot<int> slot; SequenceLocalStorageSlot<int> slot;
...@@ -2240,7 +2134,7 @@ TEST_P(MessageLoopTest, SequenceLocalStorageSetGet) { ...@@ -2240,7 +2134,7 @@ TEST_P(MessageLoopTest, SequenceLocalStorageSetGet) {
// Verify that tasks posted to and code running in different MessageLoops access // Verify that tasks posted to and code running in different MessageLoops access
// different SequenceLocalStorage values. // different SequenceLocalStorage values.
TEST_P(MessageLoopTest, SequenceLocalStorageDifferentMessageLoops) { TEST_F(MessageLoopTest, SequenceLocalStorageDifferentMessageLoops) {
SequenceLocalStorageSlot<int> slot; SequenceLocalStorageSlot<int> slot;
{ {
...@@ -2265,13 +2159,6 @@ TEST_P(MessageLoopTest, SequenceLocalStorageDifferentMessageLoops) { ...@@ -2265,13 +2159,6 @@ TEST_P(MessageLoopTest, SequenceLocalStorageDifferentMessageLoops) {
EXPECT_NE(slot.Get(), 11); EXPECT_NE(slot.Get(), 11);
} }
INSTANTIATE_TEST_CASE_P(
,
MessageLoopTest,
::testing::Values(TaskSchedulerAvailability::NO_TASK_SCHEDULER,
TaskSchedulerAvailability::WITH_TASK_SCHEDULER),
MessageLoopTest::ParamInfoToString);
namespace { namespace {
class PostTaskOnDestroy { class PostTaskOnDestroy {
......
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