OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/renderer_host/web_input_event_aura.h" | 5 #include "content/browser/renderer_host/web_input_event_aura.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "ui/events/blink/blink_event_util.h" |
9 #include "ui/events/event.h" | 10 #include "ui/events/event.h" |
10 #include "ui/events/event_utils.h" | 11 #include "ui/events/event_utils.h" |
11 #include "ui/events/keycodes/dom/dom_code.h" | 12 #include "ui/events/keycodes/dom/dom_code.h" |
12 #include "ui/events/keycodes/dom/dom_key.h" | 13 #include "ui/events/keycodes/dom/dom_key.h" |
13 #include "ui/events/keycodes/dom/keycode_converter.h" | 14 #include "ui/events/keycodes/dom/keycode_converter.h" |
14 | 15 |
15 #if defined(USE_X11) | 16 #if defined(USE_X11) |
16 #include <X11/keysym.h> | 17 #include <X11/keysym.h> |
17 #include <X11/Xlib.h> | 18 #include <X11/Xlib.h> |
18 #include "ui/events/test/events_test_utils_x11.h" | 19 #include "ui/events/test/events_test_utils_x11.h" |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 << "Failed in " << i << "th test case: " | 240 << "Failed in " << i << "th test case: " |
240 << "{dom_code:" | 241 << "{dom_code:" |
241 << ui::KeycodeConverter::DomCodeToCodeString(test_case.dom_code) | 242 << ui::KeycodeConverter::DomCodeToCodeString(test_case.dom_code) |
242 << ", ui_keycode:" << test_case.ui_keycode | 243 << ", ui_keycode:" << test_case.ui_keycode |
243 << ", x_keysym:" << test_case.x_keysym | 244 << ", x_keysym:" << test_case.x_keysym |
244 << "}, expect: " << test_case.expected_result; | 245 << "}, expect: " << test_case.expected_result; |
245 } | 246 } |
246 #endif | 247 #endif |
247 } | 248 } |
248 | 249 |
| 250 TEST(WebInputEventAuraTest, TestMakeWebMouseEvent) { |
| 251 { |
| 252 // Left pressed. |
| 253 base::TimeDelta timestamp = ui::EventTimeForNow(); |
| 254 ui::MouseEvent aura_event(ui::ET_MOUSE_PRESSED, gfx::PointF(123.0, 321.0), |
| 255 gfx::PointF(123.0, 321.0), timestamp, |
| 256 ui::EF_LEFT_MOUSE_BUTTON, |
| 257 ui::EF_LEFT_MOUSE_BUTTON); |
| 258 blink::WebMouseEvent webkit_event = MakeWebMouseEvent(aura_event); |
| 259 EXPECT_EQ(ui::EventFlagsToWebEventModifiers(aura_event.flags()), |
| 260 webkit_event.modifiers); |
| 261 EXPECT_FLOAT_EQ(timestamp.InSecondsF(), webkit_event.timeStampSeconds); |
| 262 EXPECT_EQ(blink::WebMouseEvent::ButtonLeft, webkit_event.button); |
| 263 EXPECT_EQ(blink::WebInputEvent::MouseDown, webkit_event.type); |
| 264 EXPECT_EQ(aura_event.GetClickCount(), webkit_event.clickCount); |
| 265 EXPECT_EQ(123, webkit_event.x); |
| 266 EXPECT_EQ(123, webkit_event.windowX); |
| 267 EXPECT_EQ(321, webkit_event.y); |
| 268 EXPECT_EQ(321, webkit_event.windowY); |
| 269 } |
| 270 { |
| 271 // Left released. |
| 272 base::TimeDelta timestamp = ui::EventTimeForNow(); |
| 273 ui::MouseEvent aura_event(ui::ET_MOUSE_RELEASED, gfx::PointF(123.0, 321.0), |
| 274 gfx::PointF(123.0, 321.0), timestamp, 0, |
| 275 ui::EF_LEFT_MOUSE_BUTTON); |
| 276 blink::WebMouseEvent webkit_event = MakeWebMouseEvent(aura_event); |
| 277 EXPECT_EQ(ui::EventFlagsToWebEventModifiers(aura_event.flags()), |
| 278 webkit_event.modifiers); |
| 279 EXPECT_FLOAT_EQ(timestamp.InSecondsF(), webkit_event.timeStampSeconds); |
| 280 EXPECT_EQ(blink::WebMouseEvent::ButtonLeft, webkit_event.button); |
| 281 EXPECT_EQ(blink::WebInputEvent::MouseUp, webkit_event.type); |
| 282 EXPECT_EQ(aura_event.GetClickCount(), webkit_event.clickCount); |
| 283 EXPECT_EQ(123, webkit_event.x); |
| 284 EXPECT_EQ(123, webkit_event.windowX); |
| 285 EXPECT_EQ(321, webkit_event.y); |
| 286 EXPECT_EQ(321, webkit_event.windowY); |
| 287 } |
| 288 { |
| 289 // Middle pressed. |
| 290 base::TimeDelta timestamp = ui::EventTimeForNow(); |
| 291 ui::MouseEvent aura_event(ui::ET_MOUSE_PRESSED, gfx::PointF(123.0, 321.0), |
| 292 gfx::PointF(123.0, 321.0), timestamp, |
| 293 ui::EF_MIDDLE_MOUSE_BUTTON, |
| 294 ui::EF_MIDDLE_MOUSE_BUTTON); |
| 295 blink::WebMouseEvent webkit_event = MakeWebMouseEvent(aura_event); |
| 296 EXPECT_EQ(ui::EventFlagsToWebEventModifiers(aura_event.flags()), |
| 297 webkit_event.modifiers); |
| 298 EXPECT_FLOAT_EQ(timestamp.InSecondsF(), webkit_event.timeStampSeconds); |
| 299 EXPECT_EQ(blink::WebMouseEvent::ButtonMiddle, webkit_event.button); |
| 300 EXPECT_EQ(blink::WebInputEvent::MouseDown, webkit_event.type); |
| 301 EXPECT_EQ(aura_event.GetClickCount(), webkit_event.clickCount); |
| 302 EXPECT_EQ(123, webkit_event.x); |
| 303 EXPECT_EQ(123, webkit_event.windowX); |
| 304 EXPECT_EQ(321, webkit_event.y); |
| 305 EXPECT_EQ(321, webkit_event.windowY); |
| 306 } |
| 307 { |
| 308 // Middle released. |
| 309 base::TimeDelta timestamp = ui::EventTimeForNow(); |
| 310 ui::MouseEvent aura_event(ui::ET_MOUSE_RELEASED, gfx::PointF(123.0, 321.0), |
| 311 gfx::PointF(123.0, 321.0), timestamp, 0, |
| 312 ui::EF_MIDDLE_MOUSE_BUTTON); |
| 313 blink::WebMouseEvent webkit_event = MakeWebMouseEvent(aura_event); |
| 314 EXPECT_EQ(ui::EventFlagsToWebEventModifiers(aura_event.flags()), |
| 315 webkit_event.modifiers); |
| 316 EXPECT_FLOAT_EQ(timestamp.InSecondsF(), webkit_event.timeStampSeconds); |
| 317 EXPECT_EQ(blink::WebMouseEvent::ButtonMiddle, webkit_event.button); |
| 318 EXPECT_EQ(blink::WebInputEvent::MouseUp, webkit_event.type); |
| 319 EXPECT_EQ(aura_event.GetClickCount(), webkit_event.clickCount); |
| 320 EXPECT_EQ(123, webkit_event.x); |
| 321 EXPECT_EQ(123, webkit_event.windowX); |
| 322 EXPECT_EQ(321, webkit_event.y); |
| 323 EXPECT_EQ(321, webkit_event.windowY); |
| 324 } |
| 325 { |
| 326 // Right pressed. |
| 327 base::TimeDelta timestamp = ui::EventTimeForNow(); |
| 328 ui::MouseEvent aura_event(ui::ET_MOUSE_PRESSED, gfx::PointF(123.0, 321.0), |
| 329 gfx::PointF(123.0, 321.0), timestamp, |
| 330 ui::EF_RIGHT_MOUSE_BUTTON, |
| 331 ui::EF_RIGHT_MOUSE_BUTTON); |
| 332 blink::WebMouseEvent webkit_event = MakeWebMouseEvent(aura_event); |
| 333 EXPECT_EQ(ui::EventFlagsToWebEventModifiers(aura_event.flags()), |
| 334 webkit_event.modifiers); |
| 335 EXPECT_FLOAT_EQ(timestamp.InSecondsF(), webkit_event.timeStampSeconds); |
| 336 EXPECT_EQ(blink::WebMouseEvent::ButtonRight, webkit_event.button); |
| 337 EXPECT_EQ(blink::WebInputEvent::MouseDown, webkit_event.type); |
| 338 EXPECT_EQ(aura_event.GetClickCount(), webkit_event.clickCount); |
| 339 EXPECT_EQ(123, webkit_event.x); |
| 340 EXPECT_EQ(123, webkit_event.windowX); |
| 341 EXPECT_EQ(321, webkit_event.y); |
| 342 EXPECT_EQ(321, webkit_event.windowY); |
| 343 } |
| 344 { |
| 345 // Right released. |
| 346 base::TimeDelta timestamp = ui::EventTimeForNow(); |
| 347 ui::MouseEvent aura_event(ui::ET_MOUSE_RELEASED, gfx::PointF(123.0, 321.0), |
| 348 gfx::PointF(123.0, 321.0), timestamp, 0, |
| 349 ui::EF_RIGHT_MOUSE_BUTTON); |
| 350 blink::WebMouseEvent webkit_event = MakeWebMouseEvent(aura_event); |
| 351 EXPECT_EQ(ui::EventFlagsToWebEventModifiers(aura_event.flags()), |
| 352 webkit_event.modifiers); |
| 353 EXPECT_FLOAT_EQ(timestamp.InSecondsF(), webkit_event.timeStampSeconds); |
| 354 EXPECT_EQ(blink::WebMouseEvent::ButtonRight, webkit_event.button); |
| 355 EXPECT_EQ(blink::WebInputEvent::MouseUp, webkit_event.type); |
| 356 EXPECT_EQ(aura_event.GetClickCount(), webkit_event.clickCount); |
| 357 EXPECT_EQ(123, webkit_event.x); |
| 358 EXPECT_EQ(123, webkit_event.windowX); |
| 359 EXPECT_EQ(321, webkit_event.y); |
| 360 EXPECT_EQ(321, webkit_event.windowY); |
| 361 } |
| 362 { |
| 363 // Moved |
| 364 base::TimeDelta timestamp = ui::EventTimeForNow(); |
| 365 ui::MouseEvent aura_event(ui::ET_MOUSE_MOVED, gfx::PointF(123.0, 321.0), |
| 366 gfx::PointF(123.0, 321.0), timestamp, 0, 0); |
| 367 blink::WebMouseEvent webkit_event = MakeWebMouseEvent(aura_event); |
| 368 EXPECT_EQ(ui::EventFlagsToWebEventModifiers(aura_event.flags()), |
| 369 webkit_event.modifiers); |
| 370 EXPECT_FLOAT_EQ(timestamp.InSecondsF(), webkit_event.timeStampSeconds); |
| 371 EXPECT_EQ(blink::WebMouseEvent::ButtonNone, webkit_event.button); |
| 372 EXPECT_EQ(blink::WebInputEvent::MouseMove, webkit_event.type); |
| 373 EXPECT_EQ(aura_event.GetClickCount(), webkit_event.clickCount); |
| 374 EXPECT_EQ(123, webkit_event.x); |
| 375 EXPECT_EQ(123, webkit_event.windowX); |
| 376 EXPECT_EQ(321, webkit_event.y); |
| 377 EXPECT_EQ(321, webkit_event.windowY); |
| 378 } |
| 379 { |
| 380 // Moved with left down |
| 381 base::TimeDelta timestamp = ui::EventTimeForNow(); |
| 382 ui::MouseEvent aura_event(ui::ET_MOUSE_MOVED, gfx::PointF(123.0, 321.0), |
| 383 gfx::PointF(123.0, 321.0), timestamp, |
| 384 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 385 blink::WebMouseEvent webkit_event = MakeWebMouseEvent(aura_event); |
| 386 EXPECT_EQ(ui::EventFlagsToWebEventModifiers(aura_event.flags()), |
| 387 webkit_event.modifiers); |
| 388 EXPECT_FLOAT_EQ(timestamp.InSecondsF(), webkit_event.timeStampSeconds); |
| 389 EXPECT_EQ(blink::WebMouseEvent::ButtonLeft, webkit_event.button); |
| 390 EXPECT_EQ(blink::WebInputEvent::MouseMove, webkit_event.type); |
| 391 EXPECT_EQ(aura_event.GetClickCount(), webkit_event.clickCount); |
| 392 EXPECT_EQ(123, webkit_event.x); |
| 393 EXPECT_EQ(123, webkit_event.windowX); |
| 394 EXPECT_EQ(321, webkit_event.y); |
| 395 EXPECT_EQ(321, webkit_event.windowY); |
| 396 } |
| 397 { |
| 398 // Left with shift pressed. |
| 399 base::TimeDelta timestamp = ui::EventTimeForNow(); |
| 400 ui::MouseEvent aura_event(ui::ET_MOUSE_PRESSED, gfx::PointF(123.0, 321.0), |
| 401 gfx::PointF(123.0, 321.0), timestamp, |
| 402 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_SHIFT_DOWN, |
| 403 ui::EF_LEFT_MOUSE_BUTTON); |
| 404 blink::WebMouseEvent webkit_event = MakeWebMouseEvent(aura_event); |
| 405 EXPECT_EQ(ui::EventFlagsToWebEventModifiers(aura_event.flags()), |
| 406 webkit_event.modifiers); |
| 407 EXPECT_FLOAT_EQ(timestamp.InSecondsF(), webkit_event.timeStampSeconds); |
| 408 EXPECT_EQ(blink::WebMouseEvent::ButtonLeft, webkit_event.button); |
| 409 EXPECT_EQ(blink::WebInputEvent::MouseDown, webkit_event.type); |
| 410 EXPECT_EQ(aura_event.GetClickCount(), webkit_event.clickCount); |
| 411 EXPECT_EQ(123, webkit_event.x); |
| 412 EXPECT_EQ(123, webkit_event.windowX); |
| 413 EXPECT_EQ(321, webkit_event.y); |
| 414 EXPECT_EQ(321, webkit_event.windowY); |
| 415 } |
| 416 { |
| 417 // Default values for PointerDetails. |
| 418 base::TimeDelta timestamp = ui::EventTimeForNow(); |
| 419 ui::MouseEvent aura_event(ui::ET_MOUSE_PRESSED, gfx::PointF(123.0, 321.0), |
| 420 gfx::PointF(123.0, 321.0), timestamp, |
| 421 ui::EF_LEFT_MOUSE_BUTTON, |
| 422 ui::EF_LEFT_MOUSE_BUTTON); |
| 423 blink::WebMouseEvent webkit_event = MakeWebMouseEvent(aura_event); |
| 424 |
| 425 EXPECT_EQ(blink::WebPointerProperties::PointerType::PointerTypeMouse, |
| 426 webkit_event.pointerType); |
| 427 EXPECT_EQ(0, webkit_event.tiltX); |
| 428 EXPECT_EQ(0, webkit_event.tiltY); |
| 429 EXPECT_FLOAT_EQ(0.0f, webkit_event.force); |
| 430 EXPECT_EQ(123, webkit_event.x); |
| 431 EXPECT_EQ(123, webkit_event.windowX); |
| 432 EXPECT_EQ(321, webkit_event.y); |
| 433 EXPECT_EQ(321, webkit_event.windowY); |
| 434 } |
| 435 { |
| 436 // Stylus values for PointerDetails. |
| 437 base::TimeDelta timestamp = ui::EventTimeForNow(); |
| 438 ui::MouseEvent aura_event(ui::ET_MOUSE_PRESSED, gfx::PointF(123.0, 321.0), |
| 439 gfx::PointF(123.0, 321.0), timestamp, |
| 440 ui::EF_LEFT_MOUSE_BUTTON, |
| 441 ui::EF_LEFT_MOUSE_BUTTON); |
| 442 aura_event.set_pointer_details( |
| 443 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_PEN, |
| 444 /* radius_x */ 0.0f, |
| 445 /* radius_y */ 0.0f, |
| 446 /* force */ 0.8f, |
| 447 /* tilt_x */ 89.5f, |
| 448 /* tilt_y */ -89.5f)); |
| 449 blink::WebMouseEvent webkit_event = MakeWebMouseEvent(aura_event); |
| 450 |
| 451 EXPECT_EQ(blink::WebPointerProperties::PointerType::PointerTypePen, |
| 452 webkit_event.pointerType); |
| 453 EXPECT_EQ(90, webkit_event.tiltX); |
| 454 EXPECT_EQ(-90, webkit_event.tiltY); |
| 455 EXPECT_FLOAT_EQ(0.8f, webkit_event.force); |
| 456 EXPECT_EQ(123, webkit_event.x); |
| 457 EXPECT_EQ(123, webkit_event.windowX); |
| 458 EXPECT_EQ(321, webkit_event.y); |
| 459 EXPECT_EQ(321, webkit_event.windowY); |
| 460 } |
| 461 } |
| 462 |
| 463 TEST(WebInputEventAuraTest, TestMakeWebMouseWheelEvent) { |
| 464 { |
| 465 // Mouse wheel. |
| 466 base::TimeDelta timestamp = ui::EventTimeForNow(); |
| 467 ui::MouseWheelEvent aura_event( |
| 468 gfx::Vector2d(ui::MouseWheelEvent::kWheelDelta * 2, |
| 469 -ui::MouseWheelEvent::kWheelDelta * 2), |
| 470 gfx::PointF(123.0, 321.0), gfx::PointF(123.0, 321.0), timestamp, 0, 0); |
| 471 blink::WebMouseWheelEvent webkit_event = MakeWebMouseWheelEvent(aura_event); |
| 472 EXPECT_EQ(ui::EventFlagsToWebEventModifiers(aura_event.flags()), |
| 473 webkit_event.modifiers); |
| 474 EXPECT_FLOAT_EQ(timestamp.InSecondsF(), webkit_event.timeStampSeconds); |
| 475 EXPECT_EQ(blink::WebMouseEvent::ButtonNone, webkit_event.button); |
| 476 EXPECT_EQ(blink::WebInputEvent::MouseWheel, webkit_event.type); |
| 477 EXPECT_FLOAT_EQ(aura_event.x_offset() / 53.0f, webkit_event.wheelTicksX); |
| 478 EXPECT_FLOAT_EQ(aura_event.y_offset() / 53.0f, webkit_event.wheelTicksY); |
| 479 EXPECT_EQ(blink::WebPointerProperties::PointerType::PointerTypeMouse, |
| 480 webkit_event.pointerType); |
| 481 EXPECT_EQ(0, webkit_event.tiltX); |
| 482 EXPECT_EQ(0, webkit_event.tiltY); |
| 483 EXPECT_FLOAT_EQ(0.0f, webkit_event.force); |
| 484 EXPECT_EQ(123, webkit_event.x); |
| 485 EXPECT_EQ(123, webkit_event.windowX); |
| 486 EXPECT_EQ(321, webkit_event.y); |
| 487 EXPECT_EQ(321, webkit_event.windowY); |
| 488 } |
| 489 { |
| 490 // Mouse wheel with shift and no x offset. |
| 491 base::TimeDelta timestamp = ui::EventTimeForNow(); |
| 492 ui::MouseWheelEvent aura_event( |
| 493 gfx::Vector2d(0, -ui::MouseWheelEvent::kWheelDelta * 2), |
| 494 gfx::PointF(123.0, 321.0), gfx::PointF(123.0, 321.0), timestamp, |
| 495 ui::EF_SHIFT_DOWN, 0); |
| 496 blink::WebMouseWheelEvent webkit_event = MakeWebMouseWheelEvent(aura_event); |
| 497 EXPECT_EQ(ui::EventFlagsToWebEventModifiers(aura_event.flags()), |
| 498 webkit_event.modifiers); |
| 499 EXPECT_FLOAT_EQ(timestamp.InSecondsF(), webkit_event.timeStampSeconds); |
| 500 EXPECT_EQ(blink::WebMouseEvent::ButtonNone, webkit_event.button); |
| 501 EXPECT_EQ(blink::WebInputEvent::MouseWheel, webkit_event.type); |
| 502 EXPECT_FLOAT_EQ(aura_event.y_offset() / 53.0f, webkit_event.wheelTicksX); |
| 503 EXPECT_FLOAT_EQ(0, webkit_event.wheelTicksY); |
| 504 EXPECT_EQ(blink::WebPointerProperties::PointerType::PointerTypeMouse, |
| 505 webkit_event.pointerType); |
| 506 EXPECT_EQ(0, webkit_event.tiltX); |
| 507 EXPECT_EQ(0, webkit_event.tiltY); |
| 508 EXPECT_FLOAT_EQ(0.0f, webkit_event.force); |
| 509 EXPECT_EQ(123, webkit_event.x); |
| 510 EXPECT_EQ(123, webkit_event.windowX); |
| 511 EXPECT_EQ(321, webkit_event.y); |
| 512 EXPECT_EQ(321, webkit_event.windowY); |
| 513 } |
| 514 } |
| 515 |
249 } // namespace content | 516 } // namespace content |
OLD | NEW |