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