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

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

Issue 2684523002: Check result of ApiBlacklist query in client. (Closed)
Patch Set: Fix mock collision, add test for disabled database. 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..1610684c92ae6570f69a6521c5f2e32f3daa4a17 100644
--- a/chrome/browser/permissions/permission_decision_auto_blocker_unittest.cc
+++ b/chrome/browser/permissions/permission_decision_auto_blocker_unittest.cc
@@ -7,6 +7,7 @@
#include <map>
#include "base/bind.h"
+#include "base/logging.h"
raymes 2017/02/08 01:42:06 nit: is this needed?
meredithl 2017/02/08 02:18:23 No! Forgot to remove it. Done.
#include "base/run_loop.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_clock.h"
@@ -29,17 +30,22 @@ 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 +76,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:
@@ -256,7 +265,8 @@ 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,
@@ -379,7 +389,8 @@ 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,
@@ -473,3 +484,18 @@ 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_FALSE(last_embargoed_status());
kcarattini 2017/02/08 02:07:28 Can you also check that the callback was run. Othe
meredithl 2017/02/08 02:18:23 Done.
+}
« 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