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 "chrome/browser/permissions/permission_context_base.h" | 5 #include "chrome/browser/permissions/permission_context_base.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 respond_permission_.Run(); | 160 respond_permission_.Run(); |
161 respond_permission_.Reset(); | 161 respond_permission_.Reset(); |
162 } else { | 162 } else { |
163 // Stop the run loop from spinning indefinitely if no response callback | 163 // Stop the run loop from spinning indefinitely if no response callback |
164 // has been set, as is the case with TestParallelRequests. | 164 // has been set, as is the case with TestParallelRequests. |
165 quit_closure_.Run(); | 165 quit_closure_.Run(); |
166 quit_closure_.Reset(); | 166 quit_closure_.Reset(); |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
170 // Permission request will need to be responded to, so pass a callback to be | 170 // Set the callback to run if the permission is being responded to in the |
171 // run once the request has completed and the decision has been made. | 171 // test. This is left empty where no response is needed, such as in parallel |
172 // requests, permissions blacklisting, invalid origin, and killswitch. | |
172 void SetRespondPermissionCallback(base::Closure callback) { | 173 void SetRespondPermissionCallback(base::Closure callback) { |
173 respond_permission_ = callback; | 174 respond_permission_ = callback; |
174 } | 175 } |
175 | 176 |
176 protected: | 177 protected: |
177 void UpdateTabContext(const PermissionRequestID& id, | 178 void UpdateTabContext(const PermissionRequestID& id, |
178 const GURL& requesting_origin, | 179 const GURL& requesting_origin, |
179 bool allowed) override { | 180 bool allowed) override { |
180 tab_context_updated_ = true; | 181 tab_context_updated_ = true; |
181 } | 182 } |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
628 ContentSettingsType content_settings_type, | 629 ContentSettingsType content_settings_type, |
629 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, | 630 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, |
630 const GURL& url, | 631 const GURL& url, |
631 int timeout, | 632 int timeout, |
632 ContentSetting response) { | 633 ContentSetting response) { |
633 NavigateAndCommit(url); | 634 NavigateAndCommit(url); |
634 base::test::ScopedFeatureList scoped_feature_list; | 635 base::test::ScopedFeatureList scoped_feature_list; |
635 scoped_feature_list.InitAndEnableFeature(features::kPermissionsBlacklist); | 636 scoped_feature_list.InitAndEnableFeature(features::kPermissionsBlacklist); |
636 TestPermissionContext permission_context(profile(), permission_type, | 637 TestPermissionContext permission_context(profile(), permission_type, |
637 content_settings_type); | 638 content_settings_type); |
638 permission_context.SetSafeBrowsingDatabaseManagerAndTimeoutForTest( | 639 PermissionDecisionAutoBlocker::GetForProfile(profile()) |
639 db_manager, timeout); | 640 ->SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, |
641 timeout); | |
640 const PermissionRequestID id( | 642 const PermissionRequestID id( |
641 web_contents()->GetRenderProcessHost()->GetID(), | 643 web_contents()->GetRenderProcessHost()->GetID(), |
642 web_contents()->GetMainFrame()->GetRoutingID(), -1); | 644 web_contents()->GetMainFrame()->GetRoutingID(), -1); |
643 // The response callback needs to be set here to test a response being made | 645 // The response callback needs to be set here to test a response being made |
644 // in the case of a site not being blacklisted or a safe browsing timeout. | 646 // in the case of a site not being blacklisted or a safe browsing timeout. |
645 permission_context.SetRespondPermissionCallback(base::Bind( | 647 if (response == CONTENT_SETTING_ALLOW) { |
raymes
2017/01/23 06:14:23
How come this changed?
meredithl
2017/01/24 01:20:46
Because when the permission isn't embargoed and au
raymes
2017/01/24 03:31:08
I see. I think the confusing thing here is what |r
meredithl
2017/01/24 04:52:25
Done.
| |
646 &PermissionContextBaseTests::RespondToPermission, | 648 permission_context.SetRespondPermissionCallback( |
647 base::Unretained(this), &permission_context, id, url, false, response)); | 649 base::Bind(&PermissionContextBaseTests::RespondToPermission, |
650 base::Unretained(this), &permission_context, id, url, | |
651 true /* persist */, response)); | |
652 } | |
653 | |
648 permission_context.RequestPermission( | 654 permission_context.RequestPermission( |
649 web_contents(), id, url, true /* user_gesture */, | 655 web_contents(), id, url, true /* user_gesture */, |
650 base::Bind(&TestPermissionContext::TrackPermissionDecision, | 656 base::Bind(&TestPermissionContext::TrackPermissionDecision, |
651 base::Unretained(&permission_context))); | 657 base::Unretained(&permission_context))); |
658 EXPECT_EQ(response, permission_context.GetPermissionStatus(url, url)); | |
652 | 659 |
653 ASSERT_EQ(1u, permission_context.decisions().size()); | 660 if (response == CONTENT_SETTING_ALLOW) { |
654 EXPECT_EQ(response, permission_context.decisions()[0]); | 661 ASSERT_EQ(1u, permission_context.decisions().size()); |
662 EXPECT_EQ(response, permission_context.decisions()[0]); | |
663 } | |
655 } | 664 } |
656 | 665 |
657 private: | 666 private: |
658 // ChromeRenderViewHostTestHarness: | 667 // ChromeRenderViewHostTestHarness: |
659 void SetUp() override { | 668 void SetUp() override { |
660 ChromeRenderViewHostTestHarness::SetUp(); | 669 ChromeRenderViewHostTestHarness::SetUp(); |
661 #if defined(OS_ANDROID) | 670 #if defined(OS_ANDROID) |
662 InfoBarService::CreateForWebContents(web_contents()); | 671 InfoBarService::CreateForWebContents(web_contents()); |
663 #else | 672 #else |
664 PermissionRequestManager::CreateForWebContents(web_contents()); | 673 PermissionRequestManager::CreateForWebContents(web_contents()); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
817 const GURL url("https://www.example.com"); | 826 const GURL url("https://www.example.com"); |
818 std::set<std::string> blacklisted_permissions{ | 827 std::set<std::string> blacklisted_permissions{ |
819 PermissionUtil::GetPermissionString( | 828 PermissionUtil::GetPermissionString( |
820 content::PermissionType::GEOLOCATION)}; | 829 content::PermissionType::GEOLOCATION)}; |
821 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); | 830 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); |
822 TestPermissionsBlacklisting(content::PermissionType::GEOLOCATION, | 831 TestPermissionsBlacklisting(content::PermissionType::GEOLOCATION, |
823 CONTENT_SETTINGS_TYPE_GEOLOCATION, db_manager, | 832 CONTENT_SETTINGS_TYPE_GEOLOCATION, db_manager, |
824 url, 2000 /* timeout */, CONTENT_SETTING_BLOCK); | 833 url, 2000 /* timeout */, CONTENT_SETTING_BLOCK); |
825 } | 834 } |
826 | 835 |
827 // Tests that a URL with a blacklisted permission is permitted to request a | 836 // Tests that a URL that is blacklisted for one permission can still request |
828 // non-blacklisted permission. | 837 // another and grant another. |
829 TEST_F(PermissionContextBaseTests, TestPermissionsBlacklistingAllowed) { | 838 TEST_F(PermissionContextBaseTests, TestPermissionsBlacklistingAllowed) { |
830 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = | 839 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = |
831 new MockSafeBrowsingDatabaseManager(true /* perform_callback */); | 840 new MockSafeBrowsingDatabaseManager(true /* perform_callback */); |
832 const GURL url("https://www.example.com"); | 841 const GURL url("https://www.example.com"); |
833 std::set<std::string> blacklisted_permissions{ | 842 std::set<std::string> blacklisted_permissions{ |
834 PermissionUtil::GetPermissionString( | 843 PermissionUtil::GetPermissionString( |
835 content::PermissionType::GEOLOCATION)}; | 844 content::PermissionType::GEOLOCATION)}; |
836 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); | 845 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); |
837 TestPermissionsBlacklisting( | |
838 content::PermissionType::GEOLOCATION, CONTENT_SETTINGS_TYPE_GEOLOCATION, | |
839 db_manager, url, 2000 /* timeout in ms */, CONTENT_SETTING_BLOCK); | |
840 TestPermissionsBlacklisting(content::PermissionType::NOTIFICATIONS, | 846 TestPermissionsBlacklisting(content::PermissionType::NOTIFICATIONS, |
841 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, db_manager, | 847 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, db_manager, |
842 url, 2000 /* timeout in ms */, | 848 url, 2000 /* timeout */, CONTENT_SETTING_ALLOW); |
843 CONTENT_SETTING_ALLOW); | |
844 } | 849 } |
845 | |
846 // Tests that a URL with a blacklisted permisison is permitted to request that | |
847 // permission if Safe Browsing has timed out. | |
848 TEST_F(PermissionContextBaseTests, TestSafeBrowsingTimeout) { | |
849 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = | |
850 new MockSafeBrowsingDatabaseManager(false /* perform_callback */); | |
851 const GURL url("https://www.example.com"); | |
852 std::set<std::string> blacklisted_permissions{ | |
853 PermissionUtil::GetPermissionString( | |
854 content::PermissionType::GEOLOCATION)}; | |
855 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); | |
856 TestPermissionsBlacklisting(content::PermissionType::GEOLOCATION, | |
857 CONTENT_SETTINGS_TYPE_GEOLOCATION, db_manager, | |
858 url, 0 /* timeout in ms */, CONTENT_SETTING_ASK); | |
859 } | |
OLD | NEW |