| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "core/input/EventHandler.h" | 5 #include "core/input/EventHandler.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 8 #include "core/dom/Range.h" | 9 #include "core/dom/Range.h" |
| 9 #include "core/editing/Editor.h" | 10 #include "core/editing/Editor.h" |
| 10 #include "core/editing/FrameSelection.h" | 11 #include "core/editing/FrameSelection.h" |
| 11 #include "core/frame/FrameView.h" | 12 #include "core/frame/FrameView.h" |
| 12 #include "core/frame/LocalFrame.h" | 13 #include "core/frame/LocalFrame.h" |
| 13 #include "core/frame/Settings.h" | 14 #include "core/frame/Settings.h" |
| 15 #include "core/loader/EmptyClients.h" |
| 14 #include "core/page/AutoscrollController.h" | 16 #include "core/page/AutoscrollController.h" |
| 15 #include "core/page/Page.h" | 17 #include "core/page/Page.h" |
| 16 #include "core/testing/DummyPageHolder.h" | 18 #include "core/testing/DummyPageHolder.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include <memory> | |
| 19 | 20 |
| 20 namespace blink { | 21 namespace blink { |
| 21 | 22 |
| 22 class EventHandlerTest : public ::testing::Test { | 23 class EventHandlerTest : public ::testing::Test { |
| 23 protected: | 24 protected: |
| 24 void SetUp() override; | 25 void SetUp() override; |
| 25 | 26 |
| 26 Page& page() const { return m_dummyPageHolder->page(); } | 27 Page& page() const { return m_dummyPageHolder->page(); } |
| 27 Document& document() const { return m_dummyPageHolder->document(); } | 28 Document& document() const { return m_dummyPageHolder->document(); } |
| 28 FrameSelection& selection() const { return document().frame()->selection(); } | 29 FrameSelection& selection() const { return document().frame()->selection(); } |
| 29 | 30 |
| 30 void setHtmlInnerHTML(const char* htmlContent); | 31 void setHtmlInnerHTML(const char* htmlContent); |
| 31 | 32 |
| 32 private: | 33 protected: |
| 33 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | 34 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
| 34 }; | 35 }; |
| 35 | 36 |
| 36 class TapEventBuilder : public WebGestureEvent { | 37 class TapEventBuilder : public WebGestureEvent { |
| 37 public: | 38 public: |
| 38 TapEventBuilder(IntPoint position, int tapCount) | 39 TapEventBuilder(IntPoint position, int tapCount) |
| 39 : WebGestureEvent(WebInputEvent::GestureTap, | 40 : WebGestureEvent(WebInputEvent::GestureTap, |
| 40 WebInputEvent::NoModifiers, | 41 WebInputEvent::NoModifiers, |
| 41 TimeTicks::Now().InSeconds()) { | 42 TimeTicks::Now().InSeconds()) { |
| 42 x = globalX = position.x(); | 43 x = globalX = position.x(); |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 WebInputEvent::MouseUp, WebFloatPoint(100, 50), WebFloatPoint(200, 250), | 455 WebInputEvent::MouseUp, WebFloatPoint(100, 50), WebFloatPoint(200, 250), |
| 455 WebPointerProperties::Button::Left, 1, WebInputEvent::NoModifiers, | 456 WebPointerProperties::Button::Left, 1, WebInputEvent::NoModifiers, |
| 456 TimeTicks::Now().InSeconds()); | 457 TimeTicks::Now().InSeconds()); |
| 457 mouseUpEvent.setFrameScale(1); | 458 mouseUpEvent.setFrameScale(1); |
| 458 document().frame()->eventHandler().dragSourceEndedAt(mouseUpEvent, | 459 document().frame()->eventHandler().dragSourceEndedAt(mouseUpEvent, |
| 459 DragOperationNone); | 460 DragOperationNone); |
| 460 | 461 |
| 461 // This test passes if it doesn't crash. | 462 // This test passes if it doesn't crash. |
| 462 } | 463 } |
| 463 | 464 |
| 465 class TooltipCapturingChromeClient : public EmptyChromeClient { |
| 466 public: |
| 467 TooltipCapturingChromeClient() {} |
| 468 |
| 469 void setToolTip(LocalFrame&, const String& str, TextDirection) override { |
| 470 m_lastToolTip = str; |
| 471 } |
| 472 |
| 473 String& lastToolTip() { return m_lastToolTip; } |
| 474 |
| 475 private: |
| 476 String m_lastToolTip; |
| 477 }; |
| 478 |
| 479 class EventHandlerTooltipTest : public EventHandlerTest { |
| 480 public: |
| 481 EventHandlerTooltipTest() {} |
| 482 |
| 483 void SetUp() override { |
| 484 m_chromeClient = new TooltipCapturingChromeClient(); |
| 485 Page::PageClients clients; |
| 486 fillWithEmptyClients(clients); |
| 487 clients.chromeClient = m_chromeClient.get(); |
| 488 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600), &clients); |
| 489 } |
| 490 |
| 491 String& lastToolTip() { return m_chromeClient->lastToolTip(); } |
| 492 |
| 493 private: |
| 494 Persistent<TooltipCapturingChromeClient> m_chromeClient; |
| 495 }; |
| 496 |
| 497 TEST_F(EventHandlerTooltipTest, mouseLeaveClearsTooltip) { |
| 498 setHtmlInnerHTML( |
| 499 "<style>.box { width: 100%; height: 100%; }</style>" |
| 500 "<img src='image.png' class='box' title='tooltip'>link</img>"); |
| 501 |
| 502 EXPECT_EQ(WTF::String(), lastToolTip()); |
| 503 |
| 504 WebMouseEvent mouseMoveEvent( |
| 505 WebInputEvent::MouseMove, WebFloatPoint(51, 50), WebFloatPoint(51, 50), |
| 506 WebPointerProperties::Button::NoButton, 0, WebInputEvent::NoModifiers, |
| 507 TimeTicks::Now().InSeconds()); |
| 508 mouseMoveEvent.setFrameScale(1); |
| 509 document().frame()->eventHandler().handleMouseMoveEvent( |
| 510 mouseMoveEvent, Vector<WebMouseEvent>()); |
| 511 |
| 512 EXPECT_EQ("tooltip", lastToolTip()); |
| 513 |
| 514 WebMouseEvent mouseLeaveEvent( |
| 515 WebInputEvent::MouseLeave, WebFloatPoint(0, 0), WebFloatPoint(0, 0), |
| 516 WebPointerProperties::Button::NoButton, 0, WebInputEvent::NoModifiers, |
| 517 TimeTicks::Now().InSeconds()); |
| 518 mouseLeaveEvent.setFrameScale(1); |
| 519 document().frame()->eventHandler().handleMouseLeaveEvent(mouseLeaveEvent); |
| 520 |
| 521 EXPECT_EQ(WTF::String(), lastToolTip()); |
| 522 } |
| 523 |
| 464 } // namespace blink | 524 } // namespace blink |
| OLD | NEW |