OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "extensions/common/event_filter.h" | 5 #include "extensions/common/event_filter.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 protected: | 32 protected: |
33 std::unique_ptr<base::Value> HostSuffixDict(const std::string& host_suffix) { | 33 std::unique_ptr<base::Value> HostSuffixDict(const std::string& host_suffix) { |
34 std::unique_ptr<base::DictionaryValue> dict(new DictionaryValue()); | 34 std::unique_ptr<base::DictionaryValue> dict(new DictionaryValue()); |
35 dict->Set("hostSuffix", new base::StringValue(host_suffix)); | 35 dict->Set("hostSuffix", new base::StringValue(host_suffix)); |
36 return std::unique_ptr<base::Value>(dict.release()); | 36 return std::unique_ptr<base::Value>(dict.release()); |
37 } | 37 } |
38 | 38 |
39 std::unique_ptr<base::ListValue> ValueAsList( | 39 std::unique_ptr<base::ListValue> ValueAsList( |
40 std::unique_ptr<base::Value> value) { | 40 std::unique_ptr<base::Value> value) { |
41 std::unique_ptr<base::ListValue> result(new base::ListValue()); | 41 std::unique_ptr<base::ListValue> result(new base::ListValue()); |
42 result->Append(value.release()); | 42 result->Append(std::move(value)); |
43 return result; | 43 return result; |
44 } | 44 } |
45 | 45 |
46 std::unique_ptr<EventMatcher> AllURLs() { | 46 std::unique_ptr<EventMatcher> AllURLs() { |
47 return std::unique_ptr<EventMatcher>( | 47 return std::unique_ptr<EventMatcher>( |
48 new EventMatcher(std::unique_ptr<DictionaryValue>(new DictionaryValue), | 48 new EventMatcher(std::unique_ptr<DictionaryValue>(new DictionaryValue), |
49 MSG_ROUTING_NONE)); | 49 MSG_ROUTING_NONE)); |
50 } | 50 } |
51 | 51 |
52 std::unique_ptr<EventMatcher> HostSuffixMatcher( | 52 std::unique_ptr<EventMatcher> HostSuffixMatcher( |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 int id = event_filter_.AddEventMatcher("event1", | 132 int id = event_filter_.AddEventMatcher("event1", |
133 HostSuffixMatcher("google.com")); | 133 HostSuffixMatcher("google.com")); |
134 std::set<int> matches = event_filter_.MatchEvent( | 134 std::set<int> matches = event_filter_.MatchEvent( |
135 "event1", info, MSG_ROUTING_NONE); | 135 "event1", info, MSG_ROUTING_NONE); |
136 ASSERT_EQ(1u, matches.size()); | 136 ASSERT_EQ(1u, matches.size()); |
137 ASSERT_EQ(1u, matches.count(id)); | 137 ASSERT_EQ(1u, matches.count(id)); |
138 } | 138 } |
139 | 139 |
140 TEST_F(EventFilterUnittest, TestMultipleURLFiltersMatchOnAny) { | 140 TEST_F(EventFilterUnittest, TestMultipleURLFiltersMatchOnAny) { |
141 std::unique_ptr<base::ListValue> filters(new base::ListValue()); | 141 std::unique_ptr<base::ListValue> filters(new base::ListValue()); |
142 filters->Append(HostSuffixDict("google.com").release()); | 142 filters->Append(HostSuffixDict("google.com")); |
143 filters->Append(HostSuffixDict("yahoo.com").release()); | 143 filters->Append(HostSuffixDict("yahoo.com")); |
144 | 144 |
145 std::unique_ptr<EventMatcher> matcher( | 145 std::unique_ptr<EventMatcher> matcher( |
146 MatcherFromURLFilterList(std::move(filters))); | 146 MatcherFromURLFilterList(std::move(filters))); |
147 int id = event_filter_.AddEventMatcher("event1", std::move(matcher)); | 147 int id = event_filter_.AddEventMatcher("event1", std::move(matcher)); |
148 | 148 |
149 { | 149 { |
150 std::set<int> matches = event_filter_.MatchEvent("event1", | 150 std::set<int> matches = event_filter_.MatchEvent("event1", |
151 google_event_, MSG_ROUTING_NONE); | 151 google_event_, MSG_ROUTING_NONE); |
152 ASSERT_EQ(1u, matches.size()); | 152 ASSERT_EQ(1u, matches.size()); |
153 ASSERT_EQ(1u, matches.count(id)); | 153 ASSERT_EQ(1u, matches.count(id)); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 std::unique_ptr<EventMatcher> matcher(MatcherFromURLFilterList( | 256 std::unique_ptr<EventMatcher> matcher(MatcherFromURLFilterList( |
257 ValueAsList(std::unique_ptr<Value>(new DictionaryValue())))); | 257 ValueAsList(std::unique_ptr<Value>(new DictionaryValue())))); |
258 int id = event_filter_.AddEventMatcher("event1", std::move(matcher)); | 258 int id = event_filter_.AddEventMatcher("event1", std::move(matcher)); |
259 std::set<int> matches = event_filter_.MatchEvent( | 259 std::set<int> matches = event_filter_.MatchEvent( |
260 "event1", empty_url_event_, MSG_ROUTING_NONE); | 260 "event1", empty_url_event_, MSG_ROUTING_NONE); |
261 ASSERT_EQ(1u, matches.size()); | 261 ASSERT_EQ(1u, matches.size()); |
262 ASSERT_EQ(1u, matches.count(id)); | 262 ASSERT_EQ(1u, matches.count(id)); |
263 } | 263 } |
264 | 264 |
265 } // namespace extensions | 265 } // namespace extensions |
OLD | NEW |