| OLD | NEW |
| 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/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
| 16 #include "chrome/browser/permissions/permission_manager.h" | 16 #include "chrome/browser/permissions/permission_manager.h" |
| 17 #include "chrome/browser/permissions/permission_manager_factory.h" | 17 #include "chrome/browser/permissions/permission_manager_factory.h" |
| 18 #include "chrome/browser/push_messaging/push_messaging_app_identifier.h" | 18 #include "chrome/browser/push_messaging/push_messaging_app_identifier.h" |
| 19 #include "chrome/browser/push_messaging/push_messaging_permission_context.h" | 19 #include "chrome/browser/push_messaging/push_messaging_permission_context.h" |
| 20 #include "chrome/browser/push_messaging/push_messaging_permission_context_factor
y.h" | 20 #include "chrome/browser/push_messaging/push_messaging_permission_context_factor
y.h" |
| 21 #include "chrome/browser/push_messaging/push_messaging_service_factory.h" | 21 #include "chrome/browser/push_messaging/push_messaging_service_factory.h" |
| 22 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" | 22 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" |
| 23 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" | 23 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" |
| 24 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 24 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
| 25 #include "chrome/test/base/testing_profile.h" | 25 #include "chrome/test/base/testing_profile.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_profile_service.h" | 28 #include "components/gcm_driver/gcm_profile_service.h" |
| 29 #include "content/public/common/push_event_payload.h" | 29 #include "content/public/common/push_event_payload.h" |
| 30 #include "content/public/common/push_subscription_options.h" |
| 30 #include "content/public/test/test_browser_thread_bundle.h" | 31 #include "content/public/test/test_browser_thread_bundle.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 const char kTestOrigin[] = "https://example.com"; | 36 const char kTestOrigin[] = "https://example.com"; |
| 36 const char kTestSenderId[] = "1234567890"; | 37 const char kTestSenderId[] = "1234567890"; |
| 37 const int64_t kTestServiceWorkerId = 42; | 38 const int64_t kTestServiceWorkerId = 42; |
| 38 const char kTestPayload[] = "Hello, world!"; | 39 const char kTestPayload[] = "Hello, world!"; |
| 39 | 40 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 147 |
| 147 // (1) Make sure that |kExampleOrigin| has access to use Push Messaging. | 148 // (1) Make sure that |kExampleOrigin| has access to use Push Messaging. |
| 148 ASSERT_EQ(blink::WebPushPermissionStatusGranted, | 149 ASSERT_EQ(blink::WebPushPermissionStatusGranted, |
| 149 push_service->GetPermissionStatus(origin, true)); | 150 push_service->GetPermissionStatus(origin, true)); |
| 150 | 151 |
| 151 std::string subscription_id; | 152 std::string subscription_id; |
| 152 std::vector<uint8_t> p256dh, auth; | 153 std::vector<uint8_t> p256dh, auth; |
| 153 | 154 |
| 154 // (2) Subscribe for Push Messaging, and verify that we've got the required | 155 // (2) Subscribe for Push Messaging, and verify that we've got the required |
| 155 // information in order to be able to create encrypted messages. | 156 // information in order to be able to create encrypted messages. |
| 157 content::PushSubscriptionOptions options; |
| 158 options.user_visible_only = true; |
| 159 options.sender_info = kTestSenderId; |
| 156 push_service->SubscribeFromWorker( | 160 push_service->SubscribeFromWorker( |
| 157 origin, kTestServiceWorkerId, kTestSenderId, true /* user_visible */, | 161 origin, kTestServiceWorkerId, options, |
| 158 base::Bind(&PushMessagingServiceTest::DidRegister, base::Unretained(this), | 162 base::Bind(&PushMessagingServiceTest::DidRegister, base::Unretained(this), |
| 159 &subscription_id, &p256dh, &auth)); | 163 &subscription_id, &p256dh, &auth)); |
| 160 | 164 |
| 161 EXPECT_EQ(0u, subscription_id.size()); // this must be asynchronous | 165 EXPECT_EQ(0u, subscription_id.size()); // this must be asynchronous |
| 162 | 166 |
| 163 base::RunLoop().RunUntilIdle(); | 167 base::RunLoop().RunUntilIdle(); |
| 164 | 168 |
| 165 ASSERT_GT(subscription_id.size(), 0u); | 169 ASSERT_GT(subscription_id.size(), 0u); |
| 166 ASSERT_GT(p256dh.size(), 0u); | 170 ASSERT_GT(p256dh.size(), 0u); |
| 167 ASSERT_GT(auth.size(), 0u); | 171 ASSERT_GT(auth.size(), 0u); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 // (6) Verify that the message, as received by the Push Messaging Service, has | 216 // (6) Verify that the message, as received by the Push Messaging Service, has |
| 213 // indeed been decrypted by the GCM Driver, and has been forwarded to the | 217 // indeed been decrypted by the GCM Driver, and has been forwarded to the |
| 214 // Service Worker that has been associated with the subscription. | 218 // Service Worker that has been associated with the subscription. |
| 215 EXPECT_EQ(app_identifier.app_id(), app_id); | 219 EXPECT_EQ(app_identifier.app_id(), app_id); |
| 216 EXPECT_EQ(origin, dispatched_origin); | 220 EXPECT_EQ(origin, dispatched_origin); |
| 217 EXPECT_EQ(service_worker_registration_id, kTestServiceWorkerId); | 221 EXPECT_EQ(service_worker_registration_id, kTestServiceWorkerId); |
| 218 | 222 |
| 219 EXPECT_FALSE(payload.is_null); | 223 EXPECT_FALSE(payload.is_null); |
| 220 EXPECT_EQ(kTestPayload, payload.data); | 224 EXPECT_EQ(kTestPayload, payload.data); |
| 221 } | 225 } |
| OLD | NEW |