| 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 28 matching lines...) Expand all Loading... |
| 39 void emulateMouseDrag(const IntPoint& downPoint, const IntPoint& upPoint, in
t modifiers, | 39 void emulateMouseDrag(const IntPoint& downPoint, const IntPoint& upPoint, in
t modifiers, |
| 40 DragFlags = SendDownEvent | SendUpEvent); | 40 DragFlags = SendDownEvent | SendUpEvent); |
| 41 | 41 |
| 42 void emulateMouseClick(const IntPoint& clickPoint, WebMouseEvent::Button, in
t modifiers, int count = 1); | 42 void emulateMouseClick(const IntPoint& clickPoint, WebMouseEvent::Button, in
t modifiers, int count = 1); |
| 43 void emulateMouseDown(const IntPoint& clickPoint, WebMouseEvent::Button, int
modifiers, int count = 1); | 43 void emulateMouseDown(const IntPoint& clickPoint, WebMouseEvent::Button, int
modifiers, int count = 1); |
| 44 | 44 |
| 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 RawPtrWillBePersistent<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::ButtonLeft, 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; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 emulateMouseClick(m_leftPointInLink, WebMouseEvent::ButtonLeft, WebInputEven
t::AltKey); | 193 emulateMouseClick(m_leftPointInLink, WebMouseEvent::ButtonLeft, WebInputEven
t::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 RefPtrWillBeRawPtr<Range> rangeToSelect = Range::create(*document, tex
tToSelect, 1, textToSelect, 20); | 203 const RawPtr<Range> rangeToSelect = Range::create(*document, textToSelect, 1
, textToSelect, 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::ButtonLeft, WebInputEven
t::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 PassRefPtrWillBeRawPtr<MockEventListener> create() | 216 static RawPtr<MockEventListener> create() |
| 217 { | 217 { |
| 218 return adoptRefWillBeNoop(new MockEventListener()); | 218 return new MockEventListener(); |
| 219 } | 219 } |
| 220 | 220 |
| 221 bool operator==(const EventListener& other) const final | 221 bool operator==(const EventListener& other) const final |
| 222 { | 222 { |
| 223 return this == &other; | 223 return this == &other; |
| 224 } | 224 } |
| 225 | 225 |
| 226 MOCK_METHOD2(handleEvent, void(ExecutionContext* executionContext, Event
*)); | 226 MOCK_METHOD2(handleEvent, void(ExecutionContext* executionContext, Event
*)); |
| 227 | 227 |
| 228 private: | 228 private: |
| (...skipping 26 matching lines...) Expand all Loading... |
| 255 void checkMouseClicks(Element& element, bool doubleClickEvent) | 255 void checkMouseClicks(Element& element, bool doubleClickEvent) |
| 256 { | 256 { |
| 257 struct ScopedListenersCleaner { | 257 struct ScopedListenersCleaner { |
| 258 ScopedListenersCleaner(Element* element) : m_element(element) {} | 258 ScopedListenersCleaner(Element* element) : m_element(element) {} |
| 259 | 259 |
| 260 ~ScopedListenersCleaner() | 260 ~ScopedListenersCleaner() |
| 261 { | 261 { |
| 262 m_element->removeAllEventListeners(); | 262 m_element->removeAllEventListeners(); |
| 263 } | 263 } |
| 264 | 264 |
| 265 RawPtrWillBePersistent<Element> m_element; | 265 Persistent<Element> m_element; |
| 266 } const listenersCleaner(&element); | 266 } const listenersCleaner(&element); |
| 267 | 267 |
| 268 RefPtrWillBeRawPtr<MockEventListener> eventHandler = MockEventListener::
create(); | 268 RawPtr<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::ButtonLeft, 0, cli
ckCount); |
| (...skipping 26 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 |