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

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

Issue 2684523002: Check result of ApiBlacklist query in client. (Closed)
Patch Set: Check callback. Created 3 years, 10 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
« no previous file with comments | « chrome/browser/permissions/permission_decision_auto_blocker.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/permissions/permission_decision_auto_blocker_unittest.cc
diff --git a/chrome/browser/permissions/permission_decision_auto_blocker_unittest.cc b/chrome/browser/permissions/permission_decision_auto_blocker_unittest.cc
index e1ddba59ba1235f5fb21aaeaf13f7feb2ea5a214..04b412c312322369509e8e1df5b85c8b52bd7e98 100644
--- a/chrome/browser/permissions/permission_decision_auto_blocker_unittest.cc
+++ b/chrome/browser/permissions/permission_decision_auto_blocker_unittest.cc
@@ -29,17 +29,20 @@ bool FilterAll(const GURL& url) {
return true;
}
-} // namespace
-
class MockSafeBrowsingDatabaseManager
: public safe_browsing::TestSafeBrowsingDatabaseManager {
public:
- explicit MockSafeBrowsingDatabaseManager(bool perform_callback)
- : perform_callback_(perform_callback) {}
+ explicit MockSafeBrowsingDatabaseManager(bool perform_callback, bool enabled)
+ : perform_callback_(perform_callback), enabled_(enabled) {}
bool CheckApiBlacklistUrl(
const GURL& url,
safe_browsing::SafeBrowsingDatabaseManager::Client* client) override {
+ // Return true when able to synchronously determine that the url is safe.
+ if (!enabled_) {
+ return true;
+ }
+
if (perform_callback_) {
safe_browsing::ThreatMetadata metadata;
const auto& blacklisted_permissions = permissions_blacklist_.find(url);
@@ -70,11 +73,14 @@ class MockSafeBrowsingDatabaseManager
private:
bool perform_callback_;
+ bool enabled_;
std::map<GURL, std::set<std::string>> permissions_blacklist_;
DISALLOW_COPY_AND_ASSIGN(MockSafeBrowsingDatabaseManager);
};
+} // namespace
+
class PermissionDecisionAutoBlockerUnitTest
: public ChromeRenderViewHostTestHarness {
protected:
@@ -89,6 +95,7 @@ class PermissionDecisionAutoBlockerUnitTest
base::MakeUnique<base::SimpleTestClock>();
clock_ = clock.get();
autoblocker_->SetClockForTesting(std::move(clock));
+ callback_was_run_ = false;
}
void SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(
@@ -121,6 +128,7 @@ class PermissionDecisionAutoBlockerUnitTest
PermissionDecisionAutoBlocker* autoblocker() { return autoblocker_; }
void SetLastEmbargoStatus(base::Closure quit_closure, bool status) {
+ callback_was_run_ = true;
last_embargoed_status_ = status;
if (quit_closure) {
quit_closure.Run();
@@ -130,6 +138,8 @@ class PermissionDecisionAutoBlockerUnitTest
bool last_embargoed_status() { return last_embargoed_status_; }
+ bool callback_was_run() { return callback_was_run_; }
+
base::SimpleTestClock* clock() { return clock_; }
const char* GetDismissKey() {
@@ -145,6 +155,7 @@ class PermissionDecisionAutoBlockerUnitTest
base::test::ScopedFeatureList feature_list_;
base::SimpleTestClock* clock_;
bool last_embargoed_status_;
+ bool callback_was_run_;
};
TEST_F(PermissionDecisionAutoBlockerUnitTest, RemoveCountsByUrl) {
@@ -256,13 +267,15 @@ TEST_F(PermissionDecisionAutoBlockerUnitTest, TestUpdateEmbargoBlacklist) {
GURL url("https://www.google.com");
scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager =
- new MockSafeBrowsingDatabaseManager(true /* perform_callback */);
+ new MockSafeBrowsingDatabaseManager(true /* perform_callback */,
+ true /* enabled */);
std::set<std::string> blacklisted_permissions{"GEOLOCATION"};
db_manager->BlacklistUrlPermissions(url, blacklisted_permissions);
SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager,
2000 /* timeout in ms */);
UpdateEmbargoedStatus(content::PermissionType::GEOLOCATION, url);
+ EXPECT_TRUE(callback_was_run());
EXPECT_TRUE(last_embargoed_status());
}
@@ -379,13 +392,15 @@ TEST_F(PermissionDecisionAutoBlockerUnitTest, TestSafeBrowsingTimeout) {
clock()->SetNow(base::Time::Now());
scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager =
- new MockSafeBrowsingDatabaseManager(false /* perform_callback */);
+ new MockSafeBrowsingDatabaseManager(false /* perform_callback */,
+ true /* enabled */);
std::set<std::string> blacklisted_permissions{"GEOLOCATION"};
db_manager->BlacklistUrlPermissions(url, blacklisted_permissions);
SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager,
0 /* timeout in ms */);
UpdateEmbargoedStatus(content::PermissionType::GEOLOCATION, url);
+ EXPECT_TRUE(callback_was_run());
EXPECT_FALSE(last_embargoed_status());
EXPECT_FALSE(
autoblocker()->IsUnderEmbargo(content::PermissionType::GEOLOCATION, url));
@@ -395,6 +410,7 @@ TEST_F(PermissionDecisionAutoBlockerUnitTest, TestSafeBrowsingTimeout) {
clock()->Advance(base::TimeDelta::FromDays(1));
UpdateEmbargoedStatus(content::PermissionType::GEOLOCATION, url);
+ EXPECT_TRUE(callback_was_run());
EXPECT_TRUE(last_embargoed_status());
clock()->Advance(base::TimeDelta::FromDays(1));
@@ -473,3 +489,19 @@ TEST_F(PermissionDecisionAutoBlockerUnitTest,
EXPECT_EQ(50, autoblocker()->GetIgnoreCount(
url, content::PermissionType::GEOLOCATION));
}
+
+// Test that a blacklisted permission should not be autoblocked if the database
+// manager is disabled.
+TEST_F(PermissionDecisionAutoBlockerUnitTest, TestDisabledDatabaseManager) {
+ GURL url("https://www.google.com");
+ scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager =
+ new MockSafeBrowsingDatabaseManager(true /* perform_callback */,
+ false /* enabled */);
+ std::set<std::string> blacklisted_permissions{"GEOLOCATION"};
+ db_manager->BlacklistUrlPermissions(url, blacklisted_permissions);
+ SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager,
+ 2000 /* timeout in ms */);
+ UpdateEmbargoedStatus(content::PermissionType::GEOLOCATION, url);
+ EXPECT_TRUE(callback_was_run());
+ EXPECT_FALSE(last_embargoed_status());
+}
« no previous file with comments | « chrome/browser/permissions/permission_decision_auto_blocker.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698