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

Side by Side Diff: chrome/browser/push_messaging/push_messaging_service_unittest.cc

Issue 1770763003: Revert of Partial implementation of subscription restrictions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 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"
31 #include "content/public/test/test_browser_thread_bundle.h" 30 #include "content/public/test/test_browser_thread_bundle.h"
32 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
33 32
34 namespace { 33 namespace {
35 34
36 const char kTestOrigin[] = "https://example.com"; 35 const char kTestOrigin[] = "https://example.com";
37 const char kTestSenderId[] = "1234567890"; 36 const char kTestSenderId[] = "1234567890";
38 const int64_t kTestServiceWorkerId = 42; 37 const int64_t kTestServiceWorkerId = 42;
39 const char kTestPayload[] = "Hello, world!"; 38 const char kTestPayload[] = "Hello, world!";
40 39
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 146
148 // (1) Make sure that |kExampleOrigin| has access to use Push Messaging. 147 // (1) Make sure that |kExampleOrigin| has access to use Push Messaging.
149 ASSERT_EQ(blink::WebPushPermissionStatusGranted, 148 ASSERT_EQ(blink::WebPushPermissionStatusGranted,
150 push_service->GetPermissionStatus(origin, true)); 149 push_service->GetPermissionStatus(origin, true));
151 150
152 std::string subscription_id; 151 std::string subscription_id;
153 std::vector<uint8_t> p256dh, auth; 152 std::vector<uint8_t> p256dh, auth;
154 153
155 // (2) Subscribe for Push Messaging, and verify that we've got the required 154 // (2) Subscribe for Push Messaging, and verify that we've got the required
156 // information in order to be able to create encrypted messages. 155 // 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;
160 push_service->SubscribeFromWorker( 156 push_service->SubscribeFromWorker(
161 origin, kTestServiceWorkerId, options, 157 origin, kTestServiceWorkerId, kTestSenderId, true /* user_visible */,
162 base::Bind(&PushMessagingServiceTest::DidRegister, base::Unretained(this), 158 base::Bind(&PushMessagingServiceTest::DidRegister, base::Unretained(this),
163 &subscription_id, &p256dh, &auth)); 159 &subscription_id, &p256dh, &auth));
164 160
165 EXPECT_EQ(0u, subscription_id.size()); // this must be asynchronous 161 EXPECT_EQ(0u, subscription_id.size()); // this must be asynchronous
166 162
167 base::RunLoop().RunUntilIdle(); 163 base::RunLoop().RunUntilIdle();
168 164
169 ASSERT_GT(subscription_id.size(), 0u); 165 ASSERT_GT(subscription_id.size(), 0u);
170 ASSERT_GT(p256dh.size(), 0u); 166 ASSERT_GT(p256dh.size(), 0u);
171 ASSERT_GT(auth.size(), 0u); 167 ASSERT_GT(auth.size(), 0u);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 // (6) Verify that the message, as received by the Push Messaging Service, has 212 // (6) Verify that the message, as received by the Push Messaging Service, has
217 // indeed been decrypted by the GCM Driver, and has been forwarded to the 213 // indeed been decrypted by the GCM Driver, and has been forwarded to the
218 // Service Worker that has been associated with the subscription. 214 // Service Worker that has been associated with the subscription.
219 EXPECT_EQ(app_identifier.app_id(), app_id); 215 EXPECT_EQ(app_identifier.app_id(), app_id);
220 EXPECT_EQ(origin, dispatched_origin); 216 EXPECT_EQ(origin, dispatched_origin);
221 EXPECT_EQ(service_worker_registration_id, kTestServiceWorkerId); 217 EXPECT_EQ(service_worker_registration_id, kTestServiceWorkerId);
222 218
223 EXPECT_FALSE(payload.is_null); 219 EXPECT_FALSE(payload.is_null);
224 EXPECT_EQ(kTestPayload, payload.data); 220 EXPECT_EQ(kTestPayload, payload.data);
225 } 221 }
OLDNEW
« no previous file with comments | « chrome/browser/push_messaging/push_messaging_service_impl.cc ('k') | chrome/test/data/push_messaging/push_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698