Index: components/arc/test/fake_app_instance.cc |
diff --git a/components/arc/test/fake_app_instance.cc b/components/arc/test/fake_app_instance.cc |
index 15a49c7456257163cf68badbc0764c281d1f76ab..2ea1ff0255e0e529c187991612e32f6341a9a144 100644 |
--- a/components/arc/test/fake_app_instance.cc |
+++ b/components/arc/test/fake_app_instance.cc |
@@ -12,6 +12,7 @@ |
#include "base/files/file_path.h" |
#include "base/files/file_util.h" |
#include "base/path_service.h" |
+#include "base/run_loop.h" |
#include "mojo/common/common_type_converters.h" |
namespace mojo { |
@@ -109,8 +110,18 @@ void FakeAppInstance::WaitForIncomingMethodCall() { |
} |
void FakeAppInstance::WaitForOnAppInstanceReady() { |
- WaitForIncomingMethodCall(); // Wait for Init(). |
- WaitForIncomingMethodCall(); // Wait for RefreshAppList(). |
+ // Several messages are sent back and forth when OnAppInstanceReady() is |
+ // called. Normally, it would be preferred to use a single |
+ // WaitForIncomingMethodCall() to wait for each method individually, but |
+ // QueryVersion() does require processing on the I/O thread, so |
+ // RunUntilIdle() is required to correctly dispatch it. On slower machines |
+ // (and when running under Valgrind), the two thread hops needed to send and |
+ // dispatch each Mojo message might not be picked up by a single |
+ // RunUntilIdle(), so keep pumping the message loop until all expected |
+ // messages are. |
+ while (refresh_app_list_count_ != 1) { |
+ base::RunLoop().RunUntilIdle(); |
+ } |
} |
} // namespace arc |