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
3 // found in the LICENSE file.
8 #include "base/barrier_closure.h"
10 #include "base/command_line.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/browsing_data/browsing_data_helper.h"
15 #include "chrome/browser/browsing_data/browsing_data_remover.h"
16 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h"
17 #include "chrome/browser/notifications/notification_test_util.h"
18 #include "chrome/browser/notifications/platform_notification_service_impl.h"
19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/push_messaging/push_messaging_app_identifier.h"
21 #include "chrome/browser/push_messaging/push_messaging_constants.h"
22 #include "chrome/browser/push_messaging/push_messaging_service_factory.h"
23 #include "chrome/browser/push_messaging/push_messaging_service_impl.h"
24 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h"
25 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
26 #include "chrome/browser/ui/browser.h"
27 #include "chrome/browser/ui/tabs/tab_strip_model.h"
28 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
29 #include "chrome/common/chrome_switches.h"
30 #include "chrome/test/base/in_process_browser_test.h"
31 #include "chrome/test/base/ui_test_utils.h"
32 #include "components/content_settings/core/browser/host_content_settings_map.h"
33 #include "components/content_settings/core/common/content_settings.h"
34 #include "components/content_settings/core/common/content_settings_types.h"
35 #include "components/gcm_driver/common/gcm_messages.h"
36 #include "components/gcm_driver/gcm_client.h"
37 #include "content/public/browser/web_contents.h"
38 #include "content/public/common/content_switches.h"
39 #include "content/public/test/browser_test_utils.h"
40 #include "content/public/test/test_utils.h"
41 #include "ui/base/window_open_disposition.h"
45 // Class to instantiate on the stack that is meant to be used with
46 // FakeGCMProfileService. The ::Run() method follows the signature of
47 // FakeGCMProfileService::UnregisterCallback.
48 class UnregistrationCallback
{
50 UnregistrationCallback()
51 : message_loop_runner_(new content::MessageLoopRunner
) {}
53 void Run(const std::string
& app_id
) {
55 message_loop_runner_
->Quit();
58 void WaitUntilSatisfied() {
59 message_loop_runner_
->Run();
62 const std::string
& app_id() {
67 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner_
;
73 class PushMessagingBrowserTest
: public InProcessBrowserTest
{
75 PushMessagingBrowserTest() : gcm_service_(nullptr) {}
76 ~PushMessagingBrowserTest() override
{}
78 // InProcessBrowserTest:
79 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
80 command_line
->AppendSwitch(switches::kEnablePushMessagePayload
);
81 InProcessBrowserTest::SetUpCommandLine(command_line
);
84 // InProcessBrowserTest:
85 void SetUp() override
{
86 https_server_
.reset(new net::SpawnedTestServer(
87 net::SpawnedTestServer::TYPE_HTTPS
,
88 net::BaseTestServer::SSLOptions(
89 net::BaseTestServer::SSLOptions::CERT_OK
),
90 base::FilePath(FILE_PATH_LITERAL("chrome/test/data/"))));
91 ASSERT_TRUE(https_server_
->Start());
93 #if defined(ENABLE_NOTIFICATIONS)
94 notification_manager_
.reset(new StubNotificationUIManager
);
95 notification_service()->SetNotificationUIManagerForTesting(
96 notification_manager());
99 InProcessBrowserTest::SetUp();
102 // InProcessBrowserTest:
103 void SetUpOnMainThread() override
{
104 gcm_service_
= static_cast<gcm::FakeGCMProfileService
*>(
105 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse(
106 GetBrowser()->profile(), &gcm::FakeGCMProfileService::Build
));
107 gcm_service_
->set_collect(true);
109 PushMessagingServiceFactory::GetForProfile(GetBrowser()->profile());
113 InProcessBrowserTest::SetUpOnMainThread();
116 // InProcessBrowserTest:
117 void TearDown() override
{
118 #if defined(ENABLE_NOTIFICATIONS)
119 notification_service()->SetNotificationUIManagerForTesting(nullptr);
122 InProcessBrowserTest::TearDown();
125 void LoadTestPage(const std::string
& path
) {
126 ui_test_utils::NavigateToURL(GetBrowser(), https_server_
->GetURL(path
));
129 void LoadTestPage() {
130 LoadTestPage(GetTestURL());
133 bool RunScript(const std::string
& script
, std::string
* result
) {
134 return RunScript(script
, result
, nullptr);
137 bool RunScript(const std::string
& script
, std::string
* result
,
138 content::WebContents
* web_contents
) {
140 web_contents
= GetBrowser()->tab_strip_model()->GetActiveWebContents();
141 return content::ExecuteScriptAndExtractString(web_contents
->GetMainFrame(),
146 PermissionBubbleManager
* GetPermissionBubbleManager() {
147 return PermissionBubbleManager::FromWebContents(
148 GetBrowser()->tab_strip_model()->GetActiveWebContents());
151 void RequestAndAcceptPermission();
152 void RequestAndDenyPermission();
154 void TryToSubscribeSuccessfully(
155 const std::string
& expected_push_subscription_id
);
157 std::string
GetEndpointForSubscriptionId(const std::string
& subscription_id
) {
158 return std::string(kPushMessagingEndpoint
) + "/" + subscription_id
;
161 PushMessagingAppIdentifier
GetAppIdentifierForServiceWorkerRegistration(
162 int64 service_worker_registration_id
);
164 void SendMessageAndWaitUntilHandled(
165 const PushMessagingAppIdentifier
& app_identifier
,
166 const gcm::IncomingMessage
& message
);
168 net::SpawnedTestServer
* https_server() const { return https_server_
.get(); }
170 gcm::FakeGCMProfileService
* gcm_service() const { return gcm_service_
; }
172 #if defined(ENABLE_NOTIFICATIONS)
173 // To be called when delivery of a push message has finished. The |run_loop|
174 // will be told to quit after |messages_required| messages were received.
175 void OnDeliveryFinished(std::vector
<size_t>* number_of_notifications_shown
,
176 const base::Closure
& done_closure
) {
177 DCHECK(number_of_notifications_shown
);
179 number_of_notifications_shown
->push_back(
180 notification_manager_
->GetNotificationCount());
185 StubNotificationUIManager
* notification_manager() const {
186 return notification_manager_
.get();
189 PlatformNotificationServiceImpl
* notification_service() const {
190 return PlatformNotificationServiceImpl::GetInstance();
194 PushMessagingServiceImpl
* push_service() const { return push_service_
; }
197 virtual std::string
GetTestURL() {
198 return "files/push_messaging/test.html";
201 virtual Browser
* GetBrowser() const { return browser(); }
204 scoped_ptr
<net::SpawnedTestServer
> https_server_
;
205 gcm::FakeGCMProfileService
* gcm_service_
;
206 PushMessagingServiceImpl
* push_service_
;
208 #if defined(ENABLE_NOTIFICATIONS)
209 scoped_ptr
<StubNotificationUIManager
> notification_manager_
;
212 DISALLOW_COPY_AND_ASSIGN(PushMessagingBrowserTest
);
215 class PushMessagingBrowserTestEmptySubscriptionOptions
216 : public PushMessagingBrowserTest
{
217 std::string
GetTestURL() override
{
218 return "files/push_messaging/test_no_subscription_options.html";
222 void PushMessagingBrowserTest::RequestAndAcceptPermission() {
223 std::string script_result
;
224 GetPermissionBubbleManager()->set_auto_response_for_test(
225 PermissionBubbleManager::ACCEPT_ALL
);
226 EXPECT_TRUE(RunScript("requestNotificationPermission();", &script_result
));
227 EXPECT_EQ("permission status - granted", script_result
);
230 void PushMessagingBrowserTest::RequestAndDenyPermission() {
231 std::string script_result
;
232 GetPermissionBubbleManager()->set_auto_response_for_test(
233 PermissionBubbleManager::DENY_ALL
);
234 EXPECT_TRUE(RunScript("requestNotificationPermission();", &script_result
));
235 EXPECT_EQ("permission status - denied", script_result
);
238 void PushMessagingBrowserTest::TryToSubscribeSuccessfully(
239 const std::string
& expected_push_subscription_id
) {
240 std::string script_result
;
242 EXPECT_TRUE(RunScript("registerServiceWorker()", &script_result
));
243 EXPECT_EQ("ok - service worker registered", script_result
);
245 RequestAndAcceptPermission();
247 EXPECT_TRUE(RunScript("subscribePush()", &script_result
));
248 EXPECT_EQ(GetEndpointForSubscriptionId(expected_push_subscription_id
),
252 PushMessagingAppIdentifier
253 PushMessagingBrowserTest::GetAppIdentifierForServiceWorkerRegistration(
254 int64 service_worker_registration_id
) {
255 GURL origin
= https_server()->GetURL(std::string()).GetOrigin();
256 PushMessagingAppIdentifier app_identifier
=
257 PushMessagingAppIdentifier::FindByServiceWorker(
258 GetBrowser()->profile(), origin
, service_worker_registration_id
);
259 EXPECT_FALSE(app_identifier
.is_null());
260 return app_identifier
;
263 void PushMessagingBrowserTest::SendMessageAndWaitUntilHandled(
264 const PushMessagingAppIdentifier
& app_identifier
,
265 const gcm::IncomingMessage
& message
) {
266 base::RunLoop run_loop
;
267 push_service()->SetMessageCallbackForTesting(run_loop
.QuitClosure());
268 push_service()->OnMessage(app_identifier
.app_id(), message
);
272 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest
,
273 SubscribeSuccessNotificationsGranted
) {
274 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
276 PushMessagingAppIdentifier app_identifier
=
277 GetAppIdentifierForServiceWorkerRegistration(0LL);
278 EXPECT_EQ(app_identifier
.app_id(), gcm_service()->last_registered_app_id());
279 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]);
282 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest
,
283 SubscribeSuccessNotificationsPrompt
) {
284 std::string script_result
;
286 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result
));
287 ASSERT_EQ("ok - service worker registered", script_result
);
289 GetPermissionBubbleManager()->set_auto_response_for_test(
290 PermissionBubbleManager::ACCEPT_ALL
);
291 ASSERT_TRUE(RunScript("subscribePush()", &script_result
));
292 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result
);
294 PushMessagingAppIdentifier app_identifier
=
295 GetAppIdentifierForServiceWorkerRegistration(0LL);
296 EXPECT_EQ(app_identifier
.app_id(), gcm_service()->last_registered_app_id());
297 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]);
300 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest
,
301 SubscribeFailureNotificationsBlocked
) {
302 std::string script_result
;
304 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result
));
305 ASSERT_EQ("ok - service worker registered", script_result
);
307 RequestAndDenyPermission();
309 ASSERT_TRUE(RunScript("subscribePush()", &script_result
));
310 EXPECT_EQ("AbortError - Registration failed - permission denied",
314 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest
, SubscribeFailureNoManifest
) {
315 std::string script_result
;
317 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result
));
318 ASSERT_EQ("ok - service worker registered", script_result
);
320 RequestAndAcceptPermission();
322 ASSERT_TRUE(RunScript("removeManifest()", &script_result
));
323 ASSERT_EQ("manifest removed", script_result
);
325 ASSERT_TRUE(RunScript("subscribePush()", &script_result
));
326 EXPECT_EQ("AbortError - Registration failed - no sender id provided",
330 // TODO(johnme): Test subscribing from a worker - see https://crbug.com/437298.
332 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTestEmptySubscriptionOptions
,
333 RegisterFailureEmptyPushSubscriptionOptions
) {
334 std::string script_result
;
336 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result
));
337 ASSERT_EQ("ok - service worker registered", script_result
);
339 RequestAndAcceptPermission();
341 ASSERT_TRUE(RunScript("subscribePush()", &script_result
));
342 EXPECT_EQ("AbortError - Registration failed - permission denied",
346 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest
, SubscribePersisted
) {
347 std::string script_result
;
349 // First, test that Service Worker registration IDs are assigned in order of
350 // registering the Service Workers, and the (fake) push subscription ids are
351 // assigned in order of push subscription (even when these orders are
354 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
355 PushMessagingAppIdentifier sw0_identifier
=
356 GetAppIdentifierForServiceWorkerRegistration(0LL);
357 EXPECT_EQ(sw0_identifier
.app_id(), gcm_service()->last_registered_app_id());
359 LoadTestPage("files/push_messaging/subscope1/test.html");
360 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result
));
361 ASSERT_EQ("ok - service worker registered", script_result
);
363 LoadTestPage("files/push_messaging/subscope2/test.html");
364 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result
));
365 ASSERT_EQ("ok - service worker registered", script_result
);
367 // Note that we need to reload the page after registering, otherwise
368 // navigator.serviceWorker.ready is going to be resolved with the parent
369 // Service Worker which still controls the page.
370 LoadTestPage("files/push_messaging/subscope2/test.html");
371 TryToSubscribeSuccessfully("1-1" /* expected_push_subscription_id */);
372 PushMessagingAppIdentifier sw2_identifier
=
373 GetAppIdentifierForServiceWorkerRegistration(2LL);
374 EXPECT_EQ(sw2_identifier
.app_id(), gcm_service()->last_registered_app_id());
376 LoadTestPage("files/push_messaging/subscope1/test.html");
377 TryToSubscribeSuccessfully("1-2" /* expected_push_subscription_id */);
378 PushMessagingAppIdentifier sw1_identifier
=
379 GetAppIdentifierForServiceWorkerRegistration(1LL);
380 EXPECT_EQ(sw1_identifier
.app_id(), gcm_service()->last_registered_app_id());
382 // Now test that the Service Worker registration IDs and push subscription IDs
383 // generated above were persisted to SW storage, by checking that they are
384 // unchanged despite requesting them in a different order.
385 // TODO(johnme): Ideally we would restart the browser at this point to check
386 // they were persisted to disk, but that's not currently possible since the
387 // test server uses random port numbers for each test (even PRE_Foo and Foo),
388 // so we wouldn't be able to load the test pages with the same origin.
390 LoadTestPage("files/push_messaging/subscope1/test.html");
391 TryToSubscribeSuccessfully("1-2" /* expected_push_subscription_id */);
392 EXPECT_EQ(sw1_identifier
.app_id(), gcm_service()->last_registered_app_id());
394 LoadTestPage("files/push_messaging/subscope2/test.html");
395 TryToSubscribeSuccessfully("1-1" /* expected_push_subscription_id */);
396 EXPECT_EQ(sw1_identifier
.app_id(), gcm_service()->last_registered_app_id());
399 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
400 EXPECT_EQ(sw1_identifier
.app_id(), gcm_service()->last_registered_app_id());
403 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest
, PushEventSuccess
) {
404 std::string script_result
;
406 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
408 PushMessagingAppIdentifier app_identifier
=
409 GetAppIdentifierForServiceWorkerRegistration(0LL);
410 EXPECT_EQ(app_identifier
.app_id(), gcm_service()->last_registered_app_id());
411 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]);
413 ASSERT_TRUE(RunScript("isControlled()", &script_result
));
414 ASSERT_EQ("false - is not controlled", script_result
);
416 LoadTestPage(); // Reload to become controlled.
418 ASSERT_TRUE(RunScript("isControlled()", &script_result
));
419 ASSERT_EQ("true - is controlled", script_result
);
421 gcm::IncomingMessage message
;
422 message
.sender_id
= "1234567890";
423 message
.data
["data"] = "testdata";
424 push_service()->OnMessage(app_identifier
.app_id(), message
);
425 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result
));
426 EXPECT_EQ("testdata", script_result
);
429 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest
, PushEventNoServiceWorker
) {
430 std::string script_result
;
432 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
434 PushMessagingAppIdentifier app_identifier
=
435 GetAppIdentifierForServiceWorkerRegistration(0LL);
436 EXPECT_EQ(app_identifier
.app_id(), gcm_service()->last_registered_app_id());
437 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]);
439 ASSERT_TRUE(RunScript("isControlled()", &script_result
));
440 ASSERT_EQ("false - is not controlled", script_result
);
442 LoadTestPage(); // Reload to become controlled.
444 ASSERT_TRUE(RunScript("isControlled()", &script_result
));
445 ASSERT_EQ("true - is controlled", script_result
);
447 // Unregister service worker. Sending a message should now fail.
448 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result
));
449 ASSERT_EQ("service worker unregistration status: true", script_result
);
451 // When the push service will receive it next message, given that there is no
452 // SW available, it should unregister |app_identifier.app_id()|.
453 UnregistrationCallback callback
;
454 gcm_service()->SetUnregisterCallback(base::Bind(&UnregistrationCallback::Run
,
455 base::Unretained(&callback
)));
457 gcm::IncomingMessage message
;
458 message
.sender_id
= "1234567890";
459 message
.data
["data"] = "testdata";
460 push_service()->OnMessage(app_identifier
.app_id(), message
);
462 callback
.WaitUntilSatisfied();
463 EXPECT_EQ(app_identifier
.app_id(), callback
.app_id());
465 // No push data should have been received.
466 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result
));
467 EXPECT_EQ("null", script_result
);
470 #if defined(ENABLE_NOTIFICATIONS)
471 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest
,
472 PushEventEnforcesUserVisibleNotification
) {
473 std::string script_result
;
475 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
477 PushMessagingAppIdentifier app_identifier
=
478 GetAppIdentifierForServiceWorkerRegistration(0LL);
479 EXPECT_EQ(app_identifier
.app_id(), gcm_service()->last_registered_app_id());
480 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]);
482 ASSERT_TRUE(RunScript("isControlled()", &script_result
));
483 ASSERT_EQ("false - is not controlled", script_result
);
485 LoadTestPage(); // Reload to become controlled.
487 ASSERT_TRUE(RunScript("isControlled()", &script_result
));
488 ASSERT_EQ("true - is controlled", script_result
);
490 notification_manager()->CancelAll();
491 ASSERT_EQ(0u, notification_manager()->GetNotificationCount());
493 // We'll need to specify the web_contents in which to eval script, since we're
494 // going to run script in a background tab.
495 content::WebContents
* web_contents
=
496 GetBrowser()->tab_strip_model()->GetActiveWebContents();
498 // If the site is visible in an active tab, we should not force a notification
499 // to be shown. Try it twice, since we allow one mistake per 10 push events.
500 gcm::IncomingMessage message
;
501 message
.sender_id
= "1234567890";
502 for (int n
= 0; n
< 2; n
++) {
503 message
.data
["data"] = "testdata";
504 SendMessageAndWaitUntilHandled(app_identifier
, message
);
505 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result
));
506 EXPECT_EQ("testdata", script_result
);
507 EXPECT_EQ(0u, notification_manager()->GetNotificationCount());
510 // Open a blank foreground tab so site is no longer visible.
511 ui_test_utils::NavigateToURLWithDisposition(
512 GetBrowser(), GURL("about:blank"), NEW_FOREGROUND_TAB
,
513 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB
);
515 // If the Service Worker push event handler does not show a notification, we
516 // should show a forced one, but only on the 2nd occurrence since we allow one
517 // mistake per 10 push events.
518 message
.data
["data"] = "testdata";
519 SendMessageAndWaitUntilHandled(app_identifier
, message
);
520 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result
, web_contents
));
521 EXPECT_EQ("testdata", script_result
);
522 EXPECT_EQ(0u, notification_manager()->GetNotificationCount());
523 message
.data
["data"] = "testdata";
524 SendMessageAndWaitUntilHandled(app_identifier
, message
);
525 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result
, web_contents
));
526 EXPECT_EQ("testdata", script_result
);
528 ASSERT_EQ(1u, notification_manager()->GetNotificationCount());
530 const Notification
& forced_notification
=
531 notification_manager()->GetNotificationAt(0);
533 EXPECT_EQ(kPushMessagingForcedNotificationTag
, forced_notification
.tag());
534 EXPECT_TRUE(forced_notification
.silent());
537 // The notification will be automatically dismissed when the developer shows
538 // a new notification themselves at a later point in time.
539 message
.data
["data"] = "shownotification";
540 SendMessageAndWaitUntilHandled(app_identifier
, message
);
541 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result
, web_contents
));
542 EXPECT_EQ("shownotification", script_result
);
544 ASSERT_EQ(1u, notification_manager()->GetNotificationCount());
546 const Notification
& first_notification
=
547 notification_manager()->GetNotificationAt(0);
549 EXPECT_NE(kPushMessagingForcedNotificationTag
, first_notification
.tag());
552 notification_manager()->CancelAll();
553 EXPECT_EQ(0u, notification_manager()->GetNotificationCount());
555 // However if the Service Worker push event handler shows a notification, we
556 // should not show a forced one.
557 message
.data
["data"] = "shownotification";
558 for (int n
= 0; n
< 9; n
++) {
559 SendMessageAndWaitUntilHandled(app_identifier
, message
);
560 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result
, web_contents
));
561 EXPECT_EQ("shownotification", script_result
);
562 EXPECT_EQ(1u, notification_manager()->GetNotificationCount());
563 EXPECT_EQ("push_test_tag",
564 notification_manager()->GetNotificationAt(0).tag());
565 notification_manager()->CancelAll();
568 // Now that 10 push messages in a row have shown notifications, we should
569 // allow the next one to mistakenly not show a notification.
570 message
.data
["data"] = "testdata";
571 SendMessageAndWaitUntilHandled(app_identifier
, message
);
572 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result
, web_contents
));
573 EXPECT_EQ("testdata", script_result
);
574 EXPECT_EQ(0u, notification_manager()->GetNotificationCount());
577 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest
,
578 PushEventEnforcesUserVisibleNotificationAfterQueue
) {
579 std::string script_result
;
581 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
583 PushMessagingAppIdentifier app_identifier
=
584 GetAppIdentifierForServiceWorkerRegistration(0LL);
585 EXPECT_EQ(app_identifier
.app_id(), gcm_service()->last_registered_app_id());
586 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]);
588 ASSERT_TRUE(RunScript("isControlled()", &script_result
));
589 ASSERT_EQ("false - is not controlled", script_result
);
591 LoadTestPage(); // Reload to become controlled.
593 ASSERT_TRUE(RunScript("isControlled()", &script_result
));
594 ASSERT_EQ("true - is controlled", script_result
);
596 // Fire off two push messages in sequence, only the second one of which will
597 // display a notification. The additional round-trip and I/O required by the
598 // second message, which shows a notification, should give us a reasonable
599 // confidence that the ordering will be maintained.
601 std::vector
<size_t> number_of_notifications_shown
;
603 gcm::IncomingMessage message
;
604 message
.sender_id
= "1234567890";
607 base::RunLoop run_loop
;
608 push_service()->SetMessageCallbackForTesting(
609 base::Bind(&PushMessagingBrowserTest::OnDeliveryFinished
,
610 base::Unretained(this),
611 &number_of_notifications_shown
,
612 base::BarrierClosure(2 /* num_closures */,
613 run_loop
.QuitClosure())));
615 message
.data
["data"] = "testdata";
616 push_service()->OnMessage(app_identifier
.app_id(), message
);
618 message
.data
["data"] = "shownotification";
619 push_service()->OnMessage(app_identifier
.app_id(), message
);
624 ASSERT_EQ(2u, number_of_notifications_shown
.size());
625 EXPECT_EQ(0u, number_of_notifications_shown
[0]);
626 EXPECT_EQ(1u, number_of_notifications_shown
[1]);
629 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest
,
630 PushEventNotificationWithoutEventWaitUntil
) {
631 std::string script_result
;
632 content::WebContents
* web_contents
=
633 GetBrowser()->tab_strip_model()->GetActiveWebContents();
635 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
637 PushMessagingAppIdentifier app_identifier
=
638 GetAppIdentifierForServiceWorkerRegistration(0LL);
639 EXPECT_EQ(app_identifier
.app_id(), gcm_service()->last_registered_app_id());
640 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]);
642 ASSERT_TRUE(RunScript("isControlled()", &script_result
));
643 ASSERT_EQ("false - is not controlled", script_result
);
645 LoadTestPage(); // Reload to become controlled.
647 ASSERT_TRUE(RunScript("isControlled()", &script_result
));
648 ASSERT_EQ("true - is controlled", script_result
);
650 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner
=
651 new content::MessageLoopRunner
;
652 notification_manager()->SetNotificationAddedCallback(
653 message_loop_runner
->QuitClosure());
655 gcm::IncomingMessage message
;
656 message
.sender_id
= "1234567890";
657 message
.data
["data"] = "shownotification-without-waituntil";
658 push_service()->OnMessage(app_identifier
.app_id(), message
);
659 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result
, web_contents
));
660 EXPECT_EQ("immediate:shownotification-without-waituntil", script_result
);
662 message_loop_runner
->Run();
664 ASSERT_EQ(1u, notification_manager()->GetNotificationCount());
665 EXPECT_EQ("push_test_tag",
666 notification_manager()->GetNotificationAt(0).tag());
668 // Verify that the renderer process hasn't crashed.
669 ASSERT_TRUE(RunScript("permissionState()", &script_result
));
670 EXPECT_EQ("permission status - granted", script_result
);
674 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest
, PermissionStateSaysPrompt
) {
675 std::string script_result
;
677 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result
));
678 ASSERT_EQ("ok - service worker registered", script_result
);
680 ASSERT_TRUE(RunScript("permissionState()", &script_result
));
681 ASSERT_EQ("permission status - prompt", script_result
);
684 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest
, PermissionStateSaysGranted
) {
685 std::string script_result
;
687 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result
));
688 ASSERT_EQ("ok - service worker registered", script_result
);
690 RequestAndAcceptPermission();
692 ASSERT_TRUE(RunScript("subscribePush()", &script_result
));
693 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"),
696 ASSERT_TRUE(RunScript("permissionState()", &script_result
));
697 EXPECT_EQ("permission status - granted", script_result
);
700 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest
, PermissionStateSaysDenied
) {
701 std::string script_result
;
703 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result
));
704 ASSERT_EQ("ok - service worker registered", script_result
);
706 RequestAndDenyPermission();
708 ASSERT_TRUE(RunScript("subscribePush()", &script_result
));
709 EXPECT_EQ("AbortError - Registration failed - permission denied",
712 ASSERT_TRUE(RunScript("permissionState()", &script_result
));
713 EXPECT_EQ("permission status - denied", script_result
);
716 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest
, UnsubscribeSuccess
) {
717 std::string script_result
;
719 EXPECT_TRUE(RunScript("registerServiceWorker()", &script_result
));
720 EXPECT_EQ("ok - service worker registered", script_result
);
722 // Resolves true if there was a subscription.
723 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
724 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS
);
725 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result
));
726 EXPECT_EQ("unsubscribe result: true", script_result
);
728 // Resolves false if there was no longer a subscription.
729 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result
));
730 EXPECT_EQ("unsubscribe result: false", script_result
);
732 // Doesn't reject if there was a network error (deactivates subscription
734 TryToSubscribeSuccessfully("1-1" /* expected_push_subscription_id */);
735 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::NETWORK_ERROR
);
736 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result
));
737 EXPECT_EQ("unsubscribe result: true", script_result
);
738 ASSERT_TRUE(RunScript("hasSubscription()", &script_result
));
739 EXPECT_EQ("false - not subscribed", script_result
);
741 // Doesn't reject if there were other push service errors (deactivates
742 // subscription locally anyway).
743 TryToSubscribeSuccessfully("1-2" /* expected_push_subscription_id */);
744 gcm_service()->AddExpectedUnregisterResponse(
745 gcm::GCMClient::INVALID_PARAMETER
);
746 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result
));
747 EXPECT_EQ("unsubscribe result: true", script_result
);
749 // Unsubscribing (with an existing reference to a PushSubscription), after
750 // unregistering the Service Worker, just means push subscription isn't found.
751 TryToSubscribeSuccessfully("1-3" /* expected_push_subscription_id */);
752 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result
));
753 ASSERT_EQ("service worker unregistration status: true", script_result
);
754 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result
));
755 EXPECT_EQ("unsubscribe result: false", script_result
);
758 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest
,
759 GlobalResetPushPermissionUnsubscribes
) {
760 std::string script_result
;
762 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
764 ASSERT_TRUE(RunScript("hasSubscription()", &script_result
));
765 EXPECT_EQ("true - subscribed", script_result
);
767 ASSERT_TRUE(RunScript("permissionState()", &script_result
));
768 EXPECT_EQ("permission status - granted", script_result
);
770 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner
=
771 new content::MessageLoopRunner
;
772 push_service()->SetContentSettingChangedCallbackForTesting(
773 message_loop_runner
->QuitClosure());
775 GetBrowser()->profile()->GetHostContentSettingsMap()->
776 ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING
);
778 message_loop_runner
->Run();
780 ASSERT_TRUE(RunScript("permissionState()", &script_result
));
781 EXPECT_EQ("permission status - prompt", script_result
);
783 ASSERT_TRUE(RunScript("hasSubscription()", &script_result
));
784 EXPECT_EQ("false - not subscribed", script_result
);
787 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest
,
788 LocalResetPushPermissionUnsubscribes
) {
789 std::string script_result
;
791 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
793 ASSERT_TRUE(RunScript("hasSubscription()", &script_result
));
794 EXPECT_EQ("true - subscribed", script_result
);
796 ASSERT_TRUE(RunScript("permissionState()", &script_result
));
797 EXPECT_EQ("permission status - granted", script_result
);
799 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner
=
800 new content::MessageLoopRunner
;
801 push_service()->SetContentSettingChangedCallbackForTesting(
802 message_loop_runner
->QuitClosure());
804 GURL origin
= https_server()->GetURL(std::string()).GetOrigin();
805 GetBrowser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
806 ContentSettingsPattern::FromURLNoWildcard(origin
),
807 ContentSettingsPattern::FromURLNoWildcard(origin
),
808 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING
,
810 CONTENT_SETTING_DEFAULT
);
812 message_loop_runner
->Run();
814 ASSERT_TRUE(RunScript("permissionState()", &script_result
));
815 EXPECT_EQ("permission status - prompt", script_result
);
817 ASSERT_TRUE(RunScript("hasSubscription()", &script_result
));
818 EXPECT_EQ("false - not subscribed", script_result
);
821 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest
,
822 DenyPushPermissionUnsubscribes
) {
823 std::string script_result
;
825 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
827 ASSERT_TRUE(RunScript("hasSubscription()", &script_result
));
828 EXPECT_EQ("true - subscribed", script_result
);
830 ASSERT_TRUE(RunScript("permissionState()", &script_result
));
831 EXPECT_EQ("permission status - granted", script_result
);
833 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner
=
834 new content::MessageLoopRunner
;
835 push_service()->SetContentSettingChangedCallbackForTesting(
836 message_loop_runner
->QuitClosure());
838 GURL origin
= https_server()->GetURL(std::string()).GetOrigin();
839 GetBrowser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
840 ContentSettingsPattern::FromURLNoWildcard(origin
),
841 ContentSettingsPattern::FromURLNoWildcard(origin
),
842 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING
,
844 CONTENT_SETTING_BLOCK
);
846 message_loop_runner
->Run();
848 ASSERT_TRUE(RunScript("permissionState()", &script_result
));
849 EXPECT_EQ("permission status - denied", script_result
);
851 ASSERT_TRUE(RunScript("hasSubscription()", &script_result
));
852 EXPECT_EQ("false - not subscribed", script_result
);
855 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest
,
856 GlobalResetNotificationsPermissionUnsubscribes
) {
857 std::string script_result
;
859 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
861 ASSERT_TRUE(RunScript("hasSubscription()", &script_result
));
862 EXPECT_EQ("true - subscribed", script_result
);
864 ASSERT_TRUE(RunScript("permissionState()", &script_result
));
865 EXPECT_EQ("permission status - granted", script_result
);
867 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner
=
868 new content::MessageLoopRunner
;
869 push_service()->SetContentSettingChangedCallbackForTesting(
870 message_loop_runner
->QuitClosure());
872 GetBrowser()->profile()->GetHostContentSettingsMap()->
873 ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS
);
875 message_loop_runner
->Run();
877 ASSERT_TRUE(RunScript("permissionState()", &script_result
));
878 EXPECT_EQ("permission status - prompt", script_result
);
880 ASSERT_TRUE(RunScript("hasSubscription()", &script_result
));
881 EXPECT_EQ("false - not subscribed", script_result
);
884 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest
,
885 LocalResetNotificationsPermissionUnsubscribes
) {
886 std::string script_result
;
888 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
890 ASSERT_TRUE(RunScript("hasSubscription()", &script_result
));
891 EXPECT_EQ("true - subscribed", script_result
);
893 ASSERT_TRUE(RunScript("permissionState()", &script_result
));
894 EXPECT_EQ("permission status - granted", script_result
);
896 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner
=
897 new content::MessageLoopRunner
;
898 push_service()->SetContentSettingChangedCallbackForTesting(
899 message_loop_runner
->QuitClosure());
901 GURL origin
= https_server()->GetURL(std::string()).GetOrigin();
902 GetBrowser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
903 ContentSettingsPattern::FromURLNoWildcard(origin
),
904 ContentSettingsPattern::Wildcard(),
905 CONTENT_SETTINGS_TYPE_NOTIFICATIONS
,
907 CONTENT_SETTING_DEFAULT
);
909 message_loop_runner
->Run();
911 ASSERT_TRUE(RunScript("permissionState()", &script_result
));
912 EXPECT_EQ("permission status - prompt", script_result
);
914 ASSERT_TRUE(RunScript("hasSubscription()", &script_result
));
915 EXPECT_EQ("false - not subscribed", script_result
);
918 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest
,
919 DenyNotificationsPermissionUnsubscribes
) {
920 std::string script_result
;
922 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
924 ASSERT_TRUE(RunScript("hasSubscription()", &script_result
));
925 EXPECT_EQ("true - subscribed", script_result
);
927 ASSERT_TRUE(RunScript("permissionState()", &script_result
));
928 EXPECT_EQ("permission status - granted", script_result
);
930 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner
=
931 new content::MessageLoopRunner
;
932 push_service()->SetContentSettingChangedCallbackForTesting(
933 message_loop_runner
->QuitClosure());
935 GURL origin
= https_server()->GetURL(std::string()).GetOrigin();
936 GetBrowser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
937 ContentSettingsPattern::FromURLNoWildcard(origin
),
938 ContentSettingsPattern::Wildcard(),
939 CONTENT_SETTINGS_TYPE_NOTIFICATIONS
,
941 CONTENT_SETTING_BLOCK
);
943 message_loop_runner
->Run();
945 ASSERT_TRUE(RunScript("permissionState()", &script_result
));
946 EXPECT_EQ("permission status - denied", script_result
);
948 ASSERT_TRUE(RunScript("hasSubscription()", &script_result
));
949 EXPECT_EQ("false - not subscribed", script_result
);
952 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest
,
953 GrantAlreadyGrantedPermissionDoesNotUnsubscribe
) {
954 std::string script_result
;
956 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
958 ASSERT_TRUE(RunScript("hasSubscription()", &script_result
));
959 EXPECT_EQ("true - subscribed", script_result
);
961 ASSERT_TRUE(RunScript("permissionState()", &script_result
));
962 EXPECT_EQ("permission status - granted", script_result
);
964 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner
=
965 new content::MessageLoopRunner
;
966 push_service()->SetContentSettingChangedCallbackForTesting(
967 base::BarrierClosure(2, message_loop_runner
->QuitClosure()));
969 GURL origin
= https_server()->GetURL(std::string()).GetOrigin();
970 GetBrowser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
971 ContentSettingsPattern::FromURLNoWildcard(origin
),
972 ContentSettingsPattern::Wildcard(),
973 CONTENT_SETTINGS_TYPE_NOTIFICATIONS
,
975 CONTENT_SETTING_ALLOW
);
976 GetBrowser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
977 ContentSettingsPattern::FromURLNoWildcard(origin
),
978 ContentSettingsPattern::FromURLNoWildcard(origin
),
979 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING
,
981 CONTENT_SETTING_ALLOW
);
983 message_loop_runner
->Run();
985 ASSERT_TRUE(RunScript("permissionState()", &script_result
));
986 EXPECT_EQ("permission status - granted", script_result
);
988 ASSERT_TRUE(RunScript("hasSubscription()", &script_result
));
989 EXPECT_EQ("true - subscribed", script_result
);
992 // This test is testing some non-trivial content settings rules and make sure
993 // that they are respected with regards to automatic unsubscription. In other
994 // words, it checks that the push service does not end up unsubscribing origins
995 // that have push permission with some non-common rules.
996 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest
,
997 AutomaticUnsubscriptionFollowsContentSettingRules
) {
998 std::string script_result
;
1000 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
1002 ASSERT_TRUE(RunScript("hasSubscription()", &script_result
));
1003 EXPECT_EQ("true - subscribed", script_result
);
1005 ASSERT_TRUE(RunScript("permissionState()", &script_result
));
1006 EXPECT_EQ("permission status - granted", script_result
);
1008 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner
=
1009 new content::MessageLoopRunner
;
1010 push_service()->SetContentSettingChangedCallbackForTesting(
1011 base::BarrierClosure(4, message_loop_runner
->QuitClosure()));
1013 GURL origin
= https_server()->GetURL(std::string()).GetOrigin();
1014 GetBrowser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
1015 ContentSettingsPattern::Wildcard(),
1016 ContentSettingsPattern::Wildcard(),
1017 CONTENT_SETTINGS_TYPE_NOTIFICATIONS
,
1019 CONTENT_SETTING_ALLOW
);
1020 GetBrowser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
1021 ContentSettingsPattern::FromString("https://*"),
1022 ContentSettingsPattern::FromString("https://*"),
1023 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING
,
1025 CONTENT_SETTING_ALLOW
);
1026 GetBrowser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
1027 ContentSettingsPattern::FromURLNoWildcard(origin
),
1028 ContentSettingsPattern::Wildcard(),
1029 CONTENT_SETTINGS_TYPE_NOTIFICATIONS
,
1031 CONTENT_SETTING_DEFAULT
);
1032 GetBrowser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
1033 ContentSettingsPattern::FromURLNoWildcard(origin
),
1034 ContentSettingsPattern::FromURLNoWildcard(origin
),
1035 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING
,
1037 CONTENT_SETTING_DEFAULT
);
1039 message_loop_runner
->Run();
1041 // The two first rules should give |origin| the permission to use Push even
1042 // if the rules it used to have have been reset.
1043 // The Push service should not unsubcribe |origin| because at no point it was
1044 // left without permission to use Push.
1046 ASSERT_TRUE(RunScript("permissionState()", &script_result
));
1047 EXPECT_EQ("permission status - granted", script_result
);
1049 ASSERT_TRUE(RunScript("hasSubscription()", &script_result
));
1050 EXPECT_EQ("true - subscribed", script_result
);
1053 // Checks that automatically unsubscribing due to a revoked permission is
1054 // handled well if the sender ID needed to unsubscribe was already deleted.
1055 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest
,
1056 ResetPushPermissionAfterClearingSiteData
) {
1057 std::string script_result
;
1059 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
1061 PushMessagingAppIdentifier app_identifier
=
1062 GetAppIdentifierForServiceWorkerRegistration(0LL);
1063 EXPECT_EQ(app_identifier
.app_id(), gcm_service()->last_registered_app_id());
1064 PushMessagingAppIdentifier stored_app_identifier
=
1065 PushMessagingAppIdentifier::FindByAppId(GetBrowser()->profile(),
1066 app_identifier
.app_id());
1067 EXPECT_FALSE(stored_app_identifier
.is_null());
1069 // Simulate a user clearing site data (including Service Workers, crucially).
1070 BrowsingDataRemover
* remover
=
1071 BrowsingDataRemover::CreateForUnboundedRange(GetBrowser()->profile());
1072 BrowsingDataRemoverCompletionObserver
observer(remover
);
1073 remover
->Remove(BrowsingDataRemover::REMOVE_SITE_DATA
,
1074 BrowsingDataHelper::UNPROTECTED_WEB
);
1075 observer
.BlockUntilCompletion();
1076 // BrowsingDataRemover deletes itself.
1078 base::RunLoop run_loop
;
1079 push_service()->SetContentSettingChangedCallbackForTesting(
1080 run_loop
.QuitClosure());
1082 // This shouldn't (asynchronously) cause a DCHECK.
1083 // TODO(johnme): Get this test running on Android, which has a different
1084 // codepath due to sender_id being required for unsubscribing there.
1085 GetBrowser()->profile()->GetHostContentSettingsMap()->
1086 ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING
);
1090 // |app_identifier| should no longer be stored in prefs.
1091 PushMessagingAppIdentifier stored_app_identifier2
=
1092 PushMessagingAppIdentifier::FindByAppId(GetBrowser()->profile(),
1093 app_identifier
.app_id());
1094 EXPECT_TRUE(stored_app_identifier2
.is_null());
1097 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest
, EncryptionKeyUniqueness
) {
1098 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
1100 std::string first_public_key
;
1101 ASSERT_TRUE(RunScript("getCurve25519dh()", &first_public_key
));
1102 EXPECT_GE(first_public_key
.size(), 32u);
1104 std::string script_result
;
1105 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS
);
1106 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result
));
1107 EXPECT_EQ("unsubscribe result: true", script_result
);
1109 TryToSubscribeSuccessfully("1-1" /* expected_push_subscription_id */);
1111 std::string second_public_key
;
1112 ASSERT_TRUE(RunScript("getCurve25519dh()", &second_public_key
));
1113 EXPECT_GE(second_public_key
.size(), 32u);
1115 EXPECT_NE(first_public_key
, second_public_key
);
1118 class PushMessagingIncognitoBrowserTest
: public PushMessagingBrowserTest
{
1120 ~PushMessagingIncognitoBrowserTest() override
{}
1122 // PushMessagingBrowserTest:
1123 void SetUpOnMainThread() override
{
1124 incognito_browser_
= CreateIncognitoBrowser();
1125 PushMessagingBrowserTest::SetUpOnMainThread();
1128 Browser
* GetBrowser() const override
{ return incognito_browser_
; }
1131 Browser
* incognito_browser_
= nullptr;
1134 // Regression test for https://crbug.com/476474
1135 IN_PROC_BROWSER_TEST_F(PushMessagingIncognitoBrowserTest
,
1136 IncognitoGetSubscriptionDoesNotHang
) {
1137 ASSERT_TRUE(GetBrowser()->profile()->IsOffTheRecord());
1139 std::string script_result
;
1141 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result
));
1142 ASSERT_EQ("ok - service worker registered", script_result
);
1144 // In Incognito mode the promise returned by getSubscription should not hang,
1145 // it should just fulfill with null.
1146 ASSERT_TRUE(RunScript("hasSubscription()", &script_result
));
1147 ASSERT_EQ("false - not subscribed", script_result
);