Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: ui/views/event_monitor_unittest.cc

Issue 793003004: MacViews: Implement event monitoring for a specific window (Reland) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/event_monitor_mac_unittest.mm ('k') | ui/views/mouse_watcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/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"
9
10 namespace views {
11 namespace test {
12
13 class EventMonitorTest : public WidgetTest {
14 public:
15 EventMonitorTest() : widget_(nullptr) {}
16
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);
26 }
27 void TearDown() override {
28 widget_->CloseNow();
29 WidgetTest::TearDown();
30 }
31
32 protected:
33 Widget* widget_;
34 scoped_ptr<ui::test::EventGenerator> generator_;
35 ui::test::TestEventHandler handler_;
36
37 private:
38 DISALLOW_COPY_AND_ASSIGN(EventMonitorTest);
39 };
40
41 TEST_F(EventMonitorTest, ShouldReceiveAppEventsWhileInstalled) {
42 scoped_ptr<EventMonitor> monitor(
43 EventMonitor::CreateApplicationMonitor(&handler_));
44
45 generator_->ClickLeftButton();
46 EXPECT_EQ(2, handler_.num_mouse_events());
47
48 monitor.reset();
49 generator_->ClickLeftButton();
50 EXPECT_EQ(2, handler_.num_mouse_events());
51 }
52
53 TEST_F(EventMonitorTest, ShouldReceiveWindowEventsWhileInstalled) {
54 scoped_ptr<EventMonitor> monitor(
55 EventMonitor::CreateWindowMonitor(&handler_, widget_->GetNativeWindow()));
56
57 generator_->ClickLeftButton();
58 EXPECT_EQ(2, handler_.num_mouse_events());
59
60 monitor.reset();
61 generator_->ClickLeftButton();
62 EXPECT_EQ(2, handler_.num_mouse_events());
63 }
64
65 TEST_F(EventMonitorTest, ShouldNotReceiveEventsFromOtherWindow) {
66 Widget* widget2 = CreateTopLevelNativeWidget();
67 scoped_ptr<EventMonitor> monitor(
68 EventMonitor::CreateWindowMonitor(&handler_, widget2->GetNativeWindow()));
69
70 generator_->ClickLeftButton();
71 EXPECT_EQ(0, handler_.num_mouse_events());
72
73 monitor.reset();
74 widget2->CloseNow();
75 }
76
77 } // namespace test
78 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/event_monitor_mac_unittest.mm ('k') | ui/views/mouse_watcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698