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

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

Issue 996813002: Deflake PushMessagingBrowserTest.DenyPushPermissionUnregisters & friends (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Bernhard's nit Created 5 years, 9 months 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
« no previous file with comments | « no previous file | chrome/browser/push_messaging/push_messaging_service_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <map> 5 #include <map>
6 #include <string> 6 #include <string>
7 7
8 #include "base/barrier_closure.h"
8 #include "base/bind.h" 9 #include "base/bind.h"
9 #include "base/command_line.h" 10 #include "base/command_line.h"
10 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h"
11 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/infobars/infobar_service.h" 14 #include "chrome/browser/infobars/infobar_service.h"
13 #include "chrome/browser/notifications/notification_test_util.h" 15 #include "chrome/browser/notifications/notification_test_util.h"
14 #include "chrome/browser/notifications/platform_notification_service_impl.h" 16 #include "chrome/browser/notifications/platform_notification_service_impl.h"
15 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/push_messaging/push_messaging_application_id.h" 18 #include "chrome/browser/push_messaging/push_messaging_application_id.h"
17 #include "chrome/browser/push_messaging/push_messaging_constants.h" 19 #include "chrome/browser/push_messaging/push_messaging_constants.h"
18 #include "chrome/browser/push_messaging/push_messaging_service_factory.h" 20 #include "chrome/browser/push_messaging/push_messaging_service_factory.h"
19 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" 21 #include "chrome/browser/push_messaging/push_messaging_service_impl.h"
20 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" 22 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 InfoBarService* infobar_service_; 84 InfoBarService* infobar_service_;
83 bool accept_; 85 bool accept_;
84 bool has_observed_; 86 bool has_observed_;
85 }; 87 };
86 88
87 // Class to instantiate on the stack that is meant to be used with 89 // Class to instantiate on the stack that is meant to be used with
88 // FakeGCMProfileService. The ::Run() method follows the signature of 90 // FakeGCMProfileService. The ::Run() method follows the signature of
89 // FakeGCMProfileService::UnregisterCallback. 91 // FakeGCMProfileService::UnregisterCallback.
90 class UnregistrationCallback { 92 class UnregistrationCallback {
91 public: 93 public:
92 UnregistrationCallback() : done_(false), waiting_(false) {}
93
94 void Run(const std::string& app_id) { 94 void Run(const std::string& app_id) {
95 app_id_ = app_id; 95 app_id_ = app_id;
96 done_ = true; 96 run_loop_.Quit();
97 if (waiting_)
98 base::MessageLoop::current()->Quit();
99 } 97 }
100 98
101 void WaitUntilSatisfied() { 99 void WaitUntilSatisfied() {
102 if (done_) 100 run_loop_.Run();
103 return;
104
105 waiting_ = true;
106 while (!done_)
107 content::RunMessageLoop();
108 } 101 }
109 102
110 const std::string& app_id() { 103 const std::string& app_id() {
111 return app_id_; 104 return app_id_;
112 } 105 }
113 106
114 private: 107 private:
115 bool done_; 108 base::RunLoop run_loop_;
Avi (use Gerrit) 2015/03/13 13:58:04 MessageLoopRunner.
johnme 2015/03/13 14:21:29 Done.
116 bool waiting_;
117 std::string app_id_; 109 std::string app_id_;
118 }; 110 };
119 111
120 // Class to instantiate on the stack that is meant to be used with
121 // StubNotificationUIManager::SetNotificationAddedCallback. Mind that Run()
122 // might be invoked prior to WaitUntilSatisfied() being called.
123 class NotificationAddedCallback {
124 public:
125 NotificationAddedCallback() : done_(false), waiting_(false) {}
126
127 void Run() {
128 done_ = true;
129 if (waiting_)
130 base::MessageLoop::current()->Quit();
131 }
132
133 void WaitUntilSatisfied() {
134 if (done_)
135 return;
136
137 waiting_ = true;
138 while (!done_)
139 content::RunMessageLoop();
140 }
141
142 private:
143 bool done_;
144 bool waiting_;
145 };
146
147 // The Push API depends on Web Notifications, which is only available on Android 112 // The Push API depends on Web Notifications, which is only available on Android
148 // Jelly Bean and later. 113 // Jelly Bean and later.
149 bool IsPushSupported() { 114 bool IsPushSupported() {
150 #if defined(OS_ANDROID) 115 #if defined(OS_ANDROID)
151 if (base::android::BuildInfo::GetInstance()->sdk_int() < 116 if (base::android::BuildInfo::GetInstance()->sdk_int() <
152 base::android::SDK_VERSION_JELLY_BEAN) { 117 base::android::SDK_VERSION_JELLY_BEAN) {
153 DVLOG(0) << "The Push API is only supported in Android 4.1 and later."; 118 DVLOG(0) << "The Push API is only supported in Android 4.1 and later.";
154 return false; 119 return false;
155 } 120 }
156 #endif 121 #endif
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); 597 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]);
633 598
634 ASSERT_TRUE(RunScript("isControlled()", &script_result)); 599 ASSERT_TRUE(RunScript("isControlled()", &script_result));
635 ASSERT_EQ("false - is not controlled", script_result); 600 ASSERT_EQ("false - is not controlled", script_result);
636 601
637 LoadTestPage(); // Reload to become controlled. 602 LoadTestPage(); // Reload to become controlled.
638 603
639 ASSERT_TRUE(RunScript("isControlled()", &script_result)); 604 ASSERT_TRUE(RunScript("isControlled()", &script_result));
640 ASSERT_EQ("true - is controlled", script_result); 605 ASSERT_EQ("true - is controlled", script_result);
641 606
642 NotificationAddedCallback callback; 607 base::RunLoop run_loop;
643 notification_manager()->SetNotificationAddedCallback( 608 notification_manager()->SetNotificationAddedCallback(run_loop.QuitClosure());
644 base::Bind(&NotificationAddedCallback::Run, base::Unretained(&callback)));
645 609
646 gcm::GCMClient::IncomingMessage message; 610 gcm::GCMClient::IncomingMessage message;
647 message.sender_id = "1234567890"; 611 message.sender_id = "1234567890";
648 message.data["data"] = "shownotification-without-waituntil"; 612 message.data["data"] = "shownotification-without-waituntil";
649 push_service()->OnMessage(app_id.app_id_guid(), message); 613 push_service()->OnMessage(app_id.app_id_guid(), message);
650 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); 614 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents));
651 EXPECT_EQ("immediate:shownotification-without-waituntil", script_result); 615 EXPECT_EQ("immediate:shownotification-without-waituntil", script_result);
652 616
653 callback.WaitUntilSatisfied(); 617 run_loop.Run();
654 618
655 ASSERT_EQ(1u, notification_manager()->GetNotificationCount()); 619 ASSERT_EQ(1u, notification_manager()->GetNotificationCount());
656 EXPECT_EQ("push_test_tag", 620 EXPECT_EQ("push_test_tag",
657 notification_manager()->GetNotificationAt(0).tag()); 621 notification_manager()->GetNotificationAt(0).tag());
658 622
659 // Verify that the renderer process hasn't crashed. 623 // Verify that the renderer process hasn't crashed.
660 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); 624 ASSERT_TRUE(RunScript("hasPermission()", &script_result));
661 EXPECT_EQ("permission status - granted", script_result); 625 EXPECT_EQ("permission status - granted", script_result);
662 } 626 }
663 #endif 627 #endif
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 std::string script_result; 743 std::string script_result;
780 744
781 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); 745 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */);
782 746
783 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); 747 ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
784 EXPECT_EQ("true - registered", script_result); 748 EXPECT_EQ("true - registered", script_result);
785 749
786 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); 750 ASSERT_TRUE(RunScript("hasPermission()", &script_result));
787 EXPECT_EQ("permission status - granted", script_result); 751 EXPECT_EQ("permission status - granted", script_result);
788 752
753 base::RunLoop run_loop;
754 push_service()->SetContentSettingChangedCallbackForTesting(
755 run_loop.QuitClosure());
756
789 browser()->profile()->GetHostContentSettingsMap()-> 757 browser()->profile()->GetHostContentSettingsMap()->
790 ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); 758 ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING);
791 759
760 run_loop.Run();
761
792 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); 762 ASSERT_TRUE(RunScript("hasPermission()", &script_result));
793 EXPECT_EQ("permission status - default", script_result); 763 EXPECT_EQ("permission status - default", script_result);
794 764
795 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); 765 ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
796 EXPECT_EQ("false - not registered", script_result); 766 EXPECT_EQ("false - not registered", script_result);
797 } 767 }
798 768
799 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, 769 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
800 LocalResetPushPermissionUnregisters) { 770 LocalResetPushPermissionUnregisters) {
801 std::string script_result; 771 std::string script_result;
802 772
803 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); 773 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */);
804 774
805 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); 775 ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
806 EXPECT_EQ("true - registered", script_result); 776 EXPECT_EQ("true - registered", script_result);
807 777
808 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); 778 ASSERT_TRUE(RunScript("hasPermission()", &script_result));
809 EXPECT_EQ("permission status - granted", script_result); 779 EXPECT_EQ("permission status - granted", script_result);
810 780
781 base::RunLoop run_loop;
782 push_service()->SetContentSettingChangedCallbackForTesting(
783 run_loop.QuitClosure());
784
811 GURL origin = https_server()->GetURL(std::string()).GetOrigin(); 785 GURL origin = https_server()->GetURL(std::string()).GetOrigin();
812 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( 786 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
813 ContentSettingsPattern::FromURLNoWildcard(origin), 787 ContentSettingsPattern::FromURLNoWildcard(origin),
814 ContentSettingsPattern::FromURLNoWildcard(origin), 788 ContentSettingsPattern::FromURLNoWildcard(origin),
815 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, 789 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
816 std::string(), 790 std::string(),
817 CONTENT_SETTING_DEFAULT); 791 CONTENT_SETTING_DEFAULT);
818 792
793 run_loop.Run();
794
819 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); 795 ASSERT_TRUE(RunScript("hasPermission()", &script_result));
820 EXPECT_EQ("permission status - default", script_result); 796 EXPECT_EQ("permission status - default", script_result);
821 797
822 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); 798 ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
823 EXPECT_EQ("false - not registered", script_result); 799 EXPECT_EQ("false - not registered", script_result);
824 } 800 }
825 801
826 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, 802 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
827 DenyPushPermissionUnregisters) { 803 DenyPushPermissionUnregisters) {
828 std::string script_result; 804 std::string script_result;
829 805
830 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); 806 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */);
831 807
832 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); 808 ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
833 EXPECT_EQ("true - registered", script_result); 809 EXPECT_EQ("true - registered", script_result);
834 810
835 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); 811 ASSERT_TRUE(RunScript("hasPermission()", &script_result));
836 EXPECT_EQ("permission status - granted", script_result); 812 EXPECT_EQ("permission status - granted", script_result);
837 813
814 base::RunLoop run_loop;
815 push_service()->SetContentSettingChangedCallbackForTesting(
816 run_loop.QuitClosure());
817
838 GURL origin = https_server()->GetURL(std::string()).GetOrigin(); 818 GURL origin = https_server()->GetURL(std::string()).GetOrigin();
839 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( 819 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
840 ContentSettingsPattern::FromURLNoWildcard(origin), 820 ContentSettingsPattern::FromURLNoWildcard(origin),
841 ContentSettingsPattern::FromURLNoWildcard(origin), 821 ContentSettingsPattern::FromURLNoWildcard(origin),
842 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, 822 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
843 std::string(), 823 std::string(),
844 CONTENT_SETTING_BLOCK); 824 CONTENT_SETTING_BLOCK);
845 825
826 run_loop.Run();
827
846 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); 828 ASSERT_TRUE(RunScript("hasPermission()", &script_result));
847 EXPECT_EQ("permission status - denied", script_result); 829 EXPECT_EQ("permission status - denied", script_result);
848 830
849 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); 831 ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
850 EXPECT_EQ("false - not registered", script_result); 832 EXPECT_EQ("false - not registered", script_result);
851 } 833 }
852 834
853 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, 835 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
854 GlobalResetNotificationsPermissionUnregisters) { 836 GlobalResetNotificationsPermissionUnregisters) {
855 std::string script_result; 837 std::string script_result;
856 838
857 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); 839 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */);
858 840
859 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); 841 ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
860 EXPECT_EQ("true - registered", script_result); 842 EXPECT_EQ("true - registered", script_result);
861 843
862 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); 844 ASSERT_TRUE(RunScript("hasPermission()", &script_result));
863 EXPECT_EQ("permission status - granted", script_result); 845 EXPECT_EQ("permission status - granted", script_result);
864 846
847 base::RunLoop run_loop;
848 push_service()->SetContentSettingChangedCallbackForTesting(
849 run_loop.QuitClosure());
850
865 browser()->profile()->GetHostContentSettingsMap()-> 851 browser()->profile()->GetHostContentSettingsMap()->
866 ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 852 ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
867 853
854 run_loop.Run();
855
868 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); 856 ASSERT_TRUE(RunScript("hasPermission()", &script_result));
869 EXPECT_EQ("permission status - default", script_result); 857 EXPECT_EQ("permission status - default", script_result);
870 858
871 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); 859 ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
872 EXPECT_EQ("false - not registered", script_result); 860 EXPECT_EQ("false - not registered", script_result);
873 } 861 }
874 862
875 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, 863 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
876 LocalResetNotificationsPermissionUnregisters) { 864 LocalResetNotificationsPermissionUnregisters) {
877 std::string script_result; 865 std::string script_result;
878 866
879 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); 867 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */);
880 868
881 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); 869 ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
882 EXPECT_EQ("true - registered", script_result); 870 EXPECT_EQ("true - registered", script_result);
883 871
884 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); 872 ASSERT_TRUE(RunScript("hasPermission()", &script_result));
885 EXPECT_EQ("permission status - granted", script_result); 873 EXPECT_EQ("permission status - granted", script_result);
886 874
875 base::RunLoop run_loop;
876 push_service()->SetContentSettingChangedCallbackForTesting(
877 run_loop.QuitClosure());
878
887 GURL origin = https_server()->GetURL(std::string()).GetOrigin(); 879 GURL origin = https_server()->GetURL(std::string()).GetOrigin();
888 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( 880 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
889 ContentSettingsPattern::FromURLNoWildcard(origin), 881 ContentSettingsPattern::FromURLNoWildcard(origin),
890 ContentSettingsPattern::Wildcard(), 882 ContentSettingsPattern::Wildcard(),
891 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 883 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
892 std::string(), 884 std::string(),
893 CONTENT_SETTING_DEFAULT); 885 CONTENT_SETTING_DEFAULT);
894 886
887 run_loop.Run();
888
895 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); 889 ASSERT_TRUE(RunScript("hasPermission()", &script_result));
896 EXPECT_EQ("permission status - default", script_result); 890 EXPECT_EQ("permission status - default", script_result);
897 891
898 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); 892 ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
899 EXPECT_EQ("false - not registered", script_result); 893 EXPECT_EQ("false - not registered", script_result);
900 } 894 }
901 895
902 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, 896 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
903 DenyNotificationsPermissionUnregisters) { 897 DenyNotificationsPermissionUnregisters) {
904 std::string script_result; 898 std::string script_result;
905 899
906 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); 900 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */);
907 901
908 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); 902 ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
909 EXPECT_EQ("true - registered", script_result); 903 EXPECT_EQ("true - registered", script_result);
910 904
911 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); 905 ASSERT_TRUE(RunScript("hasPermission()", &script_result));
912 EXPECT_EQ("permission status - granted", script_result); 906 EXPECT_EQ("permission status - granted", script_result);
913 907
908 base::RunLoop run_loop;
909 push_service()->SetContentSettingChangedCallbackForTesting(
910 run_loop.QuitClosure());
911
914 GURL origin = https_server()->GetURL(std::string()).GetOrigin(); 912 GURL origin = https_server()->GetURL(std::string()).GetOrigin();
915 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( 913 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
916 ContentSettingsPattern::FromURLNoWildcard(origin), 914 ContentSettingsPattern::FromURLNoWildcard(origin),
917 ContentSettingsPattern::Wildcard(), 915 ContentSettingsPattern::Wildcard(),
918 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 916 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
919 std::string(), 917 std::string(),
920 CONTENT_SETTING_BLOCK); 918 CONTENT_SETTING_BLOCK);
921 919
920 run_loop.Run();
921
922 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); 922 ASSERT_TRUE(RunScript("hasPermission()", &script_result));
923 EXPECT_EQ("permission status - denied", script_result); 923 EXPECT_EQ("permission status - denied", script_result);
924 924
925 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); 925 ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
926 EXPECT_EQ("false - not registered", script_result); 926 EXPECT_EQ("false - not registered", script_result);
927 } 927 }
928 928
929 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, 929 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
930 GrantAlreadyGrantedPermissionDoesNotUnregister) { 930 GrantAlreadyGrantedPermissionDoesNotUnregister) {
931 std::string script_result; 931 std::string script_result;
932 932
933 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); 933 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */);
934 934
935 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); 935 ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
936 EXPECT_EQ("true - registered", script_result); 936 EXPECT_EQ("true - registered", script_result);
937 937
938 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); 938 ASSERT_TRUE(RunScript("hasPermission()", &script_result));
939 EXPECT_EQ("permission status - granted", script_result); 939 EXPECT_EQ("permission status - granted", script_result);
940 940
941 base::RunLoop run_loop;
942 push_service()->SetContentSettingChangedCallbackForTesting(
943 base::BarrierClosure(2, run_loop.QuitClosure()));
944
941 GURL origin = https_server()->GetURL(std::string()).GetOrigin(); 945 GURL origin = https_server()->GetURL(std::string()).GetOrigin();
942 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( 946 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
943 ContentSettingsPattern::FromURLNoWildcard(origin), 947 ContentSettingsPattern::FromURLNoWildcard(origin),
944 ContentSettingsPattern::Wildcard(), 948 ContentSettingsPattern::Wildcard(),
945 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 949 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
946 std::string(), 950 std::string(),
947 CONTENT_SETTING_ALLOW); 951 CONTENT_SETTING_ALLOW);
948 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( 952 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
949 ContentSettingsPattern::FromURLNoWildcard(origin), 953 ContentSettingsPattern::FromURLNoWildcard(origin),
950 ContentSettingsPattern::FromURLNoWildcard(origin), 954 ContentSettingsPattern::FromURLNoWildcard(origin),
951 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, 955 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
952 std::string(), 956 std::string(),
953 CONTENT_SETTING_ALLOW); 957 CONTENT_SETTING_ALLOW);
954 958
959 run_loop.Run();
960
955 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); 961 ASSERT_TRUE(RunScript("hasPermission()", &script_result));
956 EXPECT_EQ("permission status - granted", script_result); 962 EXPECT_EQ("permission status - granted", script_result);
957 963
958 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); 964 ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
959 EXPECT_EQ("true - registered", script_result); 965 EXPECT_EQ("true - registered", script_result);
960 } 966 }
961 967
962 // This test is testing some non-trivial content settings rules and make sure 968 // This test is testing some non-trivial content settings rules and make sure
963 // that they are respected with regards to automatic unregistration. In other 969 // that they are respected with regards to automatic unregistration. In other
964 // words, it checks that the push service does not end up unregistering origins 970 // words, it checks that the push service does not end up unregistering origins
965 // that have push permission with some non-common rules. 971 // that have push permission with some non-common rules.
966 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, 972 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
967 AutomaticUnregistrationFollowsContentSettingRules) { 973 AutomaticUnregistrationFollowsContentSettingRules) {
968 std::string script_result; 974 std::string script_result;
969 975
970 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); 976 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */);
971 977
972 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); 978 ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
973 EXPECT_EQ("true - registered", script_result); 979 EXPECT_EQ("true - registered", script_result);
974 980
975 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); 981 ASSERT_TRUE(RunScript("hasPermission()", &script_result));
976 EXPECT_EQ("permission status - granted", script_result); 982 EXPECT_EQ("permission status - granted", script_result);
977 983
984 base::RunLoop run_loop;
985 push_service()->SetContentSettingChangedCallbackForTesting(
986 base::BarrierClosure(4, run_loop.QuitClosure()));
987
978 GURL origin = https_server()->GetURL(std::string()).GetOrigin(); 988 GURL origin = https_server()->GetURL(std::string()).GetOrigin();
979 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( 989 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
980 ContentSettingsPattern::Wildcard(), 990 ContentSettingsPattern::Wildcard(),
981 ContentSettingsPattern::Wildcard(), 991 ContentSettingsPattern::Wildcard(),
982 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 992 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
983 std::string(), 993 std::string(),
984 CONTENT_SETTING_ALLOW); 994 CONTENT_SETTING_ALLOW);
985 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( 995 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
986 ContentSettingsPattern::FromString("https://*"), 996 ContentSettingsPattern::FromString("https://*"),
987 ContentSettingsPattern::FromString("https://*"), 997 ContentSettingsPattern::FromString("https://*"),
988 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, 998 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
989 std::string(), 999 std::string(),
990 CONTENT_SETTING_ALLOW); 1000 CONTENT_SETTING_ALLOW);
991 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( 1001 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
992 ContentSettingsPattern::FromURLNoWildcard(origin), 1002 ContentSettingsPattern::FromURLNoWildcard(origin),
993 ContentSettingsPattern::Wildcard(), 1003 ContentSettingsPattern::Wildcard(),
994 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 1004 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
995 std::string(), 1005 std::string(),
996 CONTENT_SETTING_DEFAULT); 1006 CONTENT_SETTING_DEFAULT);
997 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( 1007 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
998 ContentSettingsPattern::FromURLNoWildcard(origin), 1008 ContentSettingsPattern::FromURLNoWildcard(origin),
999 ContentSettingsPattern::FromURLNoWildcard(origin), 1009 ContentSettingsPattern::FromURLNoWildcard(origin),
1000 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, 1010 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
1001 std::string(), 1011 std::string(),
1002 CONTENT_SETTING_DEFAULT); 1012 CONTENT_SETTING_DEFAULT);
1003 1013
1014 run_loop.Run();
1015
1004 // The two first rules should give |origin| the permission to use Push even 1016 // The two first rules should give |origin| the permission to use Push even
1005 // if the rules it used to have have been reset. 1017 // if the rules it used to have have been reset.
1006 // The Push service should not unsubcribe |origin| because at no point it was 1018 // The Push service should not unsubcribe |origin| because at no point it was
1007 // left without permission to use Push. 1019 // left without permission to use Push.
1008 1020
1009 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); 1021 ASSERT_TRUE(RunScript("hasPermission()", &script_result));
1010 EXPECT_EQ("permission status - granted", script_result); 1022 EXPECT_EQ("permission status - granted", script_result);
1011 1023
1012 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); 1024 ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
1013 EXPECT_EQ("true - registered", script_result); 1025 EXPECT_EQ("true - registered", script_result);
1014 } 1026 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/push_messaging/push_messaging_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698