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 |
| 11 #include "base/memory/ptr_util.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
12 #include "extensions/common/event_filtering_info.h" | 13 #include "extensions/common/event_filtering_info.h" |
13 #include "extensions/common/event_matcher.h" | 14 #include "extensions/common/event_matcher.h" |
14 #include "ipc/ipc_message.h" | 15 #include "ipc/ipc_message.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 using base::DictionaryValue; | 18 using base::DictionaryValue; |
18 using base::ListValue; | 19 using base::ListValue; |
19 using base::Value; | 20 using base::Value; |
20 | 21 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 int id2 = event_filter_.AddEventMatcher("event1", AllURLs()); | 208 int id2 = event_filter_.AddEventMatcher("event1", AllURLs()); |
208 int id3 = event_filter_.AddEventMatcher("event2", AllURLs()); | 209 int id3 = event_filter_.AddEventMatcher("event2", AllURLs()); |
209 | 210 |
210 ASSERT_EQ("event1", event_filter_.RemoveEventMatcher(id1)); | 211 ASSERT_EQ("event1", event_filter_.RemoveEventMatcher(id1)); |
211 ASSERT_EQ("event1", event_filter_.RemoveEventMatcher(id2)); | 212 ASSERT_EQ("event1", event_filter_.RemoveEventMatcher(id2)); |
212 ASSERT_EQ("event2", event_filter_.RemoveEventMatcher(id3)); | 213 ASSERT_EQ("event2", event_filter_.RemoveEventMatcher(id3)); |
213 } | 214 } |
214 | 215 |
215 TEST_F(EventFilterUnittest, InvalidURLFilterCantBeAdded) { | 216 TEST_F(EventFilterUnittest, InvalidURLFilterCantBeAdded) { |
216 std::unique_ptr<base::ListValue> filter_list(new base::ListValue()); | 217 std::unique_ptr<base::ListValue> filter_list(new base::ListValue()); |
217 filter_list->Append(new base::ListValue()); // Should be a dict. | 218 filter_list->Append( |
| 219 base::MakeUnique<base::ListValue>()); // Should be a dict. |
218 std::unique_ptr<EventMatcher> matcher( | 220 std::unique_ptr<EventMatcher> matcher( |
219 MatcherFromURLFilterList(std::move(filter_list))); | 221 MatcherFromURLFilterList(std::move(filter_list))); |
220 int id1 = event_filter_.AddEventMatcher("event1", std::move(matcher)); | 222 int id1 = event_filter_.AddEventMatcher("event1", std::move(matcher)); |
221 EXPECT_TRUE(event_filter_.IsURLMatcherEmpty()); | 223 EXPECT_TRUE(event_filter_.IsURLMatcherEmpty()); |
222 ASSERT_EQ(-1, id1); | 224 ASSERT_EQ(-1, id1); |
223 } | 225 } |
224 | 226 |
225 TEST_F(EventFilterUnittest, EmptyListOfURLFiltersMatchesAllURLs) { | 227 TEST_F(EventFilterUnittest, EmptyListOfURLFiltersMatchesAllURLs) { |
226 std::unique_ptr<base::ListValue> filter_list(new base::ListValue()); | 228 std::unique_ptr<base::ListValue> filter_list(new base::ListValue()); |
227 std::unique_ptr<EventMatcher> matcher( | 229 std::unique_ptr<EventMatcher> matcher( |
(...skipping 28 matching lines...) Expand all Loading... |
256 std::unique_ptr<EventMatcher> matcher(MatcherFromURLFilterList( | 258 std::unique_ptr<EventMatcher> matcher(MatcherFromURLFilterList( |
257 ValueAsList(std::unique_ptr<Value>(new DictionaryValue())))); | 259 ValueAsList(std::unique_ptr<Value>(new DictionaryValue())))); |
258 int id = event_filter_.AddEventMatcher("event1", std::move(matcher)); | 260 int id = event_filter_.AddEventMatcher("event1", std::move(matcher)); |
259 std::set<int> matches = event_filter_.MatchEvent( | 261 std::set<int> matches = event_filter_.MatchEvent( |
260 "event1", empty_url_event_, MSG_ROUTING_NONE); | 262 "event1", empty_url_event_, MSG_ROUTING_NONE); |
261 ASSERT_EQ(1u, matches.size()); | 263 ASSERT_EQ(1u, matches.size()); |
262 ASSERT_EQ(1u, matches.count(id)); | 264 ASSERT_EQ(1u, matches.count(id)); |
263 } | 265 } |
264 | 266 |
265 } // namespace extensions | 267 } // namespace extensions |
OLD | NEW |