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

Side by Side Diff: components/subresource_filter/core/browser/ruleset_service_unittest.cc

Issue 2793993002: [subresource_filter] Replace KMP by std::search. (Closed)
Patch Set: Fix DCHECK. 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 "components/subresource_filter/core/browser/ruleset_service.h" 5 #include "components/subresource_filter/core/browser/ruleset_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 #include <tuple> 12 #include <tuple>
13 #include <utility> 13 #include <utility>
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/environment.h" 16 #include "base/environment.h"
17 #include "base/files/file_util.h" 17 #include "base/files/file_util.h"
18 #include "base/files/scoped_temp_dir.h" 18 #include "base/files/scoped_temp_dir.h"
19 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/memory/ptr_util.h" 20 #include "base/memory/ptr_util.h"
21 #include "base/numerics/safe_conversions.h" 21 #include "base/numerics/safe_conversions.h"
22 #include "base/run_loop.h" 22 #include "base/run_loop.h"
23 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
24 #include "base/test/histogram_tester.h" 24 #include "base/test/histogram_tester.h"
25 #include "base/test/test_simple_task_runner.h" 25 #include "base/test/test_simple_task_runner.h"
26 #include "base/threading/thread_task_runner_handle.h" 26 #include "base/threading/thread_task_runner_handle.h"
27 #include "build/build_config.h" 27 #include "build/build_config.h"
28 #include "components/prefs/testing_pref_service.h" 28 #include "components/prefs/testing_pref_service.h"
29 #include "components/subresource_filter/core/browser/ruleset_service_delegate.h" 29 #include "components/subresource_filter/core/browser/ruleset_service_delegate.h"
30 #include "components/subresource_filter/core/common/proto/rules.pb.h"
30 #include "components/subresource_filter/core/common/test_ruleset_creator.h" 31 #include "components/subresource_filter/core/common/test_ruleset_creator.h"
31 #include "testing/gmock/include/gmock/gmock.h" 32 #include "testing/gmock/include/gmock/gmock.h"
32 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
33 34
34 namespace subresource_filter { 35 namespace subresource_filter {
35 36
36 namespace { 37 namespace {
37 38
38 // Testing constants ---------------------------------------------------------- 39 // Testing constants ----------------------------------------------------------
39 40
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 ASSERT_NO_FATAL_FAILURE(AssertValidRulesetFileWithContents( 653 ASSERT_NO_FATAL_FAILURE(AssertValidRulesetFileWithContents(
653 &mock_delegate()->published_rulesets()[0], 654 &mock_delegate()->published_rulesets()[0],
654 test_ruleset_1().indexed.contents)); 655 test_ruleset_1().indexed.contents));
655 } 656 }
656 657
657 TEST_F(SubresourceFilteringRulesetServiceTest, 658 TEST_F(SubresourceFilteringRulesetServiceTest,
658 NewRuleset_SuccessWithUnsupportedRules) { 659 NewRuleset_SuccessWithUnsupportedRules) {
659 base::HistogramTester histogram_tester; 660 base::HistogramTester histogram_tester;
660 mock_delegate()->SimulateStartupCompleted(); 661 mock_delegate()->SimulateStartupCompleted();
661 662
662 // URL patterns longer than 255 characters are not supported. 663 // The default field values are considered unsupported.
663 const std::string kTooLongSuffix(1000, 'a'); 664 proto::UrlRule unfilled_rule;
665
664 TestRulesetPair ruleset_with_unsupported_rule; 666 TestRulesetPair ruleset_with_unsupported_rule;
665 ASSERT_NO_FATAL_FAILURE( 667 ASSERT_NO_FATAL_FAILURE(
666 test_ruleset_creator() 668 test_ruleset_creator()->CreateUnindexedRulesetWithRules(
667 ->CreateUnindexedRulesetToDisallowURLsWithPathSuffix( 669 {unfilled_rule}, &ruleset_with_unsupported_rule.unindexed));
668 kTooLongSuffix, &ruleset_with_unsupported_rule.unindexed));
669 IndexAndStoreAndPublishUpdatedRuleset(ruleset_with_unsupported_rule, 670 IndexAndStoreAndPublishUpdatedRuleset(ruleset_with_unsupported_rule,
670 kTestContentVersion1); 671 kTestContentVersion1);
671 RunUntilIdle(); 672 RunUntilIdle();
672 673
673 IndexedRulesetVersion stored_version; 674 IndexedRulesetVersion stored_version;
674 stored_version.ReadFromPrefs(prefs()); 675 stored_version.ReadFromPrefs(prefs());
675 EXPECT_EQ(kTestContentVersion1, stored_version.content_version); 676 EXPECT_EQ(kTestContentVersion1, stored_version.content_version);
676 EXPECT_EQ(IndexedRulesetVersion::CurrentFormatVersion(), 677 EXPECT_EQ(IndexedRulesetVersion::CurrentFormatVersion(),
677 stored_version.format_version); 678 stored_version.format_version);
678 EXPECT_FALSE(base::PathExists(GetExpectedSentinelFilePath(stored_version))); 679 EXPECT_FALSE(base::PathExists(GetExpectedSentinelFilePath(stored_version)));
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 mock_delegate()->SimulateStartupCompleted(); 990 mock_delegate()->SimulateStartupCompleted();
990 IndexAndStoreAndPublishUpdatedRuleset(test_ruleset_1(), kTestContentVersion1); 991 IndexAndStoreAndPublishUpdatedRuleset(test_ruleset_1(), kTestContentVersion1);
991 RunUntilIdle(); 992 RunUntilIdle();
992 993
993 ASSERT_EQ(1u, mock_delegate()->published_rulesets().size()); 994 ASSERT_EQ(1u, mock_delegate()->published_rulesets().size());
994 ASSERT_NO_FATAL_FAILURE( 995 ASSERT_NO_FATAL_FAILURE(
995 AssertReadonlyRulesetFile(&mock_delegate()->published_rulesets()[0])); 996 AssertReadonlyRulesetFile(&mock_delegate()->published_rulesets()[0]));
996 } 997 }
997 998
998 } // namespace subresource_filter 999 } // namespace subresource_filter
OLDNEW
« no previous file with comments | « components/subresource_filter/core/browser/BUILD.gn ('k') | components/subresource_filter/core/common/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698