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

Side by Side Diff: chrome/browser/subresource_filter/subresource_filter_browsertest.cc

Issue 2814733002: Add the SocEng as a type for checking in CheckUrlForSubresourceFilter. (Closed)
Patch Set: . Created 3 years, 7 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 unified diff | Download patch
OLDNEW
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 <map> 5 #include <map>
6 #include <memory> 6 #include <memory>
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 constexpr const char kEvaluationTotalCPUDurationForDocument[] = 115 constexpr const char kEvaluationTotalCPUDurationForDocument[] =
116 "SubresourceFilter.DocumentLoad.SubresourceEvaluation.TotalCPUDuration"; 116 "SubresourceFilter.DocumentLoad.SubresourceEvaluation.TotalCPUDuration";
117 constexpr const char kEvaluationWallDuration[] = 117 constexpr const char kEvaluationWallDuration[] =
118 "SubresourceFilter.SubresourceLoad.Evaluation.WallDuration"; 118 "SubresourceFilter.SubresourceLoad.Evaluation.WallDuration";
119 constexpr const char kEvaluationCPUDuration[] = 119 constexpr const char kEvaluationCPUDuration[] =
120 "SubresourceFilter.SubresourceLoad.Evaluation.CPUDuration"; 120 "SubresourceFilter.SubresourceLoad.Evaluation.CPUDuration";
121 121
122 #if defined(GOOGLE_CHROME_BUILD) 122 #if defined(GOOGLE_CHROME_BUILD)
123 // Names of navigation chain patterns histogram. 123 // Names of navigation chain patterns histogram.
124 const char kMatchesPatternHistogramName[] = 124 const char kMatchesPatternHistogramName[] =
125 "SubresourceFilter.PageLoad.RedirectChainMatchPattern"; 125 "SubresourceFilter.PageLoad.FinalURLMatch";
126 const char kNavigationChainSize[] = 126 const char kNavigationChainSize[] =
127 "SubresourceFilter.PageLoad.RedirectChainLength"; 127 "SubresourceFilter.PageLoad.RedirectChainLength";
128 const char kSubresourceFilterOnlySuffix[] = ".SubresourceFilterOnly"; 128 const char kSubresourceFilterOnlySuffix[] = ".SubresourceFilterOnly";
129 const char kSocialEngineeringAdsInterstitialSuffix[] =
130 ".SocialEngineeringAdsInterstitial";
131 const char kPhishingInterstitalSuffix[] = ".PhishingInterstital";
129 #endif 132 #endif
130 133
131 // Other histograms. 134 // Other histograms.
132 const char kSubresourceFilterActionsHistogram[] = "SubresourceFilter.Actions"; 135 const char kSubresourceFilterActionsHistogram[] = "SubresourceFilter.Actions";
133 136
134 // Human readable representation of expected redirect chain match patterns.
135 // The explanations for the buckets given for the following redirect chain:
136 // A->B->C->D, where A is initial URL and D is a final URL.
137 enum RedirectChainMatchPattern {
138 EMPTY, // No histograms were recorded.
139 F0M0L1, // D is a Safe Browsing match.
140 F0M1L0, // B or C, or both are Safe Browsing matches.
141 F0M1L1, // B or C, or both and D are Safe Browsing matches.
142 F1M0L0, // A is Safe Browsing match
143 F1M0L1, // A and D are Safe Browsing matches.
144 F1M1L0, // B and/or C and A are Safe Browsing matches.
145 F1M1L1, // B and/or C and A and D are Safe Browsing matches.
146 NO_REDIRECTS_HIT, // Redirect chain consists of single URL, aka no redirects
147 // has happened, and this URL was a Safe Browsing hit.
148 NUM_HIT_PATTERNS,
149 };
150
151 // UI manager that never actually shows any interstitials, but emulates as if 137 // UI manager that never actually shows any interstitials, but emulates as if
152 // the user chose to proceed through them. 138 // the user chose to proceed through them.
153 class FakeSafeBrowsingUIManager 139 class FakeSafeBrowsingUIManager
154 : public safe_browsing::TestSafeBrowsingUIManager { 140 : public safe_browsing::TestSafeBrowsingUIManager {
155 public: 141 public:
156 FakeSafeBrowsingUIManager() {} 142 FakeSafeBrowsingUIManager() {}
157 143
158 protected: 144 protected:
159 ~FakeSafeBrowsingUIManager() override {} 145 ~FakeSafeBrowsingUIManager() override {}
160 146
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 browser()->tab_strip_model()->GetActiveWebContents(), 424 browser()->tab_strip_model()->GetActiveWebContents(),
439 base::StringPrintf("connectWebSocket('%s');", url.spec().c_str()), 425 base::StringPrintf("connectWebSocket('%s');", url.spec().c_str()),
440 &websocket_connection_succeeded)); 426 &websocket_connection_succeeded));
441 EXPECT_EQ(expect_connection_success, websocket_connection_succeeded); 427 EXPECT_EQ(expect_connection_success, websocket_connection_succeeded);
442 } 428 }
443 429
444 private: 430 private:
445 std::unique_ptr<net::SpawnedTestServer> websocket_test_server_; 431 std::unique_ptr<net::SpawnedTestServer> websocket_test_server_;
446 }; 432 };
447 433
448
449 // Tests ----------------------------------------------------------------------- 434 // Tests -----------------------------------------------------------------------
450 435
451 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, MainFrameActivation) { 436 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, MainFrameActivation) {
452 GURL url(GetTestUrl("subresource_filter/frame_with_included_script.html")); 437 GURL url(GetTestUrl("subresource_filter/frame_with_included_script.html"));
453 ConfigureAsPhishingURL(url); 438 ConfigureAsPhishingURL(url);
454 ASSERT_NO_FATAL_FAILURE(SetRulesetToDisallowURLsWithPathSuffix( 439 ASSERT_NO_FATAL_FAILURE(SetRulesetToDisallowURLsWithPathSuffix(
455 "suffix-that-does-not-match-anything")); 440 "suffix-that-does-not-match-anything"));
456 ui_test_utils::NavigateToURL(browser(), url); 441 ui_test_utils::NavigateToURL(browser(), url);
457 EXPECT_TRUE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); 442 EXPECT_TRUE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame()));
458 443
(...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 ExpectRedirectPatternHistogramsAreRecordedForSubresourceFilterOnlyMatch) { 1408 ExpectRedirectPatternHistogramsAreRecordedForSubresourceFilterOnlyMatch) {
1424 ASSERT_NO_FATAL_FAILURE(SetRulesetToDisallowURLsWithPathSuffix( 1409 ASSERT_NO_FATAL_FAILURE(SetRulesetToDisallowURLsWithPathSuffix(
1425 "suffix-that-does-not-match-anything")); 1410 "suffix-that-does-not-match-anything"));
1426 1411
1427 GURL url(GetTestUrl("subresource_filter/frame_with_included_script.html")); 1412 GURL url(GetTestUrl("subresource_filter/frame_with_included_script.html"));
1428 ConfigureAsSubresourceFilterOnlyURL(url); 1413 ConfigureAsSubresourceFilterOnlyURL(url);
1429 1414
1430 base::HistogramTester tester; 1415 base::HistogramTester tester;
1431 ui_test_utils::NavigateToURL(browser(), url); 1416 ui_test_utils::NavigateToURL(browser(), url);
1432 1417
1433 EXPECT_THAT(tester.GetAllSamples(std::string(kMatchesPatternHistogramName) + 1418 tester.ExpectUniqueSample(
1434 std::string(kSubresourceFilterOnlySuffix)), 1419 std::string(kMatchesPatternHistogramName) +
1435 ::testing::ElementsAre(base::Bucket(NO_REDIRECTS_HIT, 1))); 1420 std::string(kSocialEngineeringAdsInterstitialSuffix),
1421 false, 1);
1422 tester.ExpectUniqueSample(std::string(kMatchesPatternHistogramName) +
1423 std::string(kSubresourceFilterOnlySuffix),
1424 true, 1);
1425
1426 tester.ExpectUniqueSample(std::string(kMatchesPatternHistogramName) +
1427 std::string(kPhishingInterstitalSuffix),
1428 false, 1);
1436 EXPECT_THAT(tester.GetAllSamples(std::string(kNavigationChainSize) + 1429 EXPECT_THAT(tester.GetAllSamples(std::string(kNavigationChainSize) +
1437 std::string(kSubresourceFilterOnlySuffix)), 1430 std::string(kSubresourceFilterOnlySuffix)),
1438 ::testing::ElementsAre(base::Bucket(1, 1))); 1431 ::testing::ElementsAre(base::Bucket(1, 1)));
1439 } 1432 }
1440 1433
1441 IN_PROC_BROWSER_TEST_F( 1434 IN_PROC_BROWSER_TEST_F(
1442 SubresourceFilterBrowserTest, 1435 SubresourceFilterBrowserTest,
1443 ExpectRedirectPatternHistogramsAreRecordedForSubresourceFilterOnlyRedirectMa tch) { 1436 ExpectRedirectPatternHistogramsAreRecordedForSubresourceFilterOnlyRedirectMa tch) {
1444 ASSERT_NO_FATAL_FAILURE( 1437 ASSERT_NO_FATAL_FAILURE(
1445 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); 1438 SetRulesetToDisallowURLsWithPathSuffix("included_script.js"));
1446 const std::string initial_host("a.com"); 1439 const std::string initial_host("a.com");
1447 const std::string redirected_host("b.com"); 1440 const std::string redirected_host("b.com");
1448 1441
1449 GURL redirect_url(embedded_test_server()->GetURL( 1442 GURL redirect_url(embedded_test_server()->GetURL(
1450 redirected_host, "/subresource_filter/frame_with_included_script.html")); 1443 redirected_host, "/subresource_filter/frame_with_included_script.html"));
1451 GURL url(embedded_test_server()->GetURL( 1444 GURL url(embedded_test_server()->GetURL(
1452 initial_host, "/server-redirect?" + redirect_url.spec())); 1445 initial_host, "/server-redirect?" + redirect_url.spec()));
1453 1446
1454 ConfigureAsSubresourceFilterOnlyURL(url.GetOrigin()); 1447 ConfigureAsSubresourceFilterOnlyURL(url.GetOrigin());
1455 base::HistogramTester tester; 1448 base::HistogramTester tester;
1456 ui_test_utils::NavigateToURL(browser(), url); 1449 ui_test_utils::NavigateToURL(browser(), url);
1457 EXPECT_THAT(tester.GetAllSamples(std::string(kMatchesPatternHistogramName) + 1450 tester.ExpectUniqueSample(
1458 std::string(kSubresourceFilterOnlySuffix)), 1451 std::string(kMatchesPatternHistogramName) +
1459 ::testing::IsEmpty()); 1452 std::string(kSocialEngineeringAdsInterstitialSuffix),
1453 false, 1);
1454 tester.ExpectUniqueSample(std::string(kMatchesPatternHistogramName) +
1455 std::string(kSubresourceFilterOnlySuffix),
1456 false, 1);
1460 1457
1461 EXPECT_THAT(tester.GetAllSamples(std::string(kNavigationChainSize) + 1458 tester.ExpectUniqueSample(std::string(kMatchesPatternHistogramName) +
1462 std::string(kSubresourceFilterOnlySuffix)), 1459 std::string(kPhishingInterstitalSuffix),
1463 ::testing::IsEmpty()); 1460 false, 1);
1464 } 1461 }
1465 #endif 1462 #endif
1466 1463
1467 } // namespace subresource_filter 1464 } // namespace subresource_filter
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_service_browsertest.cc ('k') | components/safe_browsing/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698