Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Unified Diff: components/gcm_driver/gcm_client_impl_unittest.cc

Issue 2578583002: Provide a mechanism for the GCM driver to send message receipts to GCM.
Patch Set: Formatting Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/gcm_driver/gcm_client_impl_unittest.cc
diff --git a/components/gcm_driver/gcm_client_impl_unittest.cc b/components/gcm_driver/gcm_client_impl_unittest.cc
index 827a6056d468ff5ed8c453cc1b578ccfa889cf69..cee54a1e243511fff18a6d4f378690074a19e4f4 100644
--- a/components/gcm_driver/gcm_client_impl_unittest.cc
+++ b/components/gcm_driver/gcm_client_impl_unittest.cc
@@ -15,8 +15,13 @@
#include "base/files/scoped_temp_dir.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
+#include "base/metrics/field_trial.h"
+#include "base/metrics/field_trial_param_associator.h"
+#include "base/metrics/field_trial_params.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/histogram_tester.h"
+#include "base/test/mock_entropy_provider.h"
+#include "base/test/scoped_feature_list.h"
#include "base/test/test_mock_time_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/clock.h"
@@ -268,6 +273,7 @@ class GCMClientImplTest : public testing::Test,
void SetUp() override;
void SetUpUrlFetcherFactory();
+ void InitializeFieldTrials();
void BuildGCMClient(base::TimeDelta clock_step);
void InitializeGCMClient();
@@ -309,8 +315,10 @@ class GCMClientImplTest : public testing::Test,
void OnSendFinished(const std::string& app_id,
const std::string& message_id,
GCMClient::Result result) override {}
- void OnMessageReceived(const std::string& registration_id,
- const IncomingMessage& message) override;
+ void OnMessageReceived(
+ const std::string& registration_id,
+ const IncomingMessage& message,
+ const MessageReceiptCallback& optional_receipt_callback) override;
void OnMessagesDeleted(const std::string& app_id) override;
void OnMessageSendError(
const std::string& app_id,
@@ -412,6 +420,8 @@ class GCMClientImplTest : public testing::Test,
GCMClient::SendErrorDetails last_error_details_;
base::Time last_token_fetch_time_;
std::vector<AccountMapping> last_account_mappings_;
+ base::test::ScopedFeatureList scoped_feature_list_;
+ std::unique_ptr<base::FieldTrialList> field_trial_list_;
std::unique_ptr<GCMClientImpl> gcm_client_;
@@ -442,6 +452,7 @@ void GCMClientImplTest::SetUp() {
InitializeGCMClient();
StartGCMClient();
SetUpUrlFetcherFactory();
+ InitializeFieldTrials();
ASSERT_NO_FATAL_FAILURE(
CompleteCheckin(kDeviceAndroidId, kDeviceSecurityToken, std::string(),
std::map<std::string, std::string>()));
@@ -451,6 +462,32 @@ void GCMClientImplTest::SetUpUrlFetcherFactory() {
url_fetcher_factory_.set_remove_fetcher_on_delete(true);
}
+void GCMClientImplTest::InitializeFieldTrials() {
+ const std::string kTrialName = "TestGCMMessageReceipts";
+ const std::string kGroupName = "UnusedName";
+ // kFeatureName and kParam name are also defined in gcm_client_impl.cc.
+ const std::string kFeatureName = "GCMMessageReceiptsFeature";
+ const std::string kParamName = "message_receipts_to_send";
+
+ // Create the global list of field trials.
+ field_trial_list_ = base::MakeUnique<base::FieldTrialList>(
+ base::MakeUnique<base::MockEntropyProvider>());
+
+ // Create a field trial with all message receipts enabled.
+ scoped_refptr<base::FieldTrial> trial =
+ base::FieldTrialList::CreateFieldTrial(kTrialName, kGroupName);
+ std::map<std::string, std::string> trial_params;
+ trial_params[kParamName] = "2"; // SEND_ALL.
+ base::FieldTrialParamAssociator::GetInstance()->AssociateFieldTrialParams(
+ kTrialName, kGroupName, trial_params);
+
+ // Create a FeatureList and add the new trial to the list.
+ std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
+ feature_list->RegisterFieldTrialOverride(
+ kFeatureName, base::FeatureList::OVERRIDE_ENABLE_FEATURE, trial.get());
+ scoped_feature_list_.InitWithFeatureList(std::move(feature_list));
Peter Beverloo 2017/02/15 15:17:15 Can we have a test for making sure that *disabling
harkness 2017/02/22 17:19:32 Done.
+}
+
void GCMClientImplTest::PumpLoopUntilIdle() {
task_runner_->RunUntilIdle();
}
@@ -616,8 +653,10 @@ void GCMClientImplTest::OnGCMReady(
last_token_fetch_time_ = last_token_fetch_time;
}
-void GCMClientImplTest::OnMessageReceived(const std::string& registration_id,
- const IncomingMessage& message) {
+void GCMClientImplTest::OnMessageReceived(
+ const std::string& registration_id,
+ const IncomingMessage& message,
+ const MessageReceiptCallback& optional_receipt_callback) {
last_event_ = MESSAGE_RECEIVED;
last_app_id_ = registration_id;
last_message_ = message;
@@ -936,6 +975,9 @@ TEST_F(GCMClientImplTest, DispatchDownstreamMessage) {
EXPECT_TRUE(message3.IsValid());
ReceiveMessageFromMCS(message3);
+ // TODO(harkness): Add a check for invalid app handler once the
+ // DefaultAppHandler is removed.
+
EXPECT_NE(MESSAGE_RECEIVED, last_event());
EXPECT_NE(kExtensionAppId, last_app_id());
}
@@ -1789,6 +1831,24 @@ TEST_F(GCMClientInstanceIDTest, DispatchDownstreamMessageWithoutSubtype) {
EXPECT_NE(MESSAGE_RECEIVED, last_event());
+ // Check that the last message sent was a message receipt for a failed message
+ // and that it had the values expected.
+ mcs_proto::DataMessageStanza stanza =
+ mcs_client()->last_data_message_stanza();
+ EXPECT_EQ(kExtensionAppId, stanza.category());
+ const auto& app_data = stanza.app_data();
+ ASSERT_EQ(3, app_data.size());
+ for (const auto& pair : app_data) {
+ if (pair.key() == "message_id")
+ EXPECT_EQ("", pair.value());
+ else if (pair.key() == "status")
+ EXPECT_EQ("2", pair.value());
+ else if (pair.key() == "message_type")
+ EXPECT_EQ("message_receipt", pair.value());
+ else
+ FAIL() << "Unexpected key: " << pair.key();
+ }
+
reset_last_event();
// Message for kSender will be received.
@@ -1850,6 +1910,24 @@ TEST_F(GCMClientInstanceIDTest, DispatchDownstreamMessageWithSubtype) {
EXPECT_NE(MESSAGE_RECEIVED, last_event());
+ // Check that the last message sent was a message receipt for a failed message
+ // and that it had the values expected.
+ mcs_proto::DataMessageStanza stanza =
+ mcs_client()->last_data_message_stanza();
+ EXPECT_EQ(kSubtypeAppId, stanza.category());
+ const auto& app_data = stanza.app_data();
+ ASSERT_EQ(3, app_data.size());
+ for (const auto& pair : app_data) {
+ if (pair.key() == "message_id")
+ EXPECT_EQ("", pair.value());
+ else if (pair.key() == "status")
+ EXPECT_EQ("2", pair.value());
+ else if (pair.key() == "message_type")
+ EXPECT_EQ("message_receipt", pair.value());
+ else
+ FAIL() << "Unexpected key: " << pair.key();
+ }
+
reset_last_event();
// Message for kSender will be received.

Powered by Google App Engine
This is Rietveld 408576698