OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 #include "ui/views/event_monitor_mac.h" | |
6 | |
7 #include "ui/events/event.h" | |
8 #include "ui/events/event_handler.h" | |
9 #include "ui/events/event_constants.h" | |
10 #import "ui/events/test/cocoa_test_event_utils.h" | |
11 #import "ui/gfx/test/ui_cocoa_test_helper.h" | |
12 | |
13 namespace views { | |
14 | |
15 namespace { | |
16 | |
17 class EventMonitorMacTest : public ui::CocoaTest { | |
18 public: | |
19 EventMonitorMacTest() {} | |
20 | |
21 private: | |
22 DISALLOW_COPY_AND_ASSIGN(EventMonitorMacTest); | |
23 }; | |
24 | |
25 class EventCounter : public ui::EventHandler { | |
26 public: | |
27 EventCounter() : event_count_(0), last_event_type_(ui::ET_UNKNOWN) {} | |
28 int event_count() const { return event_count_; } | |
29 ui::EventType last_event_type() { return last_event_type_; } | |
30 | |
31 // ui::EventHandler implementation: | |
32 virtual void OnEvent(ui::Event* event) override { | |
33 ++event_count_; | |
34 last_event_type_ = event->type(); | |
35 } | |
36 | |
37 private: | |
38 int event_count_; | |
39 ui::EventType last_event_type_; | |
40 }; | |
41 | |
42 } // namespace | |
43 | |
44 TEST_F(EventMonitorMacTest, CountEvents) { | |
45 EventCounter counter; | |
46 NSEvent* event = | |
47 cocoa_test_event_utils::EnterExitEventWithType(NSMouseExited); | |
48 | |
49 // No monitor installed yet, should not receive events. | |
50 [NSApp sendEvent:event]; | |
51 EXPECT_EQ(0, counter.event_count()); | |
52 EXPECT_EQ(ui::ET_UNKNOWN, counter.last_event_type()); | |
53 | |
54 // Install monitor, should start receiving event. | |
55 scoped_ptr<EventMonitor> event_monitor(EventMonitor::Create(&counter)); | |
56 [NSApp sendEvent:event]; | |
57 EXPECT_EQ(1, counter.event_count()); | |
58 EXPECT_EQ(ui::ET_MOUSE_EXITED, counter.last_event_type()); | |
59 | |
60 // Uninstall monitor, should stop receiving events. | |
61 event_monitor.reset(); | |
62 [NSApp sendEvent:event]; | |
63 EXPECT_EQ(1, counter.event_count()); | |
64 EXPECT_EQ(ui::ET_MOUSE_EXITED, counter.last_event_type()); | |
65 } | |
66 | |
67 } // namespace views | |
OLD | NEW |