OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 102 |
103 const int kfakeTouchId = 7; | 103 const int kfakeTouchId = 7; |
104 | 104 |
105 class TouchActionTest : public testing::Test { | 105 class TouchActionTest : public testing::Test { |
106 public: | 106 public: |
107 TouchActionTest() | 107 TouchActionTest() |
108 : m_baseURL("http://www.test.com/") | 108 : m_baseURL("http://www.test.com/") |
109 { | 109 { |
110 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseU
RL), "touch-action-tests.css"); | 110 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseU
RL), "touch-action-tests.css"); |
111 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseU
RL), "touch-action-tests.js"); | 111 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseU
RL), "touch-action-tests.js"); |
112 WebCore::RuntimeEnabledFeatures::setCSSTouchActionEnabled(true); | 112 blink::RuntimeEnabledFeatures::setCSSTouchActionEnabled(true); |
113 } | 113 } |
114 | 114 |
115 virtual void TearDown() | 115 virtual void TearDown() |
116 { | 116 { |
117 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | 117 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
118 } | 118 } |
119 | 119 |
120 protected: | 120 protected: |
121 void runTouchActionTest(std::string file); | 121 void runTouchActionTest(std::string file); |
122 void runShadowDOMTest(std::string file); | 122 void runShadowDOMTest(std::string file); |
123 void sendTouchEvent(WebView*, WebInputEvent::Type, WebCore::IntPoint clientP
oint); | 123 void sendTouchEvent(WebView*, WebInputEvent::Type, blink::IntPoint clientPoi
nt); |
124 WebView* setupTest(std::string file, TouchActionTrackingWebViewClient&); | 124 WebView* setupTest(std::string file, TouchActionTrackingWebViewClient&); |
125 void runTestOnTree(WebCore::ContainerNode* root, WebView*, TouchActionTracki
ngWebViewClient&); | 125 void runTestOnTree(blink::ContainerNode* root, WebView*, TouchActionTracking
WebViewClient&); |
126 | 126 |
127 std::string m_baseURL; | 127 std::string m_baseURL; |
128 FrameTestHelpers::WebViewHelper m_webViewHelper; | 128 FrameTestHelpers::WebViewHelper m_webViewHelper; |
129 }; | 129 }; |
130 | 130 |
131 void TouchActionTest::runTouchActionTest(std::string file) | 131 void TouchActionTest::runTouchActionTest(std::string file) |
132 { | 132 { |
133 TouchActionTrackingWebViewClient client; | 133 TouchActionTrackingWebViewClient client; |
134 | 134 |
135 // runTouchActionTest() loads a document in a frame, setting up a | 135 // runTouchActionTest() loads a document in a frame, setting up a |
136 // nested message loop. Should any Oilpan GC happen while it is in | 136 // nested message loop. Should any Oilpan GC happen while it is in |
137 // effect, the implicit assumption that we're outside any event | 137 // effect, the implicit assumption that we're outside any event |
138 // loop (=> there being no pointers on the stack needing scanning) | 138 // loop (=> there being no pointers on the stack needing scanning) |
139 // when that GC strikes will no longer hold. | 139 // when that GC strikes will no longer hold. |
140 // | 140 // |
141 // To ensure that the references on the stack are also traced, we | 141 // To ensure that the references on the stack are also traced, we |
142 // turn them into persistent, stack allocated references. This | 142 // turn them into persistent, stack allocated references. This |
143 // workaround is sufficient to handle this artificial test | 143 // workaround is sufficient to handle this artificial test |
144 // scenario. | 144 // scenario. |
145 WebView* webView = setupTest(file, client); | 145 WebView* webView = setupTest(file, client); |
146 | 146 |
147 RefPtrWillBePersistent<WebCore::Document> document = static_cast<PassRefPtrW
illBeRawPtr<WebCore::Document> >(webView->mainFrame()->document()); | 147 RefPtrWillBePersistent<blink::Document> document = static_cast<PassRefPtrWil
lBeRawPtr<blink::Document> >(webView->mainFrame()->document()); |
148 runTestOnTree(document.get(), webView, client); | 148 runTestOnTree(document.get(), webView, client); |
149 | 149 |
150 m_webViewHelper.reset(); // Explicitly reset to break dependency on locally
scoped client. | 150 m_webViewHelper.reset(); // Explicitly reset to break dependency on locally
scoped client. |
151 } | 151 } |
152 | 152 |
153 void TouchActionTest::runShadowDOMTest(std::string file) | 153 void TouchActionTest::runShadowDOMTest(std::string file) |
154 { | 154 { |
155 TouchActionTrackingWebViewClient client; | 155 TouchActionTrackingWebViewClient client; |
156 | 156 |
157 WebView* webView = setupTest(file, client); | 157 WebView* webView = setupTest(file, client); |
158 | 158 |
159 WebCore::TrackExceptionState es; | 159 blink::TrackExceptionState es; |
160 | 160 |
161 // Oilpan: see runTouchActionTest() comment why these are persistent referen
ces. | 161 // Oilpan: see runTouchActionTest() comment why these are persistent referen
ces. |
162 RefPtrWillBePersistent<WebCore::Document> document = static_cast<PassRefPtrW
illBeRawPtr<WebCore::Document> >(webView->mainFrame()->document()); | 162 RefPtrWillBePersistent<blink::Document> document = static_cast<PassRefPtrWil
lBeRawPtr<blink::Document> >(webView->mainFrame()->document()); |
163 RefPtrWillBePersistent<WebCore::StaticNodeList> hostNodes = document->queryS
electorAll("[shadow-host]", es); | 163 RefPtrWillBePersistent<blink::StaticNodeList> hostNodes = document->querySel
ectorAll("[shadow-host]", es); |
164 ASSERT_FALSE(es.hadException()); | 164 ASSERT_FALSE(es.hadException()); |
165 ASSERT_GE(hostNodes->length(), 1u); | 165 ASSERT_GE(hostNodes->length(), 1u); |
166 | 166 |
167 for (unsigned index = 0; index < hostNodes->length(); index++) { | 167 for (unsigned index = 0; index < hostNodes->length(); index++) { |
168 WebCore::ShadowRoot* shadowRoot = WebCore::toElement(hostNodes->item(ind
ex))->shadowRoot(); | 168 blink::ShadowRoot* shadowRoot = blink::toElement(hostNodes->item(index))
->shadowRoot(); |
169 runTestOnTree(shadowRoot, webView, client); | 169 runTestOnTree(shadowRoot, webView, client); |
170 } | 170 } |
171 | 171 |
172 // Projections show up in the main document. | 172 // Projections show up in the main document. |
173 runTestOnTree(document.get(), webView, client); | 173 runTestOnTree(document.get(), webView, client); |
174 | 174 |
175 m_webViewHelper.reset(); // Explicitly reset to break dependency on locally
scoped client. | 175 m_webViewHelper.reset(); // Explicitly reset to break dependency on locally
scoped client. |
176 } | 176 } |
177 | 177 |
178 WebView* TouchActionTest::setupTest(std::string file, TouchActionTrackingWebView
Client& client) | 178 WebView* TouchActionTest::setupTest(std::string file, TouchActionTrackingWebView
Client& client) |
179 { | 179 { |
180 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL),
WebString::fromUTF8(file)); | 180 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL),
WebString::fromUTF8(file)); |
181 // Note that JavaScript must be enabled for shadow DOM tests. | 181 // Note that JavaScript must be enabled for shadow DOM tests. |
182 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + file, true,
0, &client); | 182 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + file, true,
0, &client); |
183 | 183 |
184 // Lock page scale factor to avoid zooming out to contents size. | 184 // Lock page scale factor to avoid zooming out to contents size. |
185 m_webViewHelper.webView()->setPageScaleFactorLimits(1, 1); | 185 m_webViewHelper.webView()->setPageScaleFactorLimits(1, 1); |
186 | 186 |
187 // Set size to enable hit testing, and avoid line wrapping for consistency w
ith browser. | 187 // Set size to enable hit testing, and avoid line wrapping for consistency w
ith browser. |
188 webView->resize(WebSize(800, 1200)); | 188 webView->resize(WebSize(800, 1200)); |
189 | 189 |
190 // Scroll to verify the code properly transforms windows to client co-ords. | 190 // Scroll to verify the code properly transforms windows to client co-ords. |
191 const int kScrollOffset = 100; | 191 const int kScrollOffset = 100; |
192 RefPtrWillBeRawPtr<WebCore::Document> document = static_cast<PassRefPtrWillB
eRawPtr<WebCore::Document> >(webView->mainFrame()->document()); | 192 RefPtrWillBeRawPtr<blink::Document> document = static_cast<PassRefPtrWillBeR
awPtr<blink::Document> >(webView->mainFrame()->document()); |
193 document->frame()->view()->setScrollOffset(WebCore::IntPoint(0, kScrollOffse
t)); | 193 document->frame()->view()->setScrollOffset(blink::IntPoint(0, kScrollOffset)
); |
194 | 194 |
195 return webView; | 195 return webView; |
196 } | 196 } |
197 | 197 |
198 void TouchActionTest::runTestOnTree(WebCore::ContainerNode* root, WebView* webVi
ew, TouchActionTrackingWebViewClient& client) | 198 void TouchActionTest::runTestOnTree(blink::ContainerNode* root, WebView* webView
, TouchActionTrackingWebViewClient& client) |
199 { | 199 { |
200 // Find all elements to test the touch-action of in the document. | 200 // Find all elements to test the touch-action of in the document. |
201 WebCore::TrackExceptionState es; | 201 blink::TrackExceptionState es; |
202 | 202 |
203 // Oilpan: see runTouchActionTest() comment why these are persistent referen
ces. | 203 // Oilpan: see runTouchActionTest() comment why these are persistent referen
ces. |
204 RefPtrWillBePersistent<WebCore::StaticNodeList> nodes = root->querySelectorA
ll("[expected-action]", es); | 204 RefPtrWillBePersistent<blink::StaticNodeList> nodes = root->querySelectorAll
("[expected-action]", es); |
205 ASSERT_FALSE(es.hadException()); | 205 ASSERT_FALSE(es.hadException()); |
206 | 206 |
207 for (unsigned index = 0; index < nodes->length(); index++) { | 207 for (unsigned index = 0; index < nodes->length(); index++) { |
208 WebCore::Element* element = toElement(nodes->item(index)); | 208 blink::Element* element = toElement(nodes->item(index)); |
209 element->scrollIntoViewIfNeeded(); | 209 element->scrollIntoViewIfNeeded(); |
210 ASSERT_TRUE(nodes->item(index)->isElementNode()); | 210 ASSERT_TRUE(nodes->item(index)->isElementNode()); |
211 | 211 |
212 std::string failureContext("Test case: "); | 212 std::string failureContext("Test case: "); |
213 if (element->hasID()) { | 213 if (element->hasID()) { |
214 failureContext.append(element->getIdAttribute().ascii().data()); | 214 failureContext.append(element->getIdAttribute().ascii().data()); |
215 } else if (element->firstChild()) { | 215 } else if (element->firstChild()) { |
216 failureContext.append("\""); | 216 failureContext.append("\""); |
217 failureContext.append(element->firstChild()->textContent(false).stri
pWhiteSpace().ascii().data()); | 217 failureContext.append(element->firstChild()->textContent(false).stri
pWhiteSpace().ascii().data()); |
218 failureContext.append("\""); | 218 failureContext.append("\""); |
219 } else { | 219 } else { |
220 failureContext += "<missing ID>"; | 220 failureContext += "<missing ID>"; |
221 } | 221 } |
222 | 222 |
223 // Run each test three times at different positions in the element. | 223 // Run each test three times at different positions in the element. |
224 // Note that we don't want the bounding box because our tests sometimes
have elements with | 224 // Note that we don't want the bounding box because our tests sometimes
have elements with |
225 // multiple border boxes with other elements in between. Use the first b
order box (which | 225 // multiple border boxes with other elements in between. Use the first b
order box (which |
226 // we can easily visualize in a browser for debugging). | 226 // we can easily visualize in a browser for debugging). |
227 RefPtrWillBePersistent<WebCore::ClientRectList> rects = element->getClie
ntRects(); | 227 RefPtrWillBePersistent<blink::ClientRectList> rects = element->getClient
Rects(); |
228 ASSERT_GE(rects->length(), 0u) << failureContext; | 228 ASSERT_GE(rects->length(), 0u) << failureContext; |
229 RefPtrWillBePersistent<WebCore::ClientRect> r = rects->item(0); | 229 RefPtrWillBePersistent<blink::ClientRect> r = rects->item(0); |
230 WebCore::FloatRect clientFloatRect = WebCore::FloatRect(r->left(), r->to
p(), r->width(), r->height()); | 230 blink::FloatRect clientFloatRect = blink::FloatRect(r->left(), r->top(),
r->width(), r->height()); |
231 WebCore::IntRect clientRect = enclosedIntRect(clientFloatRect); | 231 blink::IntRect clientRect = enclosedIntRect(clientFloatRect); |
232 for (int locIdx = 0; locIdx < 3; locIdx++) { | 232 for (int locIdx = 0; locIdx < 3; locIdx++) { |
233 WebCore::IntPoint clientPoint; | 233 blink::IntPoint clientPoint; |
234 std::stringstream contextStream; | 234 std::stringstream contextStream; |
235 contextStream << failureContext << " ("; | 235 contextStream << failureContext << " ("; |
236 switch (locIdx) { | 236 switch (locIdx) { |
237 case 0: | 237 case 0: |
238 clientPoint = clientRect.center(); | 238 clientPoint = clientRect.center(); |
239 contextStream << "center"; | 239 contextStream << "center"; |
240 break; | 240 break; |
241 case 1: | 241 case 1: |
242 clientPoint = clientRect.location(); | 242 clientPoint = clientRect.location(); |
243 contextStream << "top-left"; | 243 contextStream << "top-left"; |
244 break; | 244 break; |
245 case 2: | 245 case 2: |
246 clientPoint = clientRect.maxXMaxYCorner(); | 246 clientPoint = clientRect.maxXMaxYCorner(); |
247 clientPoint.move(-1, -1); | 247 clientPoint.move(-1, -1); |
248 contextStream << "bottom-right"; | 248 contextStream << "bottom-right"; |
249 break; | 249 break; |
250 default: | 250 default: |
251 FAIL() << "Invalid location index."; | 251 FAIL() << "Invalid location index."; |
252 } | 252 } |
253 contextStream << "=" << clientPoint.x() << "," << clientPoint.y() <<
")."; | 253 contextStream << "=" << clientPoint.x() << "," << clientPoint.y() <<
")."; |
254 std::string failureContextPos = contextStream.str(); | 254 std::string failureContextPos = contextStream.str(); |
255 | 255 |
256 WebCore::LocalFrame* frame = root->document().frame(); | 256 blink::LocalFrame* frame = root->document().frame(); |
257 WebCore::FrameView* frameView = frame->view(); | 257 blink::FrameView* frameView = frame->view(); |
258 WebCore::IntRect visibleRect = frameView->windowClipRect(); | 258 blink::IntRect visibleRect = frameView->windowClipRect(); |
259 ASSERT_TRUE(visibleRect.contains(clientPoint)) << failureContextPos | 259 ASSERT_TRUE(visibleRect.contains(clientPoint)) << failureContextPos |
260 << " Test point not contained in visible area: " << visibleRect.
x() << "," << visibleRect.y() | 260 << " Test point not contained in visible area: " << visibleRect.
x() << "," << visibleRect.y() |
261 << "-" << visibleRect.maxX() << "," << visibleRect.maxY(); | 261 << "-" << visibleRect.maxX() << "," << visibleRect.maxY(); |
262 | 262 |
263 // First validate that a hit test at this point will really hit the
element | 263 // First validate that a hit test at this point will really hit the
element |
264 // we intended. This is the easiest way for a test to be broken, but
has nothing really | 264 // we intended. This is the easiest way for a test to be broken, but
has nothing really |
265 // to do with touch action. | 265 // to do with touch action. |
266 // Note that we can't use WebView's hit test API because it doesn't
look into shadow DOM. | 266 // Note that we can't use WebView's hit test API because it doesn't
look into shadow DOM. |
267 WebCore::IntPoint docPoint(frameView->windowToContents(clientPoint))
; | 267 blink::IntPoint docPoint(frameView->windowToContents(clientPoint)); |
268 WebCore::HitTestResult result = frame->eventHandler().hitTestResultA
tPoint(docPoint, WebCore::HitTestRequest::ReadOnly | WebCore::HitTestRequest::Ac
tive); | 268 blink::HitTestResult result = frame->eventHandler().hitTestResultAtP
oint(docPoint, blink::HitTestRequest::ReadOnly | blink::HitTestRequest::Active); |
269 ASSERT_EQ(element, result.innerElement()) << "Unexpected hit test re
sult " << failureContextPos | 269 ASSERT_EQ(element, result.innerElement()) << "Unexpected hit test re
sult " << failureContextPos |
270 << " Got element: \"" << result.innerElement()->outerHTML().str
ipWhiteSpace().left(80).ascii().data() << "\"" | 270 << " Got element: \"" << result.innerElement()->outerHTML().str
ipWhiteSpace().left(80).ascii().data() << "\"" |
271 << std::endl << "Document render tree:" << std::endl << external
Representation(root->document().frame()).utf8().data(); | 271 << std::endl << "Document render tree:" << std::endl << external
Representation(root->document().frame()).utf8().data(); |
272 | 272 |
273 // Now send the touch event and check any touch action result. | 273 // Now send the touch event and check any touch action result. |
274 sendTouchEvent(webView, WebInputEvent::TouchStart, clientPoint); | 274 sendTouchEvent(webView, WebInputEvent::TouchStart, clientPoint); |
275 | 275 |
276 AtomicString expectedAction = element->getAttribute("expected-action
"); | 276 AtomicString expectedAction = element->getAttribute("expected-action
"); |
277 if (expectedAction == "auto") { | 277 if (expectedAction == "auto") { |
278 // Auto is the default - no action set. | 278 // Auto is the default - no action set. |
(...skipping 20 matching lines...) Expand all Loading... |
299 } | 299 } |
300 } | 300 } |
301 | 301 |
302 // Reset webview touch state. | 302 // Reset webview touch state. |
303 client.reset(); | 303 client.reset(); |
304 sendTouchEvent(webView, WebInputEvent::TouchCancel, clientPoint); | 304 sendTouchEvent(webView, WebInputEvent::TouchCancel, clientPoint); |
305 EXPECT_EQ(0, client.touchActionSetCount()); | 305 EXPECT_EQ(0, client.touchActionSetCount()); |
306 } | 306 } |
307 } | 307 } |
308 } | 308 } |
309 void TouchActionTest::sendTouchEvent(WebView* webView, WebInputEvent::Type type,
WebCore::IntPoint clientPoint) | 309 void TouchActionTest::sendTouchEvent(WebView* webView, WebInputEvent::Type type,
blink::IntPoint clientPoint) |
310 { | 310 { |
311 ASSERT_TRUE(type == WebInputEvent::TouchStart || type == WebInputEvent::Touc
hCancel); | 311 ASSERT_TRUE(type == WebInputEvent::TouchStart || type == WebInputEvent::Touc
hCancel); |
312 | 312 |
313 WebTouchEvent webTouchEvent; | 313 WebTouchEvent webTouchEvent; |
314 webTouchEvent.type = type; | 314 webTouchEvent.type = type; |
315 if (type == WebInputEvent::TouchCancel) | 315 if (type == WebInputEvent::TouchCancel) |
316 webTouchEvent.cancelable = false; | 316 webTouchEvent.cancelable = false; |
317 webTouchEvent.touchesLength = 1; | 317 webTouchEvent.touchesLength = 1; |
318 webTouchEvent.touches[0].state = (type == WebInputEvent::TouchStart ? | 318 webTouchEvent.touches[0].state = (type == WebInputEvent::TouchStart ? |
319 WebTouchPoint::StatePressed : | 319 WebTouchPoint::StatePressed : |
(...skipping 24 matching lines...) Expand all Loading... |
344 { | 344 { |
345 runShadowDOMTest("touch-action-shadow-dom.html"); | 345 runShadowDOMTest("touch-action-shadow-dom.html"); |
346 } | 346 } |
347 | 347 |
348 TEST_F(TouchActionTest, Pan) | 348 TEST_F(TouchActionTest, Pan) |
349 { | 349 { |
350 runTouchActionTest("touch-action-pan.html"); | 350 runTouchActionTest("touch-action-pan.html"); |
351 } | 351 } |
352 | 352 |
353 } | 353 } |
OLD | NEW |