Chromium Code Reviews| 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 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 427 WebInputEvent::MouseUp, WebFloatPoint(100, 50), WebFloatPoint(200, 250), | 428 WebInputEvent::MouseUp, WebFloatPoint(100, 50), WebFloatPoint(200, 250), |
| 428 WebPointerProperties::Button::Left, 1, | 429 WebPointerProperties::Button::Left, 1, |
| 429 static_cast<PlatformEvent::Modifiers>(0), TimeTicks::Now().InSeconds()); | 430 static_cast<PlatformEvent::Modifiers>(0), TimeTicks::Now().InSeconds()); |
| 430 mouseUpEvent.setFrameScale(1); | 431 mouseUpEvent.setFrameScale(1); |
| 431 document().frame()->eventHandler().dragSourceEndedAt(mouseUpEvent, | 432 document().frame()->eventHandler().dragSourceEndedAt(mouseUpEvent, |
| 432 DragOperationNone); | 433 DragOperationNone); |
| 433 | 434 |
| 434 // This test passes if it doesn't crash. | 435 // This test passes if it doesn't crash. |
| 435 } | 436 } |
| 436 | 437 |
| 438 class TooltipCapturingChromeClient : public EmptyChromeClient { | |
| 439 public: | |
| 440 TooltipCapturingChromeClient() {} | |
| 441 | |
| 442 void setToolTip(LocalFrame&, const String& str, TextDirection) override { | |
| 443 m_lastToolTip = str; | |
| 444 } | |
| 445 | |
| 446 String& lastToolTip() { return m_lastToolTip; } | |
| 447 | |
| 448 private: | |
| 449 String m_lastToolTip; | |
| 450 }; | |
| 451 | |
| 452 class EventHandlerTooltipTest : public EventHandlerTest { | |
| 453 public: | |
| 454 EventHandlerTooltipTest() {} | |
| 455 | |
| 456 void SetUp() override { | |
| 457 m_chromeClient = new TooltipCapturingChromeClient(); | |
| 458 Page::PageClients clients; | |
| 459 fillWithEmptyClients(clients); | |
| 460 clients.chromeClient = m_chromeClient.get(); | |
| 461 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600), &clients); | |
| 462 } | |
| 463 | |
| 464 String& lastToolTip() { return m_chromeClient->lastToolTip(); } | |
| 465 | |
| 466 private: | |
| 467 Persistent<TooltipCapturingChromeClient> m_chromeClient; | |
| 468 }; | |
| 469 | |
| 470 TEST_F(EventHandlerTooltipTest, mouseLeaveClearsTooltip) { | |
| 471 setHtmlInnerHTML( | |
| 472 "<style>.box { width: 100%; height: 100%; }</style>" | |
| 473 "<img src='image.png' class='box' title='tooltip'>link</img>"); | |
| 474 | |
| 475 EXPECT_EQ(nullptr, lastToolTip()); | |
|
bokan
2017/02/21 19:15:43
We're comparing a String ref to nullptr here and b
| |
| 476 | |
| 477 WebMouseEvent mouseMoveEvent( | |
| 478 WebInputEvent::MouseMove, WebFloatPoint(51, 50), WebFloatPoint(51, 50), | |
| 479 WebPointerProperties::Button::NoButton, 0, | |
| 480 PlatformEvent::Modifiers::NoModifiers, TimeTicks::Now().InSeconds()); | |
| 481 mouseMoveEvent.setFrameScale(1); | |
| 482 document().frame()->eventHandler().handleMouseMoveEvent( | |
| 483 mouseMoveEvent, Vector<WebMouseEvent>()); | |
| 484 | |
| 485 EXPECT_EQ("tooltip", lastToolTip()); | |
| 486 | |
| 487 WebMouseEvent mouseLeaveEvent( | |
| 488 WebInputEvent::MouseLeave, WebFloatPoint(0, 0), WebFloatPoint(0, 0), | |
| 489 WebPointerProperties::Button::NoButton, 0, | |
| 490 PlatformEvent::Modifiers::NoModifiers, TimeTicks::Now().InSeconds()); | |
| 491 mouseLeaveEvent.setFrameScale(1); | |
| 492 document().frame()->eventHandler().handleMouseLeaveEvent(mouseLeaveEvent); | |
| 493 | |
| 494 EXPECT_EQ(nullptr, lastToolTip()); | |
| 495 } | |
| 496 | |
| 437 } // namespace blink | 497 } // namespace blink |
| OLD | NEW |