Index: components/gcm_driver/instance_id/instance_id_driver_unittest.cc |
diff --git a/components/gcm_driver/instance_id/instance_id_driver_unittest.cc b/components/gcm_driver/instance_id/instance_id_driver_unittest.cc |
index 8997296aca9b1dad49e6749524421ca3094672b6..f6184a6b3baa45b328b6aa7c494681da2335e1b2 100644 |
--- a/components/gcm_driver/instance_id/instance_id_driver_unittest.cc |
+++ b/components/gcm_driver/instance_id/instance_id_driver_unittest.cc |
@@ -17,6 +17,11 @@ |
#include "components/gcm_driver/instance_id/instance_id.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+#if defined(OS_ANDROID) |
+#include "components/gcm_driver/instance_id/instance_id_android.h" |
+#include "content/public/test/nested_message_pump_android.h" |
+#endif // OS_ANDROID |
+ |
namespace instance_id { |
namespace { |
@@ -51,6 +56,7 @@ class InstanceIDDriverTest : public testing::Test { |
~InstanceIDDriverTest() override; |
// testing::Test: |
+ void TearDown() override; |
void SetUp() override; |
void WaitForAsyncOperation(); |
@@ -81,7 +87,7 @@ class InstanceIDDriverTest : public testing::Test { |
void GetTokenCompleted(const std::string& token, InstanceID::Result result); |
void DeleteTokenCompleted(InstanceID::Result result); |
- base::MessageLoopForUI message_loop_; |
+ scoped_ptr<base::MessageLoop> message_loop_; |
scoped_ptr<FakeGCMDriverForInstanceID> gcm_driver_; |
scoped_ptr<InstanceIDDriver> driver_; |
@@ -99,16 +105,34 @@ class InstanceIDDriverTest : public testing::Test { |
InstanceIDDriverTest::InstanceIDDriverTest() |
: result_(InstanceID::UNKNOWN_ERROR), |
async_operation_completed_(false) { |
+#if defined(OS_ANDROID) |
+ // Need a NestedMessagePumpAndroid so WaitForAsyncOperation's RunLoop will run |
+ // InstanceIDWithSubtype.java's AsyncTask onPostExecute methods. |
+ message_loop_.reset(new base::MessageLoop( |
+ scoped_ptr<base::MessagePump>(new content::NestedMessagePumpAndroid()))); |
+ static_cast<base::MessageLoopForUI*>(message_loop_.get())->Start(); |
Peter Beverloo
2016/04/11 14:57:05
You're casting an instance of base::MessageLoop to
johnme
2016/04/14 18:32:42
Bizarrely, this seems to be what you're supposed t
|
+#else |
+ message_loop_.reset(new base::MessageLoopForUI()); |
+#endif // OS_ANDROID |
} |
InstanceIDDriverTest::~InstanceIDDriverTest() { |
} |
void InstanceIDDriverTest::SetUp() { |
+#if defined(OS_ANDROID) |
+ InstanceIDAndroid::ClearDataAndSetUseFakeForTesting(true); |
+#endif // OS_ANDROID |
gcm_driver_.reset(new FakeGCMDriverForInstanceID); |
RecreateInstanceIDDriver(); |
} |
+void InstanceIDDriverTest::TearDown() { |
+#if defined(OS_ANDROID) |
+ InstanceIDAndroid::ClearDataAndSetUseFakeForTesting(false); |
+#endif // OS_ANDROID |
+} |
+ |
void InstanceIDDriverTest::RecreateInstanceIDDriver() { |
driver_.reset(new InstanceIDDriver(gcm_driver_.get())); |
} |