OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/browser/event_listener_map.h" | 5 #include "extensions/browser/event_listener_map.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "content/public/test/mock_render_process_host.h" | 8 #include "content/public/test/mock_render_process_host.h" |
9 #include "content/public/test/test_browser_context.h" | 9 #include "content/public/test/test_browser_context.h" |
10 #include "extensions/browser/event_router.h" | 10 #include "extensions/browser/event_router.h" |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 std::set<const EventListener*> targets(listeners_->GetEventListeners(*event)); | 234 std::set<const EventListener*> targets(listeners_->GetEventListeners(*event)); |
235 ASSERT_EQ(0u, targets.size()); | 235 ASSERT_EQ(0u, targets.size()); |
236 } | 236 } |
237 | 237 |
238 TEST_F(EventListenerMapTest, HostSuffixFilterEquality) { | 238 TEST_F(EventListenerMapTest, HostSuffixFilterEquality) { |
239 scoped_ptr<DictionaryValue> filter1(CreateHostSuffixFilter("google.com")); | 239 scoped_ptr<DictionaryValue> filter1(CreateHostSuffixFilter("google.com")); |
240 scoped_ptr<DictionaryValue> filter2(CreateHostSuffixFilter("google.com")); | 240 scoped_ptr<DictionaryValue> filter2(CreateHostSuffixFilter("google.com")); |
241 ASSERT_TRUE(filter1->Equals(filter2.get())); | 241 ASSERT_TRUE(filter1->Equals(filter2.get())); |
242 } | 242 } |
243 | 243 |
244 TEST_F(EventListenerMapTest, RemoveLazyListeners) { | 244 TEST_F(EventListenerMapTest, RemoveListenersForExtension) { |
245 listeners_->AddListener(EventListener::ForExtension( | 245 listeners_->AddListener(EventListener::ForExtension( |
246 kEvent1Name, kExt1Id, NULL, CreateHostSuffixFilter("google.com"))); | 246 kEvent1Name, kExt1Id, NULL, CreateHostSuffixFilter("google.com"))); |
247 listeners_->AddListener(EventListener::ForExtension( | 247 listeners_->AddListener(EventListener::ForExtension( |
248 kEvent2Name, kExt1Id, NULL, CreateHostSuffixFilter("google.com"))); | 248 kEvent2Name, kExt1Id, NULL, CreateHostSuffixFilter("google.com"))); |
249 | 249 |
250 listeners_->RemoveLazyListenersForExtension(kExt1Id); | 250 listeners_->RemoveListenersForExtension(kExt1Id); |
251 | 251 |
252 scoped_ptr<Event> event(CreateNamedEvent(kEvent1Name)); | 252 scoped_ptr<Event> event(CreateNamedEvent(kEvent1Name)); |
253 event->filter_info.SetURL(GURL("http://www.google.com")); | 253 event->filter_info.SetURL(GURL("http://www.google.com")); |
254 std::set<const EventListener*> targets(listeners_->GetEventListeners(*event)); | 254 std::set<const EventListener*> targets(listeners_->GetEventListeners(*event)); |
255 ASSERT_EQ(0u, targets.size()); | 255 ASSERT_EQ(0u, targets.size()); |
256 | 256 |
257 event->event_name = kEvent2Name; | 257 event->event_name = kEvent2Name; |
258 targets = listeners_->GetEventListeners(*event); | 258 targets = listeners_->GetEventListeners(*event); |
259 ASSERT_EQ(0u, targets.size()); | 259 ASSERT_EQ(0u, targets.size()); |
260 } | 260 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 kEvent1Name, kExt1Id, process_.get(), scoped_ptr<DictionaryValue>())); | 336 kEvent1Name, kExt1Id, process_.get(), scoped_ptr<DictionaryValue>())); |
337 // Lazy listener. | 337 // Lazy listener. |
338 listeners_->AddListener(EventListener::ForExtension( | 338 listeners_->AddListener(EventListener::ForExtension( |
339 kEvent1Name, kExt1Id, NULL, scoped_ptr<DictionaryValue>())); | 339 kEvent1Name, kExt1Id, NULL, scoped_ptr<DictionaryValue>())); |
340 | 340 |
341 ASSERT_FALSE(listeners_->HasListenerForExtension(kExt1Id, kEvent2Name)); | 341 ASSERT_FALSE(listeners_->HasListenerForExtension(kExt1Id, kEvent2Name)); |
342 ASSERT_TRUE(listeners_->HasListenerForExtension(kExt1Id, kEvent1Name)); | 342 ASSERT_TRUE(listeners_->HasListenerForExtension(kExt1Id, kEvent1Name)); |
343 ASSERT_FALSE(listeners_->HasListenerForExtension(kExt2Id, kEvent1Name)); | 343 ASSERT_FALSE(listeners_->HasListenerForExtension(kExt2Id, kEvent1Name)); |
344 listeners_->RemoveListenersForProcess(process_.get()); | 344 listeners_->RemoveListenersForProcess(process_.get()); |
345 ASSERT_TRUE(listeners_->HasListenerForExtension(kExt1Id, kEvent1Name)); | 345 ASSERT_TRUE(listeners_->HasListenerForExtension(kExt1Id, kEvent1Name)); |
346 listeners_->RemoveLazyListenersForExtension(kExt1Id); | 346 listeners_->RemoveListenersForExtension(kExt1Id); |
347 ASSERT_FALSE(listeners_->HasListenerForExtension(kExt1Id, kEvent1Name)); | 347 ASSERT_FALSE(listeners_->HasListenerForExtension(kExt1Id, kEvent1Name)); |
348 } | 348 } |
349 | 349 |
350 TEST_F(EventListenerMapTest, AddLazyListenersFromPreferences) { | 350 TEST_F(EventListenerMapTest, AddLazyListenersFromPreferences) { |
351 scoped_ptr<DictionaryValue> filter1(CreateHostSuffixFilter("google.com")); | 351 scoped_ptr<DictionaryValue> filter1(CreateHostSuffixFilter("google.com")); |
352 scoped_ptr<DictionaryValue> filter2(CreateHostSuffixFilter("yahoo.com")); | 352 scoped_ptr<DictionaryValue> filter2(CreateHostSuffixFilter("yahoo.com")); |
353 | 353 |
354 DictionaryValue filtered_listeners; | 354 DictionaryValue filtered_listeners; |
355 ListValue* filter_list = new ListValue(); | 355 ListValue* filter_list = new ListValue(); |
356 filtered_listeners.Set(kEvent1Name, filter_list); | 356 filtered_listeners.Set(kEvent1Name, filter_list); |
(...skipping 23 matching lines...) Expand all Loading... |
380 | 380 |
381 scoped_ptr<Event> event(CreateEvent(kEvent1Name, | 381 scoped_ptr<Event> event(CreateEvent(kEvent1Name, |
382 GURL("http://www.google.com"))); | 382 GURL("http://www.google.com"))); |
383 std::set<const EventListener*> targets(listeners_->GetEventListeners(*event)); | 383 std::set<const EventListener*> targets(listeners_->GetEventListeners(*event)); |
384 ASSERT_EQ(0u, targets.size()); | 384 ASSERT_EQ(0u, targets.size()); |
385 } | 385 } |
386 | 386 |
387 } // namespace | 387 } // namespace |
388 | 388 |
389 } // namespace extensions | 389 } // namespace extensions |
OLD | NEW |