Commit 6d4d0812 authored by Gabriel Charette's avatar Gabriel Charette Committed by Commit Bot

[base] Tweak MessagePumpTests with latest strong ordering expectations

In particular:
 A) Don't need to ScheduleWork around Run() in
    QuitStopsWorkWithNestedRunLoop
 B) Require GMOCK to verify that all expectations resolve InSequence
 C) Out-of-band invocations of DoIdleWork should only happen *after*
    DoWork (unexpected but loosened on OS_IOS for ignored reasons;
    keeping for now).

This is a prerequisite to make the diff smaller for tests in
https://chromium-review.googlesource.com/c/chromium/src/+/2226216

Bug: 1074019
Change-Id: I0da743e9a6737433a69cdc81669981833fbe6ab0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2313697
Commit-Queue: François Doray <fdoray@chromium.org>
Auto-Submit: Gabriel Charette <gab@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791359}
parent 33d624de
...@@ -57,6 +57,7 @@ class MessagePumpTest : public ::testing::TestWithParam<MessagePumpType> { ...@@ -57,6 +57,7 @@ class MessagePumpTest : public ::testing::TestWithParam<MessagePumpType> {
} // namespace } // namespace
TEST_P(MessagePumpTest, QuitStopsWork) { TEST_P(MessagePumpTest, QuitStopsWork) {
testing::InSequence sequence;
testing::StrictMock<MockMessagePumpDelegate> delegate; testing::StrictMock<MockMessagePumpDelegate> delegate;
// Not expecting any calls to DoIdleWork after quitting. // Not expecting any calls to DoIdleWork after quitting.
...@@ -80,19 +81,24 @@ TEST_P(MessagePumpTest, QuitStopsWorkWithNestedRunLoop) { ...@@ -80,19 +81,24 @@ TEST_P(MessagePumpTest, QuitStopsWorkWithNestedRunLoop) {
// (original) run loop. The test verifies that there are no extra calls to // (original) run loop. The test verifies that there are no extra calls to
// DoWork after the outer loop quits. // DoWork after the outer loop quits.
EXPECT_CALL(delegate, DoWork).WillOnce(Invoke([&] { EXPECT_CALL(delegate, DoWork).WillOnce(Invoke([&] {
message_pump_->ScheduleWork();
message_pump_->Run(&nested_delegate); message_pump_->Run(&nested_delegate);
message_pump_->ScheduleWork(); // A null NextWorkInfo indicates immediate follow-up work.
return MessagePump::Delegate::NextWorkInfo{TimeTicks::Max()}; return MessagePump::Delegate::NextWorkInfo();
})); }));
EXPECT_CALL(nested_delegate, DoWork).WillOnce(Invoke([&] { EXPECT_CALL(nested_delegate, DoWork).WillOnce(Invoke([&] {
// Quit the nested run loop. // Quit the nested run loop.
message_pump_->Quit(); message_pump_->Quit();
// The underlying pump should process the next task in the first run-level
// regardless of whether the nested run-level indicates there's no more work
// (e.g. can happen when the only remaining tasks are non-nestable).
return MessagePump::Delegate::NextWorkInfo{TimeTicks::Max()}; return MessagePump::Delegate::NextWorkInfo{TimeTicks::Max()};
})); }));
// The outer pump may or may not trigger idle work at this point. // The outer pump may or may not trigger idle work at this point.
// TODO(scheduler-dev): This is unexpected, attempt to remove this legacy
// allowance.
EXPECT_CALL(delegate, DoIdleWork()).Times(AnyNumber()); EXPECT_CALL(delegate, DoIdleWork()).Times(AnyNumber());
EXPECT_CALL(delegate, DoWork).WillOnce(Invoke([this] { EXPECT_CALL(delegate, DoWork).WillOnce(Invoke([this] {
message_pump_->Quit(); message_pump_->Quit();
return MessagePump::Delegate::NextWorkInfo{TimeTicks::Max()}; return MessagePump::Delegate::NextWorkInfo{TimeTicks::Max()};
...@@ -189,35 +195,39 @@ TEST_P(MessagePumpTest, TimerSlackWithLongDelays) { ...@@ -189,35 +195,39 @@ TEST_P(MessagePumpTest, TimerSlackWithLongDelays) {
} }
TEST_P(MessagePumpTest, RunWithoutScheduleWorkInvokesDoWork) { TEST_P(MessagePumpTest, RunWithoutScheduleWorkInvokesDoWork) {
testing::InSequence sequence;
testing::StrictMock<MockMessagePumpDelegate> delegate; testing::StrictMock<MockMessagePumpDelegate> delegate;
#if defined(OS_IOS)
EXPECT_CALL(delegate, DoIdleWork).Times(AnyNumber());
#endif
EXPECT_CALL(delegate, DoWork).WillOnce(Invoke([this] { EXPECT_CALL(delegate, DoWork).WillOnce(Invoke([this] {
message_pump_->Quit(); message_pump_->Quit();
return MessagePump::Delegate::NextWorkInfo{TimeTicks::Max()}; return MessagePump::Delegate::NextWorkInfo{TimeTicks::Max()};
})); }));
#if defined(OS_IOS)
EXPECT_CALL(delegate, DoIdleWork).Times(AnyNumber());
#endif
message_pump_->Run(&delegate); message_pump_->Run(&delegate);
} }
TEST_P(MessagePumpTest, NestedRunWithoutScheduleWorkInvokesDoWork) { TEST_P(MessagePumpTest, NestedRunWithoutScheduleWorkInvokesDoWork) {
testing::InSequence sequence;
testing::StrictMock<MockMessagePumpDelegate> delegate; testing::StrictMock<MockMessagePumpDelegate> delegate;
#if defined(OS_IOS)
EXPECT_CALL(delegate, DoIdleWork).Times(AnyNumber());
#endif
EXPECT_CALL(delegate, DoWork).WillOnce(Invoke([this] { EXPECT_CALL(delegate, DoWork).WillOnce(Invoke([this] {
testing::StrictMock<MockMessagePumpDelegate> nested_delegate; testing::StrictMock<MockMessagePumpDelegate> nested_delegate;
#if defined(OS_IOS)
EXPECT_CALL(nested_delegate, DoIdleWork).Times(AnyNumber());
#endif
EXPECT_CALL(nested_delegate, DoWork).WillOnce(Invoke([this] { EXPECT_CALL(nested_delegate, DoWork).WillOnce(Invoke([this] {
message_pump_->Quit(); message_pump_->Quit();
return MessagePump::Delegate::NextWorkInfo{TimeTicks::Max()}; return MessagePump::Delegate::NextWorkInfo{TimeTicks::Max()};
})); }));
#if defined(OS_IOS)
EXPECT_CALL(nested_delegate, DoIdleWork).Times(AnyNumber());
#endif
message_pump_->Run(&nested_delegate); message_pump_->Run(&nested_delegate);
message_pump_->Quit(); message_pump_->Quit();
return MessagePump::Delegate::NextWorkInfo{TimeTicks::Max()}; return MessagePump::Delegate::NextWorkInfo{TimeTicks::Max()};
})); }));
#if defined(OS_IOS)
EXPECT_CALL(delegate, DoIdleWork).Times(AnyNumber());
#endif
message_pump_->Run(&delegate); message_pump_->Run(&delegate);
} }
......
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