| 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/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" |
| 11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/infobars/infobar_service.h" | 13 #include "chrome/browser/infobars/infobar_service.h" |
| 13 #include "chrome/browser/notifications/notification_test_util.h" | 14 #include "chrome/browser/notifications/notification_test_util.h" |
| 14 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 15 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/push_messaging/push_messaging_application_id.h" | 17 #include "chrome/browser/push_messaging/push_messaging_application_id.h" |
| 17 #include "chrome/browser/push_messaging/push_messaging_constants.h" | 18 #include "chrome/browser/push_messaging/push_messaging_constants.h" |
| 18 #include "chrome/browser/push_messaging/push_messaging_service_factory.h" | 19 #include "chrome/browser/push_messaging/push_messaging_service_factory.h" |
| 19 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" | 20 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" |
| 20 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" | 21 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" |
| 21 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 22 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
| 22 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
| 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 24 #include "chrome/test/base/in_process_browser_test.h" | 25 #include "chrome/test/base/in_process_browser_test.h" |
| 25 #include "chrome/test/base/ui_test_utils.h" | 26 #include "chrome/test/base/ui_test_utils.h" |
| 26 #include "components/content_settings/core/browser/host_content_settings_map.h" | 27 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 27 #include "components/content_settings/core/common/content_settings.h" | 28 #include "components/content_settings/core/common/content_settings.h" |
| 28 #include "components/content_settings/core/common/content_settings_types.h" | 29 #include "components/content_settings/core/common/content_settings_types.h" |
| 29 #include "components/gcm_driver/gcm_client.h" | 30 #include "components/gcm_driver/gcm_client.h" |
| 30 #include "components/infobars/core/confirm_infobar_delegate.h" | 31 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 31 #include "components/infobars/core/infobar.h" | 32 #include "components/infobars/core/infobar.h" |
| 32 #include "components/infobars/core/infobar_manager.h" | 33 #include "components/infobars/core/infobar_manager.h" |
| 33 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
| 34 #include "content/public/common/content_switches.h" | 35 #include "content/public/common/content_switches.h" |
| 35 #include "content/public/test/browser_test_utils.h" | 36 #include "content/public/test/browser_test_utils.h" |
| 37 #include "content/public/test/test_utils.h" |
| 36 #include "ui/base/window_open_disposition.h" | 38 #include "ui/base/window_open_disposition.h" |
| 37 | 39 |
| 38 #if defined(OS_ANDROID) | 40 #if defined(OS_ANDROID) |
| 39 #include "base/android/build_info.h" | 41 #include "base/android/build_info.h" |
| 40 #endif | 42 #endif |
| 41 | 43 |
| 42 namespace { | 44 namespace { |
| 43 // Responds to a confirm infobar by accepting or cancelling it. Responds to at | 45 // Responds to a confirm infobar by accepting or cancelling it. Responds to at |
| 44 // most one infobar. | 46 // most one infobar. |
| 45 class InfoBarResponder : public infobars::InfoBarManager::Observer { | 47 class InfoBarResponder : public infobars::InfoBarManager::Observer { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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) {} | 94 UnregistrationCallback() |
| 95 : message_loop_runner_(new content::MessageLoopRunner) {} |
| 93 | 96 |
| 94 void Run(const std::string& app_id) { | 97 void Run(const std::string& app_id) { |
| 95 app_id_ = app_id; | 98 app_id_ = app_id; |
| 96 done_ = true; | 99 message_loop_runner_->Quit(); |
| 97 if (waiting_) | |
| 98 base::MessageLoop::current()->Quit(); | |
| 99 } | 100 } |
| 100 | 101 |
| 101 void WaitUntilSatisfied() { | 102 void WaitUntilSatisfied() { |
| 102 if (done_) | 103 message_loop_runner_->Run(); |
| 103 return; | |
| 104 | |
| 105 waiting_ = true; | |
| 106 while (!done_) | |
| 107 content::RunMessageLoop(); | |
| 108 } | 104 } |
| 109 | 105 |
| 110 const std::string& app_id() { | 106 const std::string& app_id() { |
| 111 return app_id_; | 107 return app_id_; |
| 112 } | 108 } |
| 113 | 109 |
| 114 private: | 110 private: |
| 115 bool done_; | 111 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 116 bool waiting_; | |
| 117 std::string app_id_; | 112 std::string app_id_; |
| 118 }; | 113 }; |
| 119 | 114 |
| 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 | 115 // The Push API depends on Web Notifications, which is only available on Android |
| 148 // Jelly Bean and later. | 116 // Jelly Bean and later. |
| 149 bool IsPushSupported() { | 117 bool IsPushSupported() { |
| 150 #if defined(OS_ANDROID) | 118 #if defined(OS_ANDROID) |
| 151 if (base::android::BuildInfo::GetInstance()->sdk_int() < | 119 if (base::android::BuildInfo::GetInstance()->sdk_int() < |
| 152 base::android::SDK_VERSION_JELLY_BEAN) { | 120 base::android::SDK_VERSION_JELLY_BEAN) { |
| 153 DVLOG(0) << "The Push API is only supported in Android 4.1 and later."; | 121 DVLOG(0) << "The Push API is only supported in Android 4.1 and later."; |
| 154 return false; | 122 return false; |
| 155 } | 123 } |
| 156 #endif | 124 #endif |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 600 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); |
| 633 | 601 |
| 634 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 602 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 635 ASSERT_EQ("false - is not controlled", script_result); | 603 ASSERT_EQ("false - is not controlled", script_result); |
| 636 | 604 |
| 637 LoadTestPage(); // Reload to become controlled. | 605 LoadTestPage(); // Reload to become controlled. |
| 638 | 606 |
| 639 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 607 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 640 ASSERT_EQ("true - is controlled", script_result); | 608 ASSERT_EQ("true - is controlled", script_result); |
| 641 | 609 |
| 642 NotificationAddedCallback callback; | 610 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 611 new content::MessageLoopRunner; |
| 643 notification_manager()->SetNotificationAddedCallback( | 612 notification_manager()->SetNotificationAddedCallback( |
| 644 base::Bind(&NotificationAddedCallback::Run, base::Unretained(&callback))); | 613 message_loop_runner->QuitClosure()); |
| 645 | 614 |
| 646 gcm::GCMClient::IncomingMessage message; | 615 gcm::GCMClient::IncomingMessage message; |
| 647 message.sender_id = "1234567890"; | 616 message.sender_id = "1234567890"; |
| 648 message.data["data"] = "shownotification-without-waituntil"; | 617 message.data["data"] = "shownotification-without-waituntil"; |
| 649 push_service()->OnMessage(app_id.app_id_guid(), message); | 618 push_service()->OnMessage(app_id.app_id_guid(), message); |
| 650 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); | 619 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); |
| 651 EXPECT_EQ("immediate:shownotification-without-waituntil", script_result); | 620 EXPECT_EQ("immediate:shownotification-without-waituntil", script_result); |
| 652 | 621 |
| 653 callback.WaitUntilSatisfied(); | 622 message_loop_runner->Run(); |
| 654 | 623 |
| 655 ASSERT_EQ(1u, notification_manager()->GetNotificationCount()); | 624 ASSERT_EQ(1u, notification_manager()->GetNotificationCount()); |
| 656 EXPECT_EQ("push_test_tag", | 625 EXPECT_EQ("push_test_tag", |
| 657 notification_manager()->GetNotificationAt(0).tag()); | 626 notification_manager()->GetNotificationAt(0).tag()); |
| 658 | 627 |
| 659 // Verify that the renderer process hasn't crashed. | 628 // Verify that the renderer process hasn't crashed. |
| 660 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | 629 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); |
| 661 EXPECT_EQ("permission status - granted", script_result); | 630 EXPECT_EQ("permission status - granted", script_result); |
| 662 } | 631 } |
| 663 #endif | 632 #endif |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 std::string script_result; | 748 std::string script_result; |
| 780 | 749 |
| 781 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 750 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| 782 | 751 |
| 783 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | 752 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); |
| 784 EXPECT_EQ("true - registered", script_result); | 753 EXPECT_EQ("true - registered", script_result); |
| 785 | 754 |
| 786 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | 755 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); |
| 787 EXPECT_EQ("permission status - granted", script_result); | 756 EXPECT_EQ("permission status - granted", script_result); |
| 788 | 757 |
| 758 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 759 new content::MessageLoopRunner; |
| 760 push_service()->SetContentSettingChangedCallbackForTesting( |
| 761 message_loop_runner->QuitClosure()); |
| 762 |
| 789 browser()->profile()->GetHostContentSettingsMap()-> | 763 browser()->profile()->GetHostContentSettingsMap()-> |
| 790 ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); | 764 ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); |
| 791 | 765 |
| 766 message_loop_runner->Run(); |
| 767 |
| 792 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | 768 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); |
| 793 EXPECT_EQ("permission status - default", script_result); | 769 EXPECT_EQ("permission status - default", script_result); |
| 794 | 770 |
| 795 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | 771 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); |
| 796 EXPECT_EQ("false - not registered", script_result); | 772 EXPECT_EQ("false - not registered", script_result); |
| 797 } | 773 } |
| 798 | 774 |
| 799 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 775 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 800 LocalResetPushPermissionUnregisters) { | 776 LocalResetPushPermissionUnregisters) { |
| 801 std::string script_result; | 777 std::string script_result; |
| 802 | 778 |
| 803 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 779 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| 804 | 780 |
| 805 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | 781 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); |
| 806 EXPECT_EQ("true - registered", script_result); | 782 EXPECT_EQ("true - registered", script_result); |
| 807 | 783 |
| 808 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | 784 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); |
| 809 EXPECT_EQ("permission status - granted", script_result); | 785 EXPECT_EQ("permission status - granted", script_result); |
| 810 | 786 |
| 787 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 788 new content::MessageLoopRunner; |
| 789 push_service()->SetContentSettingChangedCallbackForTesting( |
| 790 message_loop_runner->QuitClosure()); |
| 791 |
| 811 GURL origin = https_server()->GetURL(std::string()).GetOrigin(); | 792 GURL origin = https_server()->GetURL(std::string()).GetOrigin(); |
| 812 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | 793 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( |
| 813 ContentSettingsPattern::FromURLNoWildcard(origin), | 794 ContentSettingsPattern::FromURLNoWildcard(origin), |
| 814 ContentSettingsPattern::FromURLNoWildcard(origin), | 795 ContentSettingsPattern::FromURLNoWildcard(origin), |
| 815 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | 796 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 816 std::string(), | 797 std::string(), |
| 817 CONTENT_SETTING_DEFAULT); | 798 CONTENT_SETTING_DEFAULT); |
| 818 | 799 |
| 800 message_loop_runner->Run(); |
| 801 |
| 819 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | 802 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); |
| 820 EXPECT_EQ("permission status - default", script_result); | 803 EXPECT_EQ("permission status - default", script_result); |
| 821 | 804 |
| 822 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | 805 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); |
| 823 EXPECT_EQ("false - not registered", script_result); | 806 EXPECT_EQ("false - not registered", script_result); |
| 824 } | 807 } |
| 825 | 808 |
| 826 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 809 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 827 DenyPushPermissionUnregisters) { | 810 DenyPushPermissionUnregisters) { |
| 828 std::string script_result; | 811 std::string script_result; |
| 829 | 812 |
| 830 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 813 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| 831 | 814 |
| 832 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | 815 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); |
| 833 EXPECT_EQ("true - registered", script_result); | 816 EXPECT_EQ("true - registered", script_result); |
| 834 | 817 |
| 835 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | 818 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); |
| 836 EXPECT_EQ("permission status - granted", script_result); | 819 EXPECT_EQ("permission status - granted", script_result); |
| 837 | 820 |
| 821 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 822 new content::MessageLoopRunner; |
| 823 push_service()->SetContentSettingChangedCallbackForTesting( |
| 824 message_loop_runner->QuitClosure()); |
| 825 |
| 838 GURL origin = https_server()->GetURL(std::string()).GetOrigin(); | 826 GURL origin = https_server()->GetURL(std::string()).GetOrigin(); |
| 839 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | 827 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( |
| 840 ContentSettingsPattern::FromURLNoWildcard(origin), | 828 ContentSettingsPattern::FromURLNoWildcard(origin), |
| 841 ContentSettingsPattern::FromURLNoWildcard(origin), | 829 ContentSettingsPattern::FromURLNoWildcard(origin), |
| 842 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | 830 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 843 std::string(), | 831 std::string(), |
| 844 CONTENT_SETTING_BLOCK); | 832 CONTENT_SETTING_BLOCK); |
| 845 | 833 |
| 834 message_loop_runner->Run(); |
| 835 |
| 846 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | 836 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); |
| 847 EXPECT_EQ("permission status - denied", script_result); | 837 EXPECT_EQ("permission status - denied", script_result); |
| 848 | 838 |
| 849 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | 839 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); |
| 850 EXPECT_EQ("false - not registered", script_result); | 840 EXPECT_EQ("false - not registered", script_result); |
| 851 } | 841 } |
| 852 | 842 |
| 853 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 843 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 854 GlobalResetNotificationsPermissionUnregisters) { | 844 GlobalResetNotificationsPermissionUnregisters) { |
| 855 std::string script_result; | 845 std::string script_result; |
| 856 | 846 |
| 857 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 847 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| 858 | 848 |
| 859 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | 849 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); |
| 860 EXPECT_EQ("true - registered", script_result); | 850 EXPECT_EQ("true - registered", script_result); |
| 861 | 851 |
| 862 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | 852 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); |
| 863 EXPECT_EQ("permission status - granted", script_result); | 853 EXPECT_EQ("permission status - granted", script_result); |
| 864 | 854 |
| 855 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 856 new content::MessageLoopRunner; |
| 857 push_service()->SetContentSettingChangedCallbackForTesting( |
| 858 message_loop_runner->QuitClosure()); |
| 859 |
| 865 browser()->profile()->GetHostContentSettingsMap()-> | 860 browser()->profile()->GetHostContentSettingsMap()-> |
| 866 ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 861 ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 867 | 862 |
| 863 message_loop_runner->Run(); |
| 864 |
| 868 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | 865 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); |
| 869 EXPECT_EQ("permission status - default", script_result); | 866 EXPECT_EQ("permission status - default", script_result); |
| 870 | 867 |
| 871 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | 868 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); |
| 872 EXPECT_EQ("false - not registered", script_result); | 869 EXPECT_EQ("false - not registered", script_result); |
| 873 } | 870 } |
| 874 | 871 |
| 875 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 872 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 876 LocalResetNotificationsPermissionUnregisters) { | 873 LocalResetNotificationsPermissionUnregisters) { |
| 877 std::string script_result; | 874 std::string script_result; |
| 878 | 875 |
| 879 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 876 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| 880 | 877 |
| 881 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | 878 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); |
| 882 EXPECT_EQ("true - registered", script_result); | 879 EXPECT_EQ("true - registered", script_result); |
| 883 | 880 |
| 884 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | 881 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); |
| 885 EXPECT_EQ("permission status - granted", script_result); | 882 EXPECT_EQ("permission status - granted", script_result); |
| 886 | 883 |
| 884 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 885 new content::MessageLoopRunner; |
| 886 push_service()->SetContentSettingChangedCallbackForTesting( |
| 887 message_loop_runner->QuitClosure()); |
| 888 |
| 887 GURL origin = https_server()->GetURL(std::string()).GetOrigin(); | 889 GURL origin = https_server()->GetURL(std::string()).GetOrigin(); |
| 888 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | 890 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( |
| 889 ContentSettingsPattern::FromURLNoWildcard(origin), | 891 ContentSettingsPattern::FromURLNoWildcard(origin), |
| 890 ContentSettingsPattern::Wildcard(), | 892 ContentSettingsPattern::Wildcard(), |
| 891 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 893 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 892 std::string(), | 894 std::string(), |
| 893 CONTENT_SETTING_DEFAULT); | 895 CONTENT_SETTING_DEFAULT); |
| 894 | 896 |
| 897 message_loop_runner->Run(); |
| 898 |
| 895 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | 899 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); |
| 896 EXPECT_EQ("permission status - default", script_result); | 900 EXPECT_EQ("permission status - default", script_result); |
| 897 | 901 |
| 898 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | 902 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); |
| 899 EXPECT_EQ("false - not registered", script_result); | 903 EXPECT_EQ("false - not registered", script_result); |
| 900 } | 904 } |
| 901 | 905 |
| 902 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 906 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 903 DenyNotificationsPermissionUnregisters) { | 907 DenyNotificationsPermissionUnregisters) { |
| 904 std::string script_result; | 908 std::string script_result; |
| 905 | 909 |
| 906 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 910 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| 907 | 911 |
| 908 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | 912 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); |
| 909 EXPECT_EQ("true - registered", script_result); | 913 EXPECT_EQ("true - registered", script_result); |
| 910 | 914 |
| 911 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | 915 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); |
| 912 EXPECT_EQ("permission status - granted", script_result); | 916 EXPECT_EQ("permission status - granted", script_result); |
| 913 | 917 |
| 918 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 919 new content::MessageLoopRunner; |
| 920 push_service()->SetContentSettingChangedCallbackForTesting( |
| 921 message_loop_runner->QuitClosure()); |
| 922 |
| 914 GURL origin = https_server()->GetURL(std::string()).GetOrigin(); | 923 GURL origin = https_server()->GetURL(std::string()).GetOrigin(); |
| 915 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | 924 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( |
| 916 ContentSettingsPattern::FromURLNoWildcard(origin), | 925 ContentSettingsPattern::FromURLNoWildcard(origin), |
| 917 ContentSettingsPattern::Wildcard(), | 926 ContentSettingsPattern::Wildcard(), |
| 918 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 927 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 919 std::string(), | 928 std::string(), |
| 920 CONTENT_SETTING_BLOCK); | 929 CONTENT_SETTING_BLOCK); |
| 921 | 930 |
| 931 message_loop_runner->Run(); |
| 932 |
| 922 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | 933 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); |
| 923 EXPECT_EQ("permission status - denied", script_result); | 934 EXPECT_EQ("permission status - denied", script_result); |
| 924 | 935 |
| 925 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | 936 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); |
| 926 EXPECT_EQ("false - not registered", script_result); | 937 EXPECT_EQ("false - not registered", script_result); |
| 927 } | 938 } |
| 928 | 939 |
| 929 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 940 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 930 GrantAlreadyGrantedPermissionDoesNotUnregister) { | 941 GrantAlreadyGrantedPermissionDoesNotUnregister) { |
| 931 std::string script_result; | 942 std::string script_result; |
| 932 | 943 |
| 933 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 944 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| 934 | 945 |
| 935 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | 946 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); |
| 936 EXPECT_EQ("true - registered", script_result); | 947 EXPECT_EQ("true - registered", script_result); |
| 937 | 948 |
| 938 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | 949 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); |
| 939 EXPECT_EQ("permission status - granted", script_result); | 950 EXPECT_EQ("permission status - granted", script_result); |
| 940 | 951 |
| 952 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 953 new content::MessageLoopRunner; |
| 954 push_service()->SetContentSettingChangedCallbackForTesting( |
| 955 base::BarrierClosure(2, message_loop_runner->QuitClosure())); |
| 956 |
| 941 GURL origin = https_server()->GetURL(std::string()).GetOrigin(); | 957 GURL origin = https_server()->GetURL(std::string()).GetOrigin(); |
| 942 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | 958 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( |
| 943 ContentSettingsPattern::FromURLNoWildcard(origin), | 959 ContentSettingsPattern::FromURLNoWildcard(origin), |
| 944 ContentSettingsPattern::Wildcard(), | 960 ContentSettingsPattern::Wildcard(), |
| 945 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 961 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 946 std::string(), | 962 std::string(), |
| 947 CONTENT_SETTING_ALLOW); | 963 CONTENT_SETTING_ALLOW); |
| 948 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | 964 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( |
| 949 ContentSettingsPattern::FromURLNoWildcard(origin), | 965 ContentSettingsPattern::FromURLNoWildcard(origin), |
| 950 ContentSettingsPattern::FromURLNoWildcard(origin), | 966 ContentSettingsPattern::FromURLNoWildcard(origin), |
| 951 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | 967 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 952 std::string(), | 968 std::string(), |
| 953 CONTENT_SETTING_ALLOW); | 969 CONTENT_SETTING_ALLOW); |
| 954 | 970 |
| 971 message_loop_runner->Run(); |
| 972 |
| 955 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | 973 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); |
| 956 EXPECT_EQ("permission status - granted", script_result); | 974 EXPECT_EQ("permission status - granted", script_result); |
| 957 | 975 |
| 958 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | 976 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); |
| 959 EXPECT_EQ("true - registered", script_result); | 977 EXPECT_EQ("true - registered", script_result); |
| 960 } | 978 } |
| 961 | 979 |
| 962 // This test is testing some non-trivial content settings rules and make sure | 980 // 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 | 981 // 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 | 982 // words, it checks that the push service does not end up unregistering origins |
| 965 // that have push permission with some non-common rules. | 983 // that have push permission with some non-common rules. |
| 966 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 984 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 967 AutomaticUnregistrationFollowsContentSettingRules) { | 985 AutomaticUnregistrationFollowsContentSettingRules) { |
| 968 std::string script_result; | 986 std::string script_result; |
| 969 | 987 |
| 970 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 988 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| 971 | 989 |
| 972 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | 990 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); |
| 973 EXPECT_EQ("true - registered", script_result); | 991 EXPECT_EQ("true - registered", script_result); |
| 974 | 992 |
| 975 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | 993 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); |
| 976 EXPECT_EQ("permission status - granted", script_result); | 994 EXPECT_EQ("permission status - granted", script_result); |
| 977 | 995 |
| 996 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 997 new content::MessageLoopRunner; |
| 998 push_service()->SetContentSettingChangedCallbackForTesting( |
| 999 base::BarrierClosure(4, message_loop_runner->QuitClosure())); |
| 1000 |
| 978 GURL origin = https_server()->GetURL(std::string()).GetOrigin(); | 1001 GURL origin = https_server()->GetURL(std::string()).GetOrigin(); |
| 979 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | 1002 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( |
| 980 ContentSettingsPattern::Wildcard(), | 1003 ContentSettingsPattern::Wildcard(), |
| 981 ContentSettingsPattern::Wildcard(), | 1004 ContentSettingsPattern::Wildcard(), |
| 982 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 1005 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 983 std::string(), | 1006 std::string(), |
| 984 CONTENT_SETTING_ALLOW); | 1007 CONTENT_SETTING_ALLOW); |
| 985 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | 1008 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( |
| 986 ContentSettingsPattern::FromString("https://*"), | 1009 ContentSettingsPattern::FromString("https://*"), |
| 987 ContentSettingsPattern::FromString("https://*"), | 1010 ContentSettingsPattern::FromString("https://*"), |
| 988 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | 1011 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 989 std::string(), | 1012 std::string(), |
| 990 CONTENT_SETTING_ALLOW); | 1013 CONTENT_SETTING_ALLOW); |
| 991 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | 1014 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( |
| 992 ContentSettingsPattern::FromURLNoWildcard(origin), | 1015 ContentSettingsPattern::FromURLNoWildcard(origin), |
| 993 ContentSettingsPattern::Wildcard(), | 1016 ContentSettingsPattern::Wildcard(), |
| 994 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 1017 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 995 std::string(), | 1018 std::string(), |
| 996 CONTENT_SETTING_DEFAULT); | 1019 CONTENT_SETTING_DEFAULT); |
| 997 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | 1020 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( |
| 998 ContentSettingsPattern::FromURLNoWildcard(origin), | 1021 ContentSettingsPattern::FromURLNoWildcard(origin), |
| 999 ContentSettingsPattern::FromURLNoWildcard(origin), | 1022 ContentSettingsPattern::FromURLNoWildcard(origin), |
| 1000 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | 1023 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 1001 std::string(), | 1024 std::string(), |
| 1002 CONTENT_SETTING_DEFAULT); | 1025 CONTENT_SETTING_DEFAULT); |
| 1003 | 1026 |
| 1027 message_loop_runner->Run(); |
| 1028 |
| 1004 // The two first rules should give |origin| the permission to use Push even | 1029 // The two first rules should give |origin| the permission to use Push even |
| 1005 // if the rules it used to have have been reset. | 1030 // if the rules it used to have have been reset. |
| 1006 // The Push service should not unsubcribe |origin| because at no point it was | 1031 // The Push service should not unsubcribe |origin| because at no point it was |
| 1007 // left without permission to use Push. | 1032 // left without permission to use Push. |
| 1008 | 1033 |
| 1009 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | 1034 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); |
| 1010 EXPECT_EQ("permission status - granted", script_result); | 1035 EXPECT_EQ("permission status - granted", script_result); |
| 1011 | 1036 |
| 1012 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); | 1037 ASSERT_TRUE(RunScript("hasRegistration()", &script_result)); |
| 1013 EXPECT_EQ("true - registered", script_result); | 1038 EXPECT_EQ("true - registered", script_result); |
| 1014 } | 1039 } |
| OLD | NEW |