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

Side by Side Diff: components/subresource_filter/core/common/url_pattern_index_unittest.cc

Issue 2894523006: Add instrumentation hooks to mesaure which subresource filter rules are used.
Patch Set: 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
« no previous file with comments | « components/subresource_filter/core/common/url_pattern_index.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/common/url_pattern_index.h" 5 #include "components/subresource_filter/core/common/url_pattern_index.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 const flat::UrlRule* FindMatch( 45 const flat::UrlRule* FindMatch(
46 base::StringPiece url_string, 46 base::StringPiece url_string,
47 base::StringPiece document_origin_string = base::StringPiece(), 47 base::StringPiece document_origin_string = base::StringPiece(),
48 proto::ElementType element_type = kOther, 48 proto::ElementType element_type = kOther,
49 proto::ActivationType activation_type = kNoActivation, 49 proto::ActivationType activation_type = kNoActivation,
50 bool disable_generic_rules = false) { 50 bool disable_generic_rules = false) {
51 const GURL url(url_string); 51 const GURL url(url_string);
52 const url::Origin document_origin = GetOrigin(document_origin_string); 52 const url::Origin document_origin = GetOrigin(document_origin_string);
53 return index_matcher_->FindMatch( 53 return index_matcher_->FindMatch(
54 url, document_origin, element_type, activation_type, 54 url, document_origin, element_type, activation_type,
55 IsThirdParty(url, document_origin), disable_generic_rules); 55 IsThirdParty(url, document_origin), disable_generic_rules, nullptr);
56 } 56 }
57 57
58 bool IsOutOfRange(const flat::UrlRule* rule) const { 58 bool IsOutOfRange(const flat::UrlRule* rule) const {
59 if (!rule) 59 if (!rule)
60 return false; 60 return false;
61 const auto* data = reinterpret_cast<const uint8_t*>(rule); 61 const auto* data = reinterpret_cast<const uint8_t*>(rule);
62 return data < flat_builder_->GetBufferPointer() || 62 return data < flat_builder_->GetBufferPointer() ||
63 data >= flat_builder_->GetBufferPointer() + flat_builder_->GetSize(); 63 data >= flat_builder_->GetBufferPointer() + flat_builder_->GetSize();
64 } 64 }
65 65
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 ASSERT_TRUE(rule_pattern); 698 ASSERT_TRUE(rule_pattern);
699 EXPECT_EQ(url_pattern, 699 EXPECT_EQ(url_pattern,
700 base::StringPiece(rule_pattern->data(), rule_pattern->size())); 700 base::StringPiece(rule_pattern->data(), rule_pattern->size()));
701 } 701 }
702 702
703 EXPECT_FALSE( 703 EXPECT_FALSE(
704 FindMatch("http://example." + std::to_string(kNumOfPatterns) + ".com")); 704 FindMatch("http://example." + std::to_string(kNumOfPatterns) + ".com"));
705 } 705 }
706 706
707 } // namespace subresource_filter 707 } // namespace subresource_filter
OLDNEW
« no previous file with comments | « components/subresource_filter/core/common/url_pattern_index.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698