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

Side by Side Diff: chrome/browser/push_messaging/push_messaging_service_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 | « chrome/browser/gcm/fake_gcm_profile_service.cc ('k') | components/gcm_driver/fake_gcm_client.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/public/browser/push_messaging_service.h" 5 #include "content/public/browser/push_messaging_service.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
17 #include "chrome/browser/gcm/fake_gcm_profile_service.h" 17 #include "chrome/browser/gcm/fake_gcm_profile_service.h"
18 #include "chrome/browser/gcm/gcm_profile_service_factory.h" 18 #include "chrome/browser/gcm/gcm_profile_service_factory.h"
19 #include "chrome/browser/permissions/permission_manager.h" 19 #include "chrome/browser/permissions/permission_manager.h"
20 #include "chrome/browser/permissions/permission_manager_factory.h" 20 #include "chrome/browser/permissions/permission_manager_factory.h"
21 #include "chrome/browser/push_messaging/push_messaging_app_identifier.h" 21 #include "chrome/browser/push_messaging/push_messaging_app_identifier.h"
22 #include "chrome/browser/push_messaging/push_messaging_service_factory.h" 22 #include "chrome/browser/push_messaging/push_messaging_service_factory.h"
23 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" 23 #include "chrome/browser/push_messaging/push_messaging_service_impl.h"
24 #include "chrome/test/base/testing_profile.h" 24 #include "chrome/test/base/testing_profile.h"
25 #include "components/content_settings/core/browser/host_content_settings_map.h" 25 #include "components/content_settings/core/browser/host_content_settings_map.h"
26 #include "components/gcm_driver/crypto/gcm_crypto_test_helpers.h" 26 #include "components/gcm_driver/crypto/gcm_crypto_test_helpers.h"
27 #include "components/gcm_driver/fake_gcm_client_factory.h" 27 #include "components/gcm_driver/fake_gcm_client_factory.h"
28 #include "components/gcm_driver/gcm_message_status.h"
28 #include "components/gcm_driver/gcm_profile_service.h" 29 #include "components/gcm_driver/gcm_profile_service.h"
29 #include "content/public/common/push_event_payload.h" 30 #include "content/public/common/push_event_payload.h"
30 #include "content/public/common/push_subscription_options.h" 31 #include "content/public/common/push_subscription_options.h"
31 #include "content/public/test/test_browser_thread_bundle.h" 32 #include "content/public/test/test_browser_thread_bundle.h"
32 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
33 34
34 #if defined(OS_ANDROID) 35 #if defined(OS_ANDROID)
35 #include "components/gcm_driver/instance_id/instance_id_android.h" 36 #include "components/gcm_driver/instance_id/instance_id_android.h"
36 #include "components/gcm_driver/instance_id/scoped_use_fake_instance_id_android. h" 37 #include "components/gcm_driver/instance_id/scoped_use_fake_instance_id_android. h"
37 #endif // OS_ANDROID 38 #endif // OS_ANDROID
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 const std::string& app_id, 130 const std::string& app_id,
130 const GURL& origin, 131 const GURL& origin,
131 int64_t service_worker_registration_id, 132 int64_t service_worker_registration_id,
132 const content::PushEventPayload& payload) { 133 const content::PushEventPayload& payload) {
133 *app_id_out = app_id; 134 *app_id_out = app_id;
134 *origin_out = origin; 135 *origin_out = origin;
135 *service_worker_registration_id_out = service_worker_registration_id; 136 *service_worker_registration_id_out = service_worker_registration_id;
136 *payload_out = payload; 137 *payload_out = payload;
137 } 138 }
138 139
140 // Callback to use to observe message receipts returned to GCM.
141 void DidSendReceipt(gcm::GCMMessageStatus* status_out,
142 gcm::GCMMessageStatus status) {
143 *status_out = status;
144 }
145
139 protected: 146 protected:
140 PushMessagingTestingProfile* profile() { return &profile_; } 147 PushMessagingTestingProfile* profile() { return &profile_; }
141 148
142 private: 149 private:
143 content::TestBrowserThreadBundle thread_bundle_; 150 content::TestBrowserThreadBundle thread_bundle_;
144 PushMessagingTestingProfile profile_; 151 PushMessagingTestingProfile profile_;
145 152
146 #if defined(OS_ANDROID) 153 #if defined(OS_ANDROID)
147 instance_id::InstanceIDAndroid::ScopedBlockOnAsyncTasksForTesting 154 instance_id::InstanceIDAndroid::ScopedBlockOnAsyncTasksForTesting
148 block_async_; 155 block_async_;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 // dispatch the |message| on the GCM driver as if it had actually been 222 // dispatch the |message| on the GCM driver as if it had actually been
216 // received by Google Cloud Messaging. 223 // received by Google Cloud Messaging.
217 push_service->SetMessageDispatchedCallbackForTesting(base::Bind( 224 push_service->SetMessageDispatchedCallbackForTesting(base::Bind(
218 &PushMessagingServiceTest::DidDispatchMessage, base::Unretained(this), 225 &PushMessagingServiceTest::DidDispatchMessage, base::Unretained(this),
219 &app_id, &dispatched_origin, &service_worker_registration_id, &payload)); 226 &app_id, &dispatched_origin, &service_worker_registration_id, &payload));
220 227
221 gcm::FakeGCMProfileService* fake_profile_service = 228 gcm::FakeGCMProfileService* fake_profile_service =
222 static_cast<gcm::FakeGCMProfileService*>( 229 static_cast<gcm::FakeGCMProfileService*>(
223 gcm::GCMProfileServiceFactory::GetForProfile(profile())); 230 gcm::GCMProfileServiceFactory::GetForProfile(profile()));
224 231
225 fake_profile_service->DispatchMessage(app_identifier.app_id(), message); 232 gcm::GCMMessageStatus receipt_status = gcm::GCMMessageStatus::GCM_UNRESOLVED;
233
234 fake_profile_service->DispatchMessage(
235 app_identifier.app_id(), message,
236 base::Bind(&PushMessagingServiceTest::DidSendReceipt,
237 base::Unretained(this), &receipt_status));
226 238
227 base::RunLoop().RunUntilIdle(); 239 base::RunLoop().RunUntilIdle();
228 240
229 // (6) Verify that the message, as received by the Push Messaging Service, has 241 // (6) Verify that the message, as received by the Push Messaging Service, has
230 // indeed been decrypted by the GCM Driver, and has been forwarded to the 242 // indeed been decrypted by the GCM Driver, and has been forwarded to the
231 // Service Worker that has been associated with the subscription. 243 // Service Worker that has been associated with the subscription.
232 EXPECT_EQ(app_identifier.app_id(), app_id); 244 EXPECT_EQ(app_identifier.app_id(), app_id);
233 EXPECT_EQ(origin, dispatched_origin); 245 EXPECT_EQ(origin, dispatched_origin);
234 EXPECT_EQ(service_worker_registration_id, kTestServiceWorkerId); 246 EXPECT_EQ(service_worker_registration_id, kTestServiceWorkerId);
235 247
236 EXPECT_FALSE(payload.is_null); 248 EXPECT_FALSE(payload.is_null);
237 EXPECT_EQ(kTestPayload, payload.data); 249 EXPECT_EQ(kTestPayload, payload.data);
250
251 // Verify that no receipt was sent.
252 // TODO(harkness): Once the push service sends receipts for completed
253 // messages, update this check.
254 EXPECT_EQ(gcm::GCMMessageStatus::GCM_UNRESOLVED, receipt_status);
238 } 255 }
239 256
240 TEST_F(PushMessagingServiceTest, NormalizeSenderInfo) { 257 TEST_F(PushMessagingServiceTest, NormalizeSenderInfo) {
241 PushMessagingServiceImpl* push_service = profile()->GetPushMessagingService(); 258 PushMessagingServiceImpl* push_service = profile()->GetPushMessagingService();
242 ASSERT_TRUE(push_service); 259 ASSERT_TRUE(push_service);
243 260
244 std::string p256dh(kTestP256Key, kTestP256Key + arraysize(kTestP256Key)); 261 std::string p256dh(kTestP256Key, kTestP256Key + arraysize(kTestP256Key));
245 ASSERT_EQ(65u, p256dh.size()); 262 ASSERT_EQ(65u, p256dh.size());
246 263
247 // NIST P-256 public keys in uncompressed format will be encoded using the 264 // NIST P-256 public keys in uncompressed format will be encoded using the
(...skipping 10 matching lines...) Expand all
258 } 275 }
259 276
260 TEST_F(PushMessagingServiceTest, DifferentEndpoints) { 277 TEST_F(PushMessagingServiceTest, DifferentEndpoints) {
261 PushMessagingServiceImpl* push_service = profile()->GetPushMessagingService(); 278 PushMessagingServiceImpl* push_service = profile()->GetPushMessagingService();
262 ASSERT_TRUE(push_service); 279 ASSERT_TRUE(push_service);
263 280
264 // Verifies that the service returns different endpoints depending on whether 281 // Verifies that the service returns different endpoints depending on whether
265 // support for the standard protocol is requested. 282 // support for the standard protocol is requested.
266 EXPECT_NE(push_service->GetEndpoint(true), push_service->GetEndpoint(false)); 283 EXPECT_NE(push_service->GetEndpoint(true), push_service->GetEndpoint(false));
267 } 284 }
OLDNEW
« no previous file with comments | « chrome/browser/gcm/fake_gcm_profile_service.cc ('k') | components/gcm_driver/fake_gcm_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698