| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" | 5 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 | 275 |
| 276 pm->UpdateCache(prefixes_requested, fhis, negative_cache_expire); | 276 pm->UpdateCache(prefixes_requested, fhis, negative_cache_expire); |
| 277 | 277 |
| 278 // Verify the state of the cache. | 278 // Verify the state of the cache. |
| 279 const FullHashCache* cache = pm->full_hash_cache_for_tests(); | 279 const FullHashCache* cache = pm->full_hash_cache_for_tests(); |
| 280 // Check the cache. | 280 // Check the cache. |
| 281 EXPECT_EQ(0u, cache->size()); | 281 EXPECT_EQ(0u, cache->size()); |
| 282 } | 282 } |
| 283 | 283 |
| 284 TEST_F(V4GetHashProtocolManagerTest, TestGetHashRequest) { | 284 TEST_F(V4GetHashProtocolManagerTest, TestGetHashRequest) { |
| 285 HashPrefix one = "hashone"; | |
| 286 HashPrefix two = "hashtwo"; | |
| 287 std::vector<HashPrefix> prefixes_to_request = {one, two}; | |
| 288 | |
| 289 FindFullHashesRequest req; | 285 FindFullHashesRequest req; |
| 290 ThreatInfo* info = req.mutable_threat_info(); | 286 ThreatInfo* info = req.mutable_threat_info(); |
| 291 info->add_threat_types(MALWARE_THREAT); | |
| 292 info->add_threat_types(API_ABUSE); | |
| 293 | |
| 294 info->add_platform_types(GetCurrentPlatformType()); | 287 info->add_platform_types(GetCurrentPlatformType()); |
| 295 info->add_platform_types(CHROME_PLATFORM); | 288 info->add_platform_types(CHROME_PLATFORM); |
| 296 | 289 |
| 297 info->add_threat_entry_types(URL); | 290 info->add_threat_entry_types(URL); |
| 298 | 291 |
| 292 info->add_threat_types(MALWARE_THREAT); |
| 293 info->add_threat_types(API_ABUSE); |
| 294 |
| 295 HashPrefix one = "hashone"; |
| 296 HashPrefix two = "hashtwo"; |
| 299 info->add_threat_entries()->set_hash(one); | 297 info->add_threat_entries()->set_hash(one); |
| 300 info->add_threat_entries()->set_hash(two); | 298 info->add_threat_entries()->set_hash(two); |
| 301 | 299 |
| 300 std::unique_ptr<V4GetHashProtocolManager> pm(CreateProtocolManager()); |
| 301 req.mutable_client()->set_client_id(pm->config_.client_name); |
| 302 req.mutable_client()->set_client_version(pm->config_.version); |
| 303 |
| 302 // Serialize and Base64 encode. | 304 // Serialize and Base64 encode. |
| 303 std::string req_data, req_base64; | 305 std::string req_data, req_base64; |
| 304 req.SerializeToString(&req_data); | 306 req.SerializeToString(&req_data); |
| 305 base::Base64Encode(req_data, &req_base64); | 307 base::Base64Encode(req_data, &req_base64); |
| 306 | 308 |
| 307 std::unique_ptr<V4GetHashProtocolManager> pm(CreateProtocolManager()); | 309 std::vector<HashPrefix> prefixes_to_request = {one, two}; |
| 308 EXPECT_EQ(req_base64, pm->GetHashRequest(prefixes_to_request)); | 310 EXPECT_EQ(req_base64, pm->GetHashRequest(prefixes_to_request)); |
| 309 } | 311 } |
| 310 | 312 |
| 311 TEST_F(V4GetHashProtocolManagerTest, TestParseHashResponse) { | 313 TEST_F(V4GetHashProtocolManagerTest, TestParseHashResponse) { |
| 312 std::unique_ptr<V4GetHashProtocolManager> pm(CreateProtocolManager()); | 314 std::unique_ptr<V4GetHashProtocolManager> pm(CreateProtocolManager()); |
| 313 | 315 |
| 314 base::Time now = base::Time::UnixEpoch(); | 316 base::Time now = base::Time::UnixEpoch(); |
| 315 SetTestClock(now, pm.get()); | 317 SetTestClock(now, pm.get()); |
| 316 | 318 |
| 317 FullHash full_hash("Everything's shiny, Cap'n."); | 319 FullHash full_hash("Everything's shiny, Cap'n."); |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 full_hash = FullHash("Everything's shiny, Cap'n."); | 725 full_hash = FullHash("Everything's shiny, Cap'n."); |
| 724 info = ResponseInfo(full_hash, GetChromeUrlApiId()); | 726 info = ResponseInfo(full_hash, GetChromeUrlApiId()); |
| 725 info.key_values.emplace_back("permission", "GEOLOCATION"); | 727 info.key_values.emplace_back("permission", "GEOLOCATION"); |
| 726 infos.push_back(info); | 728 infos.push_back(info); |
| 727 SetupFetcherToReturnOKResponse(factory, infos); | 729 SetupFetcherToReturnOKResponse(factory, infos); |
| 728 | 730 |
| 729 EXPECT_TRUE(callback_called()); | 731 EXPECT_TRUE(callback_called()); |
| 730 } | 732 } |
| 731 | 733 |
| 732 } // namespace safe_browsing | 734 } // namespace safe_browsing |
| OLD | NEW |