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

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

Powered by Google App Engine
This is Rietveld 408576698