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