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