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" |
| 20 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
20 | 22 |
21 namespace blink { | 23 namespace blink { |
22 | 24 |
23 class EventHandlerTest : public ::testing::Test { | 25 class EventHandlerTest : public ::testing::Test { |
24 protected: | 26 protected: |
25 void SetUp() override; | 27 void SetUp() override; |
26 | 28 |
27 Page& page() const { return m_dummyPageHolder->page(); } | 29 Page& page() const { return m_dummyPageHolder->page(); } |
28 Document& document() const { return m_dummyPageHolder->document(); } | 30 Document& document() const { return m_dummyPageHolder->document(); } |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 WebInputEvent::MouseUp, WebFloatPoint(100, 50), WebFloatPoint(200, 250), | 456 WebInputEvent::MouseUp, WebFloatPoint(100, 50), WebFloatPoint(200, 250), |
455 WebPointerProperties::Button::Left, 1, WebInputEvent::NoModifiers, | 457 WebPointerProperties::Button::Left, 1, WebInputEvent::NoModifiers, |
456 TimeTicks::Now().InSeconds()); | 458 TimeTicks::Now().InSeconds()); |
457 mouseUpEvent.setFrameScale(1); | 459 mouseUpEvent.setFrameScale(1); |
458 document().frame()->eventHandler().dragSourceEndedAt(mouseUpEvent, | 460 document().frame()->eventHandler().dragSourceEndedAt(mouseUpEvent, |
459 DragOperationNone); | 461 DragOperationNone); |
460 | 462 |
461 // This test passes if it doesn't crash. | 463 // This test passes if it doesn't crash. |
462 } | 464 } |
463 | 465 |
| 466 TEST_F(EventHandlerTest, MainThreadScrollingReasonRecordTest) { |
| 467 HistogramTester histogramTester; |
| 468 // Test wheel scroll |
| 469 ScrollManager* scrollManager = new ScrollManager(*(document().frame())); |
| 470 scrollManager->recordMainThreadScrollingReasons( |
| 471 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects | |
| 472 MainThreadScrollingReason::kThreadedScrollingDisabled | |
| 473 MainThreadScrollingReason::kPageOverlay | |
| 474 MainThreadScrollingReason::kHandlingScrollFromMainThread, |
| 475 WebGestureDeviceTouchpad); |
| 476 |
| 477 histogramTester.expectBucketCount("Renderer4.MainThreadWheelScrollReason", 1, |
| 478 1); |
| 479 histogramTester.expectBucketCount("Renderer4.MainThreadWheelScrollReason", 3, |
| 480 1); |
| 481 histogramTester.expectBucketCount("Renderer4.MainThreadWheelScrollReason", 5, |
| 482 1); |
| 483 |
| 484 // We only want to record "Handling scroll from main thread" reason if it's |
| 485 // the only reason. If it's not the only reason, the "real" reason for |
| 486 // scrolling on main is something else, and we only want to pay attention to |
| 487 // that reason. So we should only include this reason in the histogram when |
| 488 // its on its own. |
| 489 scrollManager->recordMainThreadScrollingReasons( |
| 490 MainThreadScrollingReason::kHandlingScrollFromMainThread, |
| 491 blink::WebGestureDeviceTouchpad); |
| 492 |
| 493 histogramTester.expectBucketCount("Renderer4.MainThreadWheelScrollReason", 1, |
| 494 1); |
| 495 histogramTester.expectBucketCount("Renderer4.MainThreadWheelScrollReason", 3, |
| 496 1); |
| 497 histogramTester.expectBucketCount("Renderer4.MainThreadWheelScrollReason", 5, |
| 498 1); |
| 499 histogramTester.expectBucketCount("Renderer4.MainThreadWheelScrollReason", 14, |
| 500 1); |
| 501 |
| 502 scrollManager->recordMainThreadScrollingReasons( |
| 503 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects | |
| 504 MainThreadScrollingReason::kThreadedScrollingDisabled | |
| 505 MainThreadScrollingReason::kPageOverlay | |
| 506 MainThreadScrollingReason::kHandlingScrollFromMainThread, |
| 507 WebGestureDeviceTouchpad); |
| 508 |
| 509 histogramTester.expectBucketCount("Renderer4.MainThreadWheelScrollReason", 1, |
| 510 2); |
| 511 histogramTester.expectBucketCount("Renderer4.MainThreadWheelScrollReason", 3, |
| 512 2); |
| 513 histogramTester.expectBucketCount("Renderer4.MainThreadWheelScrollReason", 5, |
| 514 2); |
| 515 histogramTester.expectBucketCount("Renderer4.MainThreadWheelScrollReason", 14, |
| 516 1); |
| 517 |
| 518 // Test touch scroll |
| 519 scrollManager->recordMainThreadScrollingReasons( |
| 520 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects | |
| 521 MainThreadScrollingReason::kThreadedScrollingDisabled | |
| 522 MainThreadScrollingReason::kPageOverlay | |
| 523 MainThreadScrollingReason::kHandlingScrollFromMainThread, |
| 524 WebGestureDeviceTouchscreen); |
| 525 |
| 526 histogramTester.expectBucketCount("Renderer4.MainThreadGestureScrollReason", |
| 527 1, 1); |
| 528 histogramTester.expectBucketCount("Renderer4.MainThreadGestureScrollReason", |
| 529 3, 1); |
| 530 histogramTester.expectBucketCount("Renderer4.MainThreadGestureScrollReason", |
| 531 5, 1); |
| 532 |
| 533 scrollManager->recordMainThreadScrollingReasons( |
| 534 MainThreadScrollingReason::kHandlingScrollFromMainThread, |
| 535 blink::WebGestureDeviceTouchscreen); |
| 536 |
| 537 histogramTester.expectBucketCount("Renderer4.MainThreadGestureScrollReason", |
| 538 1, 1); |
| 539 histogramTester.expectBucketCount("Renderer4.MainThreadGestureScrollReason", |
| 540 3, 1); |
| 541 histogramTester.expectBucketCount("Renderer4.MainThreadGestureScrollReason", |
| 542 5, 1); |
| 543 histogramTester.expectBucketCount("Renderer4.MainThreadGestureScrollReason", |
| 544 14, 1); |
| 545 } |
| 546 |
464 class TooltipCapturingChromeClient : public EmptyChromeClient { | 547 class TooltipCapturingChromeClient : public EmptyChromeClient { |
465 public: | 548 public: |
466 TooltipCapturingChromeClient() {} | 549 TooltipCapturingChromeClient() {} |
467 | 550 |
468 void setToolTip(LocalFrame&, const String& str, TextDirection) override { | 551 void setToolTip(LocalFrame&, const String& str, TextDirection) override { |
469 m_lastToolTip = str; | 552 m_lastToolTip = str; |
470 } | 553 } |
471 | 554 |
472 String& lastToolTip() { return m_lastToolTip; } | 555 String& lastToolTip() { return m_lastToolTip; } |
473 | 556 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 WebInputEvent::MouseLeave, WebFloatPoint(0, 0), WebFloatPoint(0, 0), | 597 WebInputEvent::MouseLeave, WebFloatPoint(0, 0), WebFloatPoint(0, 0), |
515 WebPointerProperties::Button::NoButton, 0, WebInputEvent::NoModifiers, | 598 WebPointerProperties::Button::NoButton, 0, WebInputEvent::NoModifiers, |
516 TimeTicks::Now().InSeconds()); | 599 TimeTicks::Now().InSeconds()); |
517 mouseLeaveEvent.setFrameScale(1); | 600 mouseLeaveEvent.setFrameScale(1); |
518 document().frame()->eventHandler().handleMouseLeaveEvent(mouseLeaveEvent); | 601 document().frame()->eventHandler().handleMouseLeaveEvent(mouseLeaveEvent); |
519 | 602 |
520 EXPECT_EQ(WTF::String(), lastToolTip()); | 603 EXPECT_EQ(WTF::String(), lastToolTip()); |
521 } | 604 } |
522 | 605 |
523 } // namespace blink | 606 } // namespace blink |
OLD | NEW |