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 |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND |
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
16 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE | 16 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE |
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | 19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
23 * DAMAGE. | 23 * DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "web/LinkHighlightImpl.h" | 26 #include "web/LinkHighlightImpl.h" |
27 | 27 |
| 28 #include <memory> |
28 #include "bindings/core/v8/ExceptionState.h" | 29 #include "bindings/core/v8/ExceptionState.h" |
29 #include "core/dom/Node.h" | 30 #include "core/dom/Node.h" |
30 #include "core/frame/FrameView.h" | 31 #include "core/frame/FrameView.h" |
31 #include "core/input/EventHandler.h" | 32 #include "core/input/EventHandler.h" |
32 #include "core/page/Page.h" | 33 #include "core/page/Page.h" |
33 #include "core/page/TouchDisambiguation.h" | 34 #include "core/page/TouchDisambiguation.h" |
34 #include "platform/geometry/IntRect.h" | 35 #include "platform/geometry/IntRect.h" |
35 #include "platform/testing/URLTestHelpers.h" | 36 #include "platform/testing/URLTestHelpers.h" |
| 37 #include "platform/testing/UnitTestHelpers.h" |
36 #include "public/platform/Platform.h" | 38 #include "public/platform/Platform.h" |
37 #include "public/platform/WebContentLayer.h" | 39 #include "public/platform/WebContentLayer.h" |
38 #include "public/platform/WebFloatPoint.h" | 40 #include "public/platform/WebFloatPoint.h" |
39 #include "public/platform/WebInputEvent.h" | 41 #include "public/platform/WebInputEvent.h" |
40 #include "public/platform/WebSize.h" | 42 #include "public/platform/WebSize.h" |
41 #include "public/platform/WebURLLoaderMockFactory.h" | 43 #include "public/platform/WebURLLoaderMockFactory.h" |
42 #include "public/web/WebCache.h" | 44 #include "public/web/WebCache.h" |
43 #include "public/web/WebFrame.h" | 45 #include "public/web/WebFrame.h" |
44 #include "public/web/WebFrameClient.h" | 46 #include "public/web/WebFrameClient.h" |
45 #include "public/web/WebViewClient.h" | 47 #include "public/web/WebViewClient.h" |
46 #include "testing/gtest/include/gtest/gtest.h" | 48 #include "testing/gtest/include/gtest/gtest.h" |
47 #include "web/WebInputEventConversion.h" | 49 #include "web/WebInputEventConversion.h" |
48 #include "web/WebLocalFrameImpl.h" | 50 #include "web/WebLocalFrameImpl.h" |
49 #include "web/WebViewImpl.h" | 51 #include "web/WebViewImpl.h" |
50 #include "web/tests/FrameTestHelpers.h" | 52 #include "web/tests/FrameTestHelpers.h" |
51 #include "wtf/PtrUtil.h" | 53 #include "wtf/PtrUtil.h" |
52 #include <memory> | |
53 | 54 |
54 namespace blink { | 55 namespace blink { |
55 | 56 |
| 57 namespace { |
| 58 |
56 GestureEventWithHitTestResults getTargetedEvent(WebViewImpl* webViewImpl, | 59 GestureEventWithHitTestResults getTargetedEvent(WebViewImpl* webViewImpl, |
57 WebGestureEvent& touchEvent) { | 60 WebGestureEvent& touchEvent) { |
58 WebGestureEvent scaledEvent = TransformWebGestureEvent( | 61 WebGestureEvent scaledEvent = TransformWebGestureEvent( |
59 webViewImpl->mainFrameImpl()->frameView(), touchEvent); | 62 webViewImpl->mainFrameImpl()->frameView(), touchEvent); |
60 return webViewImpl->page() | 63 return webViewImpl->page() |
61 ->deprecatedLocalMainFrame() | 64 ->deprecatedLocalMainFrame() |
62 ->eventHandler() | 65 ->eventHandler() |
63 .targetGestureEvent(scaledEvent, true); | 66 .targetGestureEvent(scaledEvent, true); |
64 } | 67 } |
65 | 68 |
| 69 std::string registerMockedURLLoad() { |
| 70 WebURL url = URLTestHelpers::registerMockedURLLoadFromBase( |
| 71 WebString::fromUTF8("http://www.test.com/"), testing::webTestDataPath(), |
| 72 WebString::fromUTF8("test_touch_link_highlight.html")); |
| 73 return url.string().utf8(); |
| 74 } |
| 75 |
| 76 } // namespace |
| 77 |
66 TEST(LinkHighlightImplTest, verifyWebViewImplIntegration) { | 78 TEST(LinkHighlightImplTest, verifyWebViewImplIntegration) { |
67 const std::string baseURL("http://www.test.com/"); | 79 const std::string url = registerMockedURLLoad(); |
68 const std::string fileName("test_touch_link_highlight.html"); | |
69 | |
70 URLTestHelpers::registerMockedURLFromBaseURL( | |
71 WebString::fromUTF8(baseURL.c_str()), | |
72 WebString::fromUTF8("test_touch_link_highlight.html")); | |
73 FrameTestHelpers::WebViewHelper webViewHelper; | 80 FrameTestHelpers::WebViewHelper webViewHelper; |
74 WebViewImpl* webViewImpl = | 81 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(url, true); |
75 webViewHelper.initializeAndLoad(baseURL + fileName, true); | |
76 int pageWidth = 640; | 82 int pageWidth = 640; |
77 int pageHeight = 480; | 83 int pageHeight = 480; |
78 webViewImpl->resize(WebSize(pageWidth, pageHeight)); | 84 webViewImpl->resize(WebSize(pageWidth, pageHeight)); |
79 webViewImpl->updateAllLifecyclePhases(); | 85 webViewImpl->updateAllLifecyclePhases(); |
80 | 86 |
81 WebGestureEvent touchEvent(WebInputEvent::GestureShowPress, | 87 WebGestureEvent touchEvent(WebInputEvent::GestureShowPress, |
82 WebInputEvent::NoModifiers, | 88 WebInputEvent::NoModifiers, |
83 WebInputEvent::TimeStampForTesting); | 89 WebInputEvent::TimeStampForTesting); |
84 touchEvent.sourceDevice = WebGestureDeviceTouchscreen; | 90 touchEvent.sourceDevice = WebGestureDeviceTouchscreen; |
85 | 91 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 }; | 140 }; |
135 | 141 |
136 FakeCompositingWebViewClient* compositingWebViewClient() { | 142 FakeCompositingWebViewClient* compositingWebViewClient() { |
137 DEFINE_STATIC_LOCAL(FakeCompositingWebViewClient, client, ()); | 143 DEFINE_STATIC_LOCAL(FakeCompositingWebViewClient, client, ()); |
138 return &client; | 144 return &client; |
139 } | 145 } |
140 | 146 |
141 } // anonymous namespace | 147 } // anonymous namespace |
142 | 148 |
143 TEST(LinkHighlightImplTest, resetDuringNodeRemoval) { | 149 TEST(LinkHighlightImplTest, resetDuringNodeRemoval) { |
144 const std::string baseURL("http://www.test.com/"); | 150 const std::string url = registerMockedURLLoad(); |
145 const std::string fileName("test_touch_link_highlight.html"); | |
146 | |
147 URLTestHelpers::registerMockedURLFromBaseURL( | |
148 WebString::fromUTF8(baseURL.c_str()), | |
149 WebString::fromUTF8("test_touch_link_highlight.html")); | |
150 FrameTestHelpers::WebViewHelper webViewHelper; | 151 FrameTestHelpers::WebViewHelper webViewHelper; |
151 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad( | 152 WebViewImpl* webViewImpl = |
152 baseURL + fileName, true, 0, compositingWebViewClient()); | 153 webViewHelper.initializeAndLoad(url, true, 0, compositingWebViewClient()); |
153 | 154 |
154 int pageWidth = 640; | 155 int pageWidth = 640; |
155 int pageHeight = 480; | 156 int pageHeight = 480; |
156 webViewImpl->resize(WebSize(pageWidth, pageHeight)); | 157 webViewImpl->resize(WebSize(pageWidth, pageHeight)); |
157 webViewImpl->updateAllLifecyclePhases(); | 158 webViewImpl->updateAllLifecyclePhases(); |
158 | 159 |
159 WebGestureEvent touchEvent(WebInputEvent::GestureShowPress, | 160 WebGestureEvent touchEvent(WebInputEvent::GestureShowPress, |
160 WebInputEvent::NoModifiers, | 161 WebInputEvent::NoModifiers, |
161 WebInputEvent::TimeStampForTesting); | 162 WebInputEvent::TimeStampForTesting); |
162 touchEvent.sourceDevice = WebGestureDeviceTouchscreen; | 163 touchEvent.sourceDevice = WebGestureDeviceTouchscreen; |
(...skipping 19 matching lines...) Expand all Loading... |
182 | 183 |
183 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); | 184 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); |
184 WebCache::clear(); | 185 WebCache::clear(); |
185 } | 186 } |
186 | 187 |
187 // A lifetime test: delete LayerTreeView while running LinkHighlights. | 188 // A lifetime test: delete LayerTreeView while running LinkHighlights. |
188 TEST(LinkHighlightImplTest, resetLayerTreeView) { | 189 TEST(LinkHighlightImplTest, resetLayerTreeView) { |
189 std::unique_ptr<FakeCompositingWebViewClient> webViewClient = | 190 std::unique_ptr<FakeCompositingWebViewClient> webViewClient = |
190 WTF::makeUnique<FakeCompositingWebViewClient>(); | 191 WTF::makeUnique<FakeCompositingWebViewClient>(); |
191 | 192 |
192 const std::string baseURL("http://www.test.com/"); | 193 const std::string url = registerMockedURLLoad(); |
193 const std::string fileName("test_touch_link_highlight.html"); | |
194 | |
195 URLTestHelpers::registerMockedURLFromBaseURL( | |
196 WebString::fromUTF8(baseURL.c_str()), | |
197 WebString::fromUTF8("test_touch_link_highlight.html")); | |
198 FrameTestHelpers::WebViewHelper webViewHelper; | 194 FrameTestHelpers::WebViewHelper webViewHelper; |
199 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad( | 195 WebViewImpl* webViewImpl = |
200 baseURL + fileName, true, 0, webViewClient.get()); | 196 webViewHelper.initializeAndLoad(url, true, 0, webViewClient.get()); |
201 | 197 |
202 int pageWidth = 640; | 198 int pageWidth = 640; |
203 int pageHeight = 480; | 199 int pageHeight = 480; |
204 webViewImpl->resize(WebSize(pageWidth, pageHeight)); | 200 webViewImpl->resize(WebSize(pageWidth, pageHeight)); |
205 webViewImpl->updateAllLifecyclePhases(); | 201 webViewImpl->updateAllLifecyclePhases(); |
206 | 202 |
207 WebGestureEvent touchEvent(WebInputEvent::GestureShowPress, | 203 WebGestureEvent touchEvent(WebInputEvent::GestureShowPress, |
208 WebInputEvent::NoModifiers, | 204 WebInputEvent::NoModifiers, |
209 WebInputEvent::TimeStampForTesting); | 205 WebInputEvent::TimeStampForTesting); |
210 touchEvent.sourceDevice = WebGestureDeviceTouchscreen; | 206 touchEvent.sourceDevice = WebGestureDeviceTouchscreen; |
(...skipping 15 matching lines...) Expand all Loading... |
226 | 222 |
227 // Mimic the logic from RenderWidget::Close: | 223 // Mimic the logic from RenderWidget::Close: |
228 webViewImpl->willCloseLayerTreeView(); | 224 webViewImpl->willCloseLayerTreeView(); |
229 webViewHelper.reset(); | 225 webViewHelper.reset(); |
230 | 226 |
231 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); | 227 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); |
232 WebCache::clear(); | 228 WebCache::clear(); |
233 } | 229 } |
234 | 230 |
235 TEST(LinkHighlightImplTest, multipleHighlights) { | 231 TEST(LinkHighlightImplTest, multipleHighlights) { |
236 const std::string baseURL("http://www.test.com/"); | 232 const std::string url = registerMockedURLLoad(); |
237 const std::string fileName("test_touch_link_highlight.html"); | |
238 | |
239 URLTestHelpers::registerMockedURLFromBaseURL( | |
240 WebString::fromUTF8(baseURL.c_str()), | |
241 WebString::fromUTF8("test_touch_link_highlight.html")); | |
242 FrameTestHelpers::WebViewHelper webViewHelper; | 233 FrameTestHelpers::WebViewHelper webViewHelper; |
243 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad( | 234 WebViewImpl* webViewImpl = |
244 baseURL + fileName, true, 0, compositingWebViewClient()); | 235 webViewHelper.initializeAndLoad(url, true, 0, compositingWebViewClient()); |
245 | 236 |
246 int pageWidth = 640; | 237 int pageWidth = 640; |
247 int pageHeight = 480; | 238 int pageHeight = 480; |
248 webViewImpl->resize(WebSize(pageWidth, pageHeight)); | 239 webViewImpl->resize(WebSize(pageWidth, pageHeight)); |
249 webViewImpl->updateAllLifecyclePhases(); | 240 webViewImpl->updateAllLifecyclePhases(); |
250 | 241 |
251 WebGestureEvent touchEvent; | 242 WebGestureEvent touchEvent; |
252 touchEvent.x = 50; | 243 touchEvent.x = 50; |
253 touchEvent.y = 310; | 244 touchEvent.y = 310; |
254 touchEvent.data.tap.width = 30; | 245 touchEvent.data.tap.width = 30; |
255 touchEvent.data.tap.height = 30; | 246 touchEvent.data.tap.height = 30; |
256 | 247 |
257 Vector<IntRect> goodTargets; | 248 Vector<IntRect> goodTargets; |
258 HeapVector<Member<Node>> highlightNodes; | 249 HeapVector<Member<Node>> highlightNodes; |
259 IntRect boundingBox(touchEvent.x - touchEvent.data.tap.width / 2, | 250 IntRect boundingBox(touchEvent.x - touchEvent.data.tap.width / 2, |
260 touchEvent.y - touchEvent.data.tap.height / 2, | 251 touchEvent.y - touchEvent.data.tap.height / 2, |
261 touchEvent.data.tap.width, touchEvent.data.tap.height); | 252 touchEvent.data.tap.width, touchEvent.data.tap.height); |
262 findGoodTouchTargets(boundingBox, webViewImpl->mainFrameImpl()->frame(), | 253 findGoodTouchTargets(boundingBox, webViewImpl->mainFrameImpl()->frame(), |
263 goodTargets, highlightNodes); | 254 goodTargets, highlightNodes); |
264 | 255 |
265 webViewImpl->enableTapHighlights(highlightNodes); | 256 webViewImpl->enableTapHighlights(highlightNodes); |
266 EXPECT_EQ(2U, webViewImpl->numLinkHighlights()); | 257 EXPECT_EQ(2U, webViewImpl->numLinkHighlights()); |
267 | 258 |
268 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); | 259 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); |
269 WebCache::clear(); | 260 WebCache::clear(); |
270 } | 261 } |
271 | 262 |
272 } // namespace blink | 263 } // namespace blink |
OLD | NEW |