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