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 | 51 |
54 using namespace blink; | 52 using namespace blink; |
55 using namespace blink; | 53 using namespace blink; |
56 | 54 |
57 namespace { | 55 namespace { |
58 | 56 |
59 GestureEventWithHitTestResults getTargetedEvent(WebViewImpl* webViewImpl, WebGes
tureEvent& touchEvent) | |
60 { | |
61 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->fram
eView(), touchEvent); | |
62 return webViewImpl->page()->deprecatedLocalMainFrame()->eventHandler().targe
tGestureEvent(platformEvent, true); | |
63 } | |
64 | |
65 TEST(LinkHighlightTest, verifyWebViewImplIntegration) | 57 TEST(LinkHighlightTest, verifyWebViewImplIntegration) |
66 { | 58 { |
67 const std::string baseURL("http://www.test.com/"); | 59 const std::string baseURL("http://www.test.com/"); |
68 const std::string fileName("test_touch_link_highlight.html"); | 60 const std::string fileName("test_touch_link_highlight.html"); |
69 | 61 |
70 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL.c_s
tr()), WebString::fromUTF8("test_touch_link_highlight.html")); | 62 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL.c_s
tr()), WebString::fromUTF8("test_touch_link_highlight.html")); |
71 FrameTestHelpers::WebViewHelper webViewHelper; | 63 FrameTestHelpers::WebViewHelper webViewHelper; |
72 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(baseURL + fileNam
e, true); | 64 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(baseURL + fileNam
e, true); |
73 int pageWidth = 640; | 65 int pageWidth = 640; |
74 int pageHeight = 480; | 66 int pageHeight = 480; |
75 webViewImpl->resize(WebSize(pageWidth, pageHeight)); | 67 webViewImpl->resize(WebSize(pageWidth, pageHeight)); |
76 webViewImpl->layout(); | 68 webViewImpl->layout(); |
77 | 69 |
78 WebGestureEvent touchEvent; | 70 WebGestureEvent touchEvent; |
79 touchEvent.type = WebInputEvent::GestureShowPress; | 71 touchEvent.type = WebInputEvent::GestureShowPress; |
80 | 72 |
81 // The coordinates below are linked to absolute positions in the referenced
.html file. | 73 // The coordinates below are linked to absolute positions in the referenced
.html file. |
82 touchEvent.x = 20; | 74 touchEvent.x = 20; |
83 touchEvent.y = 20; | 75 touchEvent.y = 20; |
84 | 76 |
85 ASSERT_TRUE(webViewImpl->bestTapNode(getTargetedEvent(webViewImpl, touchEven
t))); | 77 { |
| 78 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->
frameView(), touchEvent); |
| 79 Node* touchNode = webViewImpl->bestTapNode(platformEvent); |
| 80 ASSERT_TRUE(touchNode); |
| 81 } |
86 | 82 |
87 touchEvent.y = 40; | 83 touchEvent.y = 40; |
88 EXPECT_FALSE(webViewImpl->bestTapNode(getTargetedEvent(webViewImpl, touchEve
nt))); | 84 { |
| 85 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->
frameView(), touchEvent); |
| 86 EXPECT_FALSE(webViewImpl->bestTapNode(platformEvent)); |
| 87 } |
89 | 88 |
90 touchEvent.y = 20; | 89 touchEvent.y = 20; |
91 // Shouldn't crash. | 90 // Shouldn't crash. |
92 webViewImpl->enableTapHighlightAtPoint(getTargetedEvent(webViewImpl, touchEv
ent)); | 91 |
| 92 { |
| 93 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->
frameView(), touchEvent); |
| 94 webViewImpl->enableTapHighlightAtPoint(platformEvent); |
| 95 } |
93 | 96 |
94 EXPECT_TRUE(webViewImpl->linkHighlight(0)); | 97 EXPECT_TRUE(webViewImpl->linkHighlight(0)); |
95 EXPECT_TRUE(webViewImpl->linkHighlight(0)->contentLayer()); | 98 EXPECT_TRUE(webViewImpl->linkHighlight(0)->contentLayer()); |
96 EXPECT_TRUE(webViewImpl->linkHighlight(0)->clipLayer()); | 99 EXPECT_TRUE(webViewImpl->linkHighlight(0)->clipLayer()); |
97 | 100 |
98 // Find a target inside a scrollable div | 101 // Find a target inside a scrollable div |
| 102 |
99 touchEvent.y = 100; | 103 touchEvent.y = 100; |
100 webViewImpl->enableTapHighlightAtPoint(getTargetedEvent(webViewImpl, touchEv
ent)); | 104 { |
| 105 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->
frameView(), touchEvent); |
| 106 webViewImpl->enableTapHighlightAtPoint(platformEvent); |
| 107 } |
| 108 |
101 ASSERT_TRUE(webViewImpl->linkHighlight(0)); | 109 ASSERT_TRUE(webViewImpl->linkHighlight(0)); |
102 | 110 |
103 // Don't highlight if no "hand cursor" | 111 // Don't highlight if no "hand cursor" |
104 touchEvent.y = 220; // An A-link with cross-hair cursor. | 112 touchEvent.y = 220; // An A-link with cross-hair cursor. |
105 webViewImpl->enableTapHighlightAtPoint(getTargetedEvent(webViewImpl, touchEv
ent)); | 113 { |
| 114 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->
frameView(), touchEvent); |
| 115 webViewImpl->enableTapHighlightAtPoint(platformEvent); |
| 116 } |
106 ASSERT_EQ(0U, webViewImpl->numLinkHighlights()); | 117 ASSERT_EQ(0U, webViewImpl->numLinkHighlights()); |
107 | 118 |
108 touchEvent.y = 260; // A text input box. | 119 touchEvent.y = 260; // A text input box. |
109 webViewImpl->enableTapHighlightAtPoint(getTargetedEvent(webViewImpl, touchEv
ent)); | 120 { |
| 121 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->
frameView(), touchEvent); |
| 122 webViewImpl->enableTapHighlightAtPoint(platformEvent); |
| 123 } |
110 ASSERT_EQ(0U, webViewImpl->numLinkHighlights()); | 124 ASSERT_EQ(0U, webViewImpl->numLinkHighlights()); |
111 | 125 |
112 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | 126 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
113 } | 127 } |
114 | 128 |
115 class FakeWebFrameClient : public WebFrameClient { | 129 class FakeWebFrameClient : public WebFrameClient { |
116 // To make the destructor public. | 130 // To make the destructor public. |
117 }; | 131 }; |
118 | 132 |
119 class FakeCompositingWebViewClient : public FrameTestHelpers::TestWebViewClient
{ | 133 class FakeCompositingWebViewClient : public FrameTestHelpers::TestWebViewClient
{ |
(...skipping 19 matching lines...) Expand all Loading... |
139 int pageWidth = 640; | 153 int pageWidth = 640; |
140 int pageHeight = 480; | 154 int pageHeight = 480; |
141 webViewImpl->resize(WebSize(pageWidth, pageHeight)); | 155 webViewImpl->resize(WebSize(pageWidth, pageHeight)); |
142 webViewImpl->layout(); | 156 webViewImpl->layout(); |
143 | 157 |
144 WebGestureEvent touchEvent; | 158 WebGestureEvent touchEvent; |
145 touchEvent.type = WebInputEvent::GestureShowPress; | 159 touchEvent.type = WebInputEvent::GestureShowPress; |
146 touchEvent.x = 20; | 160 touchEvent.x = 20; |
147 touchEvent.y = 20; | 161 touchEvent.y = 20; |
148 | 162 |
149 GestureEventWithHitTestResults targetedEvent = getTargetedEvent(webViewImpl,
touchEvent); | 163 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->fram
eView(), touchEvent); |
150 Node* touchNode = webViewImpl->bestTapNode(targetedEvent); | 164 Node* touchNode = webViewImpl->bestTapNode(platformEvent); |
151 ASSERT_TRUE(touchNode); | 165 ASSERT_TRUE(touchNode); |
152 | 166 |
153 webViewImpl->enableTapHighlightAtPoint(targetedEvent); | 167 webViewImpl->enableTapHighlightAtPoint(platformEvent); |
154 ASSERT_TRUE(webViewImpl->linkHighlight(0)); | 168 ASSERT_TRUE(webViewImpl->linkHighlight(0)); |
155 | 169 |
156 GraphicsLayer* highlightLayer = webViewImpl->linkHighlight(0)->currentGraphi
csLayerForTesting(); | 170 GraphicsLayer* highlightLayer = webViewImpl->linkHighlight(0)->currentGraphi
csLayerForTesting(); |
157 ASSERT_TRUE(highlightLayer); | 171 ASSERT_TRUE(highlightLayer); |
158 EXPECT_TRUE(highlightLayer->linkHighlight(0)); | 172 EXPECT_TRUE(highlightLayer->linkHighlight(0)); |
159 | 173 |
160 touchNode->remove(IGNORE_EXCEPTION); | 174 touchNode->remove(IGNORE_EXCEPTION); |
161 webViewImpl->layout(); | 175 webViewImpl->layout(); |
162 ASSERT_EQ(0U, highlightLayer->numLinkHighlights()); | 176 ASSERT_EQ(0U, highlightLayer->numLinkHighlights()); |
163 | 177 |
(...skipping 25 matching lines...) Expand all Loading... |
189 IntRect boundingBox(touchEvent.x - touchEvent.data.tap.width / 2, touchEvent
.y - touchEvent.data.tap.height / 2, touchEvent.data.tap.width, touchEvent.data.
tap.height); | 203 IntRect boundingBox(touchEvent.x - touchEvent.data.tap.width / 2, touchEvent
.y - touchEvent.data.tap.height / 2, touchEvent.data.tap.width, touchEvent.data.
tap.height); |
190 findGoodTouchTargets(boundingBox, webViewImpl->mainFrameImpl()->frame(), goo
dTargets, highlightNodes); | 204 findGoodTouchTargets(boundingBox, webViewImpl->mainFrameImpl()->frame(), goo
dTargets, highlightNodes); |
191 | 205 |
192 webViewImpl->enableTapHighlights(highlightNodes); | 206 webViewImpl->enableTapHighlights(highlightNodes); |
193 EXPECT_EQ(2U, webViewImpl->numLinkHighlights()); | 207 EXPECT_EQ(2U, webViewImpl->numLinkHighlights()); |
194 | 208 |
195 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | 209 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
196 } | 210 } |
197 | 211 |
198 } // namespace | 212 } // namespace |
OLD | NEW |