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

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

Issue 2838193002: Split the ScopedSubresourceFilterFeatureToggle into two helper classes. (Closed)
Patch Set: Rebase. 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"
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 GURL GetURLWithFragment(const GURL& url, base::StringPiece fragment) { 163 GURL GetURLWithFragment(const GURL& url, base::StringPiece fragment) {
164 GURL::Replacements replacements; 164 GURL::Replacements replacements;
165 replacements.SetRefStr(fragment); 165 replacements.SetRefStr(fragment);
166 return url.ReplaceComponents(replacements); 166 return url.ReplaceComponents(replacements);
167 } 167 }
168 168
169 } // namespace 169 } // namespace
170 170
171 namespace subresource_filter { 171 namespace subresource_filter {
172 172
173 using subresource_filter::testing::ScopedSubresourceFilterFeatureToggle; 173 using subresource_filter::testing::ScopedSubresourceFilterConfigurator;
174 using subresource_filter::testing::TestRulesetPublisher; 174 using subresource_filter::testing::TestRulesetPublisher;
175 using subresource_filter::testing::TestRulesetCreator; 175 using subresource_filter::testing::TestRulesetCreator;
176 using subresource_filter::testing::TestRulesetPair; 176 using subresource_filter::testing::TestRulesetPair;
177 using ActivationDecision = 177 using ActivationDecision =
178 ContentSubresourceFilterDriverFactory::ActivationDecision; 178 ContentSubresourceFilterDriverFactory::ActivationDecision;
179 179
180 // SubresourceFilterDisabledBrowserTest --------------------------------------- 180 // SubresourceFilterDisabledBrowserTest ---------------------------------------
181 181
182 class SubresourceFilterDisabledByDefaultBrowserTest 182 class SubresourceFilterDisabledByDefaultBrowserTest
183 : public InProcessBrowserTest { 183 : public InProcessBrowserTest {
(...skipping 13 matching lines...) Expand all
197 // The RulesetService should not even be instantiated when the feature is 197 // The RulesetService should not even be instantiated when the feature is
198 // disabled, which should be the default state unless there is an override 198 // disabled, which should be the default state unless there is an override
199 // specified in the field trial configuration. 199 // specified in the field trial configuration.
200 IN_PROC_BROWSER_TEST_F(SubresourceFilterDisabledByDefaultBrowserTest, 200 IN_PROC_BROWSER_TEST_F(SubresourceFilterDisabledByDefaultBrowserTest,
201 RulesetServiceNotCreated) { 201 RulesetServiceNotCreated) {
202 EXPECT_FALSE(g_browser_process->subresource_filter_ruleset_service()); 202 EXPECT_FALSE(g_browser_process->subresource_filter_ruleset_service());
203 } 203 }
204 204
205 // SubresourceFilterBrowserTest ----------------------------------------------- 205 // SubresourceFilterBrowserTest -----------------------------------------------
206 206
207 class SubresourceFilterBrowserTestImpl : public InProcessBrowserTest { 207 class SubresourceFilterBrowserTest : public InProcessBrowserTest {
208 public: 208 public:
209 explicit SubresourceFilterBrowserTestImpl(bool measure_performance, 209 SubresourceFilterBrowserTest() {}
210 bool whitelist_site_on_reload) 210 ~SubresourceFilterBrowserTest() override {}
211 : measure_performance_(measure_performance),
212 whitelist_site_on_reload_(whitelist_site_on_reload) {}
213
214 ~SubresourceFilterBrowserTestImpl() override {}
215 211
216 protected: 212 protected:
217 // It would be too late to enable the feature in SetUpOnMainThread(), as it is
218 // called after ChromeBrowserMainParts::PreBrowserStart(), which instantiates
219 // the RulesetService.
220 //
221 // On the other hand, setting up field trials in this method would be too
222 // early, as it is called before BrowserMain, which expects no FieldTrialList
223 // singleton to exist. There are no other hooks we could use either.
224 //
225 // As a workaround, enable the feature here, then enable the feature once
226 // again + set up the field trials later.
227 void SetUpCommandLine(base::CommandLine* command_line) override { 213 void SetUpCommandLine(base::CommandLine* command_line) override {
228 command_line->AppendSwitchASCII( 214 command_line->AppendSwitchASCII(
229 switches::kEnableFeatures, 215 switches::kEnableFeatures,
230 base::JoinString( 216 base::JoinString(
231 {kSafeBrowsingSubresourceFilter.name, "SafeBrowsingV4OnlyEnabled", 217 {kSafeBrowsingSubresourceFilter.name, "SafeBrowsingV4OnlyEnabled",
232 kSafeBrowsingSubresourceFilterExperimentalUI.name}, 218 kSafeBrowsingSubresourceFilterExperimentalUI.name},
233 ",")); 219 ","));
234 } 220 }
235 221
236 void SetUp() override { 222 void SetUp() override {
(...skipping 21 matching lines...) Expand all
258 InProcessBrowserTest::TearDown(); 244 InProcessBrowserTest::TearDown();
259 // Unregister test factories after InProcessBrowserTest::TearDown 245 // Unregister test factories after InProcessBrowserTest::TearDown
260 // (which destructs SafeBrowsingService). 246 // (which destructs SafeBrowsingService).
261 safe_browsing::V4GetHashProtocolManager::RegisterFactory(nullptr); 247 safe_browsing::V4GetHashProtocolManager::RegisterFactory(nullptr);
262 safe_browsing::V4Database::RegisterDatabaseFactoryForTest(nullptr); 248 safe_browsing::V4Database::RegisterDatabaseFactoryForTest(nullptr);
263 safe_browsing::V4Database::RegisterStoreFactoryForTest(nullptr); 249 safe_browsing::V4Database::RegisterStoreFactoryForTest(nullptr);
264 safe_browsing::SafeBrowsingService::RegisterFactory(nullptr); 250 safe_browsing::SafeBrowsingService::RegisterFactory(nullptr);
265 } 251 }
266 252
267 void SetUpOnMainThread() override { 253 void SetUpOnMainThread() override {
268 SetUpActivationFeature();
269 base::FilePath test_data_dir; 254 base::FilePath test_data_dir;
270 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); 255 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
271 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); 256 embedded_test_server()->ServeFilesFromDirectory(test_data_dir);
272 host_resolver()->AddSimulatedFailure("host-with-dns-lookup-failure"); 257 host_resolver()->AddSimulatedFailure("host-with-dns-lookup-failure");
273 host_resolver()->AddRule("*", "127.0.0.1"); 258 host_resolver()->AddRule("*", "127.0.0.1");
274 content::SetupCrossSiteRedirector(embedded_test_server()); 259 content::SetupCrossSiteRedirector(embedded_test_server());
275 ASSERT_TRUE(embedded_test_server()->Start()); 260 ASSERT_TRUE(embedded_test_server()->Start());
276 } 261 ResetConfigurationToEnableOnPhishingSites();
277
278 virtual void SetUpActivationFeature() {
279 ToggleFeatures(base::MakeUnique<ScopedSubresourceFilterFeatureToggle>(
280 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled,
281 kActivationScopeActivationList, kActivationListPhishingInterstitial,
282 measure_performance_ ? "1" : "0", "" /* suppress_notifications */,
283 whitelist_site_on_reload_ ? "true" : "false"));
284 } 262 }
285 263
286 GURL GetTestUrl(const std::string& relative_url) { 264 GURL GetTestUrl(const std::string& relative_url) {
287 return embedded_test_server()->base_url().Resolve(relative_url); 265 return embedded_test_server()->base_url().Resolve(relative_url);
288 } 266 }
289 267
290 void MarkUrlAsMatchingListWithId( 268 void MarkUrlAsMatchingListWithId(
291 const GURL& bad_url, 269 const GURL& bad_url,
292 const safe_browsing::ListIdentifier& list_id, 270 const safe_browsing::ListIdentifier& list_id,
293 safe_browsing::ThreatPatternType threat_pattern_type) { 271 safe_browsing::ThreatPatternType threat_pattern_type) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 test_ruleset_publisher_.SetRuleset(test_ruleset_pair.unindexed)); 349 test_ruleset_publisher_.SetRuleset(test_ruleset_pair.unindexed));
372 } 350 }
373 351
374 void SetRulesetWithRules(const std::vector<proto::UrlRule>& rules) { 352 void SetRulesetWithRules(const std::vector<proto::UrlRule>& rules) {
375 TestRulesetPair test_ruleset_pair; 353 TestRulesetPair test_ruleset_pair;
376 ruleset_creator_.CreateRulesetWithRules(rules, &test_ruleset_pair); 354 ruleset_creator_.CreateRulesetWithRules(rules, &test_ruleset_pair);
377 ASSERT_NO_FATAL_FAILURE( 355 ASSERT_NO_FATAL_FAILURE(
378 test_ruleset_publisher_.SetRuleset(test_ruleset_pair.unindexed)); 356 test_ruleset_publisher_.SetRuleset(test_ruleset_pair.unindexed));
379 } 357 }
380 358
381 void ToggleFeatures( 359 void ResetConfiguration(Configuration config) {
382 std::unique_ptr<ScopedSubresourceFilterFeatureToggle> features) { 360 scoped_configuration_.ResetConfiguration(std::move(config));
383 scoped_feature_toggle_ = std::move(features); 361 }
362
363 void ResetConfigurationToEnableOnPhishingSites(
364 bool measure_performance = false,
365 bool whitelist_site_on_reload = false) {
366 Configuration config(
367 subresource_filter::ActivationLevel::ENABLED,
368 subresource_filter::ActivationScope::ACTIVATION_LIST,
369 subresource_filter::ActivationList::PHISHING_INTERSTITIAL);
370 config.performance_measurement_rate = measure_performance ? 1.0 : 0.0;
371 config.should_whitelist_site_on_reload = whitelist_site_on_reload;
372 ResetConfiguration(std::move(config));
384 } 373 }
385 374
386 private: 375 private:
387 TestRulesetCreator ruleset_creator_; 376 TestRulesetCreator ruleset_creator_;
388 377 ScopedSubresourceFilterConfigurator scoped_configuration_;
389 std::unique_ptr<ScopedSubresourceFilterFeatureToggle> scoped_feature_toggle_;
390 TestRulesetPublisher test_ruleset_publisher_; 378 TestRulesetPublisher test_ruleset_publisher_;
391 const bool measure_performance_;
392 const bool whitelist_site_on_reload_;
393 379
394 std::unique_ptr<safe_browsing::TestSafeBrowsingServiceFactory> sb_factory_; 380 std::unique_ptr<safe_browsing::TestSafeBrowsingServiceFactory> sb_factory_;
395 // Owned by the V4Database. 381 // Owned by the V4Database.
396 safe_browsing::TestV4DatabaseFactory* v4_db_factory_; 382 safe_browsing::TestV4DatabaseFactory* v4_db_factory_;
397 // Owned by the V4GetHashProtocolManager. 383 // Owned by the V4GetHashProtocolManager.
398 safe_browsing::TestV4GetHashProtocolManagerFactory* v4_get_hash_factory_; 384 safe_browsing::TestV4GetHashProtocolManagerFactory* v4_get_hash_factory_;
399 385
400 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterBrowserTestImpl); 386 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterBrowserTest);
401 };
402
403 class SubresourceFilterBrowserTest : public SubresourceFilterBrowserTestImpl {
404 public:
405 SubresourceFilterBrowserTest()
406 : SubresourceFilterBrowserTestImpl(false, false) {}
407 };
408
409 // TODO(pkalinnikov): It should be possible to have only one fixture, i.e.,
410 // SubresourceFilterBrowserTest, unsetting |measure_performance| by default, and
411 // providing a method to switch it on. However, the current implementation of
412 // ScopedSubresourceFilterFeatureToggle in use pollutes the global
413 // FieldTrialList in such a way that variation parameters can not be reassigned.
414 class SubresourceFilterWithPerformanceMeasurementBrowserTest
415 : public SubresourceFilterBrowserTestImpl {
416 public:
417 SubresourceFilterWithPerformanceMeasurementBrowserTest()
418 : SubresourceFilterBrowserTestImpl(true, false) {}
419 };
420
421 class SubresourceFilterWhitelistSiteOnReloadBrowserTest
422 : public SubresourceFilterBrowserTestImpl {
423 public:
424 SubresourceFilterWhitelistSiteOnReloadBrowserTest()
425 : SubresourceFilterBrowserTestImpl(false, true) {}
426 }; 387 };
427 388
428 enum WebSocketCreationPolicy { 389 enum WebSocketCreationPolicy {
429 IN_MAIN_FRAME, 390 IN_MAIN_FRAME,
430 IN_WORKER, 391 IN_WORKER,
431 }; 392 };
432 class SubresourceFilterWebSocketBrowserTest 393 class SubresourceFilterWebSocketBrowserTest
433 : public SubresourceFilterBrowserTestImpl, 394 : public SubresourceFilterBrowserTest,
434 public ::testing::WithParamInterface<WebSocketCreationPolicy> { 395 public ::testing::WithParamInterface<WebSocketCreationPolicy> {
435 public: 396 public:
436 SubresourceFilterWebSocketBrowserTest() 397 SubresourceFilterWebSocketBrowserTest() {}
437 : SubresourceFilterBrowserTestImpl(false, false) {}
438 398
439 void SetUpOnMainThread() override { 399 void SetUpOnMainThread() override {
440 SubresourceFilterBrowserTestImpl::SetUpOnMainThread(); 400 SubresourceFilterBrowserTest::SetUpOnMainThread();
441 websocket_test_server_ = base::MakeUnique<net::SpawnedTestServer>( 401 websocket_test_server_ = base::MakeUnique<net::SpawnedTestServer>(
442 net::SpawnedTestServer::TYPE_WS, net::SpawnedTestServer::kLocalhost, 402 net::SpawnedTestServer::TYPE_WS, net::SpawnedTestServer::kLocalhost,
443 net::GetWebSocketTestDataDirectory()); 403 net::GetWebSocketTestDataDirectory());
444 ASSERT_TRUE(websocket_test_server_->Start()); 404 ASSERT_TRUE(websocket_test_server_->Start());
445 } 405 }
446 406
447 net::SpawnedTestServer* websocket_test_server() { 407 net::SpawnedTestServer* websocket_test_server() {
448 return websocket_test_server_.get(); 408 return websocket_test_server_.get();
449 } 409 }
450 410
(...skipping 10 matching lines...) Expand all
461 browser()->tab_strip_model()->GetActiveWebContents(), 421 browser()->tab_strip_model()->GetActiveWebContents(),
462 base::StringPrintf("connectWebSocket('%s');", url.spec().c_str()), 422 base::StringPrintf("connectWebSocket('%s');", url.spec().c_str()),
463 &websocket_connection_succeeded)); 423 &websocket_connection_succeeded));
464 EXPECT_EQ(expect_connection_success, websocket_connection_succeeded); 424 EXPECT_EQ(expect_connection_success, websocket_connection_succeeded);
465 } 425 }
466 426
467 private: 427 private:
468 std::unique_ptr<net::SpawnedTestServer> websocket_test_server_; 428 std::unique_ptr<net::SpawnedTestServer> websocket_test_server_;
469 }; 429 };
470 430
471 #if defined(GOOGLE_CHROME_BUILD)
472 class SubresourceFilterListBrowserTest
473 : public SubresourceFilterBrowserTestImpl {
474 public:
475 SubresourceFilterListBrowserTest()
476 : SubresourceFilterBrowserTestImpl(false, false) {}
477
478 void SetUpActivationFeature() override {
479 ToggleFeatures(base::MakeUnique<ScopedSubresourceFilterFeatureToggle>(
480 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled,
481 kActivationScopeActivationList, kActivationListSubresourceFilter, "0",
482 "" /* suppress_notifications */, "false"));
483 }
484 };
485 #endif
486 431
487 // Tests ----------------------------------------------------------------------- 432 // Tests -----------------------------------------------------------------------
488 433
489 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, MainFrameActivation) { 434 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, MainFrameActivation) {
490 GURL url(GetTestUrl("subresource_filter/frame_with_included_script.html")); 435 GURL url(GetTestUrl("subresource_filter/frame_with_included_script.html"));
491 ConfigureAsPhishingURL(url); 436 ConfigureAsPhishingURL(url);
492 ASSERT_NO_FATAL_FAILURE(SetRulesetToDisallowURLsWithPathSuffix( 437 ASSERT_NO_FATAL_FAILURE(SetRulesetToDisallowURLsWithPathSuffix(
493 "suffix-that-does-not-match-anything")); 438 "suffix-that-does-not-match-anything"));
494 ui_test_utils::NavigateToURL(browser(), url); 439 ui_test_utils::NavigateToURL(browser(), url);
495 EXPECT_TRUE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); 440 EXPECT_TRUE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame()));
496 441
497 ASSERT_NO_FATAL_FAILURE( 442 ASSERT_NO_FATAL_FAILURE(
498 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); 443 SetRulesetToDisallowURLsWithPathSuffix("included_script.js"));
499 ui_test_utils::NavigateToURL(browser(), url); 444 ui_test_utils::NavigateToURL(browser(), url);
500 EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); 445 EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame()));
501 446
502 // The main frame document should never be filtered. 447 // The main frame document should never be filtered.
503 SetRulesetToDisallowURLsWithPathSuffix("frame_with_included_script.html"); 448 SetRulesetToDisallowURLsWithPathSuffix("frame_with_included_script.html");
504 ui_test_utils::NavigateToURL(browser(), url); 449 ui_test_utils::NavigateToURL(browser(), url);
505 EXPECT_TRUE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); 450 EXPECT_TRUE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame()));
506 } 451 }
507 452
508 #if defined(GOOGLE_CHROME_BUILD) 453 #if defined(GOOGLE_CHROME_BUILD)
509 IN_PROC_BROWSER_TEST_F(SubresourceFilterListBrowserTest, MainFrameActivation) { 454 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest,
455 MainFrameActivation_SubresourceFilterList) {
510 GURL url(GetTestUrl("subresource_filter/frame_with_included_script.html")); 456 GURL url(GetTestUrl("subresource_filter/frame_with_included_script.html"));
511 ConfigureAsSubresourceFilterOnlyURL(url); 457 ConfigureAsSubresourceFilterOnlyURL(url);
512 ASSERT_NO_FATAL_FAILURE(SetRulesetToDisallowURLsWithPathSuffix( 458 ASSERT_NO_FATAL_FAILURE(SetRulesetToDisallowURLsWithPathSuffix(
513 "suffix-that-does-not-match-anything")); 459 "suffix-that-does-not-match-anything"));
460
461 Configuration config(subresource_filter::ActivationLevel::ENABLED,
462 subresource_filter::ActivationScope::ACTIVATION_LIST,
463 subresource_filter::ActivationList::SUBRESOURCE_FILTER);
464 ResetConfiguration(std::move(config));
465
514 ui_test_utils::NavigateToURL(browser(), url); 466 ui_test_utils::NavigateToURL(browser(), url);
515 EXPECT_TRUE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); 467 EXPECT_TRUE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame()));
516 468
517 ASSERT_NO_FATAL_FAILURE( 469 ASSERT_NO_FATAL_FAILURE(
518 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); 470 SetRulesetToDisallowURLsWithPathSuffix("included_script.js"));
519 ui_test_utils::NavigateToURL(browser(), url); 471 ui_test_utils::NavigateToURL(browser(), url);
520 EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); 472 EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame()));
521 473
522 // The main frame document should never be filtered. 474 // The main frame document should never be filtered.
523 SetRulesetToDisallowURLsWithPathSuffix("frame_with_included_script.html"); 475 SetRulesetToDisallowURLsWithPathSuffix("frame_with_included_script.html");
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 1050
1099 // Force a navigation to another page, which flushes page load metrics for the 1051 // Force a navigation to another page, which flushes page load metrics for the
1100 // previous page load. 1052 // previous page load.
1101 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); 1053 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));
1102 1054
1103 // Make sure that pages that have subresource filtered in child frames are 1055 // Make sure that pages that have subresource filtered in child frames are
1104 // also counted. 1056 // also counted.
1105 tester.ExpectTotalCount(internal::kHistogramSubresourceFilterCount, 1); 1057 tester.ExpectTotalCount(internal::kHistogramSubresourceFilterCount, 1);
1106 } 1058 }
1107 1059
1108 IN_PROC_BROWSER_TEST_F(SubresourceFilterWithPerformanceMeasurementBrowserTest, 1060 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest,
1109 ExpectHistogramsAreRecorded) { 1061 ExpectPerformanceHistogramsAreRecorded) {
1110 ASSERT_NO_FATAL_FAILURE( 1062 ASSERT_NO_FATAL_FAILURE(
1111 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); 1063 SetRulesetToDisallowURLsWithPathSuffix("included_script.js"));
1064 ResetConfigurationToEnableOnPhishingSites(
1065 true /* measure_performance */, false /* whitelist_site_on_reload */);
1112 const GURL url = GetTestUrl(kTestFrameSetPath); 1066 const GURL url = GetTestUrl(kTestFrameSetPath);
1113 ConfigureAsPhishingURL(url); 1067 ConfigureAsPhishingURL(url);
1114 1068
1115 base::HistogramTester tester; 1069 base::HistogramTester tester;
1116 ui_test_utils::NavigateToURL(browser(), url); 1070 ui_test_utils::NavigateToURL(browser(), url);
1117 1071
1118 ExpectHistogramsAreRecordedForTestFrameSet( 1072 ExpectHistogramsAreRecordedForTestFrameSet(
1119 tester, true /* expect_performance_measurements */); 1073 tester, true /* expect_performance_measurements */);
1120 } 1074 }
1121 1075
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 internal::kHistogramSubresourceFilterActivationDecision, 1139 internal::kHistogramSubresourceFilterActivationDecision,
1186 static_cast<int>(ActivationDecision::ACTIVATED), 2); 1140 static_cast<int>(ActivationDecision::ACTIVATED), 2);
1187 1141
1188 tester.ExpectTotalCount( 1142 tester.ExpectTotalCount(
1189 internal::kHistogramSubresourceFilterActivationDecisionReload, 1); 1143 internal::kHistogramSubresourceFilterActivationDecisionReload, 1);
1190 tester.ExpectBucketCount( 1144 tester.ExpectBucketCount(
1191 internal::kHistogramSubresourceFilterActivationDecisionReload, 1145 internal::kHistogramSubresourceFilterActivationDecisionReload,
1192 static_cast<int>(ActivationDecision::ACTIVATED), 1); 1146 static_cast<int>(ActivationDecision::ACTIVATED), 1);
1193 } 1147 }
1194 1148
1195 IN_PROC_BROWSER_TEST_F(SubresourceFilterWhitelistSiteOnReloadBrowserTest, 1149 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest,
1196 ActivationDisabledOnReload) { 1150 WhiteliseSiteOnReload_ActivationDisabledOnReload) {
1197 GURL url(GetTestUrl("subresource_filter/frame_with_included_script.html")); 1151 GURL url(GetTestUrl("subresource_filter/frame_with_included_script.html"));
1198 ConfigureAsPhishingURL(url); 1152 ConfigureAsPhishingURL(url);
1199 ASSERT_NO_FATAL_FAILURE( 1153 ASSERT_NO_FATAL_FAILURE(
1200 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); 1154 SetRulesetToDisallowURLsWithPathSuffix("included_script.js"));
1201 1155 ResetConfigurationToEnableOnPhishingSites(
1156 false /* measure_performance */, true /* whitelist_site_on_reload */);
1202 base::HistogramTester tester; 1157 base::HistogramTester tester;
1203 ui_test_utils::NavigateToURL(browser(), url); 1158 ui_test_utils::NavigateToURL(browser(), url);
1204 EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); 1159 EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame()));
1205 1160
1206 content::TestNavigationObserver observer( 1161 content::TestNavigationObserver observer(
1207 browser()->tab_strip_model()->GetActiveWebContents(), 1162 browser()->tab_strip_model()->GetActiveWebContents(),
1208 content::MessageLoopRunner::QuitMode::DEFERRED); 1163 content::MessageLoopRunner::QuitMode::DEFERRED);
1209 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); 1164 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB);
1210 observer.Wait(); 1165 observer.Wait();
1211 EXPECT_TRUE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); 1166 EXPECT_TRUE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame()));
1212 1167
1213 tester.ExpectTotalCount( 1168 tester.ExpectTotalCount(
1214 internal::kHistogramSubresourceFilterActivationDecision, 2); 1169 internal::kHistogramSubresourceFilterActivationDecision, 2);
1215 tester.ExpectBucketCount( 1170 tester.ExpectBucketCount(
1216 internal::kHistogramSubresourceFilterActivationDecision, 1171 internal::kHistogramSubresourceFilterActivationDecision,
1217 static_cast<int>(ActivationDecision::ACTIVATED), 1); 1172 static_cast<int>(ActivationDecision::ACTIVATED), 1);
1218 tester.ExpectBucketCount( 1173 tester.ExpectBucketCount(
1219 internal::kHistogramSubresourceFilterActivationDecision, 1174 internal::kHistogramSubresourceFilterActivationDecision,
1220 static_cast<int>(ActivationDecision::URL_WHITELISTED), 1); 1175 static_cast<int>(ActivationDecision::URL_WHITELISTED), 1);
1221 1176
1222 tester.ExpectTotalCount( 1177 tester.ExpectTotalCount(
1223 internal::kHistogramSubresourceFilterActivationDecisionReload, 1); 1178 internal::kHistogramSubresourceFilterActivationDecisionReload, 1);
1224 tester.ExpectBucketCount( 1179 tester.ExpectBucketCount(
1225 internal::kHistogramSubresourceFilterActivationDecisionReload, 1180 internal::kHistogramSubresourceFilterActivationDecisionReload,
1226 static_cast<int>(ActivationDecision::URL_WHITELISTED), 1); 1181 static_cast<int>(ActivationDecision::URL_WHITELISTED), 1);
1227 } 1182 }
1228 1183
1229 IN_PROC_BROWSER_TEST_F(SubresourceFilterWhitelistSiteOnReloadBrowserTest, 1184 IN_PROC_BROWSER_TEST_F(
1230 ActivationDisabledOnReloadFromScript) { 1185 SubresourceFilterBrowserTest,
1186 WhiteliseSiteOnReload_ActivationDisabledOnReloadFromScript) {
1231 GURL url(GetTestUrl("subresource_filter/frame_with_included_script.html")); 1187 GURL url(GetTestUrl("subresource_filter/frame_with_included_script.html"));
1232 ConfigureAsPhishingURL(url); 1188 ConfigureAsPhishingURL(url);
1233 ASSERT_NO_FATAL_FAILURE( 1189 ASSERT_NO_FATAL_FAILURE(
1234 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); 1190 SetRulesetToDisallowURLsWithPathSuffix("included_script.js"));
1235 1191 ResetConfigurationToEnableOnPhishingSites(
1192 false /* measure_performance */, true /* whitelist_site_on_reload */);
1236 base::HistogramTester tester; 1193 base::HistogramTester tester;
1237 ui_test_utils::NavigateToURL(browser(), url); 1194 ui_test_utils::NavigateToURL(browser(), url);
1238 EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); 1195 EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame()));
1239 1196
1240 content::TestNavigationObserver observer( 1197 content::TestNavigationObserver observer(
1241 browser()->tab_strip_model()->GetActiveWebContents(), 1198 browser()->tab_strip_model()->GetActiveWebContents(),
1242 content::MessageLoopRunner::QuitMode::DEFERRED); 1199 content::MessageLoopRunner::QuitMode::DEFERRED);
1243 ASSERT_TRUE(content::ExecuteScript( 1200 ASSERT_TRUE(content::ExecuteScript(
1244 browser()->tab_strip_model()->GetActiveWebContents(), 1201 browser()->tab_strip_model()->GetActiveWebContents(),
1245 "location.reload();")); 1202 "location.reload();"));
1246 observer.Wait(); 1203 observer.Wait();
1247 EXPECT_TRUE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); 1204 EXPECT_TRUE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame()));
1248 1205
1249 tester.ExpectTotalCount( 1206 tester.ExpectTotalCount(
1250 internal::kHistogramSubresourceFilterActivationDecision, 2); 1207 internal::kHistogramSubresourceFilterActivationDecision, 2);
1251 tester.ExpectBucketCount( 1208 tester.ExpectBucketCount(
1252 internal::kHistogramSubresourceFilterActivationDecision, 1209 internal::kHistogramSubresourceFilterActivationDecision,
1253 static_cast<int>(ActivationDecision::ACTIVATED), 1); 1210 static_cast<int>(ActivationDecision::ACTIVATED), 1);
1254 tester.ExpectBucketCount( 1211 tester.ExpectBucketCount(
1255 internal::kHistogramSubresourceFilterActivationDecision, 1212 internal::kHistogramSubresourceFilterActivationDecision,
1256 static_cast<int>(ActivationDecision::URL_WHITELISTED), 1); 1213 static_cast<int>(ActivationDecision::URL_WHITELISTED), 1);
1257 1214
1258 tester.ExpectTotalCount( 1215 tester.ExpectTotalCount(
1259 internal::kHistogramSubresourceFilterActivationDecisionReload, 1); 1216 internal::kHistogramSubresourceFilterActivationDecisionReload, 1);
1260 tester.ExpectBucketCount( 1217 tester.ExpectBucketCount(
1261 internal::kHistogramSubresourceFilterActivationDecisionReload, 1218 internal::kHistogramSubresourceFilterActivationDecisionReload,
1262 static_cast<int>(ActivationDecision::URL_WHITELISTED), 1); 1219 static_cast<int>(ActivationDecision::URL_WHITELISTED), 1);
1263 } 1220 }
1264 1221
1265 IN_PROC_BROWSER_TEST_F(SubresourceFilterWhitelistSiteOnReloadBrowserTest, 1222 IN_PROC_BROWSER_TEST_F(
1266 ActivationDisabledOnNavigationToSameURL) { 1223 SubresourceFilterBrowserTest,
1224 WhiteliseSiteOnReload_ActivationDisabledOnNavigationToSameURL) {
1267 GURL url(GetTestUrl("subresource_filter/frame_with_included_script.html")); 1225 GURL url(GetTestUrl("subresource_filter/frame_with_included_script.html"));
1268 ConfigureAsPhishingURL(url); 1226 ConfigureAsPhishingURL(url);
1269 ASSERT_NO_FATAL_FAILURE( 1227 ASSERT_NO_FATAL_FAILURE(
1270 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); 1228 SetRulesetToDisallowURLsWithPathSuffix("included_script.js"));
1271 1229 ResetConfigurationToEnableOnPhishingSites(
1230 false /* measure_performance */, true /* whitelist_site_on_reload */);
1272 base::HistogramTester tester; 1231 base::HistogramTester tester;
1273 ui_test_utils::NavigateToURL(browser(), url); 1232 ui_test_utils::NavigateToURL(browser(), url);
1274 EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); 1233 EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame()));
1275 1234
1276 content::TestNavigationObserver observer( 1235 content::TestNavigationObserver observer(
1277 browser()->tab_strip_model()->GetActiveWebContents(), 1236 browser()->tab_strip_model()->GetActiveWebContents(),
1278 content::MessageLoopRunner::QuitMode::DEFERRED); 1237 content::MessageLoopRunner::QuitMode::DEFERRED);
1279 std::string nav_frame_script = "location.href = '" + url.spec() + "';"; 1238 std::string nav_frame_script = "location.href = '" + url.spec() + "';";
1280 ASSERT_TRUE(content::ExecuteScript( 1239 ASSERT_TRUE(content::ExecuteScript(
1281 browser()->tab_strip_model()->GetActiveWebContents(), nav_frame_script)); 1240 browser()->tab_strip_model()->GetActiveWebContents(), nav_frame_script));
(...skipping 10 matching lines...) Expand all
1292 static_cast<int>(ActivationDecision::URL_WHITELISTED), 1); 1251 static_cast<int>(ActivationDecision::URL_WHITELISTED), 1);
1293 1252
1294 tester.ExpectTotalCount( 1253 tester.ExpectTotalCount(
1295 internal::kHistogramSubresourceFilterActivationDecisionReload, 1); 1254 internal::kHistogramSubresourceFilterActivationDecisionReload, 1);
1296 tester.ExpectBucketCount( 1255 tester.ExpectBucketCount(
1297 internal::kHistogramSubresourceFilterActivationDecisionReload, 1256 internal::kHistogramSubresourceFilterActivationDecisionReload,
1298 static_cast<int>(ActivationDecision::URL_WHITELISTED), 1); 1257 static_cast<int>(ActivationDecision::URL_WHITELISTED), 1);
1299 } 1258 }
1300 1259
1301 #if defined(GOOGLE_CHROME_BUILD) 1260 #if defined(GOOGLE_CHROME_BUILD)
1302 // This test is only enabled when GOOGLE_CHROME_BUILD is true because the store 1261 // These tests are only enabled when GOOGLE_CHROME_BUILD is true because the
1303 // that this test uses is only populated on GOOGLE_CHROME_BUILD builds. 1262 // store that this test uses is only populated on GOOGLE_CHROME_BUILD builds.
1304 IN_PROC_BROWSER_TEST_F( 1263 IN_PROC_BROWSER_TEST_F(
1305 SubresourceFilterBrowserTest, 1264 SubresourceFilterBrowserTest,
1306 ExpectRedirectPatternHistogramsAreRecordedForSubresourceFilterOnlyMatch) { 1265 ExpectRedirectPatternHistogramsAreRecordedForSubresourceFilterOnlyMatch) {
1307 ASSERT_NO_FATAL_FAILURE(SetRulesetToDisallowURLsWithPathSuffix( 1266 ASSERT_NO_FATAL_FAILURE(SetRulesetToDisallowURLsWithPathSuffix(
1308 "suffix-that-does-not-match-anything")); 1267 "suffix-that-does-not-match-anything"));
1309 1268
1310 GURL url(GetTestUrl("subresource_filter/frame_with_included_script.html")); 1269 GURL url(GetTestUrl("subresource_filter/frame_with_included_script.html"));
1311 ConfigureAsSubresourceFilterOnlyURL(url); 1270 ConfigureAsSubresourceFilterOnlyURL(url);
1312 1271
1313 base::HistogramTester tester; 1272 base::HistogramTester tester;
(...skipping 27 matching lines...) Expand all
1341 std::string(kSubresourceFilterOnlySuffix)), 1300 std::string(kSubresourceFilterOnlySuffix)),
1342 ::testing::IsEmpty()); 1301 ::testing::IsEmpty());
1343 1302
1344 EXPECT_THAT(tester.GetAllSamples(std::string(kNavigationChainSize) + 1303 EXPECT_THAT(tester.GetAllSamples(std::string(kNavigationChainSize) +
1345 std::string(kSubresourceFilterOnlySuffix)), 1304 std::string(kSubresourceFilterOnlySuffix)),
1346 ::testing::IsEmpty()); 1305 ::testing::IsEmpty());
1347 } 1306 }
1348 #endif 1307 #endif
1349 1308
1350 } // namespace subresource_filter 1309 } // namespace subresource_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698