| 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_router.h" | 5 #include "extensions/browser/event_router.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "content/public/browser/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
| 14 #include "extensions/browser/event_listener_map.h" | 14 #include "extensions/browser/event_listener_map.h" |
| 15 #include "extensions/browser/extensions_test.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 namespace extensions { | 18 namespace extensions { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // A simple mock to keep track of listener additions and removals. | 22 // A simple mock to keep track of listener additions and removals. |
| 22 class MockEventRouterObserver : public EventRouter::Observer { | 23 class MockEventRouterObserver : public EventRouter::Observer { |
| 23 public: | 24 public: |
| 24 MockEventRouterObserver() | 25 MockEventRouterObserver() |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 const GURL& listener_url, | 75 const GURL& listener_url, |
| 75 const std::string& event_name, | 76 const std::string& event_name, |
| 76 content::RenderProcessHost* process, | 77 content::RenderProcessHost* process, |
| 77 base::DictionaryValue* filter) { | 78 base::DictionaryValue* filter) { |
| 78 return EventListener::ForURL( | 79 return EventListener::ForURL( |
| 79 event_name, listener_url, process, make_scoped_ptr(filter)); | 80 event_name, listener_url, process, make_scoped_ptr(filter)); |
| 80 } | 81 } |
| 81 | 82 |
| 82 } // namespace | 83 } // namespace |
| 83 | 84 |
| 84 class EventRouterTest : public testing::Test { | 85 class EventRouterTest : public ExtensionsTest { |
| 85 public: | 86 public: |
| 86 EventRouterTest() | 87 EventRouterTest() |
| 87 : notification_service_(content::NotificationService::Create()) {} | 88 : notification_service_(content::NotificationService::Create()) {} |
| 88 | 89 |
| 89 protected: | 90 protected: |
| 90 // Tests adding and removing observers from EventRouter. | 91 // Tests adding and removing observers from EventRouter. |
| 91 void RunEventRouterObserverTest(const EventListenerConstructor& constructor); | 92 void RunEventRouterObserverTest(const EventListenerConstructor& constructor); |
| 92 | 93 |
| 93 private: | 94 private: |
| 94 scoped_ptr<content::NotificationService> notification_service_; | 95 scoped_ptr<content::NotificationService> notification_service_; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 RunEventRouterObserverTest( | 164 RunEventRouterObserverTest( |
| 164 base::Bind(&CreateEventListenerForExtension, "extension_id")); | 165 base::Bind(&CreateEventListenerForExtension, "extension_id")); |
| 165 } | 166 } |
| 166 | 167 |
| 167 TEST_F(EventRouterTest, EventRouterObserverForURLs) { | 168 TEST_F(EventRouterTest, EventRouterObserverForURLs) { |
| 168 RunEventRouterObserverTest( | 169 RunEventRouterObserverTest( |
| 169 base::Bind(&CreateEventListenerForURL, GURL("http://google.com/path"))); | 170 base::Bind(&CreateEventListenerForURL, GURL("http://google.com/path"))); |
| 170 } | 171 } |
| 171 | 172 |
| 172 } // namespace extensions | 173 } // namespace extensions |
| OLD | NEW |