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

Unified Diff: components/safe_browsing_db/database_manager_unittest.cc

Issue 1881353002: SafeBrowsing: Adds response handler for API blacklist check in Database Manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@osb-impl-1
Patch Set: Review Comments Created 4 years, 8 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 | « components/safe_browsing_db/database_manager.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/safe_browsing_db/database_manager_unittest.cc
diff --git a/components/safe_browsing_db/database_manager_unittest.cc b/components/safe_browsing_db/database_manager_unittest.cc
index 04490d985a1159d92acb19a364d749f1f862c9b2..c914a08e3beb4c7d74d6dc387cfdf938639af6ba 100644
--- a/components/safe_browsing_db/database_manager_unittest.cc
+++ b/components/safe_browsing_db/database_manager_unittest.cc
@@ -80,9 +80,16 @@ class TestClient : public SafeBrowsingDatabaseManager::Client {
~TestClient() override {}
void OnCheckApiBlacklistUrlResult(const GURL& url,
- const ThreatMetadata& metadata) override {}
+ const ThreatMetadata& metadata) override {
+ blocked_permissions_ = metadata.api_permissions;
+ }
+
+ const std::vector<std::string>& GetBlockedPermissions() {
+ return blocked_permissions_;
+ }
private:
+ std::vector<std::string> blocked_permissions_;
DISALLOW_COPY_AND_ASSIGN(TestClient);
};
@@ -131,4 +138,66 @@ TEST_F(SafeBrowsingDatabaseManagerTest, CheckApiBlacklistUrlPrefixes) {
}
}
+TEST_F(SafeBrowsingDatabaseManagerTest, HandleGetHashesWithApisResults) {
+ TestClient client;
+ const GURL url("https://www.example.com/more");
+ TestV4GetHashProtocolManager* pm = static_cast<TestV4GetHashProtocolManager*>(
+ db_manager_->v4_get_hash_protocol_manager_);
+ SBFullHashResult full_hash_result;
+ full_hash_result.hash = SBFullHashForString("example.com/");
+ full_hash_result.metadata.api_permissions.push_back("GEOLOCATION");
+ pm->AddGetFullHashResponse(full_hash_result);
+
+ EXPECT_FALSE(db_manager_->CheckApiBlacklistUrl(url, &client));
+ base::RunLoop().RunUntilIdle();
+
+ const std::vector<std::string>& permissions = client.GetBlockedPermissions();
+ EXPECT_EQ(1ul, permissions.size());
+ EXPECT_EQ("GEOLOCATION", permissions[0]);
+}
+
+TEST_F(SafeBrowsingDatabaseManagerTest, HandleGetHashesWithApisResultsNoMatch) {
+ TestClient client;
+ const GURL url("https://www.example.com/more");
+ TestV4GetHashProtocolManager* pm = static_cast<TestV4GetHashProtocolManager*>(
+ db_manager_->v4_get_hash_protocol_manager_);
+ SBFullHashResult full_hash_result;
+ full_hash_result.hash = SBFullHashForString("wrongexample.com/");
+ full_hash_result.metadata.api_permissions.push_back("GEOLOCATION");
+ pm->AddGetFullHashResponse(full_hash_result);
+
+ EXPECT_FALSE(db_manager_->CheckApiBlacklistUrl(url, &client));
+ base::RunLoop().RunUntilIdle();
+
+ const std::vector<std::string>& permissions = client.GetBlockedPermissions();
+ EXPECT_EQ(0ul, permissions.size());
+}
+
+TEST_F(SafeBrowsingDatabaseManagerTest, HandleGetHashesWithApisResultsMatches) {
+ TestClient client;
+ const GURL url("https://www.example.com/more");
+ TestV4GetHashProtocolManager* pm = static_cast<TestV4GetHashProtocolManager*>(
+ db_manager_->v4_get_hash_protocol_manager_);
+ SBFullHashResult full_hash_result;
+ full_hash_result.hash = SBFullHashForString("example.com/");
+ full_hash_result.metadata.api_permissions.push_back("GEOLOCATION");
+ pm->AddGetFullHashResponse(full_hash_result);
+ SBFullHashResult full_hash_result2;
+ full_hash_result2.hash = SBFullHashForString("example.com/more");
+ full_hash_result2.metadata.api_permissions.push_back("NOTIFICATIONS");
+ pm->AddGetFullHashResponse(full_hash_result2);
+ SBFullHashResult full_hash_result3;
+ full_hash_result3.hash = SBFullHashForString("wrongexample.com/");
+ full_hash_result3.metadata.api_permissions.push_back("AUDIO_CAPTURE");
+ pm->AddGetFullHashResponse(full_hash_result3);
+
+ EXPECT_FALSE(db_manager_->CheckApiBlacklistUrl(url, &client));
+ base::RunLoop().RunUntilIdle();
+
+ const std::vector<std::string>& permissions = client.GetBlockedPermissions();
+ EXPECT_EQ(2ul, permissions.size());
+ EXPECT_EQ("GEOLOCATION", permissions[0]);
+ EXPECT_EQ("NOTIFICATIONS", permissions[1]);
+}
+
} // namespace safe_browsing
« no previous file with comments | « components/safe_browsing_db/database_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698