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

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

Issue 730833006: MacViews: Implement event monitoring for a specific window (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
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 EventMonitorAuraTest : public WidgetTest {
14 public:
15 void SetUp() override {
tapted 2014/12/10 02:58:27 nit: // testing::Test:
Andre 2014/12/10 22:58:04 Done.
Andre 2014/12/10 22:58:04 Done.
16 WidgetTest::SetUp();
17 widget_ = CreateTopLevelNativeWidget();
18 widget_->SetSize(gfx::Size(100, 100));
19 widget_->Show();
20 generator_.reset(
21 new ui::test::EventGenerator(GetContext(), widget_->GetNativeWindow()));
22 }
23 void TearDown() override {
24 widget_->CloseNow();
25 WidgetTest::TearDown();
26 }
27
28 protected:
29 Widget* widget_;
tapted 2014/12/10 02:58:27 nit: Initialize widget_(nullptr) in a default cons
Andre 2014/12/10 22:58:04 Done.
30 scoped_ptr<ui::test::EventGenerator> generator_;
31 ui::test::TestEventHandler handler_;
32 };
tapted 2014/12/10 02:58:27 nit: private: DISALLOW_COPY_AND_ASSIGN(..)
Andre 2014/12/10 22:58:05 Done.
33
34 TEST_F(EventMonitorAuraTest, ShouldReceiveAppEventsWhileInstalled) {
35 scoped_ptr<EventMonitor> monitor(
36 EventMonitor::CreateApplicationMonitor(&handler_));
37
38 generator_->ClickLeftButton();
39 EXPECT_EQ(2, handler_.num_mouse_events());
40
41 monitor.reset();
42 generator_->ClickLeftButton();
43 EXPECT_EQ(2, handler_.num_mouse_events());
44 }
45
46 TEST_F(EventMonitorAuraTest, ShouldReceiveWindowEventsWhileInstalled) {
47 scoped_ptr<EventMonitor> monitor(
48 EventMonitor::CreateWindowMonitor(&handler_, widget_->GetNativeWindow()));
49
50 generator_->ClickLeftButton();
51 EXPECT_EQ(2, handler_.num_mouse_events());
52
53 monitor.reset();
54 generator_->ClickLeftButton();
55 EXPECT_EQ(2, handler_.num_mouse_events());
56 }
57
58 TEST_F(EventMonitorAuraTest, ShouldNotReceiveEventsFromOtherWindow) {
59 Widget* widget2 = CreateTopLevelNativeWidget();
60 scoped_ptr<EventMonitor> monitor(
61 EventMonitor::CreateWindowMonitor(&handler_, widget2->GetNativeWindow()));
62
63 generator_->ClickLeftButton();
64 EXPECT_EQ(0, handler_.num_mouse_events());
65
66 widget2->CloseNow();
67 }
68
69 } // namespace test
70 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698