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 <map> | 5 #include <map> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/browser/infobars/infobar_service.h" | 12 #include "chrome/browser/infobars/infobar_service.h" |
13 #include "chrome/browser/notifications/notification_test_util.h" | 13 #include "chrome/browser/notifications/notification_test_util.h" |
14 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 14 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" | 16 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" |
17 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 17 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
18 #include "chrome/browser/services/gcm/push_messaging_application_id.h" | 18 #include "chrome/browser/services/gcm/push_messaging_application_id.h" |
19 #include "chrome/browser/services/gcm/push_messaging_constants.h" | 19 #include "chrome/browser/services/gcm/push_messaging_constants.h" |
20 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
22 #include "chrome/test/base/in_process_browser_test.h" | 22 #include "chrome/test/base/in_process_browser_test.h" |
23 #include "chrome/test/base/ui_test_utils.h" | 23 #include "chrome/test/base/ui_test_utils.h" |
24 #include "components/content_settings/core/browser/host_content_settings_map.h" | 24 #include "components/content_settings/core/browser/host_content_settings_map.h" |
25 #include "components/content_settings/core/common/content_settings.h" | |
25 #include "components/content_settings/core/common/content_settings_types.h" | 26 #include "components/content_settings/core/common/content_settings_types.h" |
26 #include "components/gcm_driver/gcm_client.h" | 27 #include "components/gcm_driver/gcm_client.h" |
27 #include "components/infobars/core/confirm_infobar_delegate.h" | 28 #include "components/infobars/core/confirm_infobar_delegate.h" |
28 #include "components/infobars/core/infobar.h" | 29 #include "components/infobars/core/infobar.h" |
29 #include "components/infobars/core/infobar_manager.h" | 30 #include "components/infobars/core/infobar_manager.h" |
30 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
31 #include "content/public/common/content_switches.h" | 32 #include "content/public/common/content_switches.h" |
32 #include "content/public/test/browser_test_utils.h" | 33 #include "content/public/test/browser_test_utils.h" |
33 #include "ui/base/window_open_disposition.h" | 34 #include "ui/base/window_open_disposition.h" |
34 | 35 |
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
648 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 649 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
649 | 650 |
650 gcm_service()->AddExpectedUnregisterResponse(GCMClient::UNKNOWN_ERROR); | 651 gcm_service()->AddExpectedUnregisterResponse(GCMClient::UNKNOWN_ERROR); |
651 | 652 |
652 ASSERT_TRUE(RunScript("unregister()", &script_result)); | 653 ASSERT_TRUE(RunScript("unregister()", &script_result)); |
653 EXPECT_EQ("unregister error: " | 654 EXPECT_EQ("unregister error: " |
654 "UnknownError: Unexpected error while trying to unregister from the" | 655 "UnknownError: Unexpected error while trying to unregister from the" |
655 " push server.", script_result); | 656 " push server.", script_result); |
656 } | 657 } |
657 | 658 |
659 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | |
660 GlobalResetPushPermissionUnregisters) { | |
661 std::string script_result; | |
662 | |
663 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | |
664 | |
665 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | |
666 EXPECT_EQ("true - registered", script_result); | |
667 | |
668 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | |
669 EXPECT_EQ("permission status - granted", script_result); | |
670 | |
671 browser()->profile()->GetHostContentSettingsMap()-> | |
672 ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); | |
673 | |
674 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | |
675 EXPECT_EQ("permission status - default", script_result); | |
676 | |
677 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | |
678 EXPECT_EQ("false - not registered", script_result); | |
679 } | |
680 | |
681 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | |
682 LocalResetPushPermissionUnregisters) { | |
683 std::string script_result; | |
684 | |
685 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | |
686 | |
687 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | |
688 EXPECT_EQ("true - registered", script_result); | |
689 | |
690 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | |
691 EXPECT_EQ("permission status - granted", script_result); | |
692 | |
693 GURL origin = https_server()->GetURL("").GetOrigin(); | |
694 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | |
695 ContentSettingsPattern::FromURLNoWildcard(origin), | |
696 ContentSettingsPattern::FromURLNoWildcard(origin), | |
697 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | |
698 std::string(), | |
699 CONTENT_SETTING_DEFAULT); | |
700 | |
701 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | |
702 EXPECT_EQ("permission status - default", script_result); | |
703 | |
704 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | |
705 EXPECT_EQ("false - not registered", script_result); | |
706 } | |
707 | |
708 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | |
709 DenyPushPermissionUnregisters) { | |
710 std::string script_result; | |
711 | |
712 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | |
713 | |
714 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | |
715 EXPECT_EQ("true - registered", script_result); | |
716 | |
717 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | |
718 EXPECT_EQ("permission status - granted", script_result); | |
719 | |
720 GURL origin = https_server()->GetURL("").GetOrigin(); | |
721 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | |
722 ContentSettingsPattern::FromURLNoWildcard(origin), | |
723 ContentSettingsPattern::FromURLNoWildcard(origin), | |
724 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | |
725 std::string(), | |
726 CONTENT_SETTING_BLOCK); | |
727 | |
728 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | |
729 EXPECT_EQ("permission status - denied", script_result); | |
730 | |
731 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | |
732 EXPECT_EQ("false - not registered", script_result); | |
733 } | |
734 | |
735 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | |
736 GlobalResetNotificationsPermissionUnregisters) { | |
737 std::string script_result; | |
738 | |
739 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | |
740 | |
741 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | |
742 EXPECT_EQ("true - registered", script_result); | |
743 | |
744 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | |
745 EXPECT_EQ("permission status - granted", script_result); | |
746 | |
747 browser()->profile()->GetHostContentSettingsMap()-> | |
748 ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | |
749 | |
750 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | |
751 EXPECT_EQ("permission status - default", script_result); | |
752 | |
753 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | |
754 EXPECT_EQ("false - not registered", script_result); | |
755 } | |
756 | |
757 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | |
758 LocalResetNotificationsPermissionUnregisters) { | |
759 std::string script_result; | |
760 | |
761 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | |
762 | |
763 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | |
764 EXPECT_EQ("true - registered", script_result); | |
765 | |
766 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | |
767 EXPECT_EQ("permission status - granted", script_result); | |
768 | |
769 GURL origin = https_server()->GetURL("").GetOrigin(); | |
770 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | |
771 ContentSettingsPattern::FromURLNoWildcard(origin), | |
772 ContentSettingsPattern::Wildcard(), | |
773 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
774 std::string(), | |
775 CONTENT_SETTING_DEFAULT); | |
776 | |
777 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | |
778 EXPECT_EQ("permission status - default", script_result); | |
779 | |
780 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | |
781 EXPECT_EQ("false - not registered", script_result); | |
782 } | |
783 | |
784 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | |
785 DenyNotificationsPermissionUnregisters) { | |
786 std::string script_result; | |
787 | |
788 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | |
789 | |
790 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | |
791 EXPECT_EQ("true - registered", script_result); | |
792 | |
793 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | |
794 EXPECT_EQ("permission status - granted", script_result); | |
795 | |
796 GURL origin = https_server()->GetURL("").GetOrigin(); | |
797 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | |
798 ContentSettingsPattern::FromURLNoWildcard(origin), | |
799 ContentSettingsPattern::Wildcard(), | |
800 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
801 std::string(), | |
802 CONTENT_SETTING_BLOCK); | |
803 | |
804 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | |
805 EXPECT_EQ("permission status - denied", script_result); | |
806 | |
807 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | |
808 EXPECT_EQ("false - not registered", script_result); | |
809 } | |
810 | |
811 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | |
812 GrantAlreadyGrantedPermissionDoesNotUnregister) { | |
813 std::string script_result; | |
814 | |
815 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | |
816 | |
817 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | |
818 EXPECT_EQ("true - registered", script_result); | |
819 | |
820 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | |
821 EXPECT_EQ("permission status - granted", script_result); | |
822 | |
823 GURL origin = https_server()->GetURL("").GetOrigin(); | |
824 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | |
825 ContentSettingsPattern::FromURLNoWildcard(origin), | |
826 ContentSettingsPattern::Wildcard(), | |
827 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
828 std::string(), | |
829 CONTENT_SETTING_ALLOW); | |
830 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | |
831 ContentSettingsPattern::FromURLNoWildcard(origin), | |
832 ContentSettingsPattern::FromURLNoWildcard(origin), | |
833 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | |
834 std::string(), | |
835 CONTENT_SETTING_ALLOW); | |
836 | |
837 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | |
838 EXPECT_EQ("permission status - granted", script_result); | |
839 | |
840 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | |
841 EXPECT_EQ("true - registered", script_result); | |
842 } | |
843 | |
844 // This test is testing some non-trivial content settings rules and make sure | |
845 // that they are respected with regards to automatic unregistration. In other | |
846 // words, it checks that the push service does not end up unregistering origins | |
847 // that have push permission with some non-common rules. | |
848 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | |
849 AutomaticUnregistrationFollowsContentSettingRules) { | |
850 std::string script_result; | |
851 | |
852 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | |
853 | |
854 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | |
855 EXPECT_EQ("true - registered", script_result); | |
856 | |
857 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | |
858 EXPECT_EQ("permission status - granted", script_result); | |
859 | |
860 GURL origin = https_server()->GetURL("").GetOrigin(); | |
861 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | |
862 ContentSettingsPattern::Wildcard(), | |
863 ContentSettingsPattern::Wildcard(), | |
864 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
865 std::string(), | |
866 CONTENT_SETTING_ALLOW); | |
867 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | |
868 ContentSettingsPattern::FromString("https://*"), | |
869 ContentSettingsPattern::FromString("https://*"), | |
870 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | |
871 std::string(), | |
872 CONTENT_SETTING_ALLOW); | |
873 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | |
874 ContentSettingsPattern::FromURLNoWildcard(origin), | |
875 ContentSettingsPattern::Wildcard(), | |
876 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
877 std::string(), | |
878 CONTENT_SETTING_DEFAULT); | |
879 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | |
880 ContentSettingsPattern::FromURLNoWildcard(origin), | |
881 ContentSettingsPattern::FromURLNoWildcard(origin), | |
882 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | |
883 std::string(), | |
884 CONTENT_SETTING_DEFAULT); | |
885 | |
886 // The two first rules should give |origin| the permission to use Push even | |
887 // if the rules it used to have have been reset. | |
888 // The Push servire should not unsubcribe |origin| because at no point it was | |
johnme
2015/02/16 20:27:44
servire -> service
mlamouri (slow - plz ping)
2015/02/16 20:46:03
Done.
| |
889 // left without permission to use Push. | |
890 | |
891 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | |
892 EXPECT_EQ("permission status - granted", script_result); | |
893 | |
894 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | |
895 EXPECT_EQ("true - registered", script_result); | |
896 } | |
897 | |
658 } // namespace gcm | 898 } // namespace gcm |
OLD | NEW |