Chromium Code Reviews| 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.
|
| +} |