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

Side by Side Diff: ui/views/controls/menu/menu_controller_unittest.cc

Issue 785753002: Don't refcount tracking id -> slot id mapping. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comment. Created 5 years, 10 months 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
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 "ui/views/controls/menu/menu_controller.h" 5 #include "ui/views/controls/menu/menu_controller.h"
6 6
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "ui/aura/scoped_window_targeter.h" 8 #include "ui/aura/scoped_window_targeter.h"
9 #include "ui/aura/window.h" 9 #include "ui/aura/window.h"
10 #include "ui/events/event_handler.h"
10 #include "ui/events/event_targeter.h" 11 #include "ui/events/event_targeter.h"
11 #include "ui/events/platform/platform_event_source.h" 12 #include "ui/events/platform/platform_event_source.h"
12 #include "ui/views/controls/menu/menu_item_view.h" 13 #include "ui/views/controls/menu/menu_item_view.h"
13 #include "ui/views/test/views_test_base.h" 14 #include "ui/views/test/views_test_base.h"
14 #include "ui/wm/public/dispatcher_client.h" 15 #include "ui/wm/public/dispatcher_client.h"
15 16
16 #if defined(OS_WIN) 17 #if defined(OS_WIN)
17 #include "base/message_loop/message_pump_dispatcher.h" 18 #include "base/message_loop/message_pump_dispatcher.h"
18 #elif defined(USE_X11) 19 #elif defined(USE_X11)
19 #include <X11/Xlib.h> 20 #include <X11/Xlib.h>
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 180
180 #if defined(USE_X11) 181 #if defined(USE_X11)
181 void DispatchEscapeAndExpect(MenuController::ExitType exit_type) { 182 void DispatchEscapeAndExpect(MenuController::ExitType exit_type) {
182 ui::ScopedXI2Event key_event; 183 ui::ScopedXI2Event key_event;
183 key_event.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_ESCAPE, 0); 184 key_event.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_ESCAPE, 0);
184 event_source_.Dispatch(key_event); 185 event_source_.Dispatch(key_event);
185 EXPECT_EQ(exit_type, controller_->exit_type()); 186 EXPECT_EQ(exit_type, controller_->exit_type());
186 controller_->exit_type_ = MenuController::EXIT_ALL; 187 controller_->exit_type_ = MenuController::EXIT_ALL;
187 DispatchEvent(); 188 DispatchEvent();
188 } 189 }
190
191 void DispatchTouch(int evtype, int id) {
192 ui::ScopedXI2Event touch_event;
193 std::vector<ui::Valuator> valuators;
194 touch_event.InitTouchEvent(1, evtype, id, gfx::Point(10, 10), valuators);
195 event_source_.Dispatch(touch_event);
196 DispatchEvent();
197 }
189 #endif 198 #endif
190 199
191 void DispatchEvent() { 200 void DispatchEvent() {
192 #if defined(USE_X11) 201 #if defined(USE_X11)
193 XEvent xevent; 202 XEvent xevent;
194 memset(&xevent, 0, sizeof(xevent)); 203 memset(&xevent, 0, sizeof(xevent));
195 event_source_.Dispatch(&xevent); 204 event_source_.Dispatch(&xevent);
196 #elif defined(OS_WIN) 205 #elif defined(OS_WIN)
197 MSG msg; 206 MSG msg;
198 memset(&msg, 0, sizeof(MSG)); 207 memset(&msg, 0, sizeof(MSG));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 message_loop()->PostTask( 268 message_loop()->PostTask(
260 FROM_HERE, 269 FROM_HERE,
261 base::Bind(&MenuControllerTest::DispatchEscapeAndExpect, 270 base::Bind(&MenuControllerTest::DispatchEscapeAndExpect,
262 base::Unretained(this), 271 base::Unretained(this),
263 MenuController::EXIT_NONE)); 272 MenuController::EXIT_NONE));
264 RunMenu(owner.get()); 273 RunMenu(owner.get());
265 } 274 }
266 } 275 }
267 #endif 276 #endif
268 277
278 #if defined(USE_X11)
279
280 class TestEventHandler : public ui::EventHandler {
281 public:
282 TestEventHandler() : outstanding_touches_(0) {}
283
284 void OnTouchEvent(ui::TouchEvent* event) override {
285 switch(event->type()) {
286 case ui::ET_TOUCH_PRESSED:
287 outstanding_touches_++;
288 break;
289 case ui::ET_TOUCH_RELEASED:
290 case ui::ET_TOUCH_CANCELLED:
291 outstanding_touches_--;
292 break;
293 default:
294 break;
295 }
296 }
297
298 int outstanding_touches() const { return outstanding_touches_; }
299
300 private:
301 int outstanding_touches_;
302 };
303
304 // Tests that touch event ids are released correctly. See
305 // crbug.com/439051 for details. When the ids aren't managed
306 // correctly, we get stuck down touches.
307 TEST_F(MenuControllerTest, TouchIdsReleasedCorrectly) {
308 scoped_ptr<Widget> owner(CreateOwnerWidget());
309 TestEventHandler test_event_handler;
310 owner->GetNativeWindow()->GetRootWindow()->AddPreTargetHandler(
311 &test_event_handler);
312
313 std::vector<unsigned int> devices;
314 devices.push_back(1);
315 ui::SetUpTouchDevicesForTest(devices);
316
317 DispatchTouch(XI_TouchBegin, 0);
318 DispatchTouch(XI_TouchBegin, 1);
319 DispatchTouch(XI_TouchEnd, 0);
320
321 message_loop()->PostTask(FROM_HERE,
322 base::Bind(&MenuControllerTest::DispatchTouch,
323 base::Unretained(this), XI_TouchEnd, 1));
324
325 message_loop()->PostTask(
326 FROM_HERE,
327 base::Bind(&MenuControllerTest::DispatchEscapeAndExpect,
328 base::Unretained(this), MenuController::EXIT_OUTERMOST));
329
330 RunMenu(owner.get());
331 EXPECT_EQ(0, test_event_handler.outstanding_touches());
332
333 owner->GetNativeWindow()->GetRootWindow()->RemovePreTargetHandler(
334 &test_event_handler);
335 }
336 #endif // defined(USE_X11)
337
269 } // namespace views 338 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698