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

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

Issue 1616113003: List message decryption failures on chrome://gcm-internals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after CL 1619053003 Created 4 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_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"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/metrics/field_trial.h" 14 #include "base/metrics/field_trial.h"
15 #include "base/prefs/pref_registry_simple.h" 15 #include "base/prefs/pref_registry_simple.h"
16 #include "base/prefs/testing_pref_service.h" 16 #include "base/prefs/testing_pref_service.h"
17 #include "base/run_loop.h" 17 #include "base/run_loop.h"
18 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
19 #include "base/test/test_simple_task_runner.h" 19 #include "base/test/test_simple_task_runner.h"
20 #include "base/thread_task_runner_handle.h" 20 #include "base/thread_task_runner_handle.h"
21 #include "base/threading/thread.h" 21 #include "base/threading/thread.h"
22 #include "components/gcm_driver/crypto/gcm_encryption_provider.h"
22 #include "components/gcm_driver/fake_gcm_app_handler.h" 23 #include "components/gcm_driver/fake_gcm_app_handler.h"
23 #include "components/gcm_driver/fake_gcm_client.h" 24 #include "components/gcm_driver/fake_gcm_client.h"
24 #include "components/gcm_driver/fake_gcm_client_factory.h" 25 #include "components/gcm_driver/fake_gcm_client_factory.h"
25 #include "components/gcm_driver/gcm_app_handler.h" 26 #include "components/gcm_driver/gcm_app_handler.h"
26 #include "components/gcm_driver/gcm_channel_status_request.h" 27 #include "components/gcm_driver/gcm_channel_status_request.h"
27 #include "components/gcm_driver/gcm_channel_status_syncer.h" 28 #include "components/gcm_driver/gcm_channel_status_syncer.h"
28 #include "components/gcm_driver/gcm_client_factory.h" 29 #include "components/gcm_driver/gcm_client_factory.h"
29 #include "components/gcm_driver/gcm_connection_observer.h" 30 #include "components/gcm_driver/gcm_connection_observer.h"
30 #include "net/url_request/test_url_fetcher_factory.h" 31 #include "net/url_request/test_url_fetcher_factory.h"
31 #include "net/url_request/url_fetcher_delegate.h" 32 #include "net/url_request/url_fetcher_delegate.h"
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 GetGCMClient()->ReceiveMessage(kTestAppID1, message); 804 GetGCMClient()->ReceiveMessage(kTestAppID1, message);
804 gcm_app_handler()->WaitForNotification(); 805 gcm_app_handler()->WaitForNotification();
805 EXPECT_EQ(FakeGCMAppHandler::MESSAGE_EVENT, 806 EXPECT_EQ(FakeGCMAppHandler::MESSAGE_EVENT,
806 gcm_app_handler()->received_event()); 807 gcm_app_handler()->received_event());
807 EXPECT_EQ(kTestAppID1, gcm_app_handler()->app_id()); 808 EXPECT_EQ(kTestAppID1, gcm_app_handler()->app_id());
808 EXPECT_EQ(message.data, gcm_app_handler()->message().data); 809 EXPECT_EQ(message.data, gcm_app_handler()->message().data);
809 EXPECT_EQ(message.collapse_key, 810 EXPECT_EQ(message.collapse_key,
810 gcm_app_handler()->message().collapse_key); 811 gcm_app_handler()->message().collapse_key);
811 } 812 }
812 813
814 TEST_F(GCMDriverFunctionalTest, EncryptedMessageReceivedError) {
815 // GCM registration has to be performed otherwise GCM will not be started.
816 Register(kTestAppID1, ToSenderList("sender"), GCMDriverTest::WAIT);
817
818 IncomingMessage message;
819
820 // All required information to trigger the encryption path, but with an
821 // invalid Crypto-Key header value to trigger an error.
822 message.data["encryption"] = "salt=ysyxqlYTgE0WvcZrmHbUbg";
823 message.data["crypto-key"] = "hey=thereisnopublickey";
824 message.sender_id = "sender";
825 message.raw_data = "foobar";
826
827 GetGCMClient()->SetRecording(true);
828 GetGCMClient()->ReceiveMessage(kTestAppID1, message);
829
830 PumpIOLoop();
831
832 GCMClient::GCMStatistics statistics = GetGCMClient()->GetStatistics();
833 EXPECT_TRUE(statistics.is_recording);
834 EXPECT_EQ(
835 1u, statistics.recorded_activities.decryption_failure_activities.size());
836 }
837
813 TEST_F(GCMDriverFunctionalTest, MessagesDeleted) { 838 TEST_F(GCMDriverFunctionalTest, MessagesDeleted) {
814 // GCM registration has to be performed otherwise GCM will not be started. 839 // GCM registration has to be performed otherwise GCM will not be started.
815 Register(kTestAppID1, ToSenderList("sender"), GCMDriverTest::WAIT); 840 Register(kTestAppID1, ToSenderList("sender"), GCMDriverTest::WAIT);
816 841
817 GetGCMClient()->DeleteMessages(kTestAppID1); 842 GetGCMClient()->DeleteMessages(kTestAppID1);
818 gcm_app_handler()->WaitForNotification(); 843 gcm_app_handler()->WaitForNotification();
819 EXPECT_EQ(FakeGCMAppHandler::MESSAGES_DELETED_EVENT, 844 EXPECT_EQ(FakeGCMAppHandler::MESSAGES_DELETED_EVENT,
820 gcm_app_handler()->received_event()); 845 gcm_app_handler()->received_event());
821 EXPECT_EQ(kTestAppID1, gcm_app_handler()->app_id()); 846 EXPECT_EQ(kTestAppID1, gcm_app_handler()->app_id());
822 } 847 }
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 PumpUILoop(); 1311 PumpUILoop();
1287 EXPECT_EQ(GCMClient::UNKNOWN_ERROR, unregistration_result()); 1312 EXPECT_EQ(GCMClient::UNKNOWN_ERROR, unregistration_result());
1288 1313
1289 // DeleteToken operation will be invoked after GCMClient becomes ready. 1314 // DeleteToken operation will be invoked after GCMClient becomes ready.
1290 GetGCMClient()->PerformDelayedStart(); 1315 GetGCMClient()->PerformDelayedStart();
1291 WaitForAsyncOperation(); 1316 WaitForAsyncOperation();
1292 EXPECT_EQ(GCMClient::SUCCESS, unregistration_result()); 1317 EXPECT_EQ(GCMClient::SUCCESS, unregistration_result());
1293 } 1318 }
1294 1319
1295 } // namespace gcm 1320 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/gcm_driver_desktop.cc ('k') | components/gcm_driver/gcm_internals_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698