Chromium Code Reviews| Index: chrome/browser/permissions/permission_context_base_unittest.cc |
| diff --git a/chrome/browser/permissions/permission_context_base_unittest.cc b/chrome/browser/permissions/permission_context_base_unittest.cc |
| index e73f6c259bf3a18674bad6935dfdd2be91433843..9d06088c977f1626c4b1dff125b61add37b80ea5 100644 |
| --- a/chrome/browser/permissions/permission_context_base_unittest.cc |
| +++ b/chrome/browser/permissions/permission_context_base_unittest.cc |
| @@ -167,8 +167,9 @@ class TestPermissionContext : public PermissionContextBase { |
| } |
| } |
| - // Permission request will need to be responded to, so pass a callback to be |
| - // run once the request has completed and the decision has been made. |
| + // Set the callback to run if the permission is being responded to in the |
| + // test. This is left empty where no response is needed, such as in parallel |
| + // requests, permissions blacklisting, invalid origin, and killswitch. |
| void SetRespondPermissionCallback(base::Closure callback) { |
| respond_permission_ = callback; |
| } |
| @@ -635,23 +636,31 @@ class PermissionContextBaseTests : public ChromeRenderViewHostTestHarness { |
| scoped_feature_list.InitAndEnableFeature(features::kPermissionsBlacklist); |
| TestPermissionContext permission_context(profile(), permission_type, |
| content_settings_type); |
| - permission_context.SetSafeBrowsingDatabaseManagerAndTimeoutForTest( |
| - db_manager, timeout); |
| + PermissionDecisionAutoBlocker::GetForProfile(profile()) |
| + ->SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, |
| + timeout); |
| const PermissionRequestID id( |
| web_contents()->GetRenderProcessHost()->GetID(), |
| web_contents()->GetMainFrame()->GetRoutingID(), -1); |
| // The response callback needs to be set here to test a response being made |
| // in the case of a site not being blacklisted or a safe browsing timeout. |
| - permission_context.SetRespondPermissionCallback(base::Bind( |
| - &PermissionContextBaseTests::RespondToPermission, |
| - base::Unretained(this), &permission_context, id, url, false, response)); |
| + 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.
|
| + permission_context.SetRespondPermissionCallback( |
| + base::Bind(&PermissionContextBaseTests::RespondToPermission, |
| + base::Unretained(this), &permission_context, id, url, |
| + true /* persist */, response)); |
| + } |
| + |
| permission_context.RequestPermission( |
| web_contents(), id, url, true /* user_gesture */, |
| base::Bind(&TestPermissionContext::TrackPermissionDecision, |
| base::Unretained(&permission_context))); |
| + EXPECT_EQ(response, permission_context.GetPermissionStatus(url, url)); |
| - ASSERT_EQ(1u, permission_context.decisions().size()); |
| - EXPECT_EQ(response, permission_context.decisions()[0]); |
| + if (response == CONTENT_SETTING_ALLOW) { |
| + ASSERT_EQ(1u, permission_context.decisions().size()); |
| + EXPECT_EQ(response, permission_context.decisions()[0]); |
| + } |
| } |
| private: |
| @@ -824,8 +833,8 @@ TEST_F(PermissionContextBaseTests, TestPermissionsBlacklistingBlocked) { |
| url, 2000 /* timeout */, CONTENT_SETTING_BLOCK); |
| } |
| -// Tests that a URL with a blacklisted permission is permitted to request a |
| -// non-blacklisted permission. |
| +// Tests that a URL that is blacklisted for one permission can still request |
| +// another and grant another. |
| TEST_F(PermissionContextBaseTests, TestPermissionsBlacklistingAllowed) { |
| scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = |
| new MockSafeBrowsingDatabaseManager(true /* perform_callback */); |
| @@ -834,26 +843,7 @@ TEST_F(PermissionContextBaseTests, TestPermissionsBlacklistingAllowed) { |
| PermissionUtil::GetPermissionString( |
| content::PermissionType::GEOLOCATION)}; |
| db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); |
| - TestPermissionsBlacklisting( |
| - content::PermissionType::GEOLOCATION, CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| - db_manager, url, 2000 /* timeout in ms */, CONTENT_SETTING_BLOCK); |
| TestPermissionsBlacklisting(content::PermissionType::NOTIFICATIONS, |
| CONTENT_SETTINGS_TYPE_NOTIFICATIONS, db_manager, |
| - url, 2000 /* timeout in ms */, |
| - CONTENT_SETTING_ALLOW); |
| -} |
| - |
| -// Tests that a URL with a blacklisted permisison is permitted to request that |
| -// permission if Safe Browsing has timed out. |
| -TEST_F(PermissionContextBaseTests, TestSafeBrowsingTimeout) { |
| - scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = |
| - new MockSafeBrowsingDatabaseManager(false /* perform_callback */); |
| - const GURL url("https://www.example.com"); |
| - std::set<std::string> blacklisted_permissions{ |
| - PermissionUtil::GetPermissionString( |
| - content::PermissionType::GEOLOCATION)}; |
| - db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); |
| - TestPermissionsBlacklisting(content::PermissionType::GEOLOCATION, |
| - CONTENT_SETTINGS_TYPE_GEOLOCATION, db_manager, |
| - url, 0 /* timeout in ms */, CONTENT_SETTING_ASK); |
| + url, 2000 /* timeout */, CONTENT_SETTING_ALLOW); |
| } |