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

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

Issue 2838063002: [on-hold][subresource_filter] Add ActivationTracker to track all activated contents (Closed)
Patch Set: fix incognito 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"
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/content_settings/tab_specific_content_settings.h" 23 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
24 #include "chrome/browser/metrics/subprocess_metrics_provider.h" 24 #include "chrome/browser/metrics/subprocess_metrics_provider.h"
25 #include "chrome/browser/page_load_metrics/observers/subresource_filter_metrics_ observer.h" 25 #include "chrome/browser/page_load_metrics/observers/subresource_filter_metrics_ observer.h"
26 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" 26 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h"
27 #include "chrome/browser/safe_browsing/v4_test_utils.h" 27 #include "chrome/browser/safe_browsing/v4_test_utils.h"
28 #include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h" 28 #include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h"
29 #include "chrome/browser/subresource_filter/subresource_filter_activation_tracke r.h"
30 #include "chrome/browser/subresource_filter/subresource_filter_profile_context.h "
31 #include "chrome/browser/subresource_filter/subresource_filter_profile_context_f actory.h"
29 #include "chrome/browser/subresource_filter/test_ruleset_publisher.h" 32 #include "chrome/browser/subresource_filter/test_ruleset_publisher.h"
30 #include "chrome/browser/ui/browser.h" 33 #include "chrome/browser/ui/browser.h"
31 #include "chrome/browser/ui/browser_commands.h" 34 #include "chrome/browser/ui/browser_commands.h"
32 #include "chrome/browser/ui/tabs/tab_strip_model.h" 35 #include "chrome/browser/ui/tabs/tab_strip_model.h"
33 #include "chrome/common/chrome_paths.h" 36 #include "chrome/common/chrome_paths.h"
34 #include "chrome/common/url_constants.h" 37 #include "chrome/common/url_constants.h"
35 #include "chrome/test/base/in_process_browser_test.h" 38 #include "chrome/test/base/in_process_browser_test.h"
36 #include "chrome/test/base/ui_test_utils.h" 39 #include "chrome/test/base/ui_test_utils.h"
37 #include "components/content_settings/core/browser/host_content_settings_map.h" 40 #include "components/content_settings/core/browser/host_content_settings_map.h"
38 #include "components/content_settings/core/common/content_settings.h" 41 #include "components/content_settings/core/common/content_settings.h"
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 481
479 void SetUpActivationFeature() override { 482 void SetUpActivationFeature() override {
480 ToggleFeatures(base::MakeUnique<ScopedSubresourceFilterFeatureToggle>( 483 ToggleFeatures(base::MakeUnique<ScopedSubresourceFilterFeatureToggle>(
481 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, 484 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled,
482 kActivationScopeActivationList, kActivationListSubresourceFilter, "0", 485 kActivationScopeActivationList, kActivationListSubresourceFilter, "0",
483 "" /* suppress_notifications */, "false")); 486 "" /* suppress_notifications */, "false"));
484 } 487 }
485 }; 488 };
486 #endif 489 #endif
487 490
491 class SubresourceFilterDryRunBrowserTest
492 : public SubresourceFilterBrowserTestImpl {
493 public:
494 SubresourceFilterDryRunBrowserTest()
495 : SubresourceFilterBrowserTestImpl(false, false) {}
496
497 void SetUpActivationFeature() override {
498 ToggleFeatures(base::MakeUnique<ScopedSubresourceFilterFeatureToggle>(
499 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelDryRun,
500 kActivationScopeActivationList, kActivationListSubresourceFilter, "0",
501 "" /* suppress_notifications */, "false"));
502 }
503 };
504
488 // Tests ----------------------------------------------------------------------- 505 // Tests -----------------------------------------------------------------------
489 506
490 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, MainFrameActivation) { 507 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, MainFrameActivation) {
491 GURL url(GetTestUrl("subresource_filter/frame_with_included_script.html")); 508 GURL url(GetTestUrl("subresource_filter/frame_with_included_script.html"));
492 ConfigureAsPhishingURL(url); 509 ConfigureAsPhishingURL(url);
493 ASSERT_NO_FATAL_FAILURE(SetRulesetToDisallowURLsWithPathSuffix( 510 ASSERT_NO_FATAL_FAILURE(SetRulesetToDisallowURLsWithPathSuffix(
494 "suffix-that-does-not-match-anything")); 511 "suffix-that-does-not-match-anything"));
495 ui_test_utils::NavigateToURL(browser(), url); 512 ui_test_utils::NavigateToURL(browser(), url);
496 EXPECT_TRUE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); 513 EXPECT_TRUE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame()));
497 514
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 EXPECT_TRUE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); 1028 EXPECT_TRUE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame()));
1012 1029
1013 // A cross site blacklisted navigation should stay activated, however. 1030 // A cross site blacklisted navigation should stay activated, however.
1014 GURL a_url(embedded_test_server()->GetURL( 1031 GURL a_url(embedded_test_server()->GetURL(
1015 "a.com", "/subresource_filter/frame_with_included_script.html")); 1032 "a.com", "/subresource_filter/frame_with_included_script.html"));
1016 ConfigureAsPhishingURL(a_url); 1033 ConfigureAsPhishingURL(a_url);
1017 ui_test_utils::NavigateToURL(browser(), a_url); 1034 ui_test_utils::NavigateToURL(browser(), a_url);
1018 EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); 1035 EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame()));
1019 } 1036 }
1020 1037
1038 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, ActivationTracking) {
1039 SetRulesetWithRules(std::vector<proto::UrlRule>());
1040 SubresourceFilterProfileContext* context =
1041 SubresourceFilterProfileContextFactory::GetForProfile(
1042 browser()->profile());
1043
1044 const GURL kActivatedUrl = GetTestUrl(kTestFrameSetPath);
1045 ConfigureAsPhishingURL(kActivatedUrl);
1046
1047 EXPECT_FALSE(context->activation_tracker()->HasActivatedWebContents());
1048 ui_test_utils::NavigateToURL(browser(), kActivatedUrl);
1049 EXPECT_TRUE(context->activation_tracker()->HasActivatedWebContents());
1050
1051 // Add another tab without activation.
1052 AddTabAtIndex(0, GURL("about:blank"), ui::PAGE_TRANSITION_LINK);
1053 EXPECT_TRUE(context->activation_tracker()->HasActivatedWebContents());
1054 ui_test_utils::NavigateToURL(browser(), GURL("https://example.test"));
1055 EXPECT_TRUE(context->activation_tracker()->HasActivatedWebContents());
1056
1057 // Add another tab with activation, but close it.
1058 AddTabAtIndex(0, kActivatedUrl, ui::PAGE_TRANSITION_LINK);
1059 EXPECT_TRUE(context->activation_tracker()->HasActivatedWebContents());
1060 browser()->tab_strip_model()->CloseSelectedTabs();
1061 EXPECT_TRUE(context->activation_tracker()->HasActivatedWebContents());
1062
1063 // Go back to the original tab and navigate away.
1064 browser()->tab_strip_model()->ActivateTabAt(1, true /* user_gesture */);
1065 ui_test_utils::NavigateToURL(browser(), GURL("https://example.test"));
1066 EXPECT_FALSE(context->activation_tracker()->HasActivatedWebContents());
1067
1068 // Navigate once again, and close all the tabs.
1069 ui_test_utils::NavigateToURL(browser(), kActivatedUrl);
1070 EXPECT_TRUE(context->activation_tracker()->HasActivatedWebContents());
1071
1072 browser()->tab_strip_model()->CloseAllTabs();
1073 EXPECT_FALSE(context->activation_tracker()->HasActivatedWebContents());
1074 }
1075
1076 // Dry run activation should not be tracked by that activation tracker.
1077 IN_PROC_BROWSER_TEST_F(SubresourceFilterDryRunBrowserTest,
1078 DryRun_NoActivationTracking) {
1079 SetRulesetWithRules(std::vector<proto::UrlRule>());
1080 SubresourceFilterProfileContext* context =
1081 SubresourceFilterProfileContextFactory::GetForProfile(
1082 browser()->profile());
1083
1084 const GURL kActivatedUrl = GetTestUrl(kTestFrameSetPath);
1085 ConfigureAsPhishingURL(kActivatedUrl);
1086
1087 EXPECT_FALSE(context->activation_tracker()->HasActivatedWebContents());
1088 ui_test_utils::NavigateToURL(browser(), kActivatedUrl);
1089 EXPECT_FALSE(context->activation_tracker()->HasActivatedWebContents());
1090
1091 // Add another tab with activation, but close it.
1092 AddTabAtIndex(0, kActivatedUrl, ui::PAGE_TRANSITION_LINK);
1093 EXPECT_FALSE(context->activation_tracker()->HasActivatedWebContents());
1094 browser()->tab_strip_model()->CloseSelectedTabs();
1095 EXPECT_FALSE(context->activation_tracker()->HasActivatedWebContents());
1096 }
1097
1021 IN_PROC_BROWSER_TEST_P(SubresourceFilterWebSocketBrowserTest, BlockWebSocket) { 1098 IN_PROC_BROWSER_TEST_P(SubresourceFilterWebSocketBrowserTest, BlockWebSocket) {
1022 GURL url(GetTestUrl( 1099 GURL url(GetTestUrl(
1023 base::StringPrintf("subresource_filter/page_with_websocket.html?%s", 1100 base::StringPrintf("subresource_filter/page_with_websocket.html?%s",
1024 GetParam() == IN_WORKER ? "inWorker" : ""))); 1101 GetParam() == IN_WORKER ? "inWorker" : "")));
1025 GURL websocket_url(GetWebSocketUrl("echo-with-no-extension")); 1102 GURL websocket_url(GetWebSocketUrl("echo-with-no-extension"));
1026 ConfigureAsPhishingURL(url); 1103 ConfigureAsPhishingURL(url);
1027 ASSERT_NO_FATAL_FAILURE( 1104 ASSERT_NO_FATAL_FAILURE(
1028 SetRulesetToDisallowURLsWithPathSuffix("echo-with-no-extension")); 1105 SetRulesetToDisallowURLsWithPathSuffix("echo-with-no-extension"));
1029 ui_test_utils::NavigateToURL(browser(), url); 1106 ui_test_utils::NavigateToURL(browser(), url);
1030 CreateWebSocketAndExpectResult(websocket_url, 1107 CreateWebSocketAndExpectResult(websocket_url,
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1380 std::string(kSubresourceFilterOnlySuffix)), 1457 std::string(kSubresourceFilterOnlySuffix)),
1381 ::testing::IsEmpty()); 1458 ::testing::IsEmpty());
1382 1459
1383 EXPECT_THAT(tester.GetAllSamples(std::string(kNavigationChainSize) + 1460 EXPECT_THAT(tester.GetAllSamples(std::string(kNavigationChainSize) +
1384 std::string(kSubresourceFilterOnlySuffix)), 1461 std::string(kSubresourceFilterOnlySuffix)),
1385 ::testing::IsEmpty()); 1462 ::testing::IsEmpty());
1386 } 1463 }
1387 #endif 1464 #endif
1388 1465
1389 } // namespace subresource_filter 1466 } // namespace subresource_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698