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

Side by Side Diff: components/gcm_driver/gcm_driver_desktop_unittest.cc

Issue 2578583002: Provide a mechanism for the GCM driver to send message receipts to GCM.
Patch Set: Fix issue with rebase 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
« no previous file with comments | « components/gcm_driver/gcm_driver_desktop.cc ('k') | components/gcm_driver/gcm_message_status.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_driver_desktop.h" 5 #include "components/gcm_driver/gcm_driver_desktop.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 23 matching lines...) Expand all
34 #include "net/url_request/url_request_context_getter.h" 34 #include "net/url_request/url_request_context_getter.h"
35 #include "net/url_request/url_request_test_util.h" 35 #include "net/url_request/url_request_test_util.h"
36 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
37 37
38 namespace gcm { 38 namespace gcm {
39 39
40 namespace { 40 namespace {
41 41
42 const char kTestAppID1[] = "TestApp1"; 42 const char kTestAppID1[] = "TestApp1";
43 const char kTestAppID2[] = "TestApp2"; 43 const char kTestAppID2[] = "TestApp2";
44 const char kTestMessageID[] = "TestMessage1";
44 const char kUserID1[] = "user1"; 45 const char kUserID1[] = "user1";
45 const char kScope[] = "GCM"; 46 const char kScope[] = "GCM";
46 const char kInstanceID1[] = "IID1"; 47 const char kInstanceID1[] = "IID1";
47 const char kInstanceID2[] = "IID2"; 48 const char kInstanceID2[] = "IID2";
48 49
49 class FakeGCMConnectionObserver : public GCMConnectionObserver { 50 class FakeGCMConnectionObserver : public GCMConnectionObserver {
50 public: 51 public:
51 FakeGCMConnectionObserver(); 52 FakeGCMConnectionObserver();
52 ~FakeGCMConnectionObserver() override; 53 ~FakeGCMConnectionObserver() override;
53 54
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 } 835 }
835 836
836 TEST_F(GCMDriverFunctionalTest, MessageReceived) { 837 TEST_F(GCMDriverFunctionalTest, MessageReceived) {
837 // GCM registration has to be performed otherwise GCM will not be started. 838 // GCM registration has to be performed otherwise GCM will not be started.
838 Register(kTestAppID1, ToSenderList("sender"), GCMDriverTest::WAIT); 839 Register(kTestAppID1, ToSenderList("sender"), GCMDriverTest::WAIT);
839 840
840 IncomingMessage message; 841 IncomingMessage message;
841 message.data["key1"] = "value1"; 842 message.data["key1"] = "value1";
842 message.data["key2"] = "value2"; 843 message.data["key2"] = "value2";
843 message.sender_id = "sender"; 844 message.sender_id = "sender";
844 GetGCMClient()->ReceiveMessage(kTestAppID1, message); 845 GetGCMClient()->ReceiveMessage(kTestAppID1, kTestMessageID, message);
845 gcm_app_handler()->WaitForNotification(); 846 gcm_app_handler()->WaitForNotification();
846 EXPECT_EQ(FakeGCMAppHandler::MESSAGE_EVENT, 847 EXPECT_EQ(FakeGCMAppHandler::MESSAGE_EVENT,
847 gcm_app_handler()->received_event()); 848 gcm_app_handler()->received_event());
848 EXPECT_EQ(kTestAppID1, gcm_app_handler()->app_id()); 849 EXPECT_EQ(kTestAppID1, gcm_app_handler()->app_id());
849 EXPECT_EQ(message.data, gcm_app_handler()->message().data); 850 EXPECT_EQ(message.data, gcm_app_handler()->message().data);
850 EXPECT_TRUE(gcm_app_handler()->message().collapse_key.empty()); 851 EXPECT_TRUE(gcm_app_handler()->message().collapse_key.empty());
851 EXPECT_EQ(message.sender_id, gcm_app_handler()->message().sender_id); 852 EXPECT_EQ(message.sender_id, gcm_app_handler()->message().sender_id);
852 } 853 }
853 854
854 TEST_F(GCMDriverFunctionalTest, MessageWithCollapseKeyReceived) { 855 TEST_F(GCMDriverFunctionalTest, MessageWithCollapseKeyReceived) {
855 // GCM registration has to be performed otherwise GCM will not be started. 856 // GCM registration has to be performed otherwise GCM will not be started.
856 Register(kTestAppID1, ToSenderList("sender"), GCMDriverTest::WAIT); 857 Register(kTestAppID1, ToSenderList("sender"), GCMDriverTest::WAIT);
857 858
858 IncomingMessage message; 859 IncomingMessage message;
859 message.data["key1"] = "value1"; 860 message.data["key1"] = "value1";
860 message.collapse_key = "collapse_key_value"; 861 message.collapse_key = "collapse_key_value";
861 message.sender_id = "sender"; 862 message.sender_id = "sender";
862 GetGCMClient()->ReceiveMessage(kTestAppID1, message); 863 GetGCMClient()->ReceiveMessage(kTestAppID1, kTestMessageID, message);
863 gcm_app_handler()->WaitForNotification(); 864 gcm_app_handler()->WaitForNotification();
864 EXPECT_EQ(FakeGCMAppHandler::MESSAGE_EVENT, 865 EXPECT_EQ(FakeGCMAppHandler::MESSAGE_EVENT,
865 gcm_app_handler()->received_event()); 866 gcm_app_handler()->received_event());
866 EXPECT_EQ(kTestAppID1, gcm_app_handler()->app_id()); 867 EXPECT_EQ(kTestAppID1, gcm_app_handler()->app_id());
867 EXPECT_EQ(message.data, gcm_app_handler()->message().data); 868 EXPECT_EQ(message.data, gcm_app_handler()->message().data);
868 EXPECT_EQ(message.collapse_key, 869 EXPECT_EQ(message.collapse_key,
869 gcm_app_handler()->message().collapse_key); 870 gcm_app_handler()->message().collapse_key);
870 } 871 }
871 872
872 TEST_F(GCMDriverFunctionalTest, EncryptedMessageReceivedError) { 873 TEST_F(GCMDriverFunctionalTest, EncryptedMessageReceivedError) {
873 // GCM registration has to be performed otherwise GCM will not be started. 874 // GCM registration has to be performed otherwise GCM will not be started.
874 Register(kTestAppID1, ToSenderList("sender"), GCMDriverTest::WAIT); 875 Register(kTestAppID1, ToSenderList("sender"), GCMDriverTest::WAIT);
875 876
876 IncomingMessage message; 877 IncomingMessage message;
877 878
878 // All required information to trigger the encryption path, but with an 879 // All required information to trigger the encryption path, but with an
879 // invalid Crypto-Key header value to trigger an error. 880 // invalid Crypto-Key header value to trigger an error.
880 message.data["encryption"] = "salt=ysyxqlYTgE0WvcZrmHbUbg"; 881 message.data["encryption"] = "salt=ysyxqlYTgE0WvcZrmHbUbg";
881 message.data["crypto-key"] = "hey=thereisnopublickey"; 882 message.data["crypto-key"] = "hey=thereisnopublickey";
882 message.sender_id = "sender"; 883 message.sender_id = "sender";
883 message.raw_data = "foobar"; 884 message.raw_data = "foobar";
884 885
885 GetGCMClient()->SetRecording(true); 886 GetGCMClient()->SetRecording(true);
886 GetGCMClient()->ReceiveMessage(kTestAppID1, message); 887 GetGCMClient()->ReceiveMessage(kTestAppID1, kTestMessageID, message);
887 888
888 PumpIOLoop(); 889 PumpIOLoop();
889 PumpUILoop(); 890 PumpUILoop();
890 PumpIOLoop(); 891 PumpIOLoop();
891 892
892 GCMClient::GCMStatistics statistics = GetGCMClient()->GetStatistics(); 893 GCMClient::GCMStatistics statistics = GetGCMClient()->GetStatistics();
893 EXPECT_TRUE(statistics.is_recording); 894 EXPECT_TRUE(statistics.is_recording);
894 EXPECT_EQ( 895 EXPECT_EQ(
895 1u, statistics.recorded_activities.decryption_failure_activities.size()); 896 1u, statistics.recorded_activities.decryption_failure_activities.size());
896 } 897 }
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 PumpUILoop(); 1379 PumpUILoop();
1379 EXPECT_EQ(GCMClient::UNKNOWN_ERROR, unregistration_result()); 1380 EXPECT_EQ(GCMClient::UNKNOWN_ERROR, unregistration_result());
1380 1381
1381 // DeleteToken operation will be invoked after GCMClient becomes ready. 1382 // DeleteToken operation will be invoked after GCMClient becomes ready.
1382 GetGCMClient()->PerformDelayedStart(); 1383 GetGCMClient()->PerformDelayedStart();
1383 WaitForAsyncOperation(); 1384 WaitForAsyncOperation();
1384 EXPECT_EQ(GCMClient::SUCCESS, unregistration_result()); 1385 EXPECT_EQ(GCMClient::SUCCESS, unregistration_result());
1385 } 1386 }
1386 1387
1387 } // namespace gcm 1388 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/gcm_driver_desktop.cc ('k') | components/gcm_driver/gcm_message_status.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698