OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... |
41 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 41 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
42 #include "chrome/common/chrome_switches.h" | 42 #include "chrome/common/chrome_switches.h" |
43 #include "chrome/common/features.h" | 43 #include "chrome/common/features.h" |
44 #include "chrome/test/base/in_process_browser_test.h" | 44 #include "chrome/test/base/in_process_browser_test.h" |
45 #include "chrome/test/base/ui_test_utils.h" | 45 #include "chrome/test/base/ui_test_utils.h" |
46 #include "components/content_settings/core/browser/host_content_settings_map.h" | 46 #include "components/content_settings/core/browser/host_content_settings_map.h" |
47 #include "components/content_settings/core/common/content_settings.h" | 47 #include "components/content_settings/core/common/content_settings.h" |
48 #include "components/content_settings/core/common/content_settings_types.h" | 48 #include "components/content_settings/core/common/content_settings_types.h" |
49 #include "components/gcm_driver/common/gcm_messages.h" | 49 #include "components/gcm_driver/common/gcm_messages.h" |
50 #include "components/gcm_driver/gcm_client.h" | 50 #include "components/gcm_driver/gcm_client.h" |
| 51 #include "components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h" |
51 #include "content/public/browser/web_contents.h" | 52 #include "content/public/browser/web_contents.h" |
52 #include "content/public/common/content_switches.h" | 53 #include "content/public/common/content_switches.h" |
53 #include "content/public/test/browser_test_utils.h" | 54 #include "content/public/test/browser_test_utils.h" |
54 #include "content/public/test/test_utils.h" | 55 #include "content/public/test/test_utils.h" |
55 #include "net/test/embedded_test_server/embedded_test_server.h" | 56 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 57 #include "testing/gmock/include/gmock/gmock.h" |
56 #include "ui/base/window_open_disposition.h" | 58 #include "ui/base/window_open_disposition.h" |
57 | 59 |
58 #if BUILDFLAG(ENABLE_BACKGROUND) | 60 #if BUILDFLAG(ENABLE_BACKGROUND) |
59 #include "chrome/browser/background/background_mode_manager.h" | 61 #include "chrome/browser/background/background_mode_manager.h" |
60 #endif | 62 #endif |
61 | 63 |
62 namespace { | 64 namespace { |
63 | 65 |
| 66 const char kManifestSenderId[] = "1234567890"; |
| 67 |
64 // NIST P-256 public key made available to tests. Must be an uncompressed | 68 // NIST P-256 public key made available to tests. Must be an uncompressed |
65 // point in accordance with SEC1 2.3.3. | 69 // point in accordance with SEC1 2.3.3. |
66 const uint8_t kApplicationServerKey[65] = { | 70 const uint8_t kApplicationServerKey[65] = { |
67 0x04, 0x55, 0x52, 0x6A, 0xA5, 0x6E, 0x8E, 0xAA, 0x47, 0x97, 0x36, | 71 0x04, 0x55, 0x52, 0x6A, 0xA5, 0x6E, 0x8E, 0xAA, 0x47, 0x97, 0x36, |
68 0x10, 0xC1, 0x66, 0x3C, 0x1E, 0x65, 0xBF, 0xA1, 0x7B, 0xEE, 0x48, | 72 0x10, 0xC1, 0x66, 0x3C, 0x1E, 0x65, 0xBF, 0xA1, 0x7B, 0xEE, 0x48, |
69 0xC9, 0xC6, 0xBB, 0xBF, 0x02, 0x18, 0x53, 0x72, 0x1D, 0x0C, 0x7B, | 73 0xC9, 0xC6, 0xBB, 0xBF, 0x02, 0x18, 0x53, 0x72, 0x1D, 0x0C, 0x7B, |
70 0xA9, 0xE3, 0x11, 0xB7, 0x03, 0x52, 0x21, 0xD3, 0x71, 0x90, 0x13, | 74 0xA9, 0xE3, 0x11, 0xB7, 0x03, 0x52, 0x21, 0xD3, 0x71, 0x90, 0x13, |
71 0xA8, 0xC1, 0xCF, 0xED, 0x20, 0xF7, 0x1F, 0xD1, 0x7F, 0xF2, 0x76, | 75 0xA8, 0xC1, 0xCF, 0xED, 0x20, 0xF7, 0x1F, 0xD1, 0x7F, 0xF2, 0x76, |
72 0xB6, 0x01, 0x20, 0xD8, 0x35, 0xA5, 0xD9, 0x3C, 0x43, 0xFD}; | 76 0xB6, 0x01, 0x20, 0xD8, 0x35, 0xA5, 0xD9, 0x3C, 0x43, 0xFD}; |
73 | 77 |
74 // URL-safe base64 encoded version of the |kApplicationServerKey|. | 78 // URL-safe base64 encoded version of the |kApplicationServerKey|. |
75 const char kEncodedApplicationServerKey[] = | 79 const char kEncodedApplicationServerKey[] = |
76 "BFVSaqVujqpHlzYQwWY8HmW_oXvuSMnGu78CGFNyHQx7qeMRtwNSIdNxkBOowc_tIPcf0X_ydr" | 80 "BFVSaqVujqpHlzYQwWY8HmW_oXvuSMnGu78CGFNyHQx7qeMRtwNSIdNxkBOowc_tIPcf0X_ydr" |
77 "YBINg1pdk8Q_0"; | 81 "YBINg1pdk8Q_0"; |
78 | 82 |
79 std::string GetTestApplicationServerKey() { | 83 std::string GetTestApplicationServerKey() { |
80 return std::string(kApplicationServerKey, | 84 return std::string(kApplicationServerKey, |
81 kApplicationServerKey + arraysize(kApplicationServerKey)); | 85 kApplicationServerKey + arraysize(kApplicationServerKey)); |
82 } | 86 } |
83 | 87 |
84 // Class to instantiate on the stack that is meant to be used with | 88 void LegacyRegisterCallback(const base::Closure& done_callback, |
85 // FakeGCMProfileService. The ::Run() method follows the signature of | 89 std::string* out_registration_id, |
86 // FakeGCMProfileService::UnregisterCallback. | 90 gcm::GCMClient::Result* out_result, |
87 class UnregistrationCallback { | 91 const std::string& registration_id, |
88 public: | 92 gcm::GCMClient::Result result) { |
89 UnregistrationCallback() | 93 if (out_registration_id) |
90 : message_loop_runner_(new content::MessageLoopRunner) {} | 94 *out_registration_id = registration_id; |
91 | 95 if (out_result) |
92 void Run(const std::string& app_id) { | 96 *out_result = result; |
93 app_id_ = app_id; | 97 done_callback.Run(); |
94 message_loop_runner_->Quit(); | 98 } |
95 } | |
96 | |
97 void WaitUntilSatisfied() { message_loop_runner_->Run(); } | |
98 | |
99 const std::string& app_id() { return app_id_; } | |
100 | |
101 private: | |
102 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
103 std::string app_id_; | |
104 }; | |
105 | 99 |
106 } // namespace | 100 } // namespace |
107 | 101 |
108 class PushMessagingBrowserTest : public InProcessBrowserTest { | 102 class PushMessagingBrowserTest : public InProcessBrowserTest { |
109 public: | 103 public: |
110 PushMessagingBrowserTest() : gcm_service_(nullptr) {} | 104 PushMessagingBrowserTest() : gcm_service_(nullptr), gcm_driver_(nullptr) {} |
111 ~PushMessagingBrowserTest() override {} | 105 ~PushMessagingBrowserTest() override {} |
112 | 106 |
113 // InProcessBrowserTest: | 107 // InProcessBrowserTest: |
114 void SetUp() override { | 108 void SetUp() override { |
115 https_server_.reset( | 109 https_server_.reset( |
116 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); | 110 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); |
117 https_server_->ServeFilesFromSourceDirectory("chrome/test/data"); | 111 https_server_->ServeFilesFromSourceDirectory("chrome/test/data"); |
118 ASSERT_TRUE(https_server_->Start()); | 112 ASSERT_TRUE(https_server_->Start()); |
119 | 113 |
120 #if defined(ENABLE_NOTIFICATIONS) | 114 #if defined(ENABLE_NOTIFICATIONS) |
121 notification_manager_.reset(new StubNotificationUIManager); | 115 notification_manager_.reset(new StubNotificationUIManager); |
122 #endif | 116 #endif |
123 | 117 |
124 InProcessBrowserTest::SetUp(); | 118 InProcessBrowserTest::SetUp(); |
125 } | 119 } |
126 | 120 |
127 void SetUpCommandLine(base::CommandLine* command_line) override { | 121 void SetUpCommandLine(base::CommandLine* command_line) override { |
128 // Enable experimental features for subscription restrictions. | 122 // Enable experimental features for subscription restrictions. |
129 command_line->AppendSwitch( | 123 command_line->AppendSwitch( |
130 switches::kEnableExperimentalWebPlatformFeatures); | 124 switches::kEnableExperimentalWebPlatformFeatures); |
131 InProcessBrowserTest::SetUpCommandLine(command_line); | 125 InProcessBrowserTest::SetUpCommandLine(command_line); |
132 } | 126 } |
133 | 127 |
134 // InProcessBrowserTest: | 128 // InProcessBrowserTest: |
135 void SetUpOnMainThread() override { | 129 void SetUpOnMainThread() override { |
136 gcm_service_ = static_cast<gcm::FakeGCMProfileService*>( | 130 gcm_service_ = static_cast<gcm::FakeGCMProfileService*>( |
137 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 131 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
138 GetBrowser()->profile(), &gcm::FakeGCMProfileService::Build)); | 132 GetBrowser()->profile(), &gcm::FakeGCMProfileService::Build)); |
139 gcm_service_->set_collect(true); | 133 gcm_driver_ = static_cast<instance_id::FakeGCMDriverForInstanceID*>( |
| 134 gcm_service_->driver()); |
| 135 |
140 push_service_ = | 136 push_service_ = |
141 PushMessagingServiceFactory::GetForProfile(GetBrowser()->profile()); | 137 PushMessagingServiceFactory::GetForProfile(GetBrowser()->profile()); |
142 #if defined(ENABLE_NOTIFICATIONS) | 138 #if defined(ENABLE_NOTIFICATIONS) |
143 display_service_.reset(new MessageCenterDisplayService( | 139 display_service_.reset(new MessageCenterDisplayService( |
144 GetBrowser()->profile(), notification_manager_.get())); | 140 GetBrowser()->profile(), notification_manager_.get())); |
145 notification_service()->SetNotificationDisplayServiceForTesting( | 141 notification_service()->SetNotificationDisplayServiceForTesting( |
146 display_service_.get()); | 142 display_service_.get()); |
147 #endif | 143 #endif |
148 | 144 |
149 LoadTestPage(); | 145 LoadTestPage(); |
150 InProcessBrowserTest::SetUpOnMainThread(); | 146 InProcessBrowserTest::SetUpOnMainThread(); |
151 } | 147 } |
152 | 148 |
| 149 // Calls should be wrapped in the ASSERT_NO_FATAL_FAILURE() macro. |
153 void RestartPushService() { | 150 void RestartPushService() { |
154 Profile* profile = GetBrowser()->profile(); | 151 Profile* profile = GetBrowser()->profile(); |
155 PushMessagingServiceFactory::GetInstance()->SetTestingFactory(profile, | 152 PushMessagingServiceFactory::GetInstance()->SetTestingFactory(profile, |
156 nullptr); | 153 nullptr); |
157 ASSERT_EQ(nullptr, PushMessagingServiceFactory::GetForProfile(profile)); | 154 ASSERT_EQ(nullptr, PushMessagingServiceFactory::GetForProfile(profile)); |
158 PushMessagingServiceFactory::GetInstance()->RestoreFactoryForTests(profile); | 155 PushMessagingServiceFactory::GetInstance()->RestoreFactoryForTests(profile); |
159 PushMessagingServiceImpl::InitializeForProfile(profile); | 156 PushMessagingServiceImpl::InitializeForProfile(profile); |
160 push_service_ = PushMessagingServiceFactory::GetForProfile(profile); | 157 push_service_ = PushMessagingServiceFactory::GetForProfile(profile); |
161 } | 158 } |
162 | 159 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 | 193 |
197 bool RunScript(const std::string& script, std::string* result, | 194 bool RunScript(const std::string& script, std::string* result, |
198 content::WebContents* web_contents) { | 195 content::WebContents* web_contents) { |
199 if (!web_contents) | 196 if (!web_contents) |
200 web_contents = GetBrowser()->tab_strip_model()->GetActiveWebContents(); | 197 web_contents = GetBrowser()->tab_strip_model()->GetActiveWebContents(); |
201 return content::ExecuteScriptAndExtractString(web_contents->GetMainFrame(), | 198 return content::ExecuteScriptAndExtractString(web_contents->GetMainFrame(), |
202 script, result); | 199 script, result); |
203 } | 200 } |
204 | 201 |
205 gcm::GCMAppHandler* GetAppHandler() { | 202 gcm::GCMAppHandler* GetAppHandler() { |
206 return gcm_service()->driver()->GetAppHandler( | 203 return gcm_driver_->GetAppHandler(kPushMessagingAppIdentifierPrefix); |
207 kPushMessagingAppIdentifierPrefix); | |
208 } | 204 } |
209 | 205 |
210 PermissionRequestManager* GetPermissionRequestManager() { | 206 PermissionRequestManager* GetPermissionRequestManager() { |
211 return PermissionRequestManager::FromWebContents( | 207 return PermissionRequestManager::FromWebContents( |
212 GetBrowser()->tab_strip_model()->GetActiveWebContents()); | 208 GetBrowser()->tab_strip_model()->GetActiveWebContents()); |
213 } | 209 } |
214 | 210 |
| 211 // Calls should be wrapped in the ASSERT_NO_FATAL_FAILURE() macro. |
215 void RequestAndAcceptPermission(); | 212 void RequestAndAcceptPermission(); |
| 213 // Calls should be wrapped in the ASSERT_NO_FATAL_FAILURE() macro. |
216 void RequestAndDenyPermission(); | 214 void RequestAndDenyPermission(); |
217 | 215 |
218 void TryToSubscribeSuccessfully( | 216 // Sets out_token to the subscription token (not including server URL). |
219 const std::string& expected_push_subscription_info, | 217 // Calls should be wrapped in the ASSERT_NO_FATAL_FAILURE() macro. |
220 bool use_key = true); | 218 void SubscribeSuccessfully(bool use_key = true, |
| 219 std::string* out_token = nullptr); |
221 | 220 |
222 std::string GetEndpointForSubscriptionId(const std::string& subscription_id, | 221 // Legacy subscribe path using GCMDriver rather than Instance IDs. Only |
223 bool standard_protocol = true) { | 222 // for testing that we maintain support for existing stored registrations. |
224 return push_service()->GetEndpoint(standard_protocol).spec() + | 223 // Calls should be wrapped in the ASSERT_NO_FATAL_FAILURE() macro. |
225 subscription_id; | 224 void LegacySubscribeSuccessfully(std::string* out_subscription_id = nullptr); |
226 } | 225 |
| 226 // Strips server URL from a registration endpoint to get subscription token. |
| 227 // Calls should be wrapped in the ASSERT_NO_FATAL_FAILURE() macro. |
| 228 void EndpointToToken(const std::string& endpoint, |
| 229 bool standard_protocol = true, |
| 230 std::string* out_token = nullptr); |
227 | 231 |
228 PushMessagingAppIdentifier GetAppIdentifierForServiceWorkerRegistration( | 232 PushMessagingAppIdentifier GetAppIdentifierForServiceWorkerRegistration( |
229 int64_t service_worker_registration_id); | 233 int64_t service_worker_registration_id); |
230 | 234 |
231 void SendMessageAndWaitUntilHandled( | 235 void SendMessageAndWaitUntilHandled( |
232 const PushMessagingAppIdentifier& app_identifier, | 236 const PushMessagingAppIdentifier& app_identifier, |
233 const gcm::IncomingMessage& message); | 237 const gcm::IncomingMessage& message); |
234 | 238 |
235 net::EmbeddedTestServer* https_server() const { return https_server_.get(); } | 239 net::EmbeddedTestServer* https_server() const { return https_server_.get(); } |
236 | 240 |
237 gcm::FakeGCMProfileService* gcm_service() const { return gcm_service_; } | |
238 | |
239 #if defined(ENABLE_NOTIFICATIONS) | 241 #if defined(ENABLE_NOTIFICATIONS) |
240 // To be called when delivery of a push message has finished. The |run_loop| | 242 // To be called when delivery of a push message has finished. The |run_loop| |
241 // will be told to quit after |messages_required| messages were received. | 243 // will be told to quit after |messages_required| messages were received. |
242 void OnDeliveryFinished(std::vector<size_t>* number_of_notifications_shown, | 244 void OnDeliveryFinished(std::vector<size_t>* number_of_notifications_shown, |
243 const base::Closure& done_closure) { | 245 const base::Closure& done_closure) { |
244 DCHECK(number_of_notifications_shown); | 246 DCHECK(number_of_notifications_shown); |
245 | 247 |
246 number_of_notifications_shown->push_back( | 248 number_of_notifications_shown->push_back( |
247 notification_manager_->GetNotificationCount()); | 249 notification_manager_->GetNotificationCount()); |
248 | 250 |
(...skipping 17 matching lines...) Expand all Loading... |
266 service->ResetScoreForURL(url, score); | 268 service->ResetScoreForURL(url, score); |
267 } | 269 } |
268 | 270 |
269 protected: | 271 protected: |
270 virtual std::string GetTestURL() { return "/push_messaging/test.html"; } | 272 virtual std::string GetTestURL() { return "/push_messaging/test.html"; } |
271 | 273 |
272 virtual Browser* GetBrowser() const { return browser(); } | 274 virtual Browser* GetBrowser() const { return browser(); } |
273 | 275 |
274 base::HistogramTester* GetHistogramTester() { return &histogram_tester_; } | 276 base::HistogramTester* GetHistogramTester() { return &histogram_tester_; } |
275 | 277 |
276 private: | 278 protected: |
277 std::unique_ptr<net::EmbeddedTestServer> https_server_; | 279 std::unique_ptr<net::EmbeddedTestServer> https_server_; |
278 gcm::FakeGCMProfileService* gcm_service_; | 280 gcm::FakeGCMProfileService* gcm_service_; |
| 281 instance_id::FakeGCMDriverForInstanceID* gcm_driver_; |
279 PushMessagingServiceImpl* push_service_; | 282 PushMessagingServiceImpl* push_service_; |
280 base::HistogramTester histogram_tester_; | 283 base::HistogramTester histogram_tester_; |
281 | 284 |
282 #if defined(ENABLE_NOTIFICATIONS) | 285 #if defined(ENABLE_NOTIFICATIONS) |
283 std::unique_ptr<StubNotificationUIManager> notification_manager_; | 286 std::unique_ptr<StubNotificationUIManager> notification_manager_; |
284 std::unique_ptr<MessageCenterDisplayService> display_service_; | 287 std::unique_ptr<MessageCenterDisplayService> display_service_; |
285 #endif | 288 #endif |
286 | 289 |
287 DISALLOW_COPY_AND_ASSIGN(PushMessagingBrowserTest); | 290 DISALLOW_COPY_AND_ASSIGN(PushMessagingBrowserTest); |
288 }; | 291 }; |
289 | 292 |
290 class PushMessagingBrowserTestEmptySubscriptionOptions | 293 class PushMessagingBrowserTestEmptySubscriptionOptions |
291 : public PushMessagingBrowserTest { | 294 : public PushMessagingBrowserTest { |
292 std::string GetTestURL() override { | 295 std::string GetTestURL() override { |
293 return "/push_messaging/test_no_subscription_options.html"; | 296 return "/push_messaging/test_no_subscription_options.html"; |
294 } | 297 } |
295 }; | 298 }; |
296 | 299 |
297 void PushMessagingBrowserTest::RequestAndAcceptPermission() { | 300 void PushMessagingBrowserTest::RequestAndAcceptPermission() { |
298 std::string script_result; | 301 std::string script_result; |
299 GetPermissionRequestManager()->set_auto_response_for_test( | 302 GetPermissionRequestManager()->set_auto_response_for_test( |
300 PermissionRequestManager::ACCEPT_ALL); | 303 PermissionRequestManager::ACCEPT_ALL); |
301 EXPECT_TRUE(RunScript("requestNotificationPermission();", &script_result)); | 304 ASSERT_TRUE(RunScript("requestNotificationPermission();", &script_result)); |
302 EXPECT_EQ("permission status - granted", script_result); | 305 ASSERT_EQ("permission status - granted", script_result); |
303 } | 306 } |
304 | 307 |
305 void PushMessagingBrowserTest::RequestAndDenyPermission() { | 308 void PushMessagingBrowserTest::RequestAndDenyPermission() { |
306 std::string script_result; | 309 std::string script_result; |
307 GetPermissionRequestManager()->set_auto_response_for_test( | 310 GetPermissionRequestManager()->set_auto_response_for_test( |
308 PermissionRequestManager::DENY_ALL); | 311 PermissionRequestManager::DENY_ALL); |
309 EXPECT_TRUE(RunScript("requestNotificationPermission();", &script_result)); | 312 ASSERT_TRUE(RunScript("requestNotificationPermission();", &script_result)); |
310 EXPECT_EQ("permission status - denied", script_result); | 313 ASSERT_EQ("permission status - denied", script_result); |
311 } | 314 } |
312 | 315 |
313 void PushMessagingBrowserTest::TryToSubscribeSuccessfully( | 316 void PushMessagingBrowserTest::SubscribeSuccessfully(bool use_key, |
314 const std::string& expected_push_subscription_info, | 317 std::string* out_token) { |
315 bool use_key) { | |
316 std::string script_result; | 318 std::string script_result; |
317 | 319 |
318 EXPECT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 320 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
319 EXPECT_EQ("ok - service worker registered", script_result); | 321 ASSERT_EQ("ok - service worker registered", script_result); |
320 | 322 |
321 RequestAndAcceptPermission(); | 323 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission()); |
322 | 324 |
323 if (use_key) { | 325 if (use_key) { |
324 ASSERT_TRUE(RunScript("removeManifest()", &script_result)); | 326 ASSERT_TRUE(RunScript("removeManifest()", &script_result)); |
325 ASSERT_EQ("manifest removed", script_result); | 327 ASSERT_EQ("manifest removed", script_result); |
326 | 328 |
327 EXPECT_TRUE(RunScript("documentSubscribePush()", &script_result)); | 329 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); |
328 } else { | 330 } else { |
329 // Test backwards compatibility with old ID based subscriptions. | 331 // Test backwards compatibility with old ID based subscriptions. |
330 EXPECT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); | 332 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); |
331 } | 333 } |
332 | 334 |
333 EXPECT_EQ( | 335 ASSERT_NO_FATAL_FAILURE(EndpointToToken(script_result, use_key, out_token)); |
334 GetEndpointForSubscriptionId(expected_push_subscription_info, use_key), | 336 } |
335 script_result); | 337 |
| 338 void PushMessagingBrowserTest::LegacySubscribeSuccessfully( |
| 339 std::string* out_subscription_id) { |
| 340 // Create a non-InstanceID GCM registration. Have to directly access |
| 341 // GCMDriver, since this codepath has been deleted from Push. |
| 342 |
| 343 std::string script_result; |
| 344 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 345 ASSERT_EQ("ok - service worker registered", script_result); |
| 346 |
| 347 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission()); |
| 348 |
| 349 GURL requesting_origin = https_server()->GetURL("/").GetOrigin(); |
| 350 int64_t service_worker_registration_id = 0LL; |
| 351 PushMessagingAppIdentifier app_identifier = |
| 352 PushMessagingAppIdentifier::Generate(requesting_origin, |
| 353 service_worker_registration_id); |
| 354 push_service_->IncreasePushSubscriptionCount(1, true /* is_pending */); |
| 355 |
| 356 std::string subscription_id; |
| 357 { |
| 358 base::RunLoop run_loop; |
| 359 gcm::GCMClient::Result register_result = gcm::GCMClient::UNKNOWN_ERROR; |
| 360 gcm_driver_->Register( |
| 361 app_identifier.app_id(), {kManifestSenderId}, |
| 362 base::Bind(&LegacyRegisterCallback, run_loop.QuitClosure(), |
| 363 &subscription_id, ®ister_result)); |
| 364 run_loop.Run(); |
| 365 ASSERT_EQ(gcm::GCMClient::SUCCESS, register_result); |
| 366 } |
| 367 |
| 368 app_identifier.PersistToPrefs(GetBrowser()->profile()); |
| 369 push_service_->IncreasePushSubscriptionCount(1, false /* is_pending */); |
| 370 push_service_->DecreasePushSubscriptionCount(1, true /* was_pending */); |
| 371 |
| 372 { |
| 373 base::RunLoop run_loop; |
| 374 push_service_->StorePushSubscriptionForTesting( |
| 375 GetBrowser()->profile(), requesting_origin, |
| 376 service_worker_registration_id, subscription_id, kManifestSenderId, |
| 377 run_loop.QuitClosure()); |
| 378 run_loop.Run(); |
| 379 } |
| 380 |
| 381 if (out_subscription_id) |
| 382 *out_subscription_id = subscription_id; |
| 383 } |
| 384 |
| 385 void PushMessagingBrowserTest::EndpointToToken(const std::string& endpoint, |
| 386 bool standard_protocol, |
| 387 std::string* out_token) { |
| 388 size_t last_slash = endpoint.rfind('/'); |
| 389 |
| 390 ASSERT_EQ(endpoint.substr(0, last_slash + 1), |
| 391 push_service()->GetEndpoint(standard_protocol).spec()); |
| 392 |
| 393 ASSERT_LT(last_slash + 1, endpoint.length()); // Token must not be empty. |
| 394 |
| 395 if (out_token) |
| 396 *out_token = endpoint.substr(last_slash + 1); |
336 } | 397 } |
337 | 398 |
338 PushMessagingAppIdentifier | 399 PushMessagingAppIdentifier |
339 PushMessagingBrowserTest::GetAppIdentifierForServiceWorkerRegistration( | 400 PushMessagingBrowserTest::GetAppIdentifierForServiceWorkerRegistration( |
340 int64_t service_worker_registration_id) { | 401 int64_t service_worker_registration_id) { |
341 GURL origin = https_server()->GetURL("/").GetOrigin(); | 402 GURL origin = https_server()->GetURL("/").GetOrigin(); |
342 PushMessagingAppIdentifier app_identifier = | 403 PushMessagingAppIdentifier app_identifier = |
343 PushMessagingAppIdentifier::FindByServiceWorker( | 404 PushMessagingAppIdentifier::FindByServiceWorker( |
344 GetBrowser()->profile(), origin, service_worker_registration_id); | 405 GetBrowser()->profile(), origin, service_worker_registration_id); |
345 EXPECT_FALSE(app_identifier.is_null()); | 406 EXPECT_FALSE(app_identifier.is_null()); |
346 return app_identifier; | 407 return app_identifier; |
347 } | 408 } |
348 | 409 |
349 void PushMessagingBrowserTest::SendMessageAndWaitUntilHandled( | 410 void PushMessagingBrowserTest::SendMessageAndWaitUntilHandled( |
350 const PushMessagingAppIdentifier& app_identifier, | 411 const PushMessagingAppIdentifier& app_identifier, |
351 const gcm::IncomingMessage& message) { | 412 const gcm::IncomingMessage& message) { |
352 base::RunLoop run_loop; | 413 base::RunLoop run_loop; |
353 push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure()); | 414 push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure()); |
354 push_service()->OnMessage(app_identifier.app_id(), message); | 415 push_service()->OnMessage(app_identifier.app_id(), message); |
355 run_loop.Run(); | 416 run_loop.Run(); |
356 } | 417 } |
357 | 418 |
358 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 419 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
359 SubscribeWithoutKeySuccessNotificationsGranted) { | 420 SubscribeWithoutKeySuccessNotificationsGranted) { |
360 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */, false); | 421 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(false /* use_key */)); |
361 | 422 EXPECT_EQ(kManifestSenderId, gcm_driver_->last_gettoken_authorized_entity()); |
362 PushMessagingAppIdentifier app_identifier = | 423 EXPECT_EQ(GetAppIdentifierForServiceWorkerRegistration(0LL).app_id(), |
363 GetAppIdentifierForServiceWorkerRegistration(0LL); | 424 gcm_driver_->last_gettoken_app_id()); |
364 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | |
365 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | |
366 } | 425 } |
367 | 426 |
368 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 427 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
369 SubscribeSuccessNotificationsGranted) { | 428 SubscribeSuccessNotificationsGranted) { |
370 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 429 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
371 | |
372 PushMessagingAppIdentifier app_identifier = | |
373 GetAppIdentifierForServiceWorkerRegistration(0LL); | |
374 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | |
375 EXPECT_EQ(kEncodedApplicationServerKey, | 430 EXPECT_EQ(kEncodedApplicationServerKey, |
376 gcm_service()->last_registered_sender_ids()[0]); | 431 gcm_driver_->last_gettoken_authorized_entity()); |
| 432 EXPECT_EQ(GetAppIdentifierForServiceWorkerRegistration(0LL).app_id(), |
| 433 gcm_driver_->last_gettoken_app_id()); |
377 } | 434 } |
378 | 435 |
379 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 436 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
380 SubscribeSuccessNotificationsPrompt) { | 437 SubscribeSuccessNotificationsPrompt) { |
381 std::string script_result; | 438 std::string script_result; |
382 | 439 |
383 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 440 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
384 ASSERT_EQ("ok - service worker registered", script_result); | 441 ASSERT_EQ("ok - service worker registered", script_result); |
385 | 442 |
386 GetPermissionRequestManager()->set_auto_response_for_test( | 443 GetPermissionRequestManager()->set_auto_response_for_test( |
387 PermissionRequestManager::ACCEPT_ALL); | 444 PermissionRequestManager::ACCEPT_ALL); |
388 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); | 445 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); |
389 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result); | 446 // Both of these methods EXPECT that they succeed. |
390 | 447 ASSERT_NO_FATAL_FAILURE(EndpointToToken(script_result)); |
391 PushMessagingAppIdentifier app_identifier = | 448 GetAppIdentifierForServiceWorkerRegistration(0LL); |
392 GetAppIdentifierForServiceWorkerRegistration(0LL); | |
393 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | |
394 EXPECT_EQ(kEncodedApplicationServerKey, | |
395 gcm_service()->last_registered_sender_ids()[0]); | |
396 } | 449 } |
397 | 450 |
398 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureBadKey) { | 451 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureBadKey) { |
399 std::string script_result; | 452 std::string script_result; |
400 | 453 |
401 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 454 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
402 ASSERT_EQ("ok - service worker registered", script_result); | 455 ASSERT_EQ("ok - service worker registered", script_result); |
403 | 456 |
404 RequestAndAcceptPermission(); | 457 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission()); |
405 | 458 |
406 ASSERT_TRUE(RunScript("documentSubscribePushBadKey()", &script_result)); | 459 ASSERT_TRUE(RunScript("documentSubscribePushBadKey()", &script_result)); |
407 EXPECT_EQ( | 460 EXPECT_EQ( |
408 "InvalidAccessError - Failed to execute 'subscribe' on 'PushManager': " | 461 "InvalidAccessError - Failed to execute 'subscribe' on 'PushManager': " |
409 "The provided applicationServerKey is not valid.", | 462 "The provided applicationServerKey is not valid.", |
410 script_result); | 463 script_result); |
411 } | 464 } |
412 | 465 |
413 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 466 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
414 SubscribeFailureNotificationsBlocked) { | 467 SubscribeFailureNotificationsBlocked) { |
415 std::string script_result; | 468 std::string script_result; |
416 | 469 |
417 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 470 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
418 ASSERT_EQ("ok - service worker registered", script_result); | 471 ASSERT_EQ("ok - service worker registered", script_result); |
419 | 472 |
420 RequestAndDenyPermission(); | 473 ASSERT_NO_FATAL_FAILURE(RequestAndDenyPermission()); |
421 | 474 |
422 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); | 475 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); |
423 EXPECT_EQ("NotAllowedError - Registration failed - permission denied", | 476 EXPECT_EQ("NotAllowedError - Registration failed - permission denied", |
424 script_result); | 477 script_result); |
425 } | 478 } |
426 | 479 |
427 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureNoManifest) { | 480 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureNoManifest) { |
428 std::string script_result; | 481 std::string script_result; |
429 | 482 |
430 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 483 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
431 ASSERT_EQ("ok - service worker registered", script_result); | 484 ASSERT_EQ("ok - service worker registered", script_result); |
432 | 485 |
433 RequestAndAcceptPermission(); | 486 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission()); |
434 | 487 |
435 ASSERT_TRUE(RunScript("removeManifest()", &script_result)); | 488 ASSERT_TRUE(RunScript("removeManifest()", &script_result)); |
436 ASSERT_EQ("manifest removed", script_result); | 489 ASSERT_EQ("manifest removed", script_result); |
437 | 490 |
438 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); | 491 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); |
439 EXPECT_EQ( | 492 EXPECT_EQ( |
440 "AbortError - Registration failed - missing applicationServerKey, and " | 493 "AbortError - Registration failed - missing applicationServerKey, and " |
441 "manifest empty or missing", | 494 "manifest empty or missing", |
442 script_result); | 495 script_result); |
443 } | 496 } |
444 | 497 |
445 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureNoSenderId) { | 498 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureNoSenderId) { |
446 std::string script_result; | 499 std::string script_result; |
447 | 500 |
448 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 501 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
449 ASSERT_EQ("ok - service worker registered", script_result); | 502 ASSERT_EQ("ok - service worker registered", script_result); |
450 | 503 |
451 RequestAndAcceptPermission(); | 504 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission()); |
452 | 505 |
453 ASSERT_TRUE(RunScript("swapManifestNoSenderId()", &script_result)); | 506 ASSERT_TRUE(RunScript("swapManifestNoSenderId()", &script_result)); |
454 ASSERT_EQ("sender id removed from manifest", script_result); | 507 ASSERT_EQ("sender id removed from manifest", script_result); |
455 | 508 |
456 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); | 509 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); |
457 EXPECT_EQ( | 510 EXPECT_EQ( |
458 "AbortError - Registration failed - missing applicationServerKey, and " | 511 "AbortError - Registration failed - missing applicationServerKey, and " |
459 "gcm_sender_id not found in manifest", | 512 "gcm_sender_id not found in manifest", |
460 script_result); | 513 script_result); |
461 } | 514 } |
462 | 515 |
463 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTestEmptySubscriptionOptions, | 516 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTestEmptySubscriptionOptions, |
464 RegisterFailureEmptyPushSubscriptionOptions) { | 517 RegisterFailureEmptyPushSubscriptionOptions) { |
465 std::string script_result; | 518 std::string script_result; |
466 | 519 |
467 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 520 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
468 ASSERT_EQ("ok - service worker registered", script_result); | 521 ASSERT_EQ("ok - service worker registered", script_result); |
469 | 522 |
470 RequestAndAcceptPermission(); | 523 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission()); |
471 | 524 |
472 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); | 525 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); |
473 EXPECT_EQ("NotAllowedError - Registration failed - permission denied", | 526 EXPECT_EQ("NotAllowedError - Registration failed - permission denied", |
474 script_result); | 527 script_result); |
475 } | 528 } |
476 | 529 |
477 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeWorker) { | 530 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeWorker) { |
478 std::string script_result; | 531 std::string script_result; |
479 | 532 |
480 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 533 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
481 ASSERT_EQ("ok - service worker registered", script_result); | 534 ASSERT_EQ("ok - service worker registered", script_result); |
482 | 535 |
483 RequestAndAcceptPermission(); | 536 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission()); |
484 | 537 |
485 LoadTestPage(); // Reload to become controlled. | 538 LoadTestPage(); // Reload to become controlled. |
486 | 539 |
487 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 540 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
488 ASSERT_EQ("true - is controlled", script_result); | 541 ASSERT_EQ("true - is controlled", script_result); |
489 | 542 |
490 // Try to subscribe from a worker without a key. This should fail. | 543 // Try to subscribe from a worker without a key. This should fail. |
491 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); | 544 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); |
492 EXPECT_EQ( | 545 EXPECT_EQ( |
493 "AbortError - Registration failed - missing applicationServerKey, and " | 546 "AbortError - Registration failed - missing applicationServerKey, and " |
494 "gcm_sender_id not found in manifest", | 547 "gcm_sender_id not found in manifest", |
495 script_result); | 548 script_result); |
496 // Now run the subscribe from the service worker with a key. This | 549 // Now run the subscribe from the service worker with a key. This |
497 // should succeed, and write the key to the datastore. | 550 // should succeed, and write the key to the datastore. |
498 ASSERT_TRUE(RunScript("workerSubscribePush()", &script_result)); | 551 ASSERT_TRUE(RunScript("workerSubscribePush()", &script_result)); |
499 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result); | 552 std::string token1; |
| 553 ASSERT_NO_FATAL_FAILURE( |
| 554 EndpointToToken(script_result, true /* standard_protocol */, &token1)); |
500 | 555 |
501 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 556 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
502 EXPECT_EQ("unsubscribe result: true", script_result); | 557 EXPECT_EQ("unsubscribe result: true", script_result); |
503 EXPECT_NE(push_service(), GetAppHandler()); | 558 EXPECT_NE(push_service(), GetAppHandler()); |
504 | 559 |
505 // Now run the subscribe from the service worker without a key. | 560 // Now run the subscribe from the service worker without a key. |
506 // In this case, the key will be read from the datastore. | 561 // In this case, the key will be read from the datastore. |
507 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); | 562 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); |
508 EXPECT_EQ(GetEndpointForSubscriptionId("1-1"), script_result); | 563 std::string token2; |
| 564 ASSERT_NO_FATAL_FAILURE( |
| 565 EndpointToToken(script_result, true /* standard_protocol */, &token2)); |
| 566 EXPECT_NE(token1, token2); |
509 | 567 |
510 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 568 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
511 EXPECT_EQ("unsubscribe result: true", script_result); | 569 EXPECT_EQ("unsubscribe result: true", script_result); |
512 EXPECT_NE(push_service(), GetAppHandler()); | 570 EXPECT_NE(push_service(), GetAppHandler()); |
513 } | 571 } |
514 | 572 |
515 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeWorkerUsingManifest) { | 573 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeWorkerUsingManifest) { |
516 std::string script_result; | 574 std::string script_result; |
517 | 575 |
518 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 576 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
519 ASSERT_EQ("ok - service worker registered", script_result); | 577 ASSERT_EQ("ok - service worker registered", script_result); |
520 | 578 |
521 RequestAndAcceptPermission(); | 579 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission()); |
522 | 580 |
523 LoadTestPage(); // Reload to become controlled. | 581 LoadTestPage(); // Reload to become controlled. |
524 | 582 |
525 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 583 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
526 ASSERT_EQ("true - is controlled", script_result); | 584 ASSERT_EQ("true - is controlled", script_result); |
527 | 585 |
528 // Try to subscribe from a worker without a key. This should fail. | 586 // Try to subscribe from a worker without a key. This should fail. |
529 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); | 587 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); |
530 EXPECT_EQ( | 588 EXPECT_EQ( |
531 "AbortError - Registration failed - missing applicationServerKey, and " | 589 "AbortError - Registration failed - missing applicationServerKey, and " |
532 "gcm_sender_id not found in manifest", | 590 "gcm_sender_id not found in manifest", |
533 script_result); | 591 script_result); |
534 EXPECT_NE(push_service(), GetAppHandler()); | 592 EXPECT_NE(push_service(), GetAppHandler()); |
535 | 593 |
536 // Run the subscription from the document without a key, this will trigger | 594 // Run the subscription from the document without a key, this will trigger |
537 // the code to read sender id from the manifest and will write it to the | 595 // the code to read sender id from the manifest and will write it to the |
538 // datastore. | 596 // datastore. |
539 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); | 597 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); |
540 EXPECT_EQ(GetEndpointForSubscriptionId("1-0", false), script_result); | 598 std::string token1; |
| 599 ASSERT_NO_FATAL_FAILURE( |
| 600 EndpointToToken(script_result, false /* standard_protocol */, &token1)); |
541 | 601 |
542 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 602 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
543 EXPECT_EQ("unsubscribe result: true", script_result); | 603 EXPECT_EQ("unsubscribe result: true", script_result); |
544 EXPECT_NE(push_service(), GetAppHandler()); | 604 EXPECT_NE(push_service(), GetAppHandler()); |
545 | 605 |
546 // Now run the subscribe from the service worker without a key. | 606 // Now run the subscribe from the service worker without a key. |
547 // In this case, the sender id will be read from the datastore. | 607 // In this case, the sender id will be read from the datastore. |
548 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); | 608 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); |
549 EXPECT_EQ(GetEndpointForSubscriptionId("1-1", false), script_result); | 609 std::string token2; |
| 610 ASSERT_NO_FATAL_FAILURE( |
| 611 EndpointToToken(script_result, false /* standard_protocol */, &token2)); |
| 612 EXPECT_NE(token1, token2); |
550 | 613 |
551 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 614 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
552 EXPECT_EQ("unsubscribe result: true", script_result); | 615 EXPECT_EQ("unsubscribe result: true", script_result); |
553 EXPECT_NE(push_service(), GetAppHandler()); | 616 EXPECT_NE(push_service(), GetAppHandler()); |
554 } | 617 } |
555 | 618 |
556 // Disabled on Windows and Linux due to flakiness (http://crbug.com/554003). | 619 // Disabled on Windows and Linux due to flakiness (http://crbug.com/554003). |
557 #if defined(OS_WIN) || defined(OS_LINUX) | 620 #if defined(OS_WIN) || defined(OS_LINUX) |
558 #define MAYBE_SubscribePersisted DISABLED_SubscribePersisted | 621 #define MAYBE_SubscribePersisted DISABLED_SubscribePersisted |
559 #else | 622 #else |
560 #define MAYBE_SubscribePersisted SubscribePersisted | 623 #define MAYBE_SubscribePersisted SubscribePersisted |
561 #endif | 624 #endif |
562 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, MAYBE_SubscribePersisted) { | 625 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, MAYBE_SubscribePersisted) { |
563 std::string script_result; | 626 std::string script_result; |
564 | 627 |
565 // First, test that Service Worker registration IDs are assigned in order of | 628 // First, test that Service Worker registration IDs are assigned in order of |
566 // registering the Service Workers, and the (fake) push subscription ids are | 629 // registering the Service Workers, and the (fake) push subscription ids are |
567 // assigned in order of push subscription (even when these orders are | 630 // assigned in order of push subscription (even when these orders are |
568 // different). | 631 // different). |
569 | 632 |
570 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 633 std::string token1; |
| 634 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(true /* use_key */, &token1)); |
571 PushMessagingAppIdentifier sw0_identifier = | 635 PushMessagingAppIdentifier sw0_identifier = |
572 GetAppIdentifierForServiceWorkerRegistration(0LL); | 636 GetAppIdentifierForServiceWorkerRegistration(0LL); |
573 EXPECT_EQ(sw0_identifier.app_id(), gcm_service()->last_registered_app_id()); | 637 EXPECT_EQ(sw0_identifier.app_id(), gcm_driver_->last_gettoken_app_id()); |
574 | 638 |
575 LoadTestPage("/push_messaging/subscope1/test.html"); | 639 LoadTestPage("/push_messaging/subscope1/test.html"); |
576 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 640 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
577 ASSERT_EQ("ok - service worker registered", script_result); | 641 ASSERT_EQ("ok - service worker registered", script_result); |
578 | 642 |
579 LoadTestPage("/push_messaging/subscope2/test.html"); | 643 LoadTestPage("/push_messaging/subscope2/test.html"); |
580 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 644 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
581 ASSERT_EQ("ok - service worker registered", script_result); | 645 ASSERT_EQ("ok - service worker registered", script_result); |
582 | 646 |
583 // Note that we need to reload the page after registering, otherwise | 647 // Note that we need to reload the page after registering, otherwise |
584 // navigator.serviceWorker.ready is going to be resolved with the parent | 648 // navigator.serviceWorker.ready is going to be resolved with the parent |
585 // Service Worker which still controls the page. | 649 // Service Worker which still controls the page. |
586 LoadTestPage("/push_messaging/subscope2/test.html"); | 650 LoadTestPage("/push_messaging/subscope2/test.html"); |
587 TryToSubscribeSuccessfully("1-1" /* expected_push_subscription_id */); | 651 std::string token2; |
| 652 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(true /* use_key */, &token2)); |
| 653 EXPECT_NE(token1, token2); |
588 PushMessagingAppIdentifier sw2_identifier = | 654 PushMessagingAppIdentifier sw2_identifier = |
589 GetAppIdentifierForServiceWorkerRegistration(2LL); | 655 GetAppIdentifierForServiceWorkerRegistration(2LL); |
590 EXPECT_EQ(sw2_identifier.app_id(), gcm_service()->last_registered_app_id()); | 656 EXPECT_EQ(sw2_identifier.app_id(), gcm_driver_->last_gettoken_app_id()); |
591 | 657 |
592 LoadTestPage("/push_messaging/subscope1/test.html"); | 658 LoadTestPage("/push_messaging/subscope1/test.html"); |
593 TryToSubscribeSuccessfully("1-2" /* expected_push_subscription_id */); | 659 std::string token3; |
| 660 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(true /* use_key */, &token3)); |
| 661 EXPECT_NE(token1, token3); |
| 662 EXPECT_NE(token2, token3); |
594 PushMessagingAppIdentifier sw1_identifier = | 663 PushMessagingAppIdentifier sw1_identifier = |
595 GetAppIdentifierForServiceWorkerRegistration(1LL); | 664 GetAppIdentifierForServiceWorkerRegistration(1LL); |
596 EXPECT_EQ(sw1_identifier.app_id(), gcm_service()->last_registered_app_id()); | 665 EXPECT_EQ(sw1_identifier.app_id(), gcm_driver_->last_gettoken_app_id()); |
597 | 666 |
598 // Now test that the Service Worker registration IDs and push subscription IDs | 667 // Now test that the Service Worker registration IDs and push subscription IDs |
599 // generated above were persisted to SW storage, by checking that they are | 668 // generated above were persisted to SW storage, by checking that they are |
600 // unchanged despite requesting them in a different order. | 669 // unchanged despite requesting them in a different order. |
601 // TODO(johnme): Ideally we would restart the browser at this point to check | 670 // TODO(johnme): Ideally we would restart the browser at this point to check |
602 // they were persisted to disk, but that's not currently possible since the | 671 // they were persisted to disk, but that's not currently possible since the |
603 // test server uses random port numbers for each test (even PRE_Foo and Foo), | 672 // test server uses random port numbers for each test (even PRE_Foo and Foo), |
604 // so we wouldn't be able to load the test pages with the same origin. | 673 // so we wouldn't be able to load the test pages with the same origin. |
605 | 674 |
606 LoadTestPage("/push_messaging/subscope1/test.html"); | 675 LoadTestPage("/push_messaging/subscope1/test.html"); |
607 TryToSubscribeSuccessfully("1-2" /* expected_push_subscription_id */); | 676 std::string token4; |
608 EXPECT_EQ(sw1_identifier.app_id(), gcm_service()->last_registered_app_id()); | 677 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(true /* use_key */, &token4)); |
| 678 EXPECT_EQ(token3, token4); |
| 679 EXPECT_EQ(sw1_identifier.app_id(), gcm_driver_->last_gettoken_app_id()); |
609 | 680 |
610 LoadTestPage("/push_messaging/subscope2/test.html"); | 681 LoadTestPage("/push_messaging/subscope2/test.html"); |
611 TryToSubscribeSuccessfully("1-1" /* expected_push_subscription_id */); | 682 std::string token5; |
612 EXPECT_EQ(sw1_identifier.app_id(), gcm_service()->last_registered_app_id()); | 683 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(true /* use_key */, &token5)); |
| 684 EXPECT_EQ(token2, token5); |
| 685 EXPECT_EQ(sw1_identifier.app_id(), gcm_driver_->last_gettoken_app_id()); |
613 | 686 |
614 LoadTestPage(); | 687 LoadTestPage(); |
615 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 688 std::string token6; |
616 EXPECT_EQ(sw1_identifier.app_id(), gcm_service()->last_registered_app_id()); | 689 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(true /* use_key */, &token6)); |
| 690 EXPECT_EQ(token1, token6); |
| 691 EXPECT_EQ(sw1_identifier.app_id(), gcm_driver_->last_gettoken_app_id()); |
617 } | 692 } |
618 | 693 |
619 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, AppHandlerOnlyIfSubscribed) { | 694 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, AppHandlerOnlyIfSubscribed) { |
620 // This test restarts the push service to simulate restarting the browser. | 695 // This test restarts the push service to simulate restarting the browser. |
621 | 696 |
622 EXPECT_NE(push_service(), GetAppHandler()); | 697 EXPECT_NE(push_service(), GetAppHandler()); |
623 ASSERT_NO_FATAL_FAILURE(RestartPushService()); | 698 ASSERT_NO_FATAL_FAILURE(RestartPushService()); |
624 EXPECT_NE(push_service(), GetAppHandler()); | 699 EXPECT_NE(push_service(), GetAppHandler()); |
625 | 700 |
626 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 701 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
627 | 702 |
628 EXPECT_EQ(push_service(), GetAppHandler()); | 703 EXPECT_EQ(push_service(), GetAppHandler()); |
629 ASSERT_NO_FATAL_FAILURE(RestartPushService()); | 704 ASSERT_NO_FATAL_FAILURE(RestartPushService()); |
630 EXPECT_EQ(push_service(), GetAppHandler()); | 705 EXPECT_EQ(push_service(), GetAppHandler()); |
631 | 706 |
632 // Unsubscribe. | 707 // Unsubscribe. |
633 std::string script_result; | 708 std::string script_result; |
634 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | |
635 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 709 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
636 EXPECT_EQ("unsubscribe result: true", script_result); | 710 EXPECT_EQ("unsubscribe result: true", script_result); |
637 | 711 |
638 EXPECT_NE(push_service(), GetAppHandler()); | 712 EXPECT_NE(push_service(), GetAppHandler()); |
639 ASSERT_NO_FATAL_FAILURE(RestartPushService()); | 713 ASSERT_NO_FATAL_FAILURE(RestartPushService()); |
640 EXPECT_NE(push_service(), GetAppHandler()); | 714 EXPECT_NE(push_service(), GetAppHandler()); |
641 } | 715 } |
642 | 716 |
643 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventSuccess) { | 717 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventSuccess) { |
644 std::string script_result; | 718 std::string script_result; |
645 | 719 |
646 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 720 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
647 | |
648 PushMessagingAppIdentifier app_identifier = | 721 PushMessagingAppIdentifier app_identifier = |
649 GetAppIdentifierForServiceWorkerRegistration(0LL); | 722 GetAppIdentifierForServiceWorkerRegistration(0LL); |
650 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | |
651 EXPECT_EQ(kEncodedApplicationServerKey, | |
652 gcm_service()->last_registered_sender_ids()[0]); | |
653 | 723 |
654 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 724 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
655 ASSERT_EQ("false - is not controlled", script_result); | 725 ASSERT_EQ("false - is not controlled", script_result); |
656 | 726 |
657 LoadTestPage(); // Reload to become controlled. | 727 LoadTestPage(); // Reload to become controlled. |
658 | 728 |
659 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 729 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
660 ASSERT_EQ("true - is controlled", script_result); | 730 ASSERT_EQ("true - is controlled", script_result); |
661 | 731 |
662 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(false)); | 732 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(false)); |
663 gcm::IncomingMessage message; | 733 gcm::IncomingMessage message; |
664 message.sender_id = GetTestApplicationServerKey(); | 734 message.sender_id = GetTestApplicationServerKey(); |
665 message.raw_data = "testdata"; | 735 message.raw_data = "testdata"; |
666 message.decrypted = true; | 736 message.decrypted = true; |
667 push_service()->OnMessage(app_identifier.app_id(), message); | 737 push_service()->OnMessage(app_identifier.app_id(), message); |
668 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(true)); | 738 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(true)); |
669 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); | 739 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); |
670 EXPECT_EQ("testdata", script_result); | 740 EXPECT_EQ("testdata", script_result); |
671 } | 741 } |
672 | 742 |
673 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventWithoutPayload) { | 743 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventWithoutPayload) { |
674 std::string script_result; | 744 std::string script_result; |
675 | 745 |
676 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 746 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
677 | |
678 PushMessagingAppIdentifier app_identifier = | 747 PushMessagingAppIdentifier app_identifier = |
679 GetAppIdentifierForServiceWorkerRegistration(0LL); | 748 GetAppIdentifierForServiceWorkerRegistration(0LL); |
680 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | |
681 EXPECT_EQ(kEncodedApplicationServerKey, | |
682 gcm_service()->last_registered_sender_ids()[0]); | |
683 | 749 |
684 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 750 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
685 ASSERT_EQ("false - is not controlled", script_result); | 751 ASSERT_EQ("false - is not controlled", script_result); |
686 | 752 |
687 LoadTestPage(); // Reload to become controlled. | 753 LoadTestPage(); // Reload to become controlled. |
688 | 754 |
689 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 755 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
690 ASSERT_EQ("true - is controlled", script_result); | 756 ASSERT_EQ("true - is controlled", script_result); |
691 | 757 |
692 gcm::IncomingMessage message; | 758 gcm::IncomingMessage message; |
693 message.sender_id = GetTestApplicationServerKey(); | 759 message.sender_id = GetTestApplicationServerKey(); |
694 message.decrypted = false; | 760 message.decrypted = false; |
695 | 761 |
696 push_service()->OnMessage(app_identifier.app_id(), message); | 762 push_service()->OnMessage(app_identifier.app_id(), message); |
697 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); | 763 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); |
698 EXPECT_EQ("[NULL]", script_result); | 764 EXPECT_EQ("[NULL]", script_result); |
699 } | 765 } |
700 | 766 |
| 767 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, LegacyPushEvent) { |
| 768 std::string script_result; |
| 769 |
| 770 ASSERT_NO_FATAL_FAILURE(LegacySubscribeSuccessfully()); |
| 771 PushMessagingAppIdentifier app_identifier = |
| 772 GetAppIdentifierForServiceWorkerRegistration(0LL); |
| 773 |
| 774 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 775 ASSERT_EQ("false - is not controlled", script_result); |
| 776 |
| 777 LoadTestPage(); // Reload to become controlled. |
| 778 |
| 779 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 780 ASSERT_EQ("true - is controlled", script_result); |
| 781 |
| 782 gcm::IncomingMessage message; |
| 783 message.sender_id = kManifestSenderId; |
| 784 message.decrypted = false; |
| 785 |
| 786 push_service()->OnMessage(app_identifier.app_id(), message); |
| 787 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); |
| 788 EXPECT_EQ("[NULL]", script_result); |
| 789 } |
| 790 |
701 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) { | 791 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) { |
702 std::string script_result; | 792 std::string script_result; |
703 | 793 |
704 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 794 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
705 | |
706 PushMessagingAppIdentifier app_identifier = | 795 PushMessagingAppIdentifier app_identifier = |
707 GetAppIdentifierForServiceWorkerRegistration(0LL); | 796 GetAppIdentifierForServiceWorkerRegistration(0LL); |
708 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | |
709 EXPECT_EQ(kEncodedApplicationServerKey, | |
710 gcm_service()->last_registered_sender_ids()[0]); | |
711 | 797 |
712 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 798 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
713 ASSERT_EQ("false - is not controlled", script_result); | 799 ASSERT_EQ("false - is not controlled", script_result); |
714 | 800 |
715 LoadTestPage(); // Reload to become controlled. | 801 LoadTestPage(); // Reload to become controlled. |
716 | 802 |
717 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 803 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
718 ASSERT_EQ("true - is controlled", script_result); | 804 ASSERT_EQ("true - is controlled", script_result); |
719 | 805 |
720 // Unregister service worker. Sending a message should now fail. | 806 // Unregister service worker. Sending a message should now fail. |
721 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result)); | 807 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result)); |
722 ASSERT_EQ("service worker unregistration status: true", script_result); | 808 ASSERT_EQ("service worker unregistration status: true", script_result); |
723 | 809 |
724 // When the push service will receive it next message, given that there is no | 810 // Unregistering the service worker doesn't yet unsubscribe from push (though |
725 // SW available, it should unregister |app_identifier.app_id()|. | 811 // it should), and FindByServiceWorker doesn't require a live SW. |
726 UnregistrationCallback callback; | 812 GURL origin = https_server()->GetURL("/").GetOrigin(); |
727 gcm_service()->SetUnregisterCallback( | 813 PushMessagingAppIdentifier app_identifier2 = |
728 base::Bind(&UnregistrationCallback::Run, base::Unretained(&callback))); | 814 PushMessagingAppIdentifier::FindByServiceWorker( |
| 815 GetBrowser()->profile(), origin, |
| 816 0LL /* service_worker_registration_id */); |
| 817 EXPECT_FALSE(app_identifier2.is_null()); |
| 818 EXPECT_EQ(app_identifier.app_id(), app_identifier2.app_id()); |
729 | 819 |
730 gcm::IncomingMessage message; | 820 gcm::IncomingMessage message; |
731 message.sender_id = GetTestApplicationServerKey(); | 821 message.sender_id = GetTestApplicationServerKey(); |
732 message.raw_data = "testdata"; | 822 message.raw_data = "testdata"; |
733 message.decrypted = true; | 823 message.decrypted = true; |
| 824 |
| 825 base::RunLoop run_loop; |
| 826 push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure()); |
734 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(false)); | 827 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(false)); |
735 push_service()->OnMessage(app_identifier.app_id(), message); | 828 push_service()->OnMessage(app_identifier.app_id(), message); |
736 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(true)); | 829 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(true)); |
737 callback.WaitUntilSatisfied(); | 830 run_loop.Run(); |
738 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(false)); | 831 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(false)); |
739 EXPECT_EQ(app_identifier.app_id(), callback.app_id()); | 832 |
| 833 // Now the push service has received a message and failed to find its service |
| 834 // worker, it should have automatically unsubscribed app_identifier.app_id(). |
| 835 PushMessagingAppIdentifier app_identifier3 = |
| 836 PushMessagingAppIdentifier::FindByServiceWorker( |
| 837 GetBrowser()->profile(), origin, |
| 838 0LL /* service_worker_registration_id */); |
| 839 EXPECT_TRUE(app_identifier3.is_null()); |
740 | 840 |
741 // No push data should have been received. | 841 // No push data should have been received. |
742 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); | 842 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); |
743 EXPECT_EQ("null", script_result); | 843 EXPECT_EQ("null", script_result); |
744 } | 844 } |
745 | 845 |
746 #if defined(ENABLE_NOTIFICATIONS) | 846 #if defined(ENABLE_NOTIFICATIONS) |
747 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 847 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
748 PushEventEnforcesUserVisibleNotification) { | 848 PushEventEnforcesUserVisibleNotification) { |
749 std::string script_result; | 849 std::string script_result; |
750 | 850 |
751 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 851 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
752 | |
753 PushMessagingAppIdentifier app_identifier = | 852 PushMessagingAppIdentifier app_identifier = |
754 GetAppIdentifierForServiceWorkerRegistration(0LL); | 853 GetAppIdentifierForServiceWorkerRegistration(0LL); |
755 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | |
756 EXPECT_EQ(kEncodedApplicationServerKey, | |
757 gcm_service()->last_registered_sender_ids()[0]); | |
758 | 854 |
759 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 855 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
760 ASSERT_EQ("false - is not controlled", script_result); | 856 ASSERT_EQ("false - is not controlled", script_result); |
761 | 857 |
762 LoadTestPage(); // Reload to become controlled. | 858 LoadTestPage(); // Reload to become controlled. |
763 | 859 |
764 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 860 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
765 ASSERT_EQ("true - is controlled", script_result); | 861 ASSERT_EQ("true - is controlled", script_result); |
766 | 862 |
767 notification_manager()->CancelAll(); | 863 notification_manager()->CancelAll(); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
876 "PushMessaging.SESForLowBudgetOrigin"); | 972 "PushMessaging.SESForLowBudgetOrigin"); |
877 ASSERT_EQ(1.0, low_budget_buckets.size()); | 973 ASSERT_EQ(1.0, low_budget_buckets.size()); |
878 EXPECT_EQ(4, low_budget_buckets[0].min); | 974 EXPECT_EQ(4, low_budget_buckets[0].min); |
879 EXPECT_EQ(1, low_budget_buckets[0].count); | 975 EXPECT_EQ(1, low_budget_buckets[0].count); |
880 } | 976 } |
881 | 977 |
882 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 978 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
883 PushEventAllowSilentPushCommandLineFlag) { | 979 PushEventAllowSilentPushCommandLineFlag) { |
884 std::string script_result; | 980 std::string script_result; |
885 | 981 |
886 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 982 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
887 | |
888 PushMessagingAppIdentifier app_identifier = | 983 PushMessagingAppIdentifier app_identifier = |
889 GetAppIdentifierForServiceWorkerRegistration(0LL); | 984 GetAppIdentifierForServiceWorkerRegistration(0LL); |
890 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | 985 EXPECT_EQ(app_identifier.app_id(), gcm_driver_->last_gettoken_app_id()); |
891 EXPECT_EQ(kEncodedApplicationServerKey, | 986 EXPECT_EQ(kEncodedApplicationServerKey, |
892 gcm_service()->last_registered_sender_ids()[0]); | 987 gcm_driver_->last_gettoken_authorized_entity()); |
893 | 988 |
894 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 989 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
895 ASSERT_EQ("false - is not controlled", script_result); | 990 ASSERT_EQ("false - is not controlled", script_result); |
896 | 991 |
897 LoadTestPage(); // Reload to become controlled. | 992 LoadTestPage(); // Reload to become controlled. |
898 | 993 |
899 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 994 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
900 ASSERT_EQ("true - is controlled", script_result); | 995 ASSERT_EQ("true - is controlled", script_result); |
901 | 996 |
902 notification_manager()->CancelAll(); | 997 notification_manager()->CancelAll(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
947 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); | 1042 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); |
948 EXPECT_EQ("testdata", script_result); | 1043 EXPECT_EQ("testdata", script_result); |
949 | 1044 |
950 ASSERT_EQ(0u, notification_manager()->GetNotificationCount()); | 1045 ASSERT_EQ(0u, notification_manager()->GetNotificationCount()); |
951 } | 1046 } |
952 | 1047 |
953 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1048 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
954 PushEventEnforcesUserVisibleNotificationAfterQueue) { | 1049 PushEventEnforcesUserVisibleNotificationAfterQueue) { |
955 std::string script_result; | 1050 std::string script_result; |
956 | 1051 |
957 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1052 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
958 | |
959 PushMessagingAppIdentifier app_identifier = | 1053 PushMessagingAppIdentifier app_identifier = |
960 GetAppIdentifierForServiceWorkerRegistration(0LL); | 1054 GetAppIdentifierForServiceWorkerRegistration(0LL); |
961 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | |
962 EXPECT_EQ(kEncodedApplicationServerKey, | |
963 gcm_service()->last_registered_sender_ids()[0]); | |
964 | 1055 |
965 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 1056 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
966 ASSERT_EQ("false - is not controlled", script_result); | 1057 ASSERT_EQ("false - is not controlled", script_result); |
967 | 1058 |
968 LoadTestPage(); // Reload to become controlled. | 1059 LoadTestPage(); // Reload to become controlled. |
969 | 1060 |
970 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 1061 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
971 ASSERT_EQ("true - is controlled", script_result); | 1062 ASSERT_EQ("true - is controlled", script_result); |
972 | 1063 |
973 // Fire off two push messages in sequence, only the second one of which will | 1064 // Fire off two push messages in sequence, only the second one of which will |
(...skipping 27 matching lines...) Expand all Loading... |
1001 EXPECT_EQ(0u, number_of_notifications_shown[0]); | 1092 EXPECT_EQ(0u, number_of_notifications_shown[0]); |
1002 EXPECT_EQ(1u, number_of_notifications_shown[1]); | 1093 EXPECT_EQ(1u, number_of_notifications_shown[1]); |
1003 } | 1094 } |
1004 | 1095 |
1005 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1096 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
1006 PushEventNotificationWithoutEventWaitUntil) { | 1097 PushEventNotificationWithoutEventWaitUntil) { |
1007 std::string script_result; | 1098 std::string script_result; |
1008 content::WebContents* web_contents = | 1099 content::WebContents* web_contents = |
1009 GetBrowser()->tab_strip_model()->GetActiveWebContents(); | 1100 GetBrowser()->tab_strip_model()->GetActiveWebContents(); |
1010 | 1101 |
1011 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1102 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
1012 | |
1013 PushMessagingAppIdentifier app_identifier = | 1103 PushMessagingAppIdentifier app_identifier = |
1014 GetAppIdentifierForServiceWorkerRegistration(0LL); | 1104 GetAppIdentifierForServiceWorkerRegistration(0LL); |
1015 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | |
1016 EXPECT_EQ(kEncodedApplicationServerKey, | |
1017 gcm_service()->last_registered_sender_ids()[0]); | |
1018 | 1105 |
1019 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 1106 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
1020 ASSERT_EQ("false - is not controlled", script_result); | 1107 ASSERT_EQ("false - is not controlled", script_result); |
1021 | 1108 |
1022 LoadTestPage(); // Reload to become controlled. | 1109 LoadTestPage(); // Reload to become controlled. |
1023 | 1110 |
1024 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 1111 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
1025 ASSERT_EQ("true - is controlled", script_result); | 1112 ASSERT_EQ("true - is controlled", script_result); |
1026 | 1113 |
1027 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1114 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1148 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
1062 ASSERT_EQ("permission status - prompt", script_result); | 1149 ASSERT_EQ("permission status - prompt", script_result); |
1063 } | 1150 } |
1064 | 1151 |
1065 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PermissionStateSaysGranted) { | 1152 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PermissionStateSaysGranted) { |
1066 std::string script_result; | 1153 std::string script_result; |
1067 | 1154 |
1068 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 1155 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
1069 ASSERT_EQ("ok - service worker registered", script_result); | 1156 ASSERT_EQ("ok - service worker registered", script_result); |
1070 | 1157 |
1071 RequestAndAcceptPermission(); | 1158 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission()); |
1072 | 1159 |
1073 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); | 1160 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); |
1074 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result); | 1161 ASSERT_NO_FATAL_FAILURE(EndpointToToken(script_result)); |
1075 | 1162 |
1076 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1163 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
1077 EXPECT_EQ("permission status - granted", script_result); | 1164 EXPECT_EQ("permission status - granted", script_result); |
1078 } | 1165 } |
1079 | 1166 |
1080 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PermissionStateSaysDenied) { | 1167 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PermissionStateSaysDenied) { |
1081 std::string script_result; | 1168 std::string script_result; |
1082 | 1169 |
1083 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 1170 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
1084 ASSERT_EQ("ok - service worker registered", script_result); | 1171 ASSERT_EQ("ok - service worker registered", script_result); |
1085 | 1172 |
1086 RequestAndDenyPermission(); | 1173 ASSERT_NO_FATAL_FAILURE(RequestAndDenyPermission()); |
1087 | 1174 |
1088 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); | 1175 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); |
1089 EXPECT_EQ("NotAllowedError - Registration failed - permission denied", | 1176 EXPECT_EQ("NotAllowedError - Registration failed - permission denied", |
1090 script_result); | 1177 script_result); |
1091 | 1178 |
1092 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1179 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
1093 EXPECT_EQ("permission status - denied", script_result); | 1180 EXPECT_EQ("permission status - denied", script_result); |
1094 } | 1181 } |
1095 | 1182 |
1096 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, UnsubscribeSuccess) { | 1183 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, UnsubscribeSuccess) { |
1097 std::string script_result; | 1184 std::string script_result; |
1098 | 1185 |
1099 EXPECT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 1186 EXPECT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
1100 EXPECT_EQ("ok - service worker registered", script_result); | 1187 EXPECT_EQ("ok - service worker registered", script_result); |
1101 | 1188 |
1102 // Resolves true if there was a subscription. | 1189 // Resolves true if there was a subscription. |
1103 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */, false); | 1190 std::string token1; |
1104 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | 1191 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(false /* use_key */, &token1)); |
1105 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1192 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
1106 EXPECT_EQ("unsubscribe result: true", script_result); | 1193 EXPECT_EQ("unsubscribe result: true", script_result); |
1107 | 1194 |
| 1195 // Resolves false if there was no longer a subscription. |
| 1196 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 1197 EXPECT_EQ("unsubscribe result: false", script_result); |
| 1198 |
| 1199 // TODO(johnme): Test that doesn't reject if there was a network error (should |
| 1200 // deactivate subscription locally anyway). |
| 1201 // TODO(johnme): Test that doesn't reject if there were other push service |
| 1202 // errors (should deactivate subscription locally anyway). |
| 1203 |
| 1204 // Unsubscribing (with an existing reference to a PushSubscription), after |
| 1205 // unregistering the Service Worker, just means push subscription isn't found. |
| 1206 std::string token2; |
| 1207 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(false /* use_key */, &token2)); |
| 1208 EXPECT_NE(token1, token2); |
| 1209 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result)); |
| 1210 ASSERT_EQ("service worker unregistration status: true", script_result); |
| 1211 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 1212 EXPECT_EQ("unsubscribe result: false", script_result); |
| 1213 } |
| 1214 |
| 1215 // Push subscriptions used to be non-InstanceID GCM registrations. Still need |
| 1216 // to be able to unsubscribe these, even though new ones are no longer created. |
| 1217 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, LegacyUnsubscribeSuccess) { |
| 1218 std::string script_result; |
| 1219 |
| 1220 // Resolves true if there was a subscription. |
| 1221 std::string subscription_id1; |
| 1222 ASSERT_NO_FATAL_FAILURE(LegacySubscribeSuccessfully(&subscription_id1)); |
| 1223 gcm_service_->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); |
| 1224 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 1225 EXPECT_EQ("unsubscribe result: true", script_result); |
| 1226 |
1108 // Resolves false if there was no longer a subscription. | 1227 // Resolves false if there was no longer a subscription. |
1109 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1228 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
1110 EXPECT_EQ("unsubscribe result: false", script_result); | 1229 EXPECT_EQ("unsubscribe result: false", script_result); |
1111 | 1230 |
1112 // Doesn't reject if there was a network error (deactivates subscription | 1231 // Doesn't reject if there was a network error (deactivates subscription |
1113 // locally anyway). | 1232 // locally anyway). |
1114 TryToSubscribeSuccessfully("1-1" /* expected_push_subscription_id */, false); | 1233 std::string subscription_id2; |
1115 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::NETWORK_ERROR); | 1234 ASSERT_NO_FATAL_FAILURE(LegacySubscribeSuccessfully(&subscription_id2)); |
| 1235 EXPECT_NE(subscription_id1, subscription_id2); |
| 1236 gcm_service_->AddExpectedUnregisterResponse(gcm::GCMClient::NETWORK_ERROR); |
1116 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1237 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
1117 EXPECT_EQ("unsubscribe result: true", script_result); | 1238 EXPECT_EQ("unsubscribe result: true", script_result); |
1118 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1239 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
1119 EXPECT_EQ("false - not subscribed", script_result); | 1240 EXPECT_EQ("false - not subscribed", script_result); |
1120 | 1241 |
1121 // Doesn't reject if there were other push service errors (deactivates | 1242 // Doesn't reject if there were other push service errors (deactivates |
1122 // subscription locally anyway). | 1243 // subscription locally anyway). |
1123 TryToSubscribeSuccessfully("1-2" /* expected_push_subscription_id */, false); | 1244 std::string subscription_id3; |
1124 gcm_service()->AddExpectedUnregisterResponse( | 1245 ASSERT_NO_FATAL_FAILURE(LegacySubscribeSuccessfully(&subscription_id3)); |
| 1246 EXPECT_NE(subscription_id1, subscription_id3); |
| 1247 EXPECT_NE(subscription_id2, subscription_id3); |
| 1248 gcm_service_->AddExpectedUnregisterResponse( |
1125 gcm::GCMClient::INVALID_PARAMETER); | 1249 gcm::GCMClient::INVALID_PARAMETER); |
1126 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1250 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
1127 EXPECT_EQ("unsubscribe result: true", script_result); | 1251 EXPECT_EQ("unsubscribe result: true", script_result); |
1128 | 1252 |
1129 // Unsubscribing (with an existing reference to a PushSubscription), after | 1253 // Unsubscribing (with an existing reference to a PushSubscription), after |
1130 // unregistering the Service Worker, just means push subscription isn't found. | 1254 // unregistering the Service Worker, just means push subscription isn't found. |
1131 TryToSubscribeSuccessfully("1-3" /* expected_push_subscription_id */, false); | 1255 std::string subscription_id4; |
| 1256 ASSERT_NO_FATAL_FAILURE(LegacySubscribeSuccessfully(&subscription_id4)); |
| 1257 EXPECT_NE(subscription_id1, subscription_id4); |
| 1258 EXPECT_NE(subscription_id2, subscription_id4); |
| 1259 EXPECT_NE(subscription_id3, subscription_id4); |
1132 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result)); | 1260 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result)); |
1133 ASSERT_EQ("service worker unregistration status: true", script_result); | 1261 ASSERT_EQ("service worker unregistration status: true", script_result); |
1134 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1262 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
1135 EXPECT_EQ("unsubscribe result: false", script_result); | 1263 EXPECT_EQ("unsubscribe result: false", script_result); |
1136 } | 1264 } |
1137 | 1265 |
1138 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1266 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
1139 GlobalResetPushPermissionUnsubscribes) { | 1267 GlobalResetPushPermissionUnsubscribes) { |
1140 std::string script_result; | 1268 std::string script_result; |
1141 | 1269 |
1142 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1270 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
1143 | 1271 |
1144 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1272 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
1145 EXPECT_EQ("true - subscribed", script_result); | 1273 EXPECT_EQ("true - subscribed", script_result); |
1146 | 1274 |
1147 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1275 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
1148 EXPECT_EQ("permission status - granted", script_result); | 1276 EXPECT_EQ("permission status - granted", script_result); |
1149 | 1277 |
1150 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1278 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
1151 new content::MessageLoopRunner; | 1279 new content::MessageLoopRunner; |
1152 push_service()->SetContentSettingChangedCallbackForTesting( | 1280 push_service()->SetContentSettingChangedCallbackForTesting( |
1153 message_loop_runner->QuitClosure()); | 1281 message_loop_runner->QuitClosure()); |
1154 | 1282 |
1155 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 1283 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
1156 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 1284 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
1157 | 1285 |
1158 message_loop_runner->Run(); | 1286 message_loop_runner->Run(); |
1159 | 1287 |
1160 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1288 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
1161 EXPECT_EQ("permission status - prompt", script_result); | 1289 EXPECT_EQ("permission status - prompt", script_result); |
1162 | 1290 |
1163 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1291 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
1164 EXPECT_EQ("false - not subscribed", script_result); | 1292 EXPECT_EQ("false - not subscribed", script_result); |
1165 } | 1293 } |
1166 | 1294 |
1167 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1295 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
1168 LocalResetPushPermissionUnsubscribes) { | 1296 LocalResetPushPermissionUnsubscribes) { |
1169 std::string script_result; | 1297 std::string script_result; |
1170 | 1298 |
1171 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1299 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
1172 | 1300 |
1173 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1301 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
1174 EXPECT_EQ("true - subscribed", script_result); | 1302 EXPECT_EQ("true - subscribed", script_result); |
1175 | 1303 |
1176 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1304 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
1177 EXPECT_EQ("permission status - granted", script_result); | 1305 EXPECT_EQ("permission status - granted", script_result); |
1178 | 1306 |
1179 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1307 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
1180 new content::MessageLoopRunner; | 1308 new content::MessageLoopRunner; |
1181 push_service()->SetContentSettingChangedCallbackForTesting( | 1309 push_service()->SetContentSettingChangedCallbackForTesting( |
(...skipping 11 matching lines...) Expand all Loading... |
1193 EXPECT_EQ("permission status - prompt", script_result); | 1321 EXPECT_EQ("permission status - prompt", script_result); |
1194 | 1322 |
1195 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1323 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
1196 EXPECT_EQ("false - not subscribed", script_result); | 1324 EXPECT_EQ("false - not subscribed", script_result); |
1197 } | 1325 } |
1198 | 1326 |
1199 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1327 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
1200 DenyPushPermissionUnsubscribes) { | 1328 DenyPushPermissionUnsubscribes) { |
1201 std::string script_result; | 1329 std::string script_result; |
1202 | 1330 |
1203 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1331 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
1204 | 1332 |
1205 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1333 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
1206 EXPECT_EQ("true - subscribed", script_result); | 1334 EXPECT_EQ("true - subscribed", script_result); |
1207 | 1335 |
1208 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1336 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
1209 EXPECT_EQ("permission status - granted", script_result); | 1337 EXPECT_EQ("permission status - granted", script_result); |
1210 | 1338 |
1211 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1339 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
1212 new content::MessageLoopRunner; | 1340 new content::MessageLoopRunner; |
1213 push_service()->SetContentSettingChangedCallbackForTesting( | 1341 push_service()->SetContentSettingChangedCallbackForTesting( |
(...skipping 11 matching lines...) Expand all Loading... |
1225 EXPECT_EQ("permission status - denied", script_result); | 1353 EXPECT_EQ("permission status - denied", script_result); |
1226 | 1354 |
1227 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1355 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
1228 EXPECT_EQ("false - not subscribed", script_result); | 1356 EXPECT_EQ("false - not subscribed", script_result); |
1229 } | 1357 } |
1230 | 1358 |
1231 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1359 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
1232 GlobalResetNotificationsPermissionUnsubscribes) { | 1360 GlobalResetNotificationsPermissionUnsubscribes) { |
1233 std::string script_result; | 1361 std::string script_result; |
1234 | 1362 |
1235 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1363 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
1236 | 1364 |
1237 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1365 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
1238 EXPECT_EQ("true - subscribed", script_result); | 1366 EXPECT_EQ("true - subscribed", script_result); |
1239 | 1367 |
1240 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1368 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
1241 EXPECT_EQ("permission status - granted", script_result); | 1369 EXPECT_EQ("permission status - granted", script_result); |
1242 | 1370 |
1243 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1371 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
1244 new content::MessageLoopRunner; | 1372 new content::MessageLoopRunner; |
1245 push_service()->SetContentSettingChangedCallbackForTesting( | 1373 push_service()->SetContentSettingChangedCallbackForTesting( |
1246 message_loop_runner->QuitClosure()); | 1374 message_loop_runner->QuitClosure()); |
1247 | 1375 |
1248 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 1376 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
1249 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 1377 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
1250 | 1378 |
1251 message_loop_runner->Run(); | 1379 message_loop_runner->Run(); |
1252 | 1380 |
1253 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1381 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
1254 EXPECT_EQ("permission status - prompt", script_result); | 1382 EXPECT_EQ("permission status - prompt", script_result); |
1255 | 1383 |
1256 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1384 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
1257 EXPECT_EQ("false - not subscribed", script_result); | 1385 EXPECT_EQ("false - not subscribed", script_result); |
1258 } | 1386 } |
1259 | 1387 |
1260 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1388 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
1261 LocalResetNotificationsPermissionUnsubscribes) { | 1389 LocalResetNotificationsPermissionUnsubscribes) { |
1262 std::string script_result; | 1390 std::string script_result; |
1263 | 1391 |
1264 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1392 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
1265 | 1393 |
1266 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1394 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
1267 EXPECT_EQ("true - subscribed", script_result); | 1395 EXPECT_EQ("true - subscribed", script_result); |
1268 | 1396 |
1269 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1397 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
1270 EXPECT_EQ("permission status - granted", script_result); | 1398 EXPECT_EQ("permission status - granted", script_result); |
1271 | 1399 |
1272 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1400 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
1273 new content::MessageLoopRunner; | 1401 new content::MessageLoopRunner; |
1274 push_service()->SetContentSettingChangedCallbackForTesting( | 1402 push_service()->SetContentSettingChangedCallbackForTesting( |
(...skipping 11 matching lines...) Expand all Loading... |
1286 EXPECT_EQ("permission status - prompt", script_result); | 1414 EXPECT_EQ("permission status - prompt", script_result); |
1287 | 1415 |
1288 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1416 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
1289 EXPECT_EQ("false - not subscribed", script_result); | 1417 EXPECT_EQ("false - not subscribed", script_result); |
1290 } | 1418 } |
1291 | 1419 |
1292 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1420 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
1293 DenyNotificationsPermissionUnsubscribes) { | 1421 DenyNotificationsPermissionUnsubscribes) { |
1294 std::string script_result; | 1422 std::string script_result; |
1295 | 1423 |
1296 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1424 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
1297 | 1425 |
1298 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1426 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
1299 EXPECT_EQ("true - subscribed", script_result); | 1427 EXPECT_EQ("true - subscribed", script_result); |
1300 | 1428 |
1301 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1429 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
1302 EXPECT_EQ("permission status - granted", script_result); | 1430 EXPECT_EQ("permission status - granted", script_result); |
1303 | 1431 |
1304 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1432 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
1305 new content::MessageLoopRunner; | 1433 new content::MessageLoopRunner; |
1306 push_service()->SetContentSettingChangedCallbackForTesting( | 1434 push_service()->SetContentSettingChangedCallbackForTesting( |
(...skipping 11 matching lines...) Expand all Loading... |
1318 EXPECT_EQ("permission status - denied", script_result); | 1446 EXPECT_EQ("permission status - denied", script_result); |
1319 | 1447 |
1320 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1448 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
1321 EXPECT_EQ("false - not subscribed", script_result); | 1449 EXPECT_EQ("false - not subscribed", script_result); |
1322 } | 1450 } |
1323 | 1451 |
1324 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1452 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
1325 GrantAlreadyGrantedPermissionDoesNotUnsubscribe) { | 1453 GrantAlreadyGrantedPermissionDoesNotUnsubscribe) { |
1326 std::string script_result; | 1454 std::string script_result; |
1327 | 1455 |
1328 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1456 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
1329 | 1457 |
1330 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1458 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
1331 EXPECT_EQ("true - subscribed", script_result); | 1459 EXPECT_EQ("true - subscribed", script_result); |
1332 | 1460 |
1333 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1461 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
1334 EXPECT_EQ("permission status - granted", script_result); | 1462 EXPECT_EQ("permission status - granted", script_result); |
1335 | 1463 |
1336 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1464 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
1337 new content::MessageLoopRunner; | 1465 new content::MessageLoopRunner; |
1338 push_service()->SetContentSettingChangedCallbackForTesting( | 1466 push_service()->SetContentSettingChangedCallbackForTesting( |
(...skipping 15 matching lines...) Expand all Loading... |
1354 } | 1482 } |
1355 | 1483 |
1356 // This test is testing some non-trivial content settings rules and make sure | 1484 // This test is testing some non-trivial content settings rules and make sure |
1357 // that they are respected with regards to automatic unsubscription. In other | 1485 // that they are respected with regards to automatic unsubscription. In other |
1358 // words, it checks that the push service does not end up unsubscribing origins | 1486 // words, it checks that the push service does not end up unsubscribing origins |
1359 // that have push permission with some non-common rules. | 1487 // that have push permission with some non-common rules. |
1360 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1488 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
1361 AutomaticUnsubscriptionFollowsContentSettingRules) { | 1489 AutomaticUnsubscriptionFollowsContentSettingRules) { |
1362 std::string script_result; | 1490 std::string script_result; |
1363 | 1491 |
1364 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1492 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
1365 | 1493 |
1366 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1494 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
1367 EXPECT_EQ("true - subscribed", script_result); | 1495 EXPECT_EQ("true - subscribed", script_result); |
1368 | 1496 |
1369 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1497 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
1370 EXPECT_EQ("permission status - granted", script_result); | 1498 EXPECT_EQ("permission status - granted", script_result); |
1371 | 1499 |
1372 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1500 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
1373 new content::MessageLoopRunner; | 1501 new content::MessageLoopRunner; |
1374 push_service()->SetContentSettingChangedCallbackForTesting( | 1502 push_service()->SetContentSettingChangedCallbackForTesting( |
(...skipping 15 matching lines...) Expand all Loading... |
1390 // The Push service should not unsubcribe |origin| because at no point it was | 1518 // The Push service should not unsubcribe |origin| because at no point it was |
1391 // left without permission to use Push. | 1519 // left without permission to use Push. |
1392 | 1520 |
1393 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1521 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
1394 EXPECT_EQ("permission status - granted", script_result); | 1522 EXPECT_EQ("permission status - granted", script_result); |
1395 | 1523 |
1396 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1524 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
1397 EXPECT_EQ("true - subscribed", script_result); | 1525 EXPECT_EQ("true - subscribed", script_result); |
1398 } | 1526 } |
1399 | 1527 |
1400 // Checks that automatically unsubscribing due to a revoked permission is | 1528 // Checks automatically unsubscribing due to a revoked permission after |
1401 // handled well if the sender ID needed to unsubscribe was already deleted. | 1529 // previously clearing site data. |
1402 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1530 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
1403 ResetPushPermissionAfterClearingSiteData) { | 1531 ResetPushPermissionAfterClearingSiteData) { |
1404 std::string script_result; | 1532 std::string script_result; |
1405 | 1533 |
1406 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1534 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
1407 | 1535 |
1408 PushMessagingAppIdentifier app_identifier = | 1536 PushMessagingAppIdentifier app_identifier = |
1409 GetAppIdentifierForServiceWorkerRegistration(0LL); | 1537 GetAppIdentifierForServiceWorkerRegistration(0LL); |
1410 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | |
1411 PushMessagingAppIdentifier stored_app_identifier = | 1538 PushMessagingAppIdentifier stored_app_identifier = |
1412 PushMessagingAppIdentifier::FindByAppId(GetBrowser()->profile(), | 1539 PushMessagingAppIdentifier::FindByAppId(GetBrowser()->profile(), |
1413 app_identifier.app_id()); | 1540 app_identifier.app_id()); |
1414 EXPECT_FALSE(stored_app_identifier.is_null()); | 1541 EXPECT_FALSE(stored_app_identifier.is_null()); |
1415 | 1542 |
1416 // Simulate a user clearing site data (including Service Workers, crucially). | 1543 // Simulate a user clearing site data (including Service Workers, crucially). |
1417 BrowsingDataRemover* remover = | 1544 BrowsingDataRemover* remover = |
1418 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowser()->profile()); | 1545 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowser()->profile()); |
1419 BrowsingDataRemoverCompletionObserver observer(remover); | 1546 BrowsingDataRemoverCompletionObserver observer(remover); |
1420 remover->RemoveAndReply(BrowsingDataRemover::Unbounded(), | 1547 remover->RemoveAndReply(BrowsingDataRemover::Unbounded(), |
1421 BrowsingDataRemover::REMOVE_SITE_DATA, | 1548 BrowsingDataRemover::REMOVE_SITE_DATA, |
1422 BrowsingDataHelper::UNPROTECTED_WEB, &observer); | 1549 BrowsingDataHelper::UNPROTECTED_WEB, &observer); |
1423 observer.BlockUntilCompletion(); | 1550 observer.BlockUntilCompletion(); |
1424 | 1551 |
1425 base::RunLoop run_loop; | 1552 base::RunLoop run_loop; |
1426 push_service()->SetContentSettingChangedCallbackForTesting( | 1553 push_service()->SetContentSettingChangedCallbackForTesting( |
1427 run_loop.QuitClosure()); | 1554 run_loop.QuitClosure()); |
1428 | 1555 |
1429 // This shouldn't (asynchronously) cause a DCHECK. | 1556 // This shouldn't (asynchronously) cause a DCHECK. |
1430 // TODO(johnme): Get this test running on Android, which has a different | 1557 // TODO(johnme): Get this test running on Android with legacy GCM |
1431 // codepath due to sender_id being required for unsubscribing there. | 1558 // registrations, which have a different codepath due to sender_id being |
| 1559 // required for unsubscribing there. |
1432 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 1560 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
1433 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 1561 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
1434 | 1562 |
1435 run_loop.Run(); | 1563 run_loop.Run(); |
1436 | 1564 |
1437 // |app_identifier| should no longer be stored in prefs. | 1565 // |app_identifier| should no longer be stored in prefs. |
1438 PushMessagingAppIdentifier stored_app_identifier2 = | 1566 PushMessagingAppIdentifier stored_app_identifier2 = |
1439 PushMessagingAppIdentifier::FindByAppId(GetBrowser()->profile(), | 1567 PushMessagingAppIdentifier::FindByAppId(GetBrowser()->profile(), |
1440 app_identifier.app_id()); | 1568 app_identifier.app_id()); |
1441 EXPECT_TRUE(stored_app_identifier2.is_null()); | 1569 EXPECT_TRUE(stored_app_identifier2.is_null()); |
1442 } | 1570 } |
1443 | 1571 |
1444 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, EncryptionKeyUniqueness) { | 1572 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, EncryptionKeyUniqueness) { |
1445 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */, false); | 1573 std::string token1; |
| 1574 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(false /* use_key */, &token1)); |
1446 | 1575 |
1447 std::string first_public_key; | 1576 std::string first_public_key; |
1448 ASSERT_TRUE(RunScript("GetP256dh()", &first_public_key)); | 1577 ASSERT_TRUE(RunScript("GetP256dh()", &first_public_key)); |
1449 EXPECT_GE(first_public_key.size(), 32u); | 1578 EXPECT_GE(first_public_key.size(), 32u); |
1450 | 1579 |
1451 std::string script_result; | 1580 std::string script_result; |
1452 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | |
1453 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1581 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
1454 EXPECT_EQ("unsubscribe result: true", script_result); | 1582 EXPECT_EQ("unsubscribe result: true", script_result); |
1455 | 1583 |
1456 TryToSubscribeSuccessfully("1-1" /* expected_push_subscription_id */); | 1584 std::string token2; |
| 1585 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(true /* use_key */, &token2)); |
| 1586 EXPECT_NE(token1, token2); |
1457 | 1587 |
1458 std::string second_public_key; | 1588 std::string second_public_key; |
1459 ASSERT_TRUE(RunScript("GetP256dh()", &second_public_key)); | 1589 ASSERT_TRUE(RunScript("GetP256dh()", &second_public_key)); |
1460 EXPECT_GE(second_public_key.size(), 32u); | 1590 EXPECT_GE(second_public_key.size(), 32u); |
1461 | 1591 |
1462 EXPECT_NE(first_public_key, second_public_key); | 1592 EXPECT_NE(first_public_key, second_public_key); |
1463 } | 1593 } |
1464 | 1594 |
1465 class PushMessagingIncognitoBrowserTest : public PushMessagingBrowserTest { | 1595 class PushMessagingIncognitoBrowserTest : public PushMessagingBrowserTest { |
1466 public: | 1596 public: |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1498 #if BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) | 1628 #if BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) |
1499 // Push background mode is disabled by default. | 1629 // Push background mode is disabled by default. |
1500 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1630 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
1501 BackgroundModeDisabledByDefault) { | 1631 BackgroundModeDisabledByDefault) { |
1502 // Initially background mode is inactive. | 1632 // Initially background mode is inactive. |
1503 BackgroundModeManager* background_mode_manager = | 1633 BackgroundModeManager* background_mode_manager = |
1504 g_browser_process->background_mode_manager(); | 1634 g_browser_process->background_mode_manager(); |
1505 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1635 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
1506 | 1636 |
1507 // Once there is a push subscription background mode is still inactive. | 1637 // Once there is a push subscription background mode is still inactive. |
1508 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1638 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
1509 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1639 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
1510 | 1640 |
1511 // After dropping the last subscription it is still inactive. | 1641 // After dropping the last subscription it is still inactive. |
1512 std::string script_result; | 1642 std::string script_result; |
1513 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | |
1514 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1643 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
1515 EXPECT_EQ("unsubscribe result: true", script_result); | 1644 EXPECT_EQ("unsubscribe result: true", script_result); |
1516 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1645 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
1517 } | 1646 } |
1518 | 1647 |
1519 class PushMessagingBackgroundModeEnabledBrowserTest | 1648 class PushMessagingBackgroundModeEnabledBrowserTest |
1520 : public PushMessagingBrowserTest { | 1649 : public PushMessagingBrowserTest { |
1521 public: | 1650 public: |
1522 ~PushMessagingBackgroundModeEnabledBrowserTest() override {} | 1651 ~PushMessagingBackgroundModeEnabledBrowserTest() override {} |
1523 | 1652 |
1524 // PushMessagingBrowserTest: | 1653 // PushMessagingBrowserTest: |
1525 void SetUpCommandLine(base::CommandLine* command_line) override { | 1654 void SetUpCommandLine(base::CommandLine* command_line) override { |
1526 command_line->AppendSwitch(switches::kEnablePushApiBackgroundMode); | 1655 command_line->AppendSwitch(switches::kEnablePushApiBackgroundMode); |
1527 PushMessagingBrowserTest::SetUpCommandLine(command_line); | 1656 PushMessagingBrowserTest::SetUpCommandLine(command_line); |
1528 } | 1657 } |
1529 }; | 1658 }; |
1530 | 1659 |
1531 // In this test the command line enables push background mode. | 1660 // In this test the command line enables push background mode. |
1532 IN_PROC_BROWSER_TEST_F(PushMessagingBackgroundModeEnabledBrowserTest, | 1661 IN_PROC_BROWSER_TEST_F(PushMessagingBackgroundModeEnabledBrowserTest, |
1533 BackgroundModeEnabledWithCommandLine) { | 1662 BackgroundModeEnabledWithCommandLine) { |
1534 // Initially background mode is inactive. | 1663 // Initially background mode is inactive. |
1535 BackgroundModeManager* background_mode_manager = | 1664 BackgroundModeManager* background_mode_manager = |
1536 g_browser_process->background_mode_manager(); | 1665 g_browser_process->background_mode_manager(); |
1537 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1666 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
1538 | 1667 |
1539 // Once there is a push subscription background mode is active. | 1668 // Once there is a push subscription background mode is active. |
1540 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1669 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
1541 ASSERT_TRUE(background_mode_manager->IsBackgroundModeActive()); | 1670 ASSERT_TRUE(background_mode_manager->IsBackgroundModeActive()); |
1542 | 1671 |
1543 // Dropping the last subscription deactivates background mode. | 1672 // Dropping the last subscription deactivates background mode. |
1544 std::string script_result; | 1673 std::string script_result; |
1545 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | |
1546 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1674 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
1547 EXPECT_EQ("unsubscribe result: true", script_result); | 1675 EXPECT_EQ("unsubscribe result: true", script_result); |
1548 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1676 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
1549 } | 1677 } |
1550 | 1678 |
1551 class PushMessagingBackgroundModeDisabledBrowserTest | 1679 class PushMessagingBackgroundModeDisabledBrowserTest |
1552 : public PushMessagingBrowserTest { | 1680 : public PushMessagingBrowserTest { |
1553 public: | 1681 public: |
1554 ~PushMessagingBackgroundModeDisabledBrowserTest() override {} | 1682 ~PushMessagingBackgroundModeDisabledBrowserTest() override {} |
1555 | 1683 |
1556 // PushMessagingBrowserTest: | 1684 // PushMessagingBrowserTest: |
1557 void SetUpCommandLine(base::CommandLine* command_line) override { | 1685 void SetUpCommandLine(base::CommandLine* command_line) override { |
1558 command_line->AppendSwitch(switches::kDisablePushApiBackgroundMode); | 1686 command_line->AppendSwitch(switches::kDisablePushApiBackgroundMode); |
1559 PushMessagingBrowserTest::SetUpCommandLine(command_line); | 1687 PushMessagingBrowserTest::SetUpCommandLine(command_line); |
1560 } | 1688 } |
1561 }; | 1689 }; |
1562 | 1690 |
1563 // In this test the command line disables push background mode. | 1691 // In this test the command line disables push background mode. |
1564 IN_PROC_BROWSER_TEST_F(PushMessagingBackgroundModeDisabledBrowserTest, | 1692 IN_PROC_BROWSER_TEST_F(PushMessagingBackgroundModeDisabledBrowserTest, |
1565 BackgroundModeDisabledWithCommandLine) { | 1693 BackgroundModeDisabledWithCommandLine) { |
1566 // Initially background mode is inactive. | 1694 // Initially background mode is inactive. |
1567 BackgroundModeManager* background_mode_manager = | 1695 BackgroundModeManager* background_mode_manager = |
1568 g_browser_process->background_mode_manager(); | 1696 g_browser_process->background_mode_manager(); |
1569 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1697 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
1570 | 1698 |
1571 // Once there is a push subscription background mode is still inactive. | 1699 // Once there is a push subscription background mode is still inactive. |
1572 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1700 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
1573 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1701 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
1574 | 1702 |
1575 // After dropping the last subscription background mode is still inactive. | 1703 // After dropping the last subscription background mode is still inactive. |
1576 std::string script_result; | 1704 std::string script_result; |
1577 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | |
1578 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1705 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
1579 EXPECT_EQ("unsubscribe result: true", script_result); | 1706 EXPECT_EQ("unsubscribe result: true", script_result); |
1580 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1707 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
1581 } | 1708 } |
1582 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) | 1709 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) |
OLD | NEW |