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 <memory> |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/dom/Range.h" | 9 #include "core/dom/Range.h" |
| 10 #include "core/editing/Editor.h" | 10 #include "core/editing/Editor.h" |
| 11 #include "core/editing/FrameSelection.h" | 11 #include "core/editing/FrameSelection.h" |
| 12 #include "core/frame/FrameView.h" | 12 #include "core/frame/FrameView.h" |
| 13 #include "core/frame/LocalFrame.h" | 13 #include "core/frame/LocalFrame.h" |
| 14 #include "core/frame/Settings.h" | 14 #include "core/frame/Settings.h" |
| 15 #include "core/loader/EmptyClients.h" | 15 #include "core/loader/EmptyClients.h" |
| 16 #include "core/page/AutoscrollController.h" | 16 #include "core/page/AutoscrollController.h" |
| 17 #include "core/page/Page.h" | 17 #include "core/page/Page.h" |
| 18 #include "core/testing/DummyPageHolder.h" | 18 #include "core/testing/DummyPageHolder.h" |
| 19 #include "platform/testing/HistogramTester.h" | |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 21 |
| 21 namespace blink { | 22 namespace blink { |
| 22 | 23 |
| 23 class EventHandlerTest : public ::testing::Test { | 24 class EventHandlerTest : public ::testing::Test { |
| 24 protected: | 25 protected: |
| 25 void SetUp() override; | 26 void SetUp() override; |
| 26 | 27 |
| 27 Page& page() const { return m_dummyPageHolder->page(); } | 28 Page& page() const { return m_dummyPageHolder->page(); } |
| 28 Document& document() const { return m_dummyPageHolder->document(); } | 29 Document& document() const { return m_dummyPageHolder->document(); } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 WebInputEvent::NoModifiers, | 73 WebInputEvent::NoModifiers, |
| 73 TimeTicks::Now().InSeconds()) { | 74 TimeTicks::Now().InSeconds()) { |
| 74 clickCount = clickCountParam; | 75 clickCount = clickCountParam; |
| 75 button = buttonParam; | 76 button = buttonParam; |
| 76 x = globalX = position.x(); | 77 x = globalX = position.x(); |
| 77 y = globalY = position.y(); | 78 y = globalY = position.y(); |
| 78 m_frameScale = 1; | 79 m_frameScale = 1; |
| 79 } | 80 } |
| 80 }; | 81 }; |
| 81 | 82 |
| 83 class ScrollBeginEventBuilder : public WebGestureEvent { | |
| 84 public: | |
| 85 ScrollBeginEventBuilder(IntPoint position, | |
| 86 FloatPoint delta, | |
| 87 WebGestureDevice device) | |
| 88 : WebGestureEvent() { | |
| 89 m_type = WebInputEvent::GestureScrollBegin; | |
| 90 x = globalX = position.x(); | |
| 91 y = globalY = position.y(); | |
| 92 data.scrollBegin.deltaYHint = delta.y(); | |
| 93 data.scrollBegin.targetViewport = true; | |
| 94 sourceDevice = device; | |
| 95 m_frameScale = 1; | |
| 96 } | |
| 97 }; | |
| 98 | |
| 99 class ScrollEndEventBuilder : public WebGestureEvent { | |
| 100 public: | |
| 101 ScrollEndEventBuilder() : WebGestureEvent() { | |
| 102 m_type = WebInputEvent::GestureScrollEnd; | |
| 103 m_frameScale = 1; | |
| 104 } | |
| 105 }; | |
| 106 | |
| 82 void EventHandlerTest::SetUp() { | 107 void EventHandlerTest::SetUp() { |
| 83 m_dummyPageHolder = DummyPageHolder::create(IntSize(300, 400)); | 108 m_dummyPageHolder = DummyPageHolder::create(IntSize(300, 400)); |
| 84 } | 109 } |
| 85 | 110 |
| 86 void EventHandlerTest::setHtmlInnerHTML(const char* htmlContent) { | 111 void EventHandlerTest::setHtmlInnerHTML(const char* htmlContent) { |
| 87 document().documentElement()->setInnerHTML(String::fromUTF8(htmlContent)); | 112 document().documentElement()->setInnerHTML(String::fromUTF8(htmlContent)); |
| 88 document().view()->updateAllLifecyclePhases(); | 113 document().view()->updateAllLifecyclePhases(); |
| 89 } | 114 } |
| 90 | 115 |
| 91 TEST_F(EventHandlerTest, dragSelectionAfterScroll) { | 116 TEST_F(EventHandlerTest, dragSelectionAfterScroll) { |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 454 WebInputEvent::MouseUp, WebFloatPoint(100, 50), WebFloatPoint(200, 250), | 479 WebInputEvent::MouseUp, WebFloatPoint(100, 50), WebFloatPoint(200, 250), |
| 455 WebPointerProperties::Button::Left, 1, WebInputEvent::NoModifiers, | 480 WebPointerProperties::Button::Left, 1, WebInputEvent::NoModifiers, |
| 456 TimeTicks::Now().InSeconds()); | 481 TimeTicks::Now().InSeconds()); |
| 457 mouseUpEvent.setFrameScale(1); | 482 mouseUpEvent.setFrameScale(1); |
| 458 document().frame()->eventHandler().dragSourceEndedAt(mouseUpEvent, | 483 document().frame()->eventHandler().dragSourceEndedAt(mouseUpEvent, |
| 459 DragOperationNone); | 484 DragOperationNone); |
| 460 | 485 |
| 461 // This test passes if it doesn't crash. | 486 // This test passes if it doesn't crash. |
| 462 } | 487 } |
| 463 | 488 |
| 489 TEST_F(EventHandlerTest, | |
| 490 ScrollerSizeOfMainThreadScrollingHistogramRecordingTest) { | |
| 491 setHtmlInnerHTML( | |
| 492 "<style>" | |
| 493 " .box {width: 100px; height: 100px; overflow: scroll; opacity: 0.5; }" | |
| 494 " .spacer { height: 1000px;} body {height: 1000px; }" | |
| 495 "</style>" | |
| 496 "<div class='box'>" | |
| 497 " <div id='content' class='spacer'></div>" | |
| 498 "</div>"); | |
| 499 | |
| 500 HistogramTester histogramTester; | |
| 501 | |
| 502 // Test wheel scroll on the box. | |
| 503 ScrollBeginEventBuilder wheelScrollBegin( | |
| 504 IntPoint(50, 50), FloatPoint(0.f, 1.f), WebGestureDeviceTouchpad); | |
| 505 ScrollEndEventBuilder wheelScrollEnd; | |
| 506 document().frame()->eventHandler().handleGestureEvent(wheelScrollBegin); | |
| 507 document().frame()->eventHandler().handleGestureEvent(wheelScrollEnd); | |
| 508 histogramTester.expectTotalCount("Event.Scroll.ScrollerSize.OnScroll_Wheel", | |
| 509 1); | |
| 510 histogramTester.expectBucketCount("Event.Scroll.ScrollerSize.OnScroll_Wheel", | |
| 511 10000, 1); | |
| 512 | |
| 513 // Test touch scroll on the main frame. | |
| 514 ScrollBeginEventBuilder touchScrollBegin( | |
| 515 IntPoint(200, 200), FloatPoint(0.f, 1.f), WebGestureDeviceTouchscreen); | |
| 516 document().frame()->eventHandler().handleGestureEvent(touchScrollBegin); | |
| 517 document().frame()->eventHandler().handleGestureEvent(wheelScrollEnd); | |
| 518 histogramTester.expectTotalCount("Event.Scroll.ScrollerSize.OnScroll_Touch", | |
| 519 1); | |
| 520 histogramTester.expectBucketCount("Event.Scroll.ScrollerSize.OnScroll_Touch", | |
| 521 200000, 1); | |
|
bokan
2017/03/31 20:23:50
Why is this in the 200,000+ bucket? Isn't the fram
yigu
2017/03/31 20:38:32
IntPoint(200, 200) is the scrolling start position
bokan
2017/04/04 15:25:45
Right, but the viewport is 300x400 which is < 200,
| |
| 522 } | |
| 523 | |
| 464 class TooltipCapturingChromeClient : public EmptyChromeClient { | 524 class TooltipCapturingChromeClient : public EmptyChromeClient { |
| 465 public: | 525 public: |
| 466 TooltipCapturingChromeClient() {} | 526 TooltipCapturingChromeClient() {} |
| 467 | 527 |
| 468 void setToolTip(LocalFrame&, const String& str, TextDirection) override { | 528 void setToolTip(LocalFrame&, const String& str, TextDirection) override { |
| 469 m_lastToolTip = str; | 529 m_lastToolTip = str; |
| 470 } | 530 } |
| 471 | 531 |
| 472 String& lastToolTip() { return m_lastToolTip; } | 532 String& lastToolTip() { return m_lastToolTip; } |
| 473 | 533 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 WebInputEvent::MouseLeave, WebFloatPoint(0, 0), WebFloatPoint(0, 0), | 574 WebInputEvent::MouseLeave, WebFloatPoint(0, 0), WebFloatPoint(0, 0), |
| 515 WebPointerProperties::Button::NoButton, 0, WebInputEvent::NoModifiers, | 575 WebPointerProperties::Button::NoButton, 0, WebInputEvent::NoModifiers, |
| 516 TimeTicks::Now().InSeconds()); | 576 TimeTicks::Now().InSeconds()); |
| 517 mouseLeaveEvent.setFrameScale(1); | 577 mouseLeaveEvent.setFrameScale(1); |
| 518 document().frame()->eventHandler().handleMouseLeaveEvent(mouseLeaveEvent); | 578 document().frame()->eventHandler().handleMouseLeaveEvent(mouseLeaveEvent); |
| 519 | 579 |
| 520 EXPECT_EQ(WTF::String(), lastToolTip()); | 580 EXPECT_EQ(WTF::String(), lastToolTip()); |
| 521 } | 581 } |
| 522 | 582 |
| 523 } // namespace blink | 583 } // namespace blink |
| OLD | NEW |