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

Side by Side 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: Added a callback entry point to GCMDriver, moved MessageReceiptCallback to gcm_message_status. 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/gcm_driver/gcm_client_impl.h" 5 #include "components/gcm_driver/gcm_client_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <initializer_list> 9 #include <initializer_list>
10 #include <memory> 10 #include <memory>
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 void OnRegisterFinished(const linked_ptr<RegistrationInfo>& registration_info, 303 void OnRegisterFinished(const linked_ptr<RegistrationInfo>& registration_info,
304 const std::string& registration_id, 304 const std::string& registration_id,
305 GCMClient::Result result) override; 305 GCMClient::Result result) override;
306 void OnUnregisterFinished( 306 void OnUnregisterFinished(
307 const linked_ptr<RegistrationInfo>& registration_info, 307 const linked_ptr<RegistrationInfo>& registration_info,
308 GCMClient::Result result) override; 308 GCMClient::Result result) override;
309 void OnSendFinished(const std::string& app_id, 309 void OnSendFinished(const std::string& app_id,
310 const std::string& message_id, 310 const std::string& message_id,
311 GCMClient::Result result) override {} 311 GCMClient::Result result) override {}
312 void OnMessageReceived(const std::string& registration_id, 312 void OnMessageReceived(const std::string& registration_id,
313 const IncomingMessage& message) override; 313 const IncomingMessage& message,
314 const MessageReceiptCallback& callback) override;
314 void OnMessagesDeleted(const std::string& app_id) override; 315 void OnMessagesDeleted(const std::string& app_id) override;
315 void OnMessageSendError( 316 void OnMessageSendError(
316 const std::string& app_id, 317 const std::string& app_id,
317 const gcm::GCMClient::SendErrorDetails& send_error_details) override; 318 const gcm::GCMClient::SendErrorDetails& send_error_details) override;
318 void OnSendAcknowledged(const std::string& app_id, 319 void OnSendAcknowledged(const std::string& app_id,
319 const std::string& message_id) override; 320 const std::string& message_id) override;
320 void OnGCMReady(const std::vector<AccountMapping>& account_mappings, 321 void OnGCMReady(const std::vector<AccountMapping>& account_mappings,
321 const base::Time& last_token_fetch_time) override; 322 const base::Time& last_token_fetch_time) override;
322 void OnActivityRecorded() override {} 323 void OnActivityRecorded() override {}
323 void OnConnected(const net::IPEndPoint& ip_endpoint) override {} 324 void OnConnected(const net::IPEndPoint& ip_endpoint) override {}
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 } 610 }
610 611
611 void GCMClientImplTest::OnGCMReady( 612 void GCMClientImplTest::OnGCMReady(
612 const std::vector<AccountMapping>& account_mappings, 613 const std::vector<AccountMapping>& account_mappings,
613 const base::Time& last_token_fetch_time) { 614 const base::Time& last_token_fetch_time) {
614 last_event_ = LOADING_COMPLETED; 615 last_event_ = LOADING_COMPLETED;
615 last_account_mappings_ = account_mappings; 616 last_account_mappings_ = account_mappings;
616 last_token_fetch_time_ = last_token_fetch_time; 617 last_token_fetch_time_ = last_token_fetch_time;
617 } 618 }
618 619
619 void GCMClientImplTest::OnMessageReceived(const std::string& registration_id, 620 void GCMClientImplTest::OnMessageReceived(
620 const IncomingMessage& message) { 621 const std::string& registration_id,
622 const IncomingMessage& message,
623 const MessageReceiptCallback& callback) {
621 last_event_ = MESSAGE_RECEIVED; 624 last_event_ = MESSAGE_RECEIVED;
622 last_app_id_ = registration_id; 625 last_app_id_ = registration_id;
623 last_message_ = message; 626 last_message_ = message;
624 } 627 }
625 628
626 void GCMClientImplTest::OnRegisterFinished( 629 void GCMClientImplTest::OnRegisterFinished(
627 const linked_ptr<RegistrationInfo>& registration_info, 630 const linked_ptr<RegistrationInfo>& registration_info,
628 const std::string& registration_id, 631 const std::string& registration_id,
629 GCMClient::Result result) { 632 GCMClient::Result result) {
630 last_event_ = REGISTRATION_COMPLETED; 633 last_event_ = REGISTRATION_COMPLETED;
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 932
930 reset_last_event(); 933 reset_last_event();
931 934
932 // Message from kSender3 will be dropped. 935 // Message from kSender3 will be dropped.
933 MCSMessage message3(BuildDownstreamMessage( 936 MCSMessage message3(BuildDownstreamMessage(
934 kSender3, kExtensionAppId, std::string() /* subtype */, expected_data, 937 kSender3, kExtensionAppId, std::string() /* subtype */, expected_data,
935 std::string() /* raw_data */)); 938 std::string() /* raw_data */));
936 EXPECT_TRUE(message3.IsValid()); 939 EXPECT_TRUE(message3.IsValid());
937 ReceiveMessageFromMCS(message3); 940 ReceiveMessageFromMCS(message3);
938 941
942 // TODO(harkness): Add a check for invalid app handler once the
943 // DefaultAppHandler is removed.
944
939 EXPECT_NE(MESSAGE_RECEIVED, last_event()); 945 EXPECT_NE(MESSAGE_RECEIVED, last_event());
940 EXPECT_NE(kExtensionAppId, last_app_id()); 946 EXPECT_NE(kExtensionAppId, last_app_id());
941 } 947 }
942 948
943 TEST_F(GCMClientImplTest, DispatchDownstreamMessageRawData) { 949 TEST_F(GCMClientImplTest, DispatchDownstreamMessageRawData) {
944 std::vector<std::string> senders(1, kSender); 950 std::vector<std::string> senders(1, kSender);
945 AddRegistration(kExtensionAppId, senders, "reg_id"); 951 AddRegistration(kExtensionAppId, senders, "reg_id");
946 952
947 std::map<std::string, std::string> expected_data; 953 std::map<std::string, std::string> expected_data;
948 954
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after
1782 1788
1783 // Message for kSender with a subtype will be dropped. 1789 // Message for kSender with a subtype will be dropped.
1784 MCSMessage message0(BuildDownstreamMessage( 1790 MCSMessage message0(BuildDownstreamMessage(
1785 kSender, kProductCategoryForSubtypes, kExtensionAppId /* subtype */, 1791 kSender, kProductCategoryForSubtypes, kExtensionAppId /* subtype */,
1786 expected_data, std::string() /* raw_data */)); 1792 expected_data, std::string() /* raw_data */));
1787 EXPECT_TRUE(message0.IsValid()); 1793 EXPECT_TRUE(message0.IsValid());
1788 ReceiveMessageFromMCS(message0); 1794 ReceiveMessageFromMCS(message0);
1789 1795
1790 EXPECT_NE(MESSAGE_RECEIVED, last_event()); 1796 EXPECT_NE(MESSAGE_RECEIVED, last_event());
1791 1797
1798 // Check that the last message sent was a message receipt for a failed message
1799 // and that it had the values expected.
1800 mcs_proto::DataMessageStanza stanza =
1801 mcs_client()->last_data_message_stanza();
1802 EXPECT_EQ(kExtensionAppId, stanza.category());
1803 const auto& app_data = stanza.app_data();
1804 ASSERT_EQ(3, app_data.size());
1805 for (const auto& pair : app_data) {
1806 if (pair.key() == "message_id")
1807 EXPECT_EQ("", pair.value());
1808 else if (pair.key() == "status")
1809 EXPECT_EQ("2", pair.value());
1810 else if (pair.key() == "type")
1811 EXPECT_EQ("message_receipt", pair.value());
1812 else
1813 EXPECT_TRUE(0);
1814 }
1815
1792 reset_last_event(); 1816 reset_last_event();
1793 1817
1794 // Message for kSender will be received. 1818 // Message for kSender will be received.
1795 MCSMessage message1(BuildDownstreamMessage( 1819 MCSMessage message1(BuildDownstreamMessage(
1796 kSender, kExtensionAppId, std::string() /* subtype */, expected_data, 1820 kSender, kExtensionAppId, std::string() /* subtype */, expected_data,
1797 std::string() /* raw_data */)); 1821 std::string() /* raw_data */));
1798 EXPECT_TRUE(message1.IsValid()); 1822 EXPECT_TRUE(message1.IsValid());
1799 ReceiveMessageFromMCS(message1); 1823 ReceiveMessageFromMCS(message1);
1800 1824
1801 EXPECT_EQ(MESSAGE_RECEIVED, last_event()); 1825 EXPECT_EQ(MESSAGE_RECEIVED, last_event());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1843 1867
1844 // Message for kSender without a subtype will be dropped. 1868 // Message for kSender without a subtype will be dropped.
1845 MCSMessage message0(BuildDownstreamMessage( 1869 MCSMessage message0(BuildDownstreamMessage(
1846 kSender, kSubtypeAppId, std::string() /* subtype */, expected_data, 1870 kSender, kSubtypeAppId, std::string() /* subtype */, expected_data,
1847 std::string() /* raw_data */)); 1871 std::string() /* raw_data */));
1848 EXPECT_TRUE(message0.IsValid()); 1872 EXPECT_TRUE(message0.IsValid());
1849 ReceiveMessageFromMCS(message0); 1873 ReceiveMessageFromMCS(message0);
1850 1874
1851 EXPECT_NE(MESSAGE_RECEIVED, last_event()); 1875 EXPECT_NE(MESSAGE_RECEIVED, last_event());
1852 1876
1877 // Check that the last message sent was a message receipt for a failed message
1878 // and that it had the values expected.
1879 mcs_proto::DataMessageStanza stanza =
1880 mcs_client()->last_data_message_stanza();
1881 EXPECT_EQ(kSubtypeAppId, stanza.category());
1882 const auto& app_data = stanza.app_data();
1883 ASSERT_EQ(3, app_data.size());
1884 for (const auto& pair : app_data) {
1885 if (pair.key() == "message_id")
1886 EXPECT_EQ("", pair.value());
1887 else if (pair.key() == "status")
1888 EXPECT_EQ("2", pair.value());
1889 else if (pair.key() == "type")
1890 EXPECT_EQ("message_receipt", pair.value());
1891 else
1892 EXPECT_TRUE(0);
1893 }
1894
1853 reset_last_event(); 1895 reset_last_event();
1854 1896
1855 // Message for kSender will be received. 1897 // Message for kSender will be received.
1856 MCSMessage message1(BuildDownstreamMessage( 1898 MCSMessage message1(BuildDownstreamMessage(
1857 kSender, kProductCategoryForSubtypes, kSubtypeAppId /* subtype */, 1899 kSender, kProductCategoryForSubtypes, kSubtypeAppId /* subtype */,
1858 expected_data, std::string() /* raw_data */)); 1900 expected_data, std::string() /* raw_data */));
1859 EXPECT_TRUE(message1.IsValid()); 1901 EXPECT_TRUE(message1.IsValid());
1860 ReceiveMessageFromMCS(message1); 1902 ReceiveMessageFromMCS(message1);
1861 1903
1862 EXPECT_EQ(MESSAGE_RECEIVED, last_event()); 1904 EXPECT_EQ(MESSAGE_RECEIVED, last_event());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1916 ReceiveMessageFromMCS(message); 1958 ReceiveMessageFromMCS(message);
1917 1959
1918 EXPECT_EQ(MESSAGE_RECEIVED, last_event()); 1960 EXPECT_EQ(MESSAGE_RECEIVED, last_event());
1919 EXPECT_EQ(kExtensionAppId, last_app_id()); 1961 EXPECT_EQ(kExtensionAppId, last_app_id());
1920 EXPECT_EQ(expected_data.size(), last_message().data.size()); 1962 EXPECT_EQ(expected_data.size(), last_message().data.size());
1921 EXPECT_EQ(expected_data, last_message().data); 1963 EXPECT_EQ(expected_data, last_message().data);
1922 EXPECT_EQ(kSender, last_message().sender_id); 1964 EXPECT_EQ(kSender, last_message().sender_id);
1923 } 1965 }
1924 1966
1925 } // namespace gcm 1967 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698