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

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: rkaplow 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/string_util.h" 18 #include "base/strings/string_util.h"
19 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
20 #include "base/test/histogram_tester.h" 20 #include "base/test/histogram_tester.h"
21 #include "chrome/browser/browser_process.h" 21 #include "chrome/browser/browser_process.h"
22 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 22 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
23 #include "chrome/browser/metrics/subprocess_metrics_provider.h" 23 #include "chrome/browser/metrics/subprocess_metrics_provider.h"
24 #include "chrome/browser/page_load_metrics/observers/subresource_filter_metrics_ observer.h" 24 #include "chrome/browser/page_load_metrics/observers/subresource_filter_metrics_ observer.h"
25 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" 25 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h"
26 #include "chrome/browser/safe_browsing/v4_test_utils.h" 26 #include "chrome/browser/safe_browsing/v4_test_utils.h"
27 #include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h"
27 #include "chrome/browser/subresource_filter/test_ruleset_publisher.h" 28 #include "chrome/browser/subresource_filter/test_ruleset_publisher.h"
28 #include "chrome/browser/ui/browser.h" 29 #include "chrome/browser/ui/browser.h"
29 #include "chrome/browser/ui/browser_commands.h" 30 #include "chrome/browser/ui/browser_commands.h"
30 #include "chrome/browser/ui/tabs/tab_strip_model.h" 31 #include "chrome/browser/ui/tabs/tab_strip_model.h"
31 #include "chrome/common/chrome_paths.h" 32 #include "chrome/common/chrome_paths.h"
32 #include "chrome/common/url_constants.h" 33 #include "chrome/common/url_constants.h"
33 #include "chrome/test/base/in_process_browser_test.h" 34 #include "chrome/test/base/in_process_browser_test.h"
34 #include "chrome/test/base/ui_test_utils.h" 35 #include "chrome/test/base/ui_test_utils.h"
35 #include "components/content_settings/core/browser/host_content_settings_map.h" 36 #include "components/content_settings/core/browser/host_content_settings_map.h"
36 #include "components/content_settings/core/common/content_settings.h" 37 #include "components/content_settings/core/common/content_settings.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 #if defined(GOOGLE_CHROME_BUILD) 115 #if defined(GOOGLE_CHROME_BUILD)
115 // Names of navigation chain patterns histogram. 116 // Names of navigation chain patterns histogram.
116 const char kMatchesPatternHistogramName[] = 117 const char kMatchesPatternHistogramName[] =
117 "SubresourceFilter.PageLoad.RedirectChainMatchPattern"; 118 "SubresourceFilter.PageLoad.RedirectChainMatchPattern";
118 const char kNavigationChainSize[] = 119 const char kNavigationChainSize[] =
119 "SubresourceFilter.PageLoad.RedirectChainLength"; 120 "SubresourceFilter.PageLoad.RedirectChainLength";
120 const char kSubresourceFilterOnlySuffix[] = ".SubresourceFilterOnly"; 121 const char kSubresourceFilterOnlySuffix[] = ".SubresourceFilterOnly";
121 #endif 122 #endif
122 123
123 // Other histograms. 124 // Other histograms.
124 const char kSubresourceFilterPromptHistogram[] = 125 const char kSubresourceFilterActionsHistogram[] = "SubresourceFilter.Actions";
125 "SubresourceFilter.Prompt.NumVisibility";
126 126
127 // Human readable representation of expected redirect chain match patterns. 127 // Human readable representation of expected redirect chain match patterns.
128 // The explanations for the buckets given for the following redirect chain: 128 // The explanations for the buckets given for the following redirect chain:
129 // A->B->C->D, where A is initial URL and D is a final URL. 129 // A->B->C->D, where A is initial URL and D is a final URL.
130 enum RedirectChainMatchPattern { 130 enum RedirectChainMatchPattern {
131 EMPTY, // No histograms were recorded. 131 EMPTY, // No histograms were recorded.
132 F0M0L1, // D is a Safe Browsing match. 132 F0M0L1, // D is a Safe Browsing match.
133 F0M1L0, // B or C, or both are Safe Browsing matches. 133 F0M1L0, // B or C, or both are Safe Browsing matches.
134 F0M1L1, // B or C, or both and D are Safe Browsing matches. 134 F0M1L1, // B or C, or both and D are Safe Browsing matches.
135 F1M0L0, // A is Safe Browsing match 135 F1M0L0, // A is Safe Browsing match
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 ASSERT_NO_FATAL_FAILURE( 537 ASSERT_NO_FATAL_FAILURE(
538 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); 538 SetRulesetToDisallowURLsWithPathSuffix("included_script.js"));
539 base::HistogramTester tester; 539 base::HistogramTester tester;
540 ui_test_utils::NavigateToURL(browser(), url); 540 ui_test_utils::NavigateToURL(browser(), url);
541 541
542 const std::vector<const char*> kSubframeNames{"one", "two", "three"}; 542 const std::vector<const char*> kSubframeNames{"one", "two", "three"};
543 const std::vector<bool> kExpectScriptInFrameToLoad{false, true, false}; 543 const std::vector<bool> kExpectScriptInFrameToLoad{false, true, false};
544 ASSERT_NO_FATAL_FAILURE(ExpectParsedScriptElementLoadedStatusInFrames( 544 ASSERT_NO_FATAL_FAILURE(ExpectParsedScriptElementLoadedStatusInFrames(
545 kSubframeNames, kExpectScriptInFrameToLoad)); 545 kSubframeNames, kExpectScriptInFrameToLoad));
546 546
547 tester.ExpectBucketCount(kSubresourceFilterPromptHistogram, true, 1); 547 tester.ExpectBucketCount(kSubresourceFilterActionsHistogram, kActionUIShown,
548 1);
548 } 549 }
549 550
550 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, 551 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest,
551 HistoryNavigationActivation) { 552 HistoryNavigationActivation) {
552 GURL url_with_activation(GetTestUrl(kTestFrameSetPath)); 553 GURL url_with_activation(GetTestUrl(kTestFrameSetPath));
553 GURL url_without_activation( 554 GURL url_without_activation(
554 embedded_test_server()->GetURL("a.com", kTestFrameSetPath)); 555 embedded_test_server()->GetURL("a.com", kTestFrameSetPath));
555 ConfigureAsPhishingURL(url_with_activation); 556 ConfigureAsPhishingURL(url_with_activation);
556 ASSERT_NO_FATAL_FAILURE( 557 ASSERT_NO_FATAL_FAILURE(
557 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); 558 SetRulesetToDisallowURLsWithPathSuffix("included_script.js"));
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 } 789 }
789 790
790 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, 791 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest,
791 PromptShownAgainOnNextNavigation) { 792 PromptShownAgainOnNextNavigation) {
792 ASSERT_NO_FATAL_FAILURE( 793 ASSERT_NO_FATAL_FAILURE(
793 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); 794 SetRulesetToDisallowURLsWithPathSuffix("included_script.js"));
794 GURL url(GetTestUrl(kTestFrameSetPath)); 795 GURL url(GetTestUrl(kTestFrameSetPath));
795 ConfigureAsPhishingURL(url); 796 ConfigureAsPhishingURL(url);
796 base::HistogramTester tester; 797 base::HistogramTester tester;
797 ui_test_utils::NavigateToURL(browser(), url); 798 ui_test_utils::NavigateToURL(browser(), url);
798 tester.ExpectBucketCount(kSubresourceFilterPromptHistogram, true, 1); 799 tester.ExpectBucketCount(kSubresourceFilterActionsHistogram, kActionUIShown,
800 1);
799 // Check that the bubble is not shown again for this navigation. 801 // Check that the bubble is not shown again for this navigation.
800 EXPECT_FALSE(IsDynamicScriptElementLoaded(FindFrameByName("five"))); 802 EXPECT_FALSE(IsDynamicScriptElementLoaded(FindFrameByName("five")));
801 tester.ExpectBucketCount(kSubresourceFilterPromptHistogram, true, 1); 803 tester.ExpectBucketCount(kSubresourceFilterActionsHistogram, kActionUIShown,
804 1);
802 // Check that bubble is shown for new navigation. 805 // Check that bubble is shown for new navigation.
803 ui_test_utils::NavigateToURL(browser(), url); 806 ui_test_utils::NavigateToURL(browser(), url);
804 tester.ExpectBucketCount(kSubresourceFilterPromptHistogram, true, 2); 807 tester.ExpectBucketCount(kSubresourceFilterActionsHistogram, kActionUIShown,
808 2);
805 } 809 }
806 810
807 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, 811 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest,
808 CrossSiteSubFrameActivationWithoutWhitelist) { 812 CrossSiteSubFrameActivationWithoutWhitelist) {
809 GURL a_url(embedded_test_server()->GetURL( 813 GURL a_url(embedded_test_server()->GetURL(
810 "a.com", "/subresource_filter/frame_cross_site_set.html")); 814 "a.com", "/subresource_filter/frame_cross_site_set.html"));
811 ConfigureAsPhishingURL(a_url); 815 ConfigureAsPhishingURL(a_url);
812 ASSERT_NO_FATAL_FAILURE( 816 ASSERT_NO_FATAL_FAILURE(
813 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); 817 SetRulesetToDisallowURLsWithPathSuffix("included_script.js"));
814 ui_test_utils::NavigateToURL(browser(), a_url); 818 ui_test_utils::NavigateToURL(browser(), a_url);
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 std::string(kSubresourceFilterOnlySuffix)), 1292 std::string(kSubresourceFilterOnlySuffix)),
1289 ::testing::IsEmpty()); 1293 ::testing::IsEmpty());
1290 1294
1291 EXPECT_THAT(tester.GetAllSamples(std::string(kNavigationChainSize) + 1295 EXPECT_THAT(tester.GetAllSamples(std::string(kNavigationChainSize) +
1292 std::string(kSubresourceFilterOnlySuffix)), 1296 std::string(kSubresourceFilterOnlySuffix)),
1293 ::testing::IsEmpty()); 1297 ::testing::IsEmpty());
1294 } 1298 }
1295 #endif 1299 #endif
1296 1300
1297 } // namespace subresource_filter 1301 } // namespace subresource_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698