[Telemetry] Reorganize key_mobile_sites pages and update their names
[chromium-blink-merge.git] / ui / views / event_monitor_mac_unittest.mm
blobc6879a7967ad0670c03eb8e5f350c1addfc42689
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.
5 #include "ui/views/event_monitor_mac.h"
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"
13 namespace views {
15 namespace {
17 class EventMonitorMacTest : public ui::CocoaTest {
18  public:
19   EventMonitorMacTest() {}
21  private:
22   DISALLOW_COPY_AND_ASSIGN(EventMonitorMacTest);
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_; }
31   // ui::EventHandler implementation:
32   virtual void OnEvent(ui::Event* event) override {
33     ++event_count_;
34     last_event_type_ = event->type();
35   }
37  private:
38   int event_count_;
39   ui::EventType last_event_type_;
42 }  // namespace
44 TEST_F(EventMonitorMacTest, CountEvents) {
45   EventCounter counter;
46   NSEvent* event =
47       cocoa_test_event_utils::EnterExitEventWithType(NSMouseExited);
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());
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());
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());
67 }  // namespace views