Roll src/breakpad/src 242fb9a:c80d211 (svn 1471:1495)
[chromium-blink-merge.git] / ui / views / event_monitor_unittest.cc
blob4d8b02b85ef332d50aafa0a0cb4f774a8eb71783
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/events/test/event_generator.h"
6 #include "ui/events/test/test_event_handler.h"
7 #include "ui/views/event_monitor.h"
8 #include "ui/views/test/widget_test.h"
10 namespace views {
11 namespace test {
13 class EventMonitorTest : public WidgetTest {
14 public:
15 EventMonitorTest() : widget_(nullptr) {}
17 // testing::Test:
18 void SetUp() override {
19 WidgetTest::SetUp();
20 widget_ = CreateTopLevelNativeWidget();
21 widget_->SetSize(gfx::Size(100, 100));
22 widget_->Show();
23 generator_.reset(
24 new ui::test::EventGenerator(GetContext(), widget_->GetNativeWindow()));
25 generator_->set_targeting_application(true);
27 void TearDown() override {
28 widget_->CloseNow();
29 WidgetTest::TearDown();
32 protected:
33 Widget* widget_;
34 scoped_ptr<ui::test::EventGenerator> generator_;
35 ui::test::TestEventHandler handler_;
37 private:
38 DISALLOW_COPY_AND_ASSIGN(EventMonitorTest);
41 TEST_F(EventMonitorTest, ShouldReceiveAppEventsWhileInstalled) {
42 scoped_ptr<EventMonitor> monitor(
43 EventMonitor::CreateApplicationMonitor(&handler_));
45 generator_->ClickLeftButton();
46 EXPECT_EQ(2, handler_.num_mouse_events());
48 monitor.reset();
49 generator_->ClickLeftButton();
50 EXPECT_EQ(2, handler_.num_mouse_events());
53 TEST_F(EventMonitorTest, ShouldReceiveWindowEventsWhileInstalled) {
54 scoped_ptr<EventMonitor> monitor(
55 EventMonitor::CreateWindowMonitor(&handler_, widget_->GetNativeWindow()));
57 generator_->ClickLeftButton();
58 EXPECT_EQ(2, handler_.num_mouse_events());
60 monitor.reset();
61 generator_->ClickLeftButton();
62 EXPECT_EQ(2, handler_.num_mouse_events());
65 TEST_F(EventMonitorTest, ShouldNotReceiveEventsFromOtherWindow) {
66 Widget* widget2 = CreateTopLevelNativeWidget();
67 scoped_ptr<EventMonitor> monitor(
68 EventMonitor::CreateWindowMonitor(&handler_, widget2->GetNativeWindow()));
70 generator_->ClickLeftButton();
71 EXPECT_EQ(0, handler_.num_mouse_events());
73 monitor.reset();
74 widget2->CloseNow();
77 } // namespace test
78 } // namespace views