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

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: Created 4 years 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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) override;
314 void OnMessageReceivedError(const std::string& app_id,
315 const std::string& message_id,
316 int status) override;
314 void OnMessagesDeleted(const std::string& app_id) override; 317 void OnMessagesDeleted(const std::string& app_id) override;
315 void OnMessageSendError( 318 void OnMessageSendError(
316 const std::string& app_id, 319 const std::string& app_id,
317 const gcm::GCMClient::SendErrorDetails& send_error_details) override; 320 const gcm::GCMClient::SendErrorDetails& send_error_details) override;
318 void OnSendAcknowledged(const std::string& app_id, 321 void OnSendAcknowledged(const std::string& app_id,
319 const std::string& message_id) override; 322 const std::string& message_id) override;
320 void OnGCMReady(const std::vector<AccountMapping>& account_mappings, 323 void OnGCMReady(const std::vector<AccountMapping>& account_mappings,
321 const base::Time& last_token_fetch_time) override; 324 const base::Time& last_token_fetch_time) override;
322 void OnActivityRecorded() override {} 325 void OnActivityRecorded() override {}
323 void OnConnected(const net::IPEndPoint& ip_endpoint) override {} 326 void OnConnected(const net::IPEndPoint& ip_endpoint) override {}
(...skipping 16 matching lines...) Expand all
340 } 343 }
341 344
342 void reset_last_event() { 345 void reset_last_event() {
343 last_event_ = NONE; 346 last_event_ = NONE;
344 last_app_id_.clear(); 347 last_app_id_.clear();
345 last_registration_id_.clear(); 348 last_registration_id_.clear();
346 last_message_id_.clear(); 349 last_message_id_.clear();
347 last_result_ = GCMClient::UNKNOWN_ERROR; 350 last_result_ = GCMClient::UNKNOWN_ERROR;
348 last_account_mappings_.clear(); 351 last_account_mappings_.clear();
349 last_token_fetch_time_ = base::Time(); 352 last_token_fetch_time_ = base::Time();
353 last_receipt_app_id_.clear();
354 last_receipt_message_id_.clear();
355 last_receipt_status_ = 0;
350 } 356 }
351 357
352 LastEvent last_event() const { return last_event_; } 358 LastEvent last_event() const { return last_event_; }
353 const std::string& last_app_id() const { return last_app_id_; } 359 const std::string& last_app_id() const { return last_app_id_; }
354 const std::string& last_registration_id() const { 360 const std::string& last_registration_id() const {
355 return last_registration_id_; 361 return last_registration_id_;
356 } 362 }
357 const std::string& last_message_id() const { return last_message_id_; } 363 const std::string& last_message_id() const { return last_message_id_; }
358 GCMClient::Result last_result() const { return last_result_; } 364 GCMClient::Result last_result() const { return last_result_; }
365 const std::string& last_receipt_app_id() const {
366 return last_receipt_app_id_;
367 }
368 const std::string& last_receipt_message_id() const {
369 return last_receipt_message_id_;
370 }
371 int last_receipt_status() const { return last_receipt_status_; }
359 const IncomingMessage& last_message() const { return last_message_; } 372 const IncomingMessage& last_message() const { return last_message_; }
360 const GCMClient::SendErrorDetails& last_error_details() const { 373 const GCMClient::SendErrorDetails& last_error_details() const {
361 return last_error_details_; 374 return last_error_details_;
362 } 375 }
363 const base::Time& last_token_fetch_time() const { 376 const base::Time& last_token_fetch_time() const {
364 return last_token_fetch_time_; 377 return last_token_fetch_time_;
365 } 378 }
366 const std::vector<AccountMapping>& last_account_mappings() { 379 const std::vector<AccountMapping>& last_account_mappings() {
367 return last_account_mappings_; 380 return last_account_mappings_;
368 } 381 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 // Variables used for verification. 418 // Variables used for verification.
406 LastEvent last_event_; 419 LastEvent last_event_;
407 std::string last_app_id_; 420 std::string last_app_id_;
408 std::string last_registration_id_; 421 std::string last_registration_id_;
409 std::string last_message_id_; 422 std::string last_message_id_;
410 GCMClient::Result last_result_; 423 GCMClient::Result last_result_;
411 IncomingMessage last_message_; 424 IncomingMessage last_message_;
412 GCMClient::SendErrorDetails last_error_details_; 425 GCMClient::SendErrorDetails last_error_details_;
413 base::Time last_token_fetch_time_; 426 base::Time last_token_fetch_time_;
414 std::vector<AccountMapping> last_account_mappings_; 427 std::vector<AccountMapping> last_account_mappings_;
428 std::string last_receipt_app_id_;
429 std::string last_receipt_message_id_;
430 int last_receipt_status_;
415 431
416 std::unique_ptr<GCMClientImpl> gcm_client_; 432 std::unique_ptr<GCMClientImpl> gcm_client_;
417 433
418 net::TestURLFetcherFactory url_fetcher_factory_; 434 net::TestURLFetcherFactory url_fetcher_factory_;
419 435
420 scoped_refptr<base::TestMockTimeTaskRunner> task_runner_; 436 scoped_refptr<base::TestMockTimeTaskRunner> task_runner_;
421 base::ThreadTaskRunnerHandle task_runner_handle_; 437 base::ThreadTaskRunnerHandle task_runner_handle_;
422 438
423 // Injected to GCM client. 439 // Injected to GCM client.
424 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_; 440 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_;
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 last_token_fetch_time_ = last_token_fetch_time; 632 last_token_fetch_time_ = last_token_fetch_time;
617 } 633 }
618 634
619 void GCMClientImplTest::OnMessageReceived(const std::string& registration_id, 635 void GCMClientImplTest::OnMessageReceived(const std::string& registration_id,
620 const IncomingMessage& message) { 636 const IncomingMessage& message) {
621 last_event_ = MESSAGE_RECEIVED; 637 last_event_ = MESSAGE_RECEIVED;
622 last_app_id_ = registration_id; 638 last_app_id_ = registration_id;
623 last_message_ = message; 639 last_message_ = message;
624 } 640 }
625 641
642 void GCMClientImplTest::OnMessageReceivedError(const std::string& app_id,
643 const std::string& message_id,
644 int status) {
645 last_receipt_app_id_ = app_id;
646 last_receipt_message_id_ = message_id;
647 last_receipt_status_ = status;
648 }
649
626 void GCMClientImplTest::OnRegisterFinished( 650 void GCMClientImplTest::OnRegisterFinished(
627 const linked_ptr<RegistrationInfo>& registration_info, 651 const linked_ptr<RegistrationInfo>& registration_info,
628 const std::string& registration_id, 652 const std::string& registration_id,
629 GCMClient::Result result) { 653 GCMClient::Result result) {
630 last_event_ = REGISTRATION_COMPLETED; 654 last_event_ = REGISTRATION_COMPLETED;
631 last_app_id_ = registration_info->app_id; 655 last_app_id_ = registration_info->app_id;
632 last_registration_id_ = registration_id; 656 last_registration_id_ = registration_id;
633 last_result_ = result; 657 last_result_ = result;
634 } 658 }
635 659
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 953
930 reset_last_event(); 954 reset_last_event();
931 955
932 // Message from kSender3 will be dropped. 956 // Message from kSender3 will be dropped.
933 MCSMessage message3(BuildDownstreamMessage( 957 MCSMessage message3(BuildDownstreamMessage(
934 kSender3, kExtensionAppId, std::string() /* subtype */, expected_data, 958 kSender3, kExtensionAppId, std::string() /* subtype */, expected_data,
935 std::string() /* raw_data */)); 959 std::string() /* raw_data */));
936 EXPECT_TRUE(message3.IsValid()); 960 EXPECT_TRUE(message3.IsValid());
937 ReceiveMessageFromMCS(message3); 961 ReceiveMessageFromMCS(message3);
938 962
963 // TODO(harkness): Add a check for invalid app handler once the
964 // DefaultAppHandler is removed.
965
939 EXPECT_NE(MESSAGE_RECEIVED, last_event()); 966 EXPECT_NE(MESSAGE_RECEIVED, last_event());
940 EXPECT_NE(kExtensionAppId, last_app_id()); 967 EXPECT_NE(kExtensionAppId, last_app_id());
941 } 968 }
942 969
943 TEST_F(GCMClientImplTest, DispatchDownstreamMessageRawData) { 970 TEST_F(GCMClientImplTest, DispatchDownstreamMessageRawData) {
944 std::vector<std::string> senders(1, kSender); 971 std::vector<std::string> senders(1, kSender);
945 AddRegistration(kExtensionAppId, senders, "reg_id"); 972 AddRegistration(kExtensionAppId, senders, "reg_id");
946 973
947 std::map<std::string, std::string> expected_data; 974 std::map<std::string, std::string> expected_data;
948 975
(...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after
1781 std::map<std::string, std::string> expected_data; 1808 std::map<std::string, std::string> expected_data;
1782 1809
1783 // Message for kSender with a subtype will be dropped. 1810 // Message for kSender with a subtype will be dropped.
1784 MCSMessage message0(BuildDownstreamMessage( 1811 MCSMessage message0(BuildDownstreamMessage(
1785 kSender, kProductCategoryForSubtypes, kExtensionAppId /* subtype */, 1812 kSender, kProductCategoryForSubtypes, kExtensionAppId /* subtype */,
1786 expected_data, std::string() /* raw_data */)); 1813 expected_data, std::string() /* raw_data */));
1787 EXPECT_TRUE(message0.IsValid()); 1814 EXPECT_TRUE(message0.IsValid());
1788 ReceiveMessageFromMCS(message0); 1815 ReceiveMessageFromMCS(message0);
1789 1816
1790 EXPECT_NE(MESSAGE_RECEIVED, last_event()); 1817 EXPECT_NE(MESSAGE_RECEIVED, last_event());
1818 EXPECT_EQ(kExtensionAppId, last_receipt_app_id());
1819 EXPECT_EQ(GCMClient::GCM_INVALID_SUBTYPE, last_receipt_status());
1791 1820
1792 reset_last_event(); 1821 reset_last_event();
1793 1822
1794 // Message for kSender will be received. 1823 // Message for kSender will be received.
1795 MCSMessage message1(BuildDownstreamMessage( 1824 MCSMessage message1(BuildDownstreamMessage(
1796 kSender, kExtensionAppId, std::string() /* subtype */, expected_data, 1825 kSender, kExtensionAppId, std::string() /* subtype */, expected_data,
1797 std::string() /* raw_data */)); 1826 std::string() /* raw_data */));
1798 EXPECT_TRUE(message1.IsValid()); 1827 EXPECT_TRUE(message1.IsValid());
1799 ReceiveMessageFromMCS(message1); 1828 ReceiveMessageFromMCS(message1);
1800 1829
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1842 std::map<std::string, std::string> expected_data; 1871 std::map<std::string, std::string> expected_data;
1843 1872
1844 // Message for kSender without a subtype will be dropped. 1873 // Message for kSender without a subtype will be dropped.
1845 MCSMessage message0(BuildDownstreamMessage( 1874 MCSMessage message0(BuildDownstreamMessage(
1846 kSender, kSubtypeAppId, std::string() /* subtype */, expected_data, 1875 kSender, kSubtypeAppId, std::string() /* subtype */, expected_data,
1847 std::string() /* raw_data */)); 1876 std::string() /* raw_data */));
1848 EXPECT_TRUE(message0.IsValid()); 1877 EXPECT_TRUE(message0.IsValid());
1849 ReceiveMessageFromMCS(message0); 1878 ReceiveMessageFromMCS(message0);
1850 1879
1851 EXPECT_NE(MESSAGE_RECEIVED, last_event()); 1880 EXPECT_NE(MESSAGE_RECEIVED, last_event());
1881 EXPECT_EQ(kSubtypeAppId, last_receipt_app_id());
1882 EXPECT_EQ(GCMClient::GCM_INVALID_SUBTYPE, last_receipt_status());
1852 1883
1853 reset_last_event(); 1884 reset_last_event();
1854 1885
1855 // Message for kSender will be received. 1886 // Message for kSender will be received.
1856 MCSMessage message1(BuildDownstreamMessage( 1887 MCSMessage message1(BuildDownstreamMessage(
1857 kSender, kProductCategoryForSubtypes, kSubtypeAppId /* subtype */, 1888 kSender, kProductCategoryForSubtypes, kSubtypeAppId /* subtype */,
1858 expected_data, std::string() /* raw_data */)); 1889 expected_data, std::string() /* raw_data */));
1859 EXPECT_TRUE(message1.IsValid()); 1890 EXPECT_TRUE(message1.IsValid());
1860 ReceiveMessageFromMCS(message1); 1891 ReceiveMessageFromMCS(message1);
1861 1892
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1916 ReceiveMessageFromMCS(message); 1947 ReceiveMessageFromMCS(message);
1917 1948
1918 EXPECT_EQ(MESSAGE_RECEIVED, last_event()); 1949 EXPECT_EQ(MESSAGE_RECEIVED, last_event());
1919 EXPECT_EQ(kExtensionAppId, last_app_id()); 1950 EXPECT_EQ(kExtensionAppId, last_app_id());
1920 EXPECT_EQ(expected_data.size(), last_message().data.size()); 1951 EXPECT_EQ(expected_data.size(), last_message().data.size());
1921 EXPECT_EQ(expected_data, last_message().data); 1952 EXPECT_EQ(expected_data, last_message().data);
1922 EXPECT_EQ(kSender, last_message().sender_id); 1953 EXPECT_EQ(kSender, last_message().sender_id);
1923 } 1954 }
1924 1955
1925 } // namespace gcm 1956 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698