Devlin Cronin | ffbd2fe2 | 2018-07-20 17:20:17 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef EXTENSIONS_BROWSER_TEST_EVENT_ROUTER_OBSERVER_H_ |
| 6 | #define EXTENSIONS_BROWSER_TEST_EVENT_ROUTER_OBSERVER_H_ |
| 7 | |
| 8 | #include <map> |
| 9 | #include <memory> |
| 10 | #include <string> |
| 11 | |
| 12 | #include "extensions/browser/event_router.h" |
| 13 | |
| 14 | namespace extensions { |
| 15 | |
| 16 | class TestEventRouterObserver : public EventRouter::TestObserver { |
| 17 | public: |
| 18 | using EventMap = std::map<std::string, std::unique_ptr<Event>>; |
| 19 | |
| 20 | explicit TestEventRouterObserver(EventRouter* event_router); |
| 21 | ~TestEventRouterObserver() override; |
| 22 | |
| 23 | // Clears all recorded events. |
| 24 | void ClearEvents(); |
| 25 | |
Devlin Cronin | 2ff7567 | 2018-09-06 01:34:33 | [diff] [blame] | 26 | const EventMap& events() const { return events_; } |
| 27 | const EventMap& dispatched_events() const { return dispatched_events_; } |
Devlin Cronin | ffbd2fe2 | 2018-07-20 17:20:17 | [diff] [blame] | 28 | |
| 29 | private: |
| 30 | // EventRouter::TestObserver: |
| 31 | void OnWillDispatchEvent(const Event& event) override; |
Ramin Halavati | a487022 | 2018-07-31 05:41:04 | [diff] [blame] | 32 | void OnDidDispatchEventToProcess(const Event& event) override; |
Devlin Cronin | ffbd2fe2 | 2018-07-20 17:20:17 | [diff] [blame] | 33 | |
| 34 | EventMap events_; |
Ramin Halavati | a487022 | 2018-07-31 05:41:04 | [diff] [blame] | 35 | EventMap dispatched_events_; |
Devlin Cronin | ffbd2fe2 | 2018-07-20 17:20:17 | [diff] [blame] | 36 | EventRouter* event_router_; |
| 37 | |
| 38 | DISALLOW_COPY_AND_ASSIGN(TestEventRouterObserver); |
| 39 | }; |
| 40 | |
| 41 | } // namespace extensions |
| 42 | |
| 43 | #endif // EXTENSIONS_BROWSER_TEST_EVENT_ROUTER_OBSERVER_H_ |