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/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/permissions/permission_manager.h" | 17 #include "chrome/browser/permissions/permission_manager.h" |
18 #include "chrome/browser/permissions/permission_manager_factory.h" | 18 #include "chrome/browser/permissions/permission_manager_factory.h" |
19 #include "chrome/browser/push_messaging/push_messaging_app_identifier.h" | 19 #include "chrome/browser/push_messaging/push_messaging_app_identifier.h" |
20 #include "chrome/browser/push_messaging/push_messaging_service_factory.h" | 20 #include "chrome/browser/push_messaging/push_messaging_service_factory.h" |
21 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" | 21 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" |
22 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" | |
23 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 22 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
24 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
25 #include "components/content_settings/core/browser/host_content_settings_map.h" | 24 #include "components/content_settings/core/browser/host_content_settings_map.h" |
26 #include "components/gcm_driver/crypto/gcm_crypto_test_helpers.h" | 25 #include "components/gcm_driver/crypto/gcm_crypto_test_helpers.h" |
27 #include "components/gcm_driver/fake_gcm_client_factory.h" | 26 #include "components/gcm_driver/fake_gcm_client_factory.h" |
| 27 #include "components/gcm_driver/fake_gcm_profile_service.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/common/push_subscription_options.h" |
31 #include "content/public/test/test_browser_thread_bundle.h" | 31 #include "content/public/test/test_browser_thread_bundle.h" |
32 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
36 const char kTestOrigin[] = "https://example.com"; | 36 const char kTestOrigin[] = "https://example.com"; |
37 const char kTestSenderId[] = "1234567890"; | 37 const char kTestSenderId[] = "1234567890"; |
(...skipping 29 matching lines...) Expand all Loading... |
67 } | 67 } |
68 | 68 |
69 PermissionManager* GetPermissionManager() override { | 69 PermissionManager* GetPermissionManager() override { |
70 return PermissionManagerFactory::GetForProfile(this); | 70 return PermissionManagerFactory::GetForProfile(this); |
71 } | 71 } |
72 | 72 |
73 private: | 73 private: |
74 DISALLOW_COPY_AND_ASSIGN(PushMessagingTestingProfile); | 74 DISALLOW_COPY_AND_ASSIGN(PushMessagingTestingProfile); |
75 }; | 75 }; |
76 | 76 |
77 std::unique_ptr<KeyedService> BuildFakeGCMProfileService( | |
78 content::BrowserContext* context) { | |
79 return gcm::FakeGCMProfileService::Build(static_cast<Profile*>(context)); | |
80 } | |
81 | |
82 } // namespace | 77 } // namespace |
83 | 78 |
84 class PushMessagingServiceTest : public ::testing::Test { | 79 class PushMessagingServiceTest : public ::testing::Test { |
85 public: | 80 public: |
86 PushMessagingServiceTest() { | 81 PushMessagingServiceTest() { |
87 // Always allow push notifications in the profile. | 82 // Always allow push notifications in the profile. |
88 HostContentSettingsMap* host_content_settings_map = | 83 HostContentSettingsMap* host_content_settings_map = |
89 HostContentSettingsMapFactory::GetForProfile(&profile_); | 84 HostContentSettingsMapFactory::GetForProfile(&profile_); |
90 host_content_settings_map->SetDefaultContentSetting( | 85 host_content_settings_map->SetDefaultContentSetting( |
91 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW); | 86 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW); |
92 | 87 |
93 // Override the GCM Profile service so that we can send fake messages. | 88 // Override the GCM Profile service so that we can send fake messages. |
94 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactory( | 89 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactory( |
95 &profile_, &BuildFakeGCMProfileService); | 90 &profile_, &gcm::FakeGCMProfileService::Build); |
96 } | 91 } |
97 | 92 |
98 ~PushMessagingServiceTest() override {} | 93 ~PushMessagingServiceTest() override {} |
99 | 94 |
100 // Callback to use when the subscription may have been subscribed. | 95 // Callback to use when the subscription may have been subscribed. |
101 void DidRegister(std::string* subscription_id_out, | 96 void DidRegister(std::string* subscription_id_out, |
102 std::vector<uint8_t>* p256dh_out, | 97 std::vector<uint8_t>* p256dh_out, |
103 std::vector<uint8_t>* auth_out, | 98 std::vector<uint8_t>* auth_out, |
104 const std::string& registration_id, | 99 const std::string& registration_id, |
105 const std::vector<uint8_t>& p256dh, | 100 const std::vector<uint8_t>& p256dh, |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 } | 237 } |
243 | 238 |
244 TEST_F(PushMessagingServiceTest, DifferentEndpoints) { | 239 TEST_F(PushMessagingServiceTest, DifferentEndpoints) { |
245 PushMessagingServiceImpl* push_service = profile()->GetPushMessagingService(); | 240 PushMessagingServiceImpl* push_service = profile()->GetPushMessagingService(); |
246 ASSERT_TRUE(push_service); | 241 ASSERT_TRUE(push_service); |
247 | 242 |
248 // Verifies that the service returns different endpoints depending on whether | 243 // Verifies that the service returns different endpoints depending on whether |
249 // support for the standard protocol is requested. | 244 // support for the standard protocol is requested. |
250 EXPECT_NE(push_service->GetEndpoint(true), push_service->GetEndpoint(false)); | 245 EXPECT_NE(push_service->GetEndpoint(true), push_service->GetEndpoint(false)); |
251 } | 246 } |
OLD | NEW |