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

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

Issue 2469293002: Handle push resubscribes with no sender info (avoids DCHECK) (Closed)
Patch Set: rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 180
181 InProcessBrowserTest::TearDown(); 181 InProcessBrowserTest::TearDown();
182 } 182 }
183 183
184 void LoadTestPage(const std::string& path) { 184 void LoadTestPage(const std::string& path) {
185 ui_test_utils::NavigateToURL(GetBrowser(), https_server_->GetURL(path)); 185 ui_test_utils::NavigateToURL(GetBrowser(), https_server_->GetURL(path));
186 } 186 }
187 187
188 void LoadTestPage() { LoadTestPage(GetTestURL()); } 188 void LoadTestPage() { LoadTestPage(GetTestURL()); }
189 189
190 void LoadTestPageWithoutManifest() { LoadTestPage(GetNoManifestTestURL()); }
191
190 bool RunScript(const std::string& script, std::string* result) { 192 bool RunScript(const std::string& script, std::string* result) {
191 return RunScript(script, result, nullptr); 193 return RunScript(script, result, nullptr);
192 } 194 }
193 195
194 bool RunScript(const std::string& script, std::string* result, 196 bool RunScript(const std::string& script, std::string* result,
195 content::WebContents* web_contents) { 197 content::WebContents* web_contents) {
196 if (!web_contents) 198 if (!web_contents)
197 web_contents = GetBrowser()->tab_strip_model()->GetActiveWebContents(); 199 web_contents = GetBrowser()->tab_strip_model()->GetActiveWebContents();
198 return content::ExecuteScriptAndExtractString(web_contents->GetMainFrame(), 200 return content::ExecuteScriptAndExtractString(web_contents->GetMainFrame(),
199 script, result); 201 script, result);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 266
265 void SetSiteEngagementScore(const GURL& url, double score) { 267 void SetSiteEngagementScore(const GURL& url, double score) {
266 SiteEngagementService* service = 268 SiteEngagementService* service =
267 SiteEngagementService::Get(GetBrowser()->profile()); 269 SiteEngagementService::Get(GetBrowser()->profile());
268 service->ResetScoreForURL(url, score); 270 service->ResetScoreForURL(url, score);
269 } 271 }
270 272
271 protected: 273 protected:
272 virtual std::string GetTestURL() { return "/push_messaging/test.html"; } 274 virtual std::string GetTestURL() { return "/push_messaging/test.html"; }
273 275
276 virtual std::string GetNoManifestTestURL() {
277 return "/push_messaging/test_no_manifest.html";
278 }
279
274 virtual Browser* GetBrowser() const { return browser(); } 280 virtual Browser* GetBrowser() const { return browser(); }
275 281
276 gcm::FakeGCMProfileService* gcm_service_; 282 gcm::FakeGCMProfileService* gcm_service_;
277 instance_id::FakeGCMDriverForInstanceID* gcm_driver_; 283 instance_id::FakeGCMDriverForInstanceID* gcm_driver_;
278 base::HistogramTester histogram_tester_; 284 base::HistogramTester histogram_tester_;
279 285
280 private: 286 private:
281 std::unique_ptr<net::EmbeddedTestServer> https_server_; 287 std::unique_ptr<net::EmbeddedTestServer> https_server_;
282 PushMessagingServiceImpl* push_service_; 288 PushMessagingServiceImpl* push_service_;
283 289
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 523
518 ASSERT_TRUE(RunScript("isControlled()", &script_result)); 524 ASSERT_TRUE(RunScript("isControlled()", &script_result));
519 ASSERT_EQ("true - is controlled", script_result); 525 ASSERT_EQ("true - is controlled", script_result);
520 526
521 // Try to subscribe from a worker without a key. This should fail. 527 // Try to subscribe from a worker without a key. This should fail.
522 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); 528 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result));
523 EXPECT_EQ( 529 EXPECT_EQ(
524 "AbortError - Registration failed - missing applicationServerKey, and " 530 "AbortError - Registration failed - missing applicationServerKey, and "
525 "gcm_sender_id not found in manifest", 531 "gcm_sender_id not found in manifest",
526 script_result); 532 script_result);
527 // Now run the subscribe from the service worker with a key. This 533
528 // should succeed, and write the key to the datastore. 534 // Now run the subscribe from the service worker with a key.
johnme 2016/11/04 17:43:36 Nit: I know you didn't write this sentence, but it
awdf 2016/11/07 16:54:30 Done.
535 // This should succeed.
529 ASSERT_TRUE(RunScript("workerSubscribePush()", &script_result)); 536 ASSERT_TRUE(RunScript("workerSubscribePush()", &script_result));
530 std::string token1;
531 ASSERT_NO_FATAL_FAILURE( 537 ASSERT_NO_FATAL_FAILURE(
532 EndpointToToken(script_result, true /* standard_protocol */, &token1)); 538 EndpointToToken(script_result, true /* standard_protocol */));
533 539
534 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); 540 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
535 EXPECT_EQ("unsubscribe result: true", script_result); 541 EXPECT_EQ("unsubscribe result: true", script_result);
536 EXPECT_NE(push_service(), GetAppHandler());
537
538 // Now run the subscribe from the service worker without a key.
539 // In this case, the key will be read from the datastore.
540 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result));
541 std::string token2;
542 ASSERT_NO_FATAL_FAILURE(
543 EndpointToToken(script_result, true /* standard_protocol */, &token2));
544 EXPECT_NE(token1, token2);
545
546 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
547 EXPECT_EQ("unsubscribe result: true", script_result);
548 EXPECT_NE(push_service(), GetAppHandler()); 542 EXPECT_NE(push_service(), GetAppHandler());
549 } 543 }
550 544
551 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, 545 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
552 SubscribeWorkerUsingManifest) { 546 SubscribeWorkerUsingManifest) {
johnme 2016/11/04 17:43:36 I've suggested adding an extra unsubscribe and res
awdf 2016/11/07 16:54:30 Done.
553 std::string script_result; 547 std::string script_result;
554 548
555 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); 549 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
556 ASSERT_EQ("ok - service worker registered", script_result); 550 ASSERT_EQ("ok - service worker registered", script_result);
557 551
558 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission()); 552 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission());
559 553
560 LoadTestPage(); // Reload to become controlled. 554 LoadTestPage(); // Reload to become controlled.
561 555
562 ASSERT_TRUE(RunScript("isControlled()", &script_result)); 556 ASSERT_TRUE(RunScript("isControlled()", &script_result));
(...skipping 25 matching lines...) Expand all
588 std::string token2; 582 std::string token2;
589 ASSERT_NO_FATAL_FAILURE( 583 ASSERT_NO_FATAL_FAILURE(
590 EndpointToToken(script_result, false /* standard_protocol */, &token2)); 584 EndpointToToken(script_result, false /* standard_protocol */, &token2));
591 EXPECT_NE(token1, token2); 585 EXPECT_NE(token1, token2);
592 586
593 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); 587 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
594 EXPECT_EQ("unsubscribe result: true", script_result); 588 EXPECT_EQ("unsubscribe result: true", script_result);
595 EXPECT_NE(push_service(), GetAppHandler()); 589 EXPECT_NE(push_service(), GetAppHandler());
596 } 590 }
597 591
592 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
593 ResubscribeWithoutKeyAfterSubscribingWithKeyInManifest) {
johnme 2016/11/04 17:43:37 Nit: These test names could probably be shortened
awdf 2016/11/07 16:54:30 Very good point that WithoutKeyFailure can be pars
johnme 2016/11/07 18:11:59 Since each of these tests is testing three things
awdf 2016/11/07 19:13:22 Done.
594 std::string script_result;
595
596 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
597 ASSERT_EQ("ok - service worker registered", script_result);
598
599 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission());
600
601 LoadTestPage(); // Reload to become controlled.
602
603 ASSERT_TRUE(RunScript("isControlled()", &script_result));
604 ASSERT_EQ("true - is controlled", script_result);
605
606 // Run the subscription from the document without a key, this will trigger
607 // the code to read sender id from the manifest and will write it to the
608 // datastore.
609 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result));
610 std::string token1;
611 ASSERT_NO_FATAL_FAILURE(
612 EndpointToToken(script_result, false /* standard_protocol */, &token1));
613
614 ASSERT_TRUE(RunScript("removeManifest()", &script_result));
615 ASSERT_EQ("manifest removed", script_result);
616
617 // Try to resubscribe from the document without a key or manifest.
618 // This should fail.
619 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result));
620 EXPECT_EQ(
621 "AbortError - Registration failed - missing applicationServerKey, "
622 "and manifest empty or missing",
623 script_result);
624
625 // Now run the subscribe from the service worker without a key.
626 // In this case, the sender id should be read from the datastore.
627 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result));
628 std::string token2;
629 ASSERT_NO_FATAL_FAILURE(
630 EndpointToToken(script_result, false /* standard_protocol */, &token2));
631 EXPECT_EQ(token1, token2);
johnme 2016/11/04 17:43:37 Now unsubscribe then subscribe successfully from a
awdf 2016/11/07 16:54:30 Done.
632
633 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
634 EXPECT_EQ("unsubscribe result: true", script_result);
635 EXPECT_NE(push_service(), GetAppHandler());
636 }
637
638 IN_PROC_BROWSER_TEST_F(
639 PushMessagingBrowserTest,
640 ResubscribeWithoutKeyFailureAfterSubscribingFromDocumentWithP256Key) {
641 std::string script_result;
642
643 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
644 ASSERT_EQ("ok - service worker registered", script_result);
645
646 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission());
647
648 LoadTestPageWithoutManifest(); // Reload to become controlled.
649
650 ASSERT_TRUE(RunScript("isControlled()", &script_result));
651 ASSERT_EQ("true - is controlled", script_result);
652
653 // Run the subscription from the document with a key.
654 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result));
655 ASSERT_NO_FATAL_FAILURE(EndpointToToken(script_result));
656
657 // Try to resubscribe from the document without a key - should fail.
658 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result));
659 EXPECT_EQ(
660 "AbortError - Registration failed - missing applicationServerKey, "
661 "and manifest empty or missing",
662 script_result);
663
664 // Now try to resubscribe from the service worker without a key.
665 // This should also fail as the original key was not numeric.
666 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result));
667 EXPECT_EQ(
668 "AbortError - Registration failed - missing applicationServerKey, "
669 "and gcm_sender_id not found in manifest",
670 script_result);
johnme 2016/11/04 17:43:37 Now unsubscribe then subscribe successfully from a
awdf 2016/11/07 16:54:30 I don't think that would be successful actually, d
johnme 2016/11/07 18:11:59 Sorry yes, I mean unsubscribe then check that it s
awdf 2016/11/07 19:13:22 Done.
671
672 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
673 EXPECT_EQ("unsubscribe result: true", script_result);
674 EXPECT_NE(push_service(), GetAppHandler());
675 }
676
677 IN_PROC_BROWSER_TEST_F(
678 PushMessagingBrowserTest,
679 ResubscribeWithoutKeyFailureAfterSubscribingFromWorkerWithP256Key) {
680 std::string script_result;
681
682 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
683 ASSERT_EQ("ok - service worker registered", script_result);
684
685 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission());
686
687 LoadTestPageWithoutManifest(); // Reload to become controlled.
688
689 ASSERT_TRUE(RunScript("isControlled()", &script_result));
690 ASSERT_EQ("true - is controlled", script_result);
691
692 // Run the subscribe from the service worker with a key.
693 // This should succeed.
694 ASSERT_TRUE(RunScript("workerSubscribePush()", &script_result));
695 ASSERT_NO_FATAL_FAILURE(
696 EndpointToToken(script_result, true /* standard_protocol */));
697
698 // Try to resubscribe from the document without a key - should fail.
699 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result));
700 EXPECT_EQ(
701 "AbortError - Registration failed - missing applicationServerKey, "
702 "and manifest empty or missing",
703 script_result);
704
705 // Now try to resubscribe from the service worker without a key.
706 // This should also fail as the original key was not numeric.
707 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result));
708 EXPECT_EQ(
709 "AbortError - Registration failed - missing applicationServerKey, and "
710 "gcm_sender_id not found in manifest",
711 script_result);
johnme 2016/11/04 17:43:36 Now unsubscribe then subscribe successfully from a
awdf 2016/11/07 16:54:30 Same here, shouldn't it fail again?
johnme 2016/11/07 18:11:59 Yup, I also meant unsubscribe then check that it s
awdf 2016/11/07 19:13:22 Done.
712
713 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
714 EXPECT_EQ("unsubscribe result: true", script_result);
715 EXPECT_NE(push_service(), GetAppHandler());
716 }
717
718 IN_PROC_BROWSER_TEST_F(
719 PushMessagingBrowserTest,
720 ResubscribeWithoutKeyFailureAfterSubscribingFromDocumentWithNumber) {
721 std::string script_result;
722
723 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
724 ASSERT_EQ("ok - service worker registered", script_result);
725
726 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission());
727
728 LoadTestPageWithoutManifest(); // Reload to become controlled.
729
730 ASSERT_TRUE(RunScript("isControlled()", &script_result));
731 ASSERT_EQ("true - is controlled", script_result);
732
733 // Run the subscribe from the service worker with a key.
734 // This should succeed.
735 ASSERT_TRUE(
736 RunScript("documentSubscribePushWithNumericKey()", &script_result));
737 ASSERT_NO_FATAL_FAILURE(
738 EndpointToToken(script_result, false /* standard_protocol */));
739
740 // Try to resubscribe from the document without a key - should fail.
741 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result));
742 EXPECT_EQ(
743 "AbortError - Registration failed - missing applicationServerKey, "
744 "and manifest empty or missing",
745 script_result);
johnme 2016/11/04 17:43:37 Now subscribe successfully from a worker without k
awdf 2016/11/07 16:54:30 and here..
johnme 2016/11/07 18:11:59 No, these do indeed succeed. And I see that you ch
awdf 2016/11/07 19:13:22 Acknowledged.
746
747 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
748 EXPECT_EQ("unsubscribe result: true", script_result);
749 EXPECT_NE(push_service(), GetAppHandler());
750 }
751
752 IN_PROC_BROWSER_TEST_F(
753 PushMessagingBrowserTest,
754 ResubscribeWithoutKeyFailureAfterSubscribingFromWorkerWithNumber) {
755 std::string script_result;
756
757 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
758 ASSERT_EQ("ok - service worker registered", script_result);
759
760 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission());
761
762 LoadTestPageWithoutManifest(); // Reload to become controlled.
763
764 ASSERT_TRUE(RunScript("isControlled()", &script_result));
765 ASSERT_EQ("true - is controlled", script_result);
766
767 // Run the subscribe from the service worker with a key.
768 // This should succeed.
769 ASSERT_TRUE(
770 RunScript("documentSubscribePushWithNumericKey()", &script_result));
johnme 2016/11/04 17:43:37 s/document/worker/, based on test name
awdf 2016/11/07 16:54:30 Done.
771 ASSERT_NO_FATAL_FAILURE(
772 EndpointToToken(script_result, false /* standard_protocol */));
773
774 // Try to resubscribe from the document without a key - should fail.
775 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result));
776 EXPECT_EQ(
777 "AbortError - Registration failed - missing applicationServerKey, "
778 "and manifest empty or missing",
779 script_result);
johnme 2016/11/04 17:43:37 Now subscribe successfully from a worker without k
awdf 2016/11/07 16:54:30 ..
johnme 2016/11/07 18:11:59 Ditto I see that you check they succeed :)
780
781 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
782 EXPECT_EQ("unsubscribe result: true", script_result);
783 EXPECT_NE(push_service(), GetAppHandler());
784 }
785
598 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribePersisted) { 786 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribePersisted) {
599 std::string script_result; 787 std::string script_result;
600 788
601 // First, test that Service Worker registration IDs are assigned in order of 789 // First, test that Service Worker registration IDs are assigned in order of
602 // registering the Service Workers, and the (fake) push subscription ids are 790 // registering the Service Workers, and the (fake) push subscription ids are
603 // assigned in order of push subscription (even when these orders are 791 // assigned in order of push subscription (even when these orders are
604 // different). 792 // different).
605 793
606 std::string token1; 794 std::string token1;
607 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(true /* use_key */, &token1)); 795 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(true /* use_key */, &token1));
(...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1858 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); 2046 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully());
1859 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); 2047 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive());
1860 2048
1861 // After dropping the last subscription background mode is still inactive. 2049 // After dropping the last subscription background mode is still inactive.
1862 std::string script_result; 2050 std::string script_result;
1863 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); 2051 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
1864 EXPECT_EQ("unsubscribe result: true", script_result); 2052 EXPECT_EQ("unsubscribe result: true", script_result);
1865 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); 2053 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive());
1866 } 2054 }
1867 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) 2055 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698