OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 11 matching lines...) Expand all Loading... |
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
23 */ | 23 */ |
24 | 24 |
25 #include "config.h" | 25 #include "config.h" |
26 | 26 |
27 #include "web/LinkHighlight.h" | 27 #include "web/LinkHighlight.h" |
28 | 28 |
29 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 29 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
30 #include "core/dom/Node.h" | 30 #include "core/dom/Node.h" |
31 #include "core/frame/FrameView.h" | 31 #include "core/frame/FrameView.h" |
32 #include "core/page/EventHandler.h" | |
33 #include "core/page/Page.h" | |
34 #include "core/page/TouchDisambiguation.h" | 32 #include "core/page/TouchDisambiguation.h" |
35 #include "core/testing/URLTestHelpers.h" | 33 #include "core/testing/URLTestHelpers.h" |
36 #include "platform/geometry/IntRect.h" | 34 #include "platform/geometry/IntRect.h" |
37 #include "public/platform/Platform.h" | 35 #include "public/platform/Platform.h" |
38 #include "public/platform/WebContentLayer.h" | 36 #include "public/platform/WebContentLayer.h" |
39 #include "public/platform/WebFloatPoint.h" | 37 #include "public/platform/WebFloatPoint.h" |
40 #include "public/platform/WebSize.h" | 38 #include "public/platform/WebSize.h" |
41 #include "public/platform/WebUnitTestSupport.h" | 39 #include "public/platform/WebUnitTestSupport.h" |
42 #include "public/web/WebFrame.h" | 40 #include "public/web/WebFrame.h" |
43 #include "public/web/WebFrameClient.h" | 41 #include "public/web/WebFrameClient.h" |
44 #include "public/web/WebInputEvent.h" | 42 #include "public/web/WebInputEvent.h" |
45 #include "public/web/WebViewClient.h" | 43 #include "public/web/WebViewClient.h" |
46 #include "web/WebInputEventConversion.h" | 44 #include "web/WebInputEventConversion.h" |
47 #include "web/WebLocalFrameImpl.h" | 45 #include "web/WebLocalFrameImpl.h" |
48 #include "web/WebViewImpl.h" | 46 #include "web/WebViewImpl.h" |
49 #include "web/tests/FrameTestHelpers.h" | 47 #include "web/tests/FrameTestHelpers.h" |
50 #include "wtf/PassOwnPtr.h" | 48 #include "wtf/PassOwnPtr.h" |
51 #include <gtest/gtest.h> | 49 #include <gtest/gtest.h> |
52 | 50 |
53 using namespace blink; | 51 using namespace blink; |
54 | 52 |
55 namespace { | 53 namespace { |
56 | 54 |
57 GestureEventWithHitTestResults getTargetedEvent(WebViewImpl* webViewImpl, WebGes
tureEvent& touchEvent) | |
58 { | |
59 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->fram
eView(), touchEvent); | |
60 return webViewImpl->page()->deprecatedLocalMainFrame()->eventHandler().targe
tGestureEvent(platformEvent, true); | |
61 } | |
62 | |
63 TEST(LinkHighlightTest, verifyWebViewImplIntegration) | 55 TEST(LinkHighlightTest, verifyWebViewImplIntegration) |
64 { | 56 { |
65 const std::string baseURL("http://www.test.com/"); | 57 const std::string baseURL("http://www.test.com/"); |
66 const std::string fileName("test_touch_link_highlight.html"); | 58 const std::string fileName("test_touch_link_highlight.html"); |
67 | 59 |
68 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL.c_s
tr()), WebString::fromUTF8("test_touch_link_highlight.html")); | 60 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL.c_s
tr()), WebString::fromUTF8("test_touch_link_highlight.html")); |
69 FrameTestHelpers::WebViewHelper webViewHelper; | 61 FrameTestHelpers::WebViewHelper webViewHelper; |
70 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(baseURL + fileNam
e, true); | 62 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(baseURL + fileNam
e, true); |
71 int pageWidth = 640; | 63 int pageWidth = 640; |
72 int pageHeight = 480; | 64 int pageHeight = 480; |
73 webViewImpl->resize(WebSize(pageWidth, pageHeight)); | 65 webViewImpl->resize(WebSize(pageWidth, pageHeight)); |
74 webViewImpl->layout(); | 66 webViewImpl->layout(); |
75 | 67 |
76 WebGestureEvent touchEvent; | 68 WebGestureEvent touchEvent; |
77 touchEvent.type = WebInputEvent::GestureShowPress; | 69 touchEvent.type = WebInputEvent::GestureShowPress; |
78 | 70 |
79 // The coordinates below are linked to absolute positions in the referenced
.html file. | 71 // The coordinates below are linked to absolute positions in the referenced
.html file. |
80 touchEvent.x = 20; | 72 touchEvent.x = 20; |
81 touchEvent.y = 20; | 73 touchEvent.y = 20; |
82 | 74 |
83 ASSERT_TRUE(webViewImpl->bestTapNode(getTargetedEvent(webViewImpl, touchEven
t))); | 75 { |
| 76 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->
frameView(), touchEvent); |
| 77 Node* touchNode = webViewImpl->bestTapNode(platformEvent); |
| 78 ASSERT_TRUE(touchNode); |
| 79 } |
84 | 80 |
85 touchEvent.y = 40; | 81 touchEvent.y = 40; |
86 EXPECT_FALSE(webViewImpl->bestTapNode(getTargetedEvent(webViewImpl, touchEve
nt))); | 82 { |
| 83 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->
frameView(), touchEvent); |
| 84 EXPECT_FALSE(webViewImpl->bestTapNode(platformEvent)); |
| 85 } |
87 | 86 |
88 touchEvent.y = 20; | 87 touchEvent.y = 20; |
89 // Shouldn't crash. | 88 // Shouldn't crash. |
90 webViewImpl->enableTapHighlightAtPoint(getTargetedEvent(webViewImpl, touchEv
ent)); | 89 |
| 90 { |
| 91 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->
frameView(), touchEvent); |
| 92 webViewImpl->enableTapHighlightAtPoint(platformEvent); |
| 93 } |
91 | 94 |
92 EXPECT_TRUE(webViewImpl->linkHighlight(0)); | 95 EXPECT_TRUE(webViewImpl->linkHighlight(0)); |
93 EXPECT_TRUE(webViewImpl->linkHighlight(0)->contentLayer()); | 96 EXPECT_TRUE(webViewImpl->linkHighlight(0)->contentLayer()); |
94 EXPECT_TRUE(webViewImpl->linkHighlight(0)->clipLayer()); | 97 EXPECT_TRUE(webViewImpl->linkHighlight(0)->clipLayer()); |
95 | 98 |
96 // Find a target inside a scrollable div | 99 // Find a target inside a scrollable div |
| 100 |
97 touchEvent.y = 100; | 101 touchEvent.y = 100; |
98 webViewImpl->enableTapHighlightAtPoint(getTargetedEvent(webViewImpl, touchEv
ent)); | 102 { |
| 103 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->
frameView(), touchEvent); |
| 104 webViewImpl->enableTapHighlightAtPoint(platformEvent); |
| 105 } |
| 106 |
99 ASSERT_TRUE(webViewImpl->linkHighlight(0)); | 107 ASSERT_TRUE(webViewImpl->linkHighlight(0)); |
100 | 108 |
101 // Don't highlight if no "hand cursor" | 109 // Don't highlight if no "hand cursor" |
102 touchEvent.y = 220; // An A-link with cross-hair cursor. | 110 touchEvent.y = 220; // An A-link with cross-hair cursor. |
103 webViewImpl->enableTapHighlightAtPoint(getTargetedEvent(webViewImpl, touchEv
ent)); | 111 { |
| 112 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->
frameView(), touchEvent); |
| 113 webViewImpl->enableTapHighlightAtPoint(platformEvent); |
| 114 } |
104 ASSERT_EQ(0U, webViewImpl->numLinkHighlights()); | 115 ASSERT_EQ(0U, webViewImpl->numLinkHighlights()); |
105 | 116 |
106 touchEvent.y = 260; // A text input box. | 117 touchEvent.y = 260; // A text input box. |
107 webViewImpl->enableTapHighlightAtPoint(getTargetedEvent(webViewImpl, touchEv
ent)); | 118 { |
| 119 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->
frameView(), touchEvent); |
| 120 webViewImpl->enableTapHighlightAtPoint(platformEvent); |
| 121 } |
108 ASSERT_EQ(0U, webViewImpl->numLinkHighlights()); | 122 ASSERT_EQ(0U, webViewImpl->numLinkHighlights()); |
109 | 123 |
110 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | 124 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
111 } | 125 } |
112 | 126 |
113 class FakeWebFrameClient : public WebFrameClient { | 127 class FakeWebFrameClient : public WebFrameClient { |
114 // To make the destructor public. | 128 // To make the destructor public. |
115 }; | 129 }; |
116 | 130 |
117 class FakeCompositingWebViewClient : public FrameTestHelpers::TestWebViewClient
{ | 131 class FakeCompositingWebViewClient : public FrameTestHelpers::TestWebViewClient
{ |
(...skipping 19 matching lines...) Expand all Loading... |
137 int pageWidth = 640; | 151 int pageWidth = 640; |
138 int pageHeight = 480; | 152 int pageHeight = 480; |
139 webViewImpl->resize(WebSize(pageWidth, pageHeight)); | 153 webViewImpl->resize(WebSize(pageWidth, pageHeight)); |
140 webViewImpl->layout(); | 154 webViewImpl->layout(); |
141 | 155 |
142 WebGestureEvent touchEvent; | 156 WebGestureEvent touchEvent; |
143 touchEvent.type = WebInputEvent::GestureShowPress; | 157 touchEvent.type = WebInputEvent::GestureShowPress; |
144 touchEvent.x = 20; | 158 touchEvent.x = 20; |
145 touchEvent.y = 20; | 159 touchEvent.y = 20; |
146 | 160 |
147 GestureEventWithHitTestResults targetedEvent = getTargetedEvent(webViewImpl,
touchEvent); | 161 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->fram
eView(), touchEvent); |
148 Node* touchNode = webViewImpl->bestTapNode(targetedEvent); | 162 Node* touchNode = webViewImpl->bestTapNode(platformEvent); |
149 ASSERT_TRUE(touchNode); | 163 ASSERT_TRUE(touchNode); |
150 | 164 |
151 webViewImpl->enableTapHighlightAtPoint(targetedEvent); | 165 webViewImpl->enableTapHighlightAtPoint(platformEvent); |
152 ASSERT_TRUE(webViewImpl->linkHighlight(0)); | 166 ASSERT_TRUE(webViewImpl->linkHighlight(0)); |
153 | 167 |
154 GraphicsLayer* highlightLayer = webViewImpl->linkHighlight(0)->currentGraphi
csLayerForTesting(); | 168 GraphicsLayer* highlightLayer = webViewImpl->linkHighlight(0)->currentGraphi
csLayerForTesting(); |
155 ASSERT_TRUE(highlightLayer); | 169 ASSERT_TRUE(highlightLayer); |
156 EXPECT_TRUE(highlightLayer->linkHighlight(0)); | 170 EXPECT_TRUE(highlightLayer->linkHighlight(0)); |
157 | 171 |
158 touchNode->remove(IGNORE_EXCEPTION); | 172 touchNode->remove(IGNORE_EXCEPTION); |
159 webViewImpl->layout(); | 173 webViewImpl->layout(); |
160 ASSERT_EQ(0U, highlightLayer->numLinkHighlights()); | 174 ASSERT_EQ(0U, highlightLayer->numLinkHighlights()); |
161 | 175 |
(...skipping 25 matching lines...) Expand all Loading... |
187 IntRect boundingBox(touchEvent.x - touchEvent.data.tap.width / 2, touchEvent
.y - touchEvent.data.tap.height / 2, touchEvent.data.tap.width, touchEvent.data.
tap.height); | 201 IntRect boundingBox(touchEvent.x - touchEvent.data.tap.width / 2, touchEvent
.y - touchEvent.data.tap.height / 2, touchEvent.data.tap.width, touchEvent.data.
tap.height); |
188 findGoodTouchTargets(boundingBox, webViewImpl->mainFrameImpl()->frame(), goo
dTargets, highlightNodes); | 202 findGoodTouchTargets(boundingBox, webViewImpl->mainFrameImpl()->frame(), goo
dTargets, highlightNodes); |
189 | 203 |
190 webViewImpl->enableTapHighlights(highlightNodes); | 204 webViewImpl->enableTapHighlights(highlightNodes); |
191 EXPECT_EQ(2U, webViewImpl->numLinkHighlights()); | 205 EXPECT_EQ(2U, webViewImpl->numLinkHighlights()); |
192 | 206 |
193 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | 207 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
194 } | 208 } |
195 | 209 |
196 } // namespace | 210 } // namespace |
OLD | NEW |