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

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: 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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 std::string token2; 594 std::string token2;
589 ASSERT_NO_FATAL_FAILURE( 595 ASSERT_NO_FATAL_FAILURE(
590 EndpointToToken(script_result, false /* standard_protocol */, &token2)); 596 EndpointToToken(script_result, false /* standard_protocol */, &token2));
591 EXPECT_NE(token1, token2); 597 EXPECT_NE(token1, token2);
592 598
593 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); 599 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
594 EXPECT_EQ("unsubscribe result: true", script_result); 600 EXPECT_EQ("unsubscribe result: true", script_result);
595 EXPECT_NE(push_service(), GetAppHandler()); 601 EXPECT_NE(push_service(), GetAppHandler());
596 } 602 }
597 603
604 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
605 ResubscribeWithoutKeyAfterSubscribingWithKeyInManifest) {
606 std::string script_result;
607
608 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
609 ASSERT_EQ("ok - service worker registered", script_result);
610
611 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission());
612
613 LoadTestPage(); // Reload to become controlled.
614
615 ASSERT_TRUE(RunScript("isControlled()", &script_result));
616 ASSERT_EQ("true - is controlled", script_result);
617
618 // Run the subscription from the document without a key, this will trigger
619 // the code to read sender id from the manifest and will write it to the
620 // datastore.
621 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result));
622 std::string token1;
623 ASSERT_NO_FATAL_FAILURE(
624 EndpointToToken(script_result, false /* standard_protocol */, &token1));
625
626 ASSERT_TRUE(RunScript("removeManifest()", &script_result));
627 ASSERT_EQ("manifest removed", script_result);
628
629 // Try to resubscribe from the document without a key or manifest.
630 // This should fail.
631 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result));
632 EXPECT_EQ(
633 "AbortError - Registration failed - missing applicationServerKey, "
634 "and manifest empty or missing",
635 script_result);
636
637 // Now run the subscribe from the service worker without a key.
638 // In this case, the sender id should be read from the datastore.
639 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result));
640 std::string token2;
641 ASSERT_NO_FATAL_FAILURE(
642 EndpointToToken(script_result, false /* standard_protocol */, &token2));
643 EXPECT_EQ(token1, token2);
644
645 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
646 EXPECT_EQ("unsubscribe result: true", script_result);
647 EXPECT_NE(push_service(), GetAppHandler());
648 }
649
650 IN_PROC_BROWSER_TEST_F(
651 PushMessagingBrowserTest,
652 ResubscribeWithoutKeyFailureAfterSubscribingFromDocumentWithP256Key) {
653 std::string script_result;
654
655 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
656 ASSERT_EQ("ok - service worker registered", script_result);
657
658 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission());
659
660 LoadTestPageWithoutManifest(); // Reload to become controlled.
661
662 ASSERT_TRUE(RunScript("isControlled()", &script_result));
663 ASSERT_EQ("true - is controlled", script_result);
664
665 // Run the subscription from the document with a key.
666 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result));
667 ASSERT_NO_FATAL_FAILURE(EndpointToToken(script_result));
668
669 // Try to resubscribe from the document without a key - should fail.
670 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result));
671 EXPECT_EQ(
672 "AbortError - Registration failed - missing applicationServerKey, "
673 "and manifest empty or missing",
674 script_result);
675
676 // Now try to resubscribe from the service worker without a key.
677 // This should also fail as the original key was not a gcm_sender_id.
harkness 2016/11/02 18:48:12 Maybe call it a numeric string, since we're not re
awdf 2016/11/03 14:10:11 Done.
678 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result));
679 EXPECT_EQ(
680 "AbortError - Registration failed - missing applicationServerKey, "
681 "and gcm_sender_id not found in manifest",
682 script_result);
683
684 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
685 EXPECT_EQ("unsubscribe result: true", script_result);
686 EXPECT_NE(push_service(), GetAppHandler());
687 }
688
689 IN_PROC_BROWSER_TEST_F(
690 PushMessagingBrowserTest,
691 ResubscribeWithoutKeyFailureAfterSubscribingFromWorkerWithP256Key) {
692 std::string script_result;
693
694 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
695 ASSERT_EQ("ok - service worker registered", script_result);
696
697 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission());
698
699 LoadTestPageWithoutManifest(); // Reload to become controlled.
700
701 ASSERT_TRUE(RunScript("isControlled()", &script_result));
702 ASSERT_EQ("true - is controlled", script_result);
703
704 // Run the subscribe from the service worker with a key.
705 // This should succeed.
706 ASSERT_TRUE(RunScript("workerSubscribePush()", &script_result));
707 ASSERT_NO_FATAL_FAILURE(
708 EndpointToToken(script_result, true /* standard_protocol */));
709
710 // Try to resubscribe from the document without a key - should fail.
711 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result));
712 EXPECT_EQ(
713 "AbortError - Registration failed - missing applicationServerKey, "
714 "and manifest empty or missing",
715 script_result);
716
717 // Now try to resubscribe from the service worker without a key.
718 // This should also fail as the original key was not a gcm_sender_id.
719 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result));
720 EXPECT_EQ(
721 "AbortError - Registration failed - missing applicationServerKey, and "
722 "gcm_sender_id not found in manifest",
723 script_result);
724
725 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
726 EXPECT_EQ("unsubscribe result: true", script_result);
727 EXPECT_NE(push_service(), GetAppHandler());
728 }
729
730 IN_PROC_BROWSER_TEST_F(
731 PushMessagingBrowserTest,
732 ResubscribeWithoutKeyFailureAfterSubscribingFromDocumentWithNumber) {
733 std::string script_result;
734
735 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
736 ASSERT_EQ("ok - service worker registered", script_result);
737
738 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission());
739
740 LoadTestPageWithoutManifest(); // Reload to become controlled.
741
742 ASSERT_TRUE(RunScript("isControlled()", &script_result));
743 ASSERT_EQ("true - is controlled", script_result);
744
745 // Run the subscribe from the service worker with a key.
746 // This should succeed.
747 ASSERT_TRUE(RunScript("documentSubscribePushWithNumber()", &script_result));
748 ASSERT_NO_FATAL_FAILURE(
749 EndpointToToken(script_result, false /* standard_protocol */));
750
751 // Try to resubscribe from the document without a key - should fail.
752 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result));
753 EXPECT_EQ(
754 "AbortError - Registration failed - missing applicationServerKey, "
755 "and manifest empty or missing",
756 script_result);
757
758 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
759 EXPECT_EQ("unsubscribe result: true", script_result);
760 EXPECT_NE(push_service(), GetAppHandler());
761 }
762
763 IN_PROC_BROWSER_TEST_F(
764 PushMessagingBrowserTest,
765 ResubscribeWithoutKeyFailureAfterSubscribingFromWorkerWithNumber) {
766 std::string script_result;
767
768 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
769 ASSERT_EQ("ok - service worker registered", script_result);
770
771 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission());
772
773 LoadTestPageWithoutManifest(); // Reload to become controlled.
774
775 ASSERT_TRUE(RunScript("isControlled()", &script_result));
776 ASSERT_EQ("true - is controlled", script_result);
777
778 // Run the subscribe from the service worker with a key.
779 // This should succeed.
780 ASSERT_TRUE(RunScript("documentSubscribePushWithNumber()", &script_result));
781 ASSERT_NO_FATAL_FAILURE(
782 EndpointToToken(script_result, false /* standard_protocol */));
783
784 // Try to resubscribe from the document without a key - should fail.
785 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result));
786 EXPECT_EQ(
787 "AbortError - Registration failed - missing applicationServerKey, "
788 "and manifest empty or missing",
789 script_result);
790
791 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
792 EXPECT_EQ("unsubscribe result: true", script_result);
793 EXPECT_NE(push_service(), GetAppHandler());
794 }
795
598 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribePersisted) { 796 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribePersisted) {
599 std::string script_result; 797 std::string script_result;
600 798
601 // First, test that Service Worker registration IDs are assigned in order of 799 // First, test that Service Worker registration IDs are assigned in order of
602 // registering the Service Workers, and the (fake) push subscription ids are 800 // registering the Service Workers, and the (fake) push subscription ids are
603 // assigned in order of push subscription (even when these orders are 801 // assigned in order of push subscription (even when these orders are
604 // different). 802 // different).
605 803
606 std::string token1; 804 std::string token1;
607 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully(true /* use_key */, &token1)); 805 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()); 2056 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully());
1859 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); 2057 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive());
1860 2058
1861 // After dropping the last subscription background mode is still inactive. 2059 // After dropping the last subscription background mode is still inactive.
1862 std::string script_result; 2060 std::string script_result;
1863 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); 2061 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
1864 EXPECT_EQ("unsubscribe result: true", script_result); 2062 EXPECT_EQ("unsubscribe result: true", script_result);
1865 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); 2063 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive());
1866 } 2064 }
1867 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) 2065 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS)
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/push_messaging/push_test.js » ('j') | chrome/test/data/push_messaging/push_test.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698