| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This test creates a safebrowsing service using test safebrowsing database | 5 // This test creates a safebrowsing service using test safebrowsing database |
| 6 // and a test protocol manager. It is used to test logics in safebrowsing | 6 // and a test protocol manager. It is used to test logics in safebrowsing |
| 7 // service. | 7 // service. |
| 8 | 8 |
| 9 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 9 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 10 | 10 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 #include "components/safe_browsing_db/test_database_manager.h" | 58 #include "components/safe_browsing_db/test_database_manager.h" |
| 59 #include "components/safe_browsing_db/util.h" | 59 #include "components/safe_browsing_db/util.h" |
| 60 #include "components/safe_browsing_db/v4_database.h" | 60 #include "components/safe_browsing_db/v4_database.h" |
| 61 #include "components/safe_browsing_db/v4_feature_list.h" | 61 #include "components/safe_browsing_db/v4_feature_list.h" |
| 62 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" | 62 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" |
| 63 #include "components/safe_browsing_db/v4_protocol_manager_util.h" | 63 #include "components/safe_browsing_db/v4_protocol_manager_util.h" |
| 64 #include "content/public/browser/interstitial_page.h" | 64 #include "content/public/browser/interstitial_page.h" |
| 65 #include "content/public/browser/navigation_entry.h" | 65 #include "content/public/browser/navigation_entry.h" |
| 66 #include "content/public/browser/render_frame_host.h" | 66 #include "content/public/browser/render_frame_host.h" |
| 67 #include "content/public/browser/web_contents.h" | 67 #include "content/public/browser/web_contents.h" |
| 68 #include "content/public/common/content_switches.h" | 68 #include "content/public/common/content_features.h" |
| 69 #include "content/public/test/browser_test_utils.h" | 69 #include "content/public/test/browser_test_utils.h" |
| 70 #include "crypto/sha2.h" | 70 #include "crypto/sha2.h" |
| 71 #include "net/cookies/cookie_store.h" | 71 #include "net/cookies/cookie_store.h" |
| 72 #include "net/cookies/cookie_util.h" | 72 #include "net/cookies/cookie_util.h" |
| 73 #include "net/test/embedded_test_server/embedded_test_server.h" | 73 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 74 #include "net/test/embedded_test_server/http_request.h" | 74 #include "net/test/embedded_test_server/http_request.h" |
| 75 #include "net/test/embedded_test_server/http_response.h" | 75 #include "net/test/embedded_test_server/http_response.h" |
| 76 #include "sql/connection.h" | 76 #include "sql/connection.h" |
| 77 #include "sql/statement.h" | 77 #include "sql/statement.h" |
| 78 #include "testing/gmock/include/gmock/gmock.h" | 78 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1477 // Delete the Profile. SBS stops again. | 1477 // Delete the Profile. SBS stops again. |
| 1478 pref_service2 = nullptr; | 1478 pref_service2 = nullptr; |
| 1479 profile2.reset(); | 1479 profile2.reset(); |
| 1480 EXPECT_FALSE(sb_service->enabled_by_prefs()); | 1480 EXPECT_FALSE(sb_service->enabled_by_prefs()); |
| 1481 WaitForIOAndCheckEnabled(sb_service, false); | 1481 WaitForIOAndCheckEnabled(sb_service, false); |
| 1482 EXPECT_FALSE(csd_service->enabled()); | 1482 EXPECT_FALSE(csd_service->enabled()); |
| 1483 } | 1483 } |
| 1484 | 1484 |
| 1485 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, MalwareWebSocketBlocked) { | 1485 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, MalwareWebSocketBlocked) { |
| 1486 // This test currently only passes when the network service is enabled. | 1486 // This test currently only passes when the network service is enabled. |
| 1487 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 1487 if (!base::FeatureList::IsEnabled(features::kNetworkService)) |
| 1488 ::switches::kEnableNetworkService)) { | |
| 1489 return; | 1488 return; |
| 1490 } | |
| 1491 GURL main_url = embedded_test_server()->GetURL(kMalwareWebSocketPage); | 1489 GURL main_url = embedded_test_server()->GetURL(kMalwareWebSocketPage); |
| 1492 // This constructs the URL with the same logic as malware_websocket.html. | 1490 // This constructs the URL with the same logic as malware_websocket.html. |
| 1493 GURL resolved = main_url.Resolve("/safe_browsing/malware-ws"); | 1491 GURL resolved = main_url.Resolve("/safe_browsing/malware-ws"); |
| 1494 GURL::Replacements replace_scheme; | 1492 GURL::Replacements replace_scheme; |
| 1495 replace_scheme.SetScheme("ws", url::Component(0, strlen("ws"))); | 1493 replace_scheme.SetScheme("ws", url::Component(0, strlen("ws"))); |
| 1496 GURL websocket_url = resolved.ReplaceComponents(replace_scheme); | 1494 GURL websocket_url = resolved.ReplaceComponents(replace_scheme); |
| 1497 | 1495 |
| 1498 // Add the WebSocket url as malware. | 1496 // Add the WebSocket url as malware. |
| 1499 SBFullHashResult uws_full_hash; | 1497 SBFullHashResult uws_full_hash; |
| 1500 GenUrlFullHashResult(websocket_url, MALWARE, &uws_full_hash); | 1498 GenUrlFullHashResult(websocket_url, MALWARE, &uws_full_hash); |
| (...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2250 client->CheckBrowseUrl(bad_url); | 2248 client->CheckBrowseUrl(bad_url); |
| 2251 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, client->GetThreatType()); | 2249 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, client->GetThreatType()); |
| 2252 } | 2250 } |
| 2253 } | 2251 } |
| 2254 | 2252 |
| 2255 // This is almost identical to | 2253 // This is almost identical to |
| 2256 // SafeBrowsingServiceTest.MalwareWebSocketBlocked. That test will be deleted | 2254 // SafeBrowsingServiceTest.MalwareWebSocketBlocked. That test will be deleted |
| 2257 // when the old database backend stops being used. | 2255 // when the old database backend stops being used. |
| 2258 IN_PROC_BROWSER_TEST_F(V4SafeBrowsingServiceTest, MalwareWebSocketBlocked) { | 2256 IN_PROC_BROWSER_TEST_F(V4SafeBrowsingServiceTest, MalwareWebSocketBlocked) { |
| 2259 // This test currently only passes when the network service is enabled. | 2257 // This test currently only passes when the network service is enabled. |
| 2260 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 2258 if (!base::FeatureList::IsEnabled(features::kNetworkService)) |
| 2261 ::switches::kEnableNetworkService)) { | |
| 2262 return; | 2259 return; |
| 2263 } | |
| 2264 GURL main_url = embedded_test_server()->GetURL(kMalwareWebSocketPage); | 2260 GURL main_url = embedded_test_server()->GetURL(kMalwareWebSocketPage); |
| 2265 // This constructs the URL with the same logic as malware_websocket.html. | 2261 // This constructs the URL with the same logic as malware_websocket.html. |
| 2266 GURL resolved = main_url.Resolve("/safe_browsing/malware-ws"); | 2262 GURL resolved = main_url.Resolve("/safe_browsing/malware-ws"); |
| 2267 GURL::Replacements replace_scheme; | 2263 GURL::Replacements replace_scheme; |
| 2268 replace_scheme.SetScheme("ws", url::Component(0, strlen("ws"))); | 2264 replace_scheme.SetScheme("ws", url::Component(0, strlen("ws"))); |
| 2269 GURL websocket_url = resolved.ReplaceComponents(replace_scheme); | 2265 GURL websocket_url = resolved.ReplaceComponents(replace_scheme); |
| 2270 | 2266 |
| 2271 MarkUrlForMalwareUnexpired(websocket_url); | 2267 MarkUrlForMalwareUnexpired(websocket_url); |
| 2272 | 2268 |
| 2273 // Brute force method for waiting for the interstitial to be displayed. | 2269 // Brute force method for waiting for the interstitial to be displayed. |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2479 } | 2475 } |
| 2480 | 2476 |
| 2481 INSTANTIATE_TEST_CASE_P( | 2477 INSTANTIATE_TEST_CASE_P( |
| 2482 MaybeSetMetadata, | 2478 MaybeSetMetadata, |
| 2483 V4SafeBrowsingServiceMetadataTest, | 2479 V4SafeBrowsingServiceMetadataTest, |
| 2484 testing::Values(ThreatPatternType::NONE, | 2480 testing::Values(ThreatPatternType::NONE, |
| 2485 ThreatPatternType::MALWARE_LANDING, | 2481 ThreatPatternType::MALWARE_LANDING, |
| 2486 ThreatPatternType::MALWARE_DISTRIBUTION)); | 2482 ThreatPatternType::MALWARE_DISTRIBUTION)); |
| 2487 | 2483 |
| 2488 } // namespace safe_browsing | 2484 } // namespace safe_browsing |
| OLD | NEW |