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

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

Issue 2777093007: [subresource_filter] Add metrics for UI / related things (Closed)
Patch Set: msramek review Created 3 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 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"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/strings/string_piece.h" 17 #include "base/strings/string_piece.h"
18 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "base/test/histogram_tester.h" 19 #include "base/test/histogram_tester.h"
20 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 21 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
22 #include "chrome/browser/metrics/subprocess_metrics_provider.h" 22 #include "chrome/browser/metrics/subprocess_metrics_provider.h"
23 #include "chrome/browser/page_load_metrics/observers/subresource_filter_metrics_ observer.h" 23 #include "chrome/browser/page_load_metrics/observers/subresource_filter_metrics_ observer.h"
24 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" 24 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h"
25 #include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h"
25 #include "chrome/browser/subresource_filter/test_ruleset_publisher.h" 26 #include "chrome/browser/subresource_filter/test_ruleset_publisher.h"
26 #include "chrome/browser/ui/browser.h" 27 #include "chrome/browser/ui/browser.h"
27 #include "chrome/browser/ui/browser_commands.h" 28 #include "chrome/browser/ui/browser_commands.h"
28 #include "chrome/browser/ui/tabs/tab_strip_model.h" 29 #include "chrome/browser/ui/tabs/tab_strip_model.h"
29 #include "chrome/common/chrome_paths.h" 30 #include "chrome/common/chrome_paths.h"
30 #include "chrome/common/url_constants.h" 31 #include "chrome/common/url_constants.h"
31 #include "chrome/test/base/in_process_browser_test.h" 32 #include "chrome/test/base/in_process_browser_test.h"
32 #include "chrome/test/base/ui_test_utils.h" 33 #include "chrome/test/base/ui_test_utils.h"
33 #include "components/content_settings/core/browser/host_content_settings_map.h" 34 #include "components/content_settings/core/browser/host_content_settings_map.h"
34 #include "components/content_settings/core/common/content_settings.h" 35 #include "components/content_settings/core/common/content_settings.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 constexpr const char kEvaluationTotalWallDurationForDocument[] = 103 constexpr const char kEvaluationTotalWallDurationForDocument[] =
103 "SubresourceFilter.DocumentLoad.SubresourceEvaluation.TotalWallDuration"; 104 "SubresourceFilter.DocumentLoad.SubresourceEvaluation.TotalWallDuration";
104 constexpr const char kEvaluationTotalCPUDurationForDocument[] = 105 constexpr const char kEvaluationTotalCPUDurationForDocument[] =
105 "SubresourceFilter.DocumentLoad.SubresourceEvaluation.TotalCPUDuration"; 106 "SubresourceFilter.DocumentLoad.SubresourceEvaluation.TotalCPUDuration";
106 constexpr const char kEvaluationWallDuration[] = 107 constexpr const char kEvaluationWallDuration[] =
107 "SubresourceFilter.SubresourceLoad.Evaluation.WallDuration"; 108 "SubresourceFilter.SubresourceLoad.Evaluation.WallDuration";
108 constexpr const char kEvaluationCPUDuration[] = 109 constexpr const char kEvaluationCPUDuration[] =
109 "SubresourceFilter.SubresourceLoad.Evaluation.CPUDuration"; 110 "SubresourceFilter.SubresourceLoad.Evaluation.CPUDuration";
110 111
111 // Other histograms. 112 // Other histograms.
112 const char kSubresourceFilterPromptHistogram[] = 113 const char kSubresourceFilterActionsHistogram[] = "SubresourceFilter.Actions";
113 "SubresourceFilter.Prompt.NumVisibility";
114 114
115 // Database manager that allows any URL to be configured as blacklisted for 115 // Database manager that allows any URL to be configured as blacklisted for
116 // testing. 116 // testing.
117 class FakeSafeBrowsingDatabaseManager 117 class FakeSafeBrowsingDatabaseManager
118 : public safe_browsing::TestSafeBrowsingDatabaseManager { 118 : public safe_browsing::TestSafeBrowsingDatabaseManager {
119 public: 119 public:
120 FakeSafeBrowsingDatabaseManager() {} 120 FakeSafeBrowsingDatabaseManager() {}
121 121
122 void AddBlacklistedURL(const GURL& url, 122 void AddBlacklistedURL(const GURL& url,
123 safe_browsing::SBThreatType threat_type) { 123 safe_browsing::SBThreatType threat_type) {
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 ASSERT_NO_FATAL_FAILURE( 479 ASSERT_NO_FATAL_FAILURE(
480 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); 480 SetRulesetToDisallowURLsWithPathSuffix("included_script.js"));
481 base::HistogramTester tester; 481 base::HistogramTester tester;
482 ui_test_utils::NavigateToURL(browser(), url); 482 ui_test_utils::NavigateToURL(browser(), url);
483 483
484 const std::vector<const char*> kSubframeNames{"one", "two", "three"}; 484 const std::vector<const char*> kSubframeNames{"one", "two", "three"};
485 const std::vector<bool> kExpectScriptInFrameToLoad{false, true, false}; 485 const std::vector<bool> kExpectScriptInFrameToLoad{false, true, false};
486 ASSERT_NO_FATAL_FAILURE(ExpectParsedScriptElementLoadedStatusInFrames( 486 ASSERT_NO_FATAL_FAILURE(ExpectParsedScriptElementLoadedStatusInFrames(
487 kSubframeNames, kExpectScriptInFrameToLoad)); 487 kSubframeNames, kExpectScriptInFrameToLoad));
488 488
489 tester.ExpectBucketCount(kSubresourceFilterPromptHistogram, true, 1); 489 tester.ExpectBucketCount(kSubresourceFilterActionsHistogram, kActionUIShown,
490 1);
490 } 491 }
491 492
492 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, 493 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest,
493 HistoryNavigationActivation) { 494 HistoryNavigationActivation) {
494 GURL url_without_activation(GetTestUrl(kTestFrameSetPath)); 495 GURL url_without_activation(GetTestUrl(kTestFrameSetPath));
495 GURL url_with_activation( 496 GURL url_with_activation(
496 GetURLWithQuery(url_without_activation, "activation")); 497 GetURLWithQuery(url_without_activation, "activation"));
497 ConfigureAsPhishingURL(url_with_activation); 498 ConfigureAsPhishingURL(url_with_activation);
498 ASSERT_NO_FATAL_FAILURE( 499 ASSERT_NO_FATAL_FAILURE(
499 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); 500 SetRulesetToDisallowURLsWithPathSuffix("included_script.js"));
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 } 731 }
731 732
732 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, 733 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest,
733 PromptShownAgainOnNextNavigation) { 734 PromptShownAgainOnNextNavigation) {
734 ASSERT_NO_FATAL_FAILURE( 735 ASSERT_NO_FATAL_FAILURE(
735 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); 736 SetRulesetToDisallowURLsWithPathSuffix("included_script.js"));
736 GURL url(GetTestUrl(kTestFrameSetPath)); 737 GURL url(GetTestUrl(kTestFrameSetPath));
737 ConfigureAsPhishingURL(url); 738 ConfigureAsPhishingURL(url);
738 base::HistogramTester tester; 739 base::HistogramTester tester;
739 ui_test_utils::NavigateToURL(browser(), url); 740 ui_test_utils::NavigateToURL(browser(), url);
740 tester.ExpectBucketCount(kSubresourceFilterPromptHistogram, true, 1); 741 tester.ExpectBucketCount(kSubresourceFilterActionsHistogram, kActionUIShown,
742 1);
741 // Check that the bubble is not shown again for this navigation. 743 // Check that the bubble is not shown again for this navigation.
742 EXPECT_FALSE(IsDynamicScriptElementLoaded(FindFrameByName("five"))); 744 EXPECT_FALSE(IsDynamicScriptElementLoaded(FindFrameByName("five")));
743 tester.ExpectBucketCount(kSubresourceFilterPromptHistogram, true, 1); 745 tester.ExpectBucketCount(kSubresourceFilterActionsHistogram, kActionUIShown,
746 1);
744 // Check that bubble is shown for new navigation. 747 // Check that bubble is shown for new navigation.
745 ui_test_utils::NavigateToURL(browser(), url); 748 ui_test_utils::NavigateToURL(browser(), url);
746 tester.ExpectBucketCount(kSubresourceFilterPromptHistogram, true, 2); 749 tester.ExpectBucketCount(kSubresourceFilterActionsHistogram, kActionUIShown,
750 2);
747 } 751 }
748 752
749 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, 753 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest,
750 CrossSiteSubFrameActivationWithoutWhitelist) { 754 CrossSiteSubFrameActivationWithoutWhitelist) {
751 GURL a_url(embedded_test_server()->GetURL( 755 GURL a_url(embedded_test_server()->GetURL(
752 "a.com", "/subresource_filter/frame_cross_site_set.html")); 756 "a.com", "/subresource_filter/frame_cross_site_set.html"));
753 ConfigureAsPhishingURL(a_url); 757 ConfigureAsPhishingURL(a_url);
754 ASSERT_NO_FATAL_FAILURE( 758 ASSERT_NO_FATAL_FAILURE(
755 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); 759 SetRulesetToDisallowURLsWithPathSuffix("included_script.js"));
756 ui_test_utils::NavigateToURL(browser(), a_url); 760 ui_test_utils::NavigateToURL(browser(), a_url);
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 static_cast<int>(ActivationDecision::URL_WHITELISTED), 1); 1185 static_cast<int>(ActivationDecision::URL_WHITELISTED), 1);
1182 1186
1183 tester.ExpectTotalCount( 1187 tester.ExpectTotalCount(
1184 internal::kHistogramSubresourceFilterActivationDecisionReload, 1); 1188 internal::kHistogramSubresourceFilterActivationDecisionReload, 1);
1185 tester.ExpectBucketCount( 1189 tester.ExpectBucketCount(
1186 internal::kHistogramSubresourceFilterActivationDecisionReload, 1190 internal::kHistogramSubresourceFilterActivationDecisionReload,
1187 static_cast<int>(ActivationDecision::URL_WHITELISTED), 1); 1191 static_cast<int>(ActivationDecision::URL_WHITELISTED), 1);
1188 } 1192 }
1189 1193
1190 } // namespace subresource_filter 1194 } // namespace subresource_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698