Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1409)

Side by Side Diff: Source/core/page/EventHandlerTest.cpp

Issue 1113323002: [Reland] Refactor the selection code in EventHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "core/page/EventHandler.h"
7
8 #include "core/dom/Document.h"
9 #include "core/dom/Range.h"
10 #include "core/editing/FrameSelection.h"
11 #include "core/frame/FrameView.h"
12 #include "core/frame/LocalFrame.h"
13 #include "core/html/HTMLDocument.h"
14 #include "core/page/AutoscrollController.h"
15 #include "core/page/Page.h"
16 #include "core/testing/CoreTestHelpers.h"
17 #include "core/testing/DummyPageHolder.h"
18 #include "platform/PlatformMouseEvent.h"
19 #include <gtest/gtest.h>
20
21 namespace blink {
22
23 class EventHandlerTest : public ::testing::Test {
24 protected:
25 virtual void SetUp() override;
26
27 Page& page() const { return m_dummyPageHolder->page(); }
28 Document& document() const { return m_dummyPageHolder->document(); }
29
30 void setHtmlInnerHTML(const char* htmlContent);
31
32 private:
33 OwnPtr<DummyPageHolder> m_dummyPageHolder;
34 };
35
36 void EventHandlerTest::SetUp()
37 {
38 m_dummyPageHolder = DummyPageHolder::create(IntSize(300, 400));
39 }
40
41 void EventHandlerTest::setHtmlInnerHTML(const char* htmlContent)
42 {
43 document().documentElement()->setInnerHTML(String::fromUTF8(htmlContent), AS SERT_NO_EXCEPTION);
44 document().view()->updateLayoutAndStyleForPainting();
45 }
46
47 TEST_F(EventHandlerTest, dragSelectionAfterScroll)
48 {
49 setHtmlInnerHTML("<style> body { margin: 0px; } .upper { width: 300px; heigh t: 400px; }"
50 ".lower { margin: 0px; width: 300px; height: 400px; } .line { display: b lock; width: 300px; height: 30px; } </style>"
51 "<div class=\"upper\"></div>"
52 "<div class=\"lower\">"
53 "<span class=\"line\">Line 1</span><span class=\"line\">Line 2</span><sp an class=\"line\">Line 3</span><span class=\"line\">Line 4</span><span class=\"l ine\">Line 5</span>"
54 "<span class=\"line\">Line 6</span><span class=\"line\">Line 7</span><sp an class=\"line\">Line 8</span><span class=\"line\">Line 9</span><span class=\"l ine\">Line 10</span>"
55 "</div>");
56
57 FrameView* frameView = document().view();
58 frameView->scrollTo(DoublePoint(0, 400));
59
60 PlatformMouseEvent mouseDownEvent(
61 IntPoint(0, 0),
62 IntPoint(100, 200),
63 LeftButton,
64 PlatformEvent::MousePressed,
65 1,
66 static_cast<PlatformEvent::Modifiers>(0),
67 WTF::currentTime());
68 document().frame()->eventHandler().handleMousePressEvent(mouseDownEvent);
69
70 PlatformMouseEvent mouseMoveEvent(
71 IntPoint(100, 50),
72 IntPoint(200, 250),
73 LeftButton,
74 PlatformEvent::MouseMoved,
75 1,
76 static_cast<PlatformEvent::Modifiers>(0),
77 WTF::currentTime());
78 document().frame()->eventHandler().handleMouseMoveEvent(mouseMoveEvent);
79
80 page().autoscrollController().animate(WTF::currentTime());
81 page().animator().serviceScriptedAnimations(WTF::currentTime());
82
83 PlatformMouseEvent mouseUpEvent(
84 IntPoint(100, 50),
85 IntPoint(200, 250),
86 LeftButton,
87 PlatformEvent::MouseReleased,
88 1,
89 static_cast<PlatformEvent::Modifiers>(0),
90 WTF::currentTime());
91 document().frame()->eventHandler().handleMouseReleaseEvent(mouseUpEvent);
92
93 FrameSelection& selection = document().frame()->selection();
94 ASSERT_TRUE(selection.isRange());
95 RefPtrWillBeRawPtr<Range> range = selection.toNormalizedRange();
96 ASSERT_TRUE(range.get());
97 EXPECT_EQ("Line 1\nLine 2", range->text());
98 }
99
100 } // namespace blink
OLDNEW
« Source/core/editing/SelectionController.cpp ('K') | « Source/core/page/EventHandler.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698