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

Unified Diff: chrome/browser/permissions/permission_context_base_unittest.cc

Issue 2640033006: Convert AutoBlocker static class to KeyedService. (Closed)
Patch Set: Remove ShouldChangeDismissalToBlock Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
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..5b734df1371956d3810ff33842fe8ae25759c8d7 100644
--- a/chrome/browser/permissions/permission_context_base_unittest.cc
+++ b/chrome/browser/permissions/permission_context_base_unittest.cc
@@ -167,8 +167,10 @@ 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.
dominickn 2017/01/20 04:03:47 Nit: comment indentation
meredithl 2017/01/20 04:21:33 Done.
+ // 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 +637,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) {
+ 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 +834,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 +844,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);
}

Powered by Google App Engine
This is Rietveld 408576698