OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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/dom/Range.h" | 5 #include "core/dom/Range.h" |
6 #include "core/frame/FrameView.h" | 6 #include "core/frame/FrameView.h" |
7 #include "core/input/EventHandler.h" | 7 #include "core/input/EventHandler.h" |
8 #include "core/page/ChromeClient.h" | 8 #include "core/page/ChromeClient.h" |
9 #include "core/page/ContextMenuController.h" | 9 #include "core/page/ContextMenuController.h" |
10 #include "core/page/FocusController.h" | 10 #include "core/page/FocusController.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 String getSelectionText(); | 45 String getSelectionText(); |
46 | 46 |
47 FrameTestHelpers::WebViewHelper m_helper; | 47 FrameTestHelpers::WebViewHelper m_helper; |
48 WebViewImpl* m_webView = nullptr; | 48 WebViewImpl* m_webView = nullptr; |
49 Persistent<WebLocalFrameImpl> m_mainFrame = nullptr; | 49 Persistent<WebLocalFrameImpl> m_mainFrame = nullptr; |
50 }; | 50 }; |
51 | 51 |
52 void LinkSelectionTestBase::emulateMouseDrag(const IntPoint& downPoint, const In
tPoint& upPoint, int modifiers, DragFlags dragFlags) | 52 void LinkSelectionTestBase::emulateMouseDrag(const IntPoint& downPoint, const In
tPoint& upPoint, int modifiers, DragFlags dragFlags) |
53 { | 53 { |
54 if (dragFlags & SendDownEvent) { | 54 if (dragFlags & SendDownEvent) { |
55 const auto& downEvent = FrameTestHelpers::createMouseEvent(WebMouseEvent
::MouseDown, WebMouseEvent::ButtonLeft, downPoint, modifiers); | 55 const auto& downEvent = FrameTestHelpers::createMouseEvent(WebMouseEvent
::MouseDown, WebMouseEvent::Button::Left, downPoint, modifiers); |
56 m_webView->handleInputEvent(downEvent); | 56 m_webView->handleInputEvent(downEvent); |
57 } | 57 } |
58 | 58 |
59 const int kMoveEventsNumber = 10; | 59 const int kMoveEventsNumber = 10; |
60 const float kMoveIncrementFraction = 1. / kMoveEventsNumber; | 60 const float kMoveIncrementFraction = 1. / kMoveEventsNumber; |
61 const auto& upDownVector = upPoint - downPoint; | 61 const auto& upDownVector = upPoint - downPoint; |
62 for (int i = 0; i < kMoveEventsNumber; ++i) { | 62 for (int i = 0; i < kMoveEventsNumber; ++i) { |
63 const auto& movePoint = downPoint + scaled(upDownVector, i * kMoveIncrem
entFraction); | 63 const auto& movePoint = downPoint + scaled(upDownVector, i * kMoveIncrem
entFraction); |
64 const auto& moveEvent = FrameTestHelpers::createMouseEvent(WebMouseEvent
::MouseMove, WebMouseEvent::ButtonLeft, movePoint, modifiers); | 64 const auto& moveEvent = FrameTestHelpers::createMouseEvent(WebMouseEvent
::MouseMove, WebMouseEvent::Button::Left, movePoint, modifiers); |
65 m_webView->handleInputEvent(moveEvent); | 65 m_webView->handleInputEvent(moveEvent); |
66 } | 66 } |
67 | 67 |
68 if (dragFlags & SendUpEvent) { | 68 if (dragFlags & SendUpEvent) { |
69 const auto& upEvent = FrameTestHelpers::createMouseEvent(WebMouseEvent::
MouseUp, WebMouseEvent::ButtonLeft, upPoint, modifiers); | 69 const auto& upEvent = FrameTestHelpers::createMouseEvent(WebMouseEvent::
MouseUp, WebMouseEvent::Button::Left, upPoint, modifiers); |
70 m_webView->handleInputEvent(upEvent); | 70 m_webView->handleInputEvent(upEvent); |
71 } | 71 } |
72 } | 72 } |
73 | 73 |
74 void LinkSelectionTestBase::emulateMouseClick(const IntPoint& clickPoint, WebMou
seEvent::Button button, int modifiers, int count) | 74 void LinkSelectionTestBase::emulateMouseClick(const IntPoint& clickPoint, WebMou
seEvent::Button button, int modifiers, int count) |
75 { | 75 { |
76 auto event = FrameTestHelpers::createMouseEvent(WebMouseEvent::MouseDown, bu
tton, clickPoint, modifiers); | 76 auto event = FrameTestHelpers::createMouseEvent(WebMouseEvent::MouseDown, bu
tton, clickPoint, modifiers); |
77 event.clickCount = count; | 77 event.clickCount = count; |
78 m_webView->handleInputEvent(event); | 78 m_webView->handleInputEvent(event); |
79 event.type = WebMouseEvent::MouseUp; | 79 event.type = WebMouseEvent::MouseUp; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 EXPECT_EQ(Cursor::IBeam, cursor.getType()); | 168 EXPECT_EQ(Cursor::IBeam, cursor.getType()); |
169 } | 169 } |
170 | 170 |
171 TEST_F(LinkSelectionTest, HandCursorOverLinkAfterContextMenu) | 171 TEST_F(LinkSelectionTest, HandCursorOverLinkAfterContextMenu) |
172 { | 172 { |
173 // Move mouse. | 173 // Move mouse. |
174 emulateMouseDrag(m_rightPointInLink, m_leftPointInLink, 0, 0); | 174 emulateMouseDrag(m_rightPointInLink, m_leftPointInLink, 0, 0); |
175 | 175 |
176 // Show context menu. We don't send mouseup event here since in browser it d
oesn't reach | 176 // Show context menu. We don't send mouseup event here since in browser it d
oesn't reach |
177 // blink because of shown context menu. | 177 // blink because of shown context menu. |
178 emulateMouseDown(m_leftPointInLink, WebMouseEvent::ButtonRight, 0, 1); | 178 emulateMouseDown(m_leftPointInLink, WebMouseEvent::Button::Right, 0, 1); |
179 | 179 |
180 LocalFrame* frame = m_mainFrame->frame(); | 180 LocalFrame* frame = m_mainFrame->frame(); |
181 // Hide context menu. | 181 // Hide context menu. |
182 frame->page()->contextMenuController().clearContextMenu(); | 182 frame->page()->contextMenuController().clearContextMenu(); |
183 | 183 |
184 frame->localFrameRoot()->eventHandler().scheduleCursorUpdate(); | 184 frame->localFrameRoot()->eventHandler().scheduleCursorUpdate(); |
185 testing::runDelayedTasks(50); | 185 testing::runDelayedTasks(50); |
186 const auto& cursor = m_mainFrame->frame()->chromeClient().lastSetCursorForTe
sting(); | 186 const auto& cursor = m_mainFrame->frame()->chromeClient().lastSetCursorForTe
sting(); |
187 EXPECT_EQ(Cursor::Hand, cursor.getType()); | 187 EXPECT_EQ(Cursor::Hand, cursor.getType()); |
188 } | 188 } |
189 | 189 |
190 TEST_F(LinkSelectionTest, SingleClickWithAltStartsDownload) | 190 TEST_F(LinkSelectionTest, SingleClickWithAltStartsDownload) |
191 { | 191 { |
192 EXPECT_CALL(m_testFrameClient, loadURLExternally(_, WebNavigationPolicy::Web
NavigationPolicyDownload, WebString(), _)); | 192 EXPECT_CALL(m_testFrameClient, loadURLExternally(_, WebNavigationPolicy::Web
NavigationPolicyDownload, WebString(), _)); |
193 emulateMouseClick(m_leftPointInLink, WebMouseEvent::ButtonLeft, WebInputEven
t::AltKey); | 193 emulateMouseClick(m_leftPointInLink, WebMouseEvent::Button::Left, WebInputEv
ent::AltKey); |
194 } | 194 } |
195 | 195 |
196 TEST_F(LinkSelectionTest, SingleClickWithAltStartsDownloadWhenTextSelected) | 196 TEST_F(LinkSelectionTest, SingleClickWithAltStartsDownloadWhenTextSelected) |
197 { | 197 { |
198 auto* document = m_mainFrame->frame()->document(); | 198 auto* document = m_mainFrame->frame()->document(); |
199 auto* textToSelect = document->getElementById("page_text")->firstChild(); | 199 auto* textToSelect = document->getElementById("page_text")->firstChild(); |
200 ASSERT_NE(nullptr, textToSelect); | 200 ASSERT_NE(nullptr, textToSelect); |
201 | 201 |
202 // Select some page text outside the link element. | 202 // Select some page text outside the link element. |
203 const Range* rangeToSelect = Range::create(*document, textToSelect, 1, textT
oSelect, 20); | 203 const Range* rangeToSelect = Range::create(*document, textToSelect, 1, textT
oSelect, 20); |
204 const auto& selectionRect = rangeToSelect->boundingBox(); | 204 const auto& selectionRect = rangeToSelect->boundingBox(); |
205 m_mainFrame->moveRangeSelection(selectionRect.minXMinYCorner(), selectionRec
t.maxXMaxYCorner()); | 205 m_mainFrame->moveRangeSelection(selectionRect.minXMinYCorner(), selectionRec
t.maxXMaxYCorner()); |
206 EXPECT_FALSE(getSelectionText().isEmpty()); | 206 EXPECT_FALSE(getSelectionText().isEmpty()); |
207 | 207 |
208 EXPECT_CALL(m_testFrameClient, loadURLExternally(_, WebNavigationPolicy::Web
NavigationPolicyDownload, WebString(), _)); | 208 EXPECT_CALL(m_testFrameClient, loadURLExternally(_, WebNavigationPolicy::Web
NavigationPolicyDownload, WebString(), _)); |
209 emulateMouseClick(m_leftPointInLink, WebMouseEvent::ButtonLeft, WebInputEven
t::AltKey); | 209 emulateMouseClick(m_leftPointInLink, WebMouseEvent::Button::Left, WebInputEv
ent::AltKey); |
210 } | 210 } |
211 | 211 |
212 class LinkSelectionClickEventsTest : public LinkSelectionTestBase { | 212 class LinkSelectionClickEventsTest : public LinkSelectionTestBase { |
213 protected: | 213 protected: |
214 class MockEventListener final : public EventListener { | 214 class MockEventListener final : public EventListener { |
215 public: | 215 public: |
216 static MockEventListener* create() | 216 static MockEventListener* create() |
217 { | 217 { |
218 return new MockEventListener(); | 218 return new MockEventListener(); |
219 } | 219 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 MockEventListener* eventHandler = MockEventListener::create(); | 268 MockEventListener* eventHandler = MockEventListener::create(); |
269 element.addEventListener( | 269 element.addEventListener( |
270 doubleClickEvent ? EventTypeNames::dblclick : EventTypeNames::click, | 270 doubleClickEvent ? EventTypeNames::dblclick : EventTypeNames::click, |
271 eventHandler); | 271 eventHandler); |
272 | 272 |
273 ::testing::InSequence s; | 273 ::testing::InSequence s; |
274 EXPECT_CALL(*eventHandler, handleEvent(_, _)).Times(1); | 274 EXPECT_CALL(*eventHandler, handleEvent(_, _)).Times(1); |
275 | 275 |
276 const auto& elemBounds = element.boundsInViewport(); | 276 const auto& elemBounds = element.boundsInViewport(); |
277 const int clickCount = doubleClickEvent ? 2 : 1; | 277 const int clickCount = doubleClickEvent ? 2 : 1; |
278 emulateMouseClick(elemBounds.center(), WebMouseEvent::ButtonLeft, 0, cli
ckCount); | 278 emulateMouseClick(elemBounds.center(), WebMouseEvent::Button::Left, 0, c
lickCount); |
279 | 279 |
280 if (doubleClickEvent) { | 280 if (doubleClickEvent) { |
281 EXPECT_EQ(element.innerText().isEmpty(), getSelectionText().isEmpty(
)); | 281 EXPECT_EQ(element.innerText().isEmpty(), getSelectionText().isEmpty(
)); |
282 } | 282 } |
283 } | 283 } |
284 }; | 284 }; |
285 | 285 |
286 TEST_F(LinkSelectionClickEventsTest, SingleAndDoubleClickWillBeHandled) | 286 TEST_F(LinkSelectionClickEventsTest, SingleAndDoubleClickWillBeHandled) |
287 { | 287 { |
288 auto* document = m_mainFrame->frame()->document(); | 288 auto* document = m_mainFrame->frame()->document(); |
(...skipping 16 matching lines...) Expand all Loading... |
305 checkMouseClicks(*element, false); | 305 checkMouseClicks(*element, false); |
306 } | 306 } |
307 | 307 |
308 { | 308 { |
309 SCOPED_TRACE("Text div, double click"); | 309 SCOPED_TRACE("Text div, double click"); |
310 checkMouseClicks(*element, true); | 310 checkMouseClicks(*element, true); |
311 } | 311 } |
312 } | 312 } |
313 | 313 |
314 } // namespace blink | 314 } // namespace blink |
OLD | NEW |