| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "base/macros.h" | 5 #include "base/macros.h" |
| 6 #include "ui/events/test/event_generator.h" | 6 #include "ui/events/test/event_generator.h" |
| 7 #include "ui/events/test/test_event_handler.h" | 7 #include "ui/events/test/test_event_handler.h" |
| 8 #include "ui/views/event_monitor.h" | 8 #include "ui/views/event_monitor.h" |
| 9 #include "ui/views/test/widget_test.h" | 9 #include "ui/views/test/widget_test.h" |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 new ui::test::EventGenerator(GetContext(), widget_->GetNativeWindow())); | 25 new ui::test::EventGenerator(GetContext(), widget_->GetNativeWindow())); |
| 26 generator_->set_targeting_application(true); | 26 generator_->set_targeting_application(true); |
| 27 } | 27 } |
| 28 void TearDown() override { | 28 void TearDown() override { |
| 29 widget_->CloseNow(); | 29 widget_->CloseNow(); |
| 30 WidgetTest::TearDown(); | 30 WidgetTest::TearDown(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 protected: | 33 protected: |
| 34 Widget* widget_; | 34 Widget* widget_; |
| 35 scoped_ptr<ui::test::EventGenerator> generator_; | 35 std::unique_ptr<ui::test::EventGenerator> generator_; |
| 36 ui::test::TestEventHandler handler_; | 36 ui::test::TestEventHandler handler_; |
| 37 | 37 |
| 38 private: | 38 private: |
| 39 DISALLOW_COPY_AND_ASSIGN(EventMonitorTest); | 39 DISALLOW_COPY_AND_ASSIGN(EventMonitorTest); |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 TEST_F(EventMonitorTest, ShouldReceiveAppEventsWhileInstalled) { | 42 TEST_F(EventMonitorTest, ShouldReceiveAppEventsWhileInstalled) { |
| 43 scoped_ptr<EventMonitor> monitor( | 43 std::unique_ptr<EventMonitor> monitor( |
| 44 EventMonitor::CreateApplicationMonitor(&handler_)); | 44 EventMonitor::CreateApplicationMonitor(&handler_)); |
| 45 | 45 |
| 46 generator_->ClickLeftButton(); | 46 generator_->ClickLeftButton(); |
| 47 EXPECT_EQ(2, handler_.num_mouse_events()); | 47 EXPECT_EQ(2, handler_.num_mouse_events()); |
| 48 | 48 |
| 49 monitor.reset(); | 49 monitor.reset(); |
| 50 generator_->ClickLeftButton(); | 50 generator_->ClickLeftButton(); |
| 51 EXPECT_EQ(2, handler_.num_mouse_events()); | 51 EXPECT_EQ(2, handler_.num_mouse_events()); |
| 52 } | 52 } |
| 53 | 53 |
| 54 TEST_F(EventMonitorTest, ShouldReceiveWindowEventsWhileInstalled) { | 54 TEST_F(EventMonitorTest, ShouldReceiveWindowEventsWhileInstalled) { |
| 55 scoped_ptr<EventMonitor> monitor( | 55 std::unique_ptr<EventMonitor> monitor( |
| 56 EventMonitor::CreateWindowMonitor(&handler_, widget_->GetNativeWindow())); | 56 EventMonitor::CreateWindowMonitor(&handler_, widget_->GetNativeWindow())); |
| 57 | 57 |
| 58 generator_->ClickLeftButton(); | 58 generator_->ClickLeftButton(); |
| 59 EXPECT_EQ(2, handler_.num_mouse_events()); | 59 EXPECT_EQ(2, handler_.num_mouse_events()); |
| 60 | 60 |
| 61 monitor.reset(); | 61 monitor.reset(); |
| 62 generator_->ClickLeftButton(); | 62 generator_->ClickLeftButton(); |
| 63 EXPECT_EQ(2, handler_.num_mouse_events()); | 63 EXPECT_EQ(2, handler_.num_mouse_events()); |
| 64 } | 64 } |
| 65 | 65 |
| 66 TEST_F(EventMonitorTest, ShouldNotReceiveEventsFromOtherWindow) { | 66 TEST_F(EventMonitorTest, ShouldNotReceiveEventsFromOtherWindow) { |
| 67 Widget* widget2 = CreateTopLevelNativeWidget(); | 67 Widget* widget2 = CreateTopLevelNativeWidget(); |
| 68 scoped_ptr<EventMonitor> monitor( | 68 std::unique_ptr<EventMonitor> monitor( |
| 69 EventMonitor::CreateWindowMonitor(&handler_, widget2->GetNativeWindow())); | 69 EventMonitor::CreateWindowMonitor(&handler_, widget2->GetNativeWindow())); |
| 70 | 70 |
| 71 generator_->ClickLeftButton(); | 71 generator_->ClickLeftButton(); |
| 72 EXPECT_EQ(0, handler_.num_mouse_events()); | 72 EXPECT_EQ(0, handler_.num_mouse_events()); |
| 73 | 73 |
| 74 monitor.reset(); | 74 monitor.reset(); |
| 75 widget2->CloseNow(); | 75 widget2->CloseNow(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 } // namespace test | 78 } // namespace test |
| 79 } // namespace views | 79 } // namespace views |
| OLD | NEW |