Commit a42e46ee authored by toyoshim's avatar toyoshim Committed by Commit bot

Use RunLoop, but do not call RunUntilIdle() multiple times

In unit tests for MidiManager, RunLoop was used, and is used to wait
a posted task finished. But, RunUntilIdle() can not be called
multiple times. To avoid this restriction, we can just create new
instance again for another iteration.

TEST=media_unittests

Review URL: https://codereview.chromium.org/656793004

Cr-Commit-Position: refs/heads/master@{#300240}
parent 0e460196
...@@ -75,24 +75,11 @@ class FakeMidiManagerClient : public MidiManagerClient { ...@@ -75,24 +75,11 @@ class FakeMidiManagerClient : public MidiManagerClient {
int client_id() const { return client_id_; } int client_id() const { return client_id_; }
MidiResult result() const { return result_; } MidiResult result() const { return result_; }
void HandleContinuationMessage() {
// Stop posting a dummy message once CompleteStartSession() is invoked.
if (!wait_for_result_)
return;
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&FakeMidiManagerClient::HandleContinuationMessage,
base::Unretained(this)));
}
MidiResult WaitForResult() { MidiResult WaitForResult() {
base::RunLoop run_loop; while (wait_for_result_) {
// Post a dummy task not to stop the following event loop. base::RunLoop run_loop;
HandleContinuationMessage(); run_loop.RunUntilIdle();
// CompleteStartSession() is called inside the message loop on the same }
// thread. Protection for |wait_for_result_| is not needed.
run_loop.RunUntilIdle();
return result(); return result();
} }
......
...@@ -178,9 +178,10 @@ class MidiManagerUsbTest : public ::testing::Test { ...@@ -178,9 +178,10 @@ class MidiManagerUsbTest : public ::testing::Test {
void RunCallbackUntilCallbackInvoked( void RunCallbackUntilCallbackInvoked(
bool result, UsbMidiDevice::Devices* devices) { bool result, UsbMidiDevice::Devices* devices) {
factory_->callback_.Run(result, devices); factory_->callback_.Run(result, devices);
base::RunLoop run_loop; while (!client_->complete_start_session_) {
while (!client_->complete_start_session_) base::RunLoop run_loop;
run_loop.RunUntilIdle(); run_loop.RunUntilIdle();
}
} }
scoped_ptr<MidiManagerUsbForTesting> manager_; scoped_ptr<MidiManagerUsbForTesting> manager_;
......
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