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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/memory/scoped_vector.h" | 7 #include "base/memory/scoped_vector.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/events/event.h" | 10 #include "ui/events/event.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 close(events_in_); | 113 close(events_in_); |
114 close(events_out_); | 114 close(events_out_); |
115 } | 115 } |
116 | 116 |
117 ui::MockCursorEvdev* cursor() { return cursor_.get(); } | 117 ui::MockCursorEvdev* cursor() { return cursor_.get(); } |
118 ui::MockEventConverterEvdevImpl* device() { return device_.get(); } | 118 ui::MockEventConverterEvdevImpl* device() { return device_.get(); } |
119 | 119 |
120 unsigned size() { return dispatched_events_.size(); } | 120 unsigned size() { return dispatched_events_.size(); } |
121 ui::KeyEvent* dispatched_event(unsigned index) { | 121 ui::KeyEvent* dispatched_event(unsigned index) { |
122 DCHECK_GT(dispatched_events_.size(), index); | 122 DCHECK_GT(dispatched_events_.size(), index); |
123 ui::Event* ev = dispatched_events_[index]; | 123 ui::Event* ev = dispatched_events_[index].get(); |
124 DCHECK(ev->IsKeyEvent()); | 124 DCHECK(ev->IsKeyEvent()); |
125 return static_cast<ui::KeyEvent*>(ev); | 125 return static_cast<ui::KeyEvent*>(ev); |
126 } | 126 } |
127 ui::MouseEvent* dispatched_mouse_event(unsigned index) { | 127 ui::MouseEvent* dispatched_mouse_event(unsigned index) { |
128 DCHECK_GT(dispatched_events_.size(), index); | 128 DCHECK_GT(dispatched_events_.size(), index); |
129 ui::Event* ev = dispatched_events_[index]; | 129 ui::Event* ev = dispatched_events_[index].get(); |
130 DCHECK(ev->IsMouseEvent()); | 130 DCHECK(ev->IsMouseEvent()); |
131 return static_cast<ui::MouseEvent*>(ev); | 131 return static_cast<ui::MouseEvent*>(ev); |
132 } | 132 } |
133 | 133 |
134 void ClearDispatchedEvents() { | 134 void ClearDispatchedEvents() { |
135 dispatched_events_.clear(); | 135 dispatched_events_.clear(); |
136 } | 136 } |
137 | 137 |
138 void DestroyDevice() { device_.reset(); } | 138 void DestroyDevice() { device_.reset(); } |
139 | 139 |
140 private: | 140 private: |
141 void DispatchEventForTest(ui::Event* event) { | 141 void DispatchEventForTest(ui::Event* event) { |
142 scoped_ptr<ui::Event> cloned_event = ui::Event::Clone(*event); | 142 scoped_ptr<ui::Event> cloned_event = ui::Event::Clone(*event); |
143 dispatched_events_.push_back(cloned_event.Pass()); | 143 dispatched_events_.push_back(cloned_event.Pass()); |
144 } | 144 } |
145 | 145 |
146 base::MessageLoopForUI ui_loop_; | 146 base::MessageLoopForUI ui_loop_; |
147 | 147 |
148 scoped_ptr<ui::MockCursorEvdev> cursor_; | 148 scoped_ptr<ui::MockCursorEvdev> cursor_; |
149 scoped_ptr<ui::DeviceManager> device_manager_; | 149 scoped_ptr<ui::DeviceManager> device_manager_; |
150 scoped_ptr<ui::EventFactoryEvdev> event_factory_; | 150 scoped_ptr<ui::EventFactoryEvdev> event_factory_; |
151 scoped_ptr<ui::DeviceEventDispatcherEvdev> dispatcher_; | 151 scoped_ptr<ui::DeviceEventDispatcherEvdev> dispatcher_; |
152 scoped_ptr<ui::MockEventConverterEvdevImpl> device_; | 152 scoped_ptr<ui::MockEventConverterEvdevImpl> device_; |
153 | 153 |
154 ScopedVector<ui::Event> dispatched_events_; | 154 std::vector<scoped_ptr<ui::Event>> dispatched_events_; |
155 | 155 |
156 int events_out_; | 156 int events_out_; |
157 int events_in_; | 157 int events_in_; |
158 | 158 |
159 DISALLOW_COPY_AND_ASSIGN(EventConverterEvdevImplTest); | 159 DISALLOW_COPY_AND_ASSIGN(EventConverterEvdevImplTest); |
160 }; | 160 }; |
161 | 161 |
162 TEST_F(EventConverterEvdevImplTest, KeyPress) { | 162 TEST_F(EventConverterEvdevImplTest, KeyPress) { |
163 ui::MockEventConverterEvdevImpl* dev = device(); | 163 ui::MockEventConverterEvdevImpl* dev = device(); |
164 | 164 |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 dev->SetKeyFilter(true /* enable_filter */, allowed_keys); | 655 dev->SetKeyFilter(true /* enable_filter */, allowed_keys); |
656 ASSERT_EQ(1u, size()); | 656 ASSERT_EQ(1u, size()); |
657 event = dispatched_event(0); | 657 event = dispatched_event(0); |
658 EXPECT_EQ(ui::ET_KEY_RELEASED, event->type()); | 658 EXPECT_EQ(ui::ET_KEY_RELEASED, event->type()); |
659 | 659 |
660 // The real key release should be dropped, whenever it comes. | 660 // The real key release should be dropped, whenever it comes. |
661 ClearDispatchedEvents(); | 661 ClearDispatchedEvents(); |
662 dev->ProcessEvents(key_release, arraysize(key_release)); | 662 dev->ProcessEvents(key_release, arraysize(key_release)); |
663 ASSERT_EQ(0u, size()); | 663 ASSERT_EQ(0u, size()); |
664 } | 664 } |
OLD | NEW |