Chromium Code Reviews| Index: chrome/browser/push_messaging/push_messaging_service_unittest.cc |
| diff --git a/chrome/browser/push_messaging/push_messaging_service_unittest.cc b/chrome/browser/push_messaging/push_messaging_service_unittest.cc |
| index 19167e4b1e75482f415716974daf48fc9a16270d..902e44966d04641670d1d5c418dc6011380202eb 100644 |
| --- a/chrome/browser/push_messaging/push_messaging_service_unittest.cc |
| +++ b/chrome/browser/push_messaging/push_messaging_service_unittest.cc |
| @@ -11,6 +11,7 @@ |
| #include "base/command_line.h" |
| #include "base/macros.h" |
| +#include "base/metrics/field_trial.h" |
| #include "base/run_loop.h" |
| #include "base/thread_task_runner_handle.h" |
| #include "chrome/browser/permissions/permission_manager.h" |
| @@ -31,6 +32,10 @@ |
| #include "content/public/test/test_browser_thread_bundle.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +#if defined(OS_ANDROID) |
| +#include "components/gcm_driver/instance_id/instance_id_android.h" |
| +#endif // OS_ANDROID |
| + |
| namespace { |
| const char kTestOrigin[] = "https://example.com"; |
| @@ -88,7 +93,12 @@ scoped_ptr<KeyedService> BuildFakeGCMProfileService( |
| class PushMessagingServiceTest : public ::testing::Test { |
| public: |
| - PushMessagingServiceTest() { |
| + PushMessagingServiceTest() |
| + : thread_bundle_( |
| + content::TestBrowserThreadBundle::NESTED_JAVA_ON_ANDROID), |
| + field_trial_list_(nullptr /* entropy_provider */) { |
| + base::FieldTrialList::CreateFieldTrial("InstanceID", "Enabled"); |
|
Peter Beverloo
2016/04/11 15:47:56
Why are you removing the enable-InstanceID-field-t
johnme
2016/04/21 10:58:37
Hadn't yet rebased this. Removed.
|
| + |
| // Override the permission context factory to always allow Push Messaging. |
| PushMessagingPermissionContextFactory::GetInstance()->SetTestingFactory( |
| &profile_, &BuildFakePushMessagingPermissionContext); |
| @@ -100,20 +110,32 @@ class PushMessagingServiceTest : public ::testing::Test { |
| ~PushMessagingServiceTest() override {} |
| +#if defined(OS_ANDROID) |
| + void SetUp() override { |
| + instance_id::InstanceIDAndroid::ClearDataAndSetUseFakeForTesting(true); |
| + } |
| + void TearDown() override { |
| + instance_id::InstanceIDAndroid::ClearDataAndSetUseFakeForTesting(false); |
| + } |
| +#endif // OS_ANDROID |
| + |
| // Callback to use when the subscription may have been subscribed. |
| void DidRegister(std::string* subscription_id_out, |
| std::vector<uint8_t>* p256dh_out, |
| std::vector<uint8_t>* auth_out, |
| + base::Closure done_callback, |
| const std::string& registration_id, |
| const std::vector<uint8_t>& p256dh, |
| const std::vector<uint8_t>& auth, |
| content::PushRegistrationStatus status) { |
| - ASSERT_EQ(content::PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE, |
| + EXPECT_EQ(content::PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE, |
| status); |
| *subscription_id_out = registration_id; |
| *p256dh_out = p256dh; |
| *auth_out = auth; |
| + |
| + done_callback.Run(); |
| } |
| // Callback to use when observing messages dispatched by the push service. |
| @@ -137,6 +159,7 @@ class PushMessagingServiceTest : public ::testing::Test { |
| private: |
| content::TestBrowserThreadBundle thread_bundle_; |
| PushMessagingTestingProfile profile_; |
| + base::FieldTrialList field_trial_list_; |
| }; |
| TEST_F(PushMessagingServiceTest, PayloadEncryptionTest) { |
| @@ -152,6 +175,8 @@ TEST_F(PushMessagingServiceTest, PayloadEncryptionTest) { |
| std::string subscription_id; |
| std::vector<uint8_t> p256dh, auth; |
| + base::RunLoop run_loop; |
| + |
| // (2) Subscribe for Push Messaging, and verify that we've got the required |
| // information in order to be able to create encrypted messages. |
| content::PushSubscriptionOptions options; |
| @@ -160,11 +185,11 @@ TEST_F(PushMessagingServiceTest, PayloadEncryptionTest) { |
| push_service->SubscribeFromWorker( |
| origin, kTestServiceWorkerId, options, |
| base::Bind(&PushMessagingServiceTest::DidRegister, base::Unretained(this), |
| - &subscription_id, &p256dh, &auth)); |
| + &subscription_id, &p256dh, &auth, run_loop.QuitClosure())); |
| EXPECT_EQ(0u, subscription_id.size()); // this must be asynchronous |
| - base::RunLoop().RunUntilIdle(); |
| + run_loop.Run(); |
| ASSERT_GT(subscription_id.size(), 0u); |
| ASSERT_GT(p256dh.size(), 0u); |