Chromium Code Reviews| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 } | 112 } |
| 113 | 113 |
| 114 virtual void TearDown() | 114 virtual void TearDown() |
| 115 { | 115 { |
| 116 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | 116 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 protected: | 119 protected: |
| 120 void runTouchActionTest(std::string file); | 120 void runTouchActionTest(std::string file); |
| 121 void runShadowDOMTest(std::string file); | 121 void runShadowDOMTest(std::string file); |
| 122 void runTouchActionHitTest(std::string file); | |
| 122 void sendTouchEvent(WebView*, WebInputEvent::Type, WebCore::IntPoint clientP oint); | 123 void sendTouchEvent(WebView*, WebInputEvent::Type, WebCore::IntPoint clientP oint); |
| 123 WebView* setupTest(std::string file, TouchActionTrackingWebViewClient&); | 124 WebView* setupTest(std::string file, TouchActionTrackingWebViewClient&); |
| 124 void runTestOnTree(WebCore::Node* root, WebView*, TouchActionTrackingWebView Client&); | 125 void runTestOnTree(WebCore::Node* root, WebView*, TouchActionTrackingWebView Client&); |
| 126 void runHitTestOnTree(WebCore::Node* root, WebView*, TouchActionTrackingWebV iewClient&); | |
| 125 | 127 |
| 126 std::string m_baseURL; | 128 std::string m_baseURL; |
| 127 FrameTestHelpers::WebViewHelper m_webViewHelper; | 129 FrameTestHelpers::WebViewHelper m_webViewHelper; |
| 128 }; | 130 }; |
| 129 | 131 |
| 130 void TouchActionTest::runTouchActionTest(std::string file) | 132 void TouchActionTest::runTouchActionTest(std::string file) |
| 131 { | 133 { |
| 132 TouchActionTrackingWebViewClient client; | 134 TouchActionTrackingWebViewClient client; |
| 133 | 135 |
| 134 WebView* webView = setupTest(file, client); | 136 WebView* webView = setupTest(file, client); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 151 | 153 |
| 152 for (unsigned index = 0; index < hostNodes->length(); index++) { | 154 for (unsigned index = 0; index < hostNodes->length(); index++) { |
| 153 WebCore::ShadowRoot* shadowRoot = WebCore::toElement(hostNodes->item(ind ex))->shadowRoot(); | 155 WebCore::ShadowRoot* shadowRoot = WebCore::toElement(hostNodes->item(ind ex))->shadowRoot(); |
| 154 runTestOnTree(shadowRoot, webView, client); | 156 runTestOnTree(shadowRoot, webView, client); |
| 155 } | 157 } |
| 156 | 158 |
| 157 // Projections show up in the main document. | 159 // Projections show up in the main document. |
| 158 runTestOnTree(document.get(), webView, client); | 160 runTestOnTree(document.get(), webView, client); |
| 159 } | 161 } |
| 160 | 162 |
| 163 void TouchActionTest::runTouchActionHitTest(std::string file) | |
| 164 { | |
| 165 TouchActionTrackingWebViewClient client; | |
| 166 | |
| 167 WebView* webView = setupTest(file, client); | |
| 168 | |
| 169 RefPtr<WebCore::Document> document = static_cast<PassRefPtr<WebCore::Documen t> >(webView->mainFrame()->document()); | |
| 170 runHitTestOnTree(document.get(), webView, client); | |
| 171 } | |
| 172 | |
| 161 WebView* TouchActionTest::setupTest(std::string file, TouchActionTrackingWebView Client& client) | 173 WebView* TouchActionTest::setupTest(std::string file, TouchActionTrackingWebView Client& client) |
| 162 { | 174 { |
| 163 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL), WebString::fromUTF8(file)); | 175 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL), WebString::fromUTF8(file)); |
| 164 // Note that JavaScript must be enabled for shadow DOM tests. | 176 // Note that JavaScript must be enabled for shadow DOM tests. |
| 165 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + file, true, 0, &client); | 177 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + file, true, 0, &client); |
| 166 | 178 |
| 167 // Set size to enable hit testing, and avoid line wrapping for consistency w ith browser. | 179 // Set size to enable hit testing, and avoid line wrapping for consistency w ith browser. |
| 168 webView->resize(WebSize(700, 1000)); | 180 webView->resize(WebSize(700, 1000)); |
| 169 | 181 |
| 170 // Scroll to verify the code properly transforms windows to client co-ords. | 182 // Scroll to verify the code properly transforms windows to client co-ords. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 } | 287 } |
| 276 } | 288 } |
| 277 | 289 |
| 278 // Reset webview touch state. | 290 // Reset webview touch state. |
| 279 client.reset(); | 291 client.reset(); |
| 280 sendTouchEvent(webView, WebInputEvent::TouchCancel, clientPoint); | 292 sendTouchEvent(webView, WebInputEvent::TouchCancel, clientPoint); |
| 281 EXPECT_EQ(0, client.touchActionSetCount()); | 293 EXPECT_EQ(0, client.touchActionSetCount()); |
| 282 } | 294 } |
| 283 } | 295 } |
| 284 } | 296 } |
| 297 | |
| 298 void TouchActionTest::runHitTestOnTree(WebCore::Node* root, WebView* webView, To uchActionTrackingWebViewClient& client) | |
|
Rick Byers
2014/01/17 16:12:46
Is there reason you need to add a new type of test
gnana
2014/01/21 14:00:16
Ok. i understood. i will apply this in next patch.
| |
| 299 { | |
| 300 // Find all elements to test the touch-action of in the document. | |
| 301 WebCore::TrackExceptionState es; | |
| 302 RefPtr<WebCore::NodeList> expectedNodes = root->querySelectorAll("[expected- hittest]", es); | |
| 303 ASSERT_FALSE(es.hadException()); | |
| 304 | |
| 305 RefPtr<WebCore::NodeList> nodes = root->querySelectorAll("[hittest]", es); | |
| 306 ASSERT_FALSE(es.hadException()); | |
| 307 | |
| 308 for (unsigned index = 0; index < nodes->length(); index++) { | |
| 309 WebCore::Element* element = toElement(nodes->item(index)); | |
| 310 element->scrollIntoViewIfNeeded(); | |
| 311 ASSERT_TRUE(nodes->item(index)->isElementNode()); | |
| 312 | |
| 313 std::string failureContext("Test case: "); | |
| 314 if (element->hasID()) { | |
| 315 failureContext.append(element->getIdAttribute().ascii().data()); | |
| 316 } else if (element->firstChild()) { | |
| 317 failureContext.append("\""); | |
| 318 failureContext.append(element->firstChild()->textContent(false).stri pWhiteSpace().ascii().data()); | |
| 319 failureContext.append("\""); | |
| 320 } else { | |
| 321 failureContext += "<missing ID>"; | |
| 322 } | |
| 323 | |
| 324 // Run each test three times at different positions in the element. | |
| 325 // Note that we don't want the bounding box because our tests sometimes have elements with | |
| 326 // multiple border boxes with other elements in between. Use the first b order box (which | |
| 327 // we can easily visualize in a browser for debugging). | |
| 328 RefPtr<WebCore::ClientRectList> rects = element->getClientRects(); | |
| 329 ASSERT_GE(rects->length(), 0u) << failureContext; | |
| 330 RefPtr<WebCore::ClientRect> r = rects->item(0); | |
| 331 WebCore::FloatRect clientFloatRect = WebCore::FloatRect(r->left(), r->to p(), r->width(), r->height()); | |
| 332 WebCore::IntRect clientRect = enclosedIntRect(clientFloatRect); | |
| 333 for (int locIdx = 0; locIdx < 3; locIdx++) { | |
| 334 WebCore::IntPoint clientPoint; | |
| 335 std::stringstream contextStream; | |
| 336 contextStream << failureContext << " ("; | |
| 337 switch (locIdx) { | |
| 338 case 0: | |
| 339 clientPoint = clientRect.center(); | |
| 340 contextStream << "center"; | |
| 341 break; | |
| 342 case 1: | |
| 343 clientPoint = clientRect.location(); | |
| 344 contextStream << "top-left"; | |
| 345 break; | |
| 346 case 2: | |
| 347 clientPoint = clientRect.maxXMaxYCorner(); | |
| 348 clientPoint.move(-1, -1); | |
| 349 contextStream << "bottom-right"; | |
| 350 break; | |
| 351 default: | |
| 352 FAIL() << "Invalid location index."; | |
| 353 } | |
| 354 contextStream << "=" << clientPoint.x() << "," << clientPoint.y() << ")."; | |
| 355 std::string failureContextPos = contextStream.str(); | |
| 356 | |
| 357 WebCore::Frame* frame = root->document().frame(); | |
| 358 WebCore::FrameView* frameView = frame->view(); | |
| 359 WebCore::IntRect visibleRect = frameView->windowClipRect(); | |
| 360 ASSERT_TRUE(visibleRect.contains(clientPoint)) << failureContextPos | |
| 361 << " Test point not contained in visible area: " << visibleRect. x() << "," << visibleRect.y() | |
| 362 << "-" << visibleRect.maxX() << "," << visibleRect.maxY(); | |
| 363 | |
| 364 // First validate that a hit test at this point will really hit the element | |
| 365 // we intended. This is the easiest way for a test to be broken, but has nothing really | |
| 366 // to do with touch action. | |
| 367 // Note that we can't use WebView's hit test API because it doesn't look into shadow DOM. | |
| 368 WebCore::IntPoint docPoint(frameView->windowToContents(clientPoint)) ; | |
| 369 WebCore::HitTestResult result = frame->eventHandler().hitTestResultA tPoint(docPoint, WebCore::HitTestRequest::ReadOnly | WebCore::HitTestRequest::Ac tive | WebCore::HitTestRequest::TouchAction); | |
| 370 WebCore::Element* expectedElement = toElement(expectedNodes->item(in dex)); | |
| 371 ASSERT_EQ(expectedElement, result.innerElement()) << "Unexpected hit test result " << failureContextPos | |
| 372 << " Got element: \"" << result.innerElement()->outerHTML().str ipWhiteSpace().left(80).ascii().data() << "\"" | |
| 373 << std::endl << "Document render tree:" << std::endl << external Representation(root->document().frame()).utf8().data(); | |
| 374 } | |
| 375 } | |
| 376 } | |
| 377 | |
| 285 void TouchActionTest::sendTouchEvent(WebView* webView, WebInputEvent::Type type, WebCore::IntPoint clientPoint) | 378 void TouchActionTest::sendTouchEvent(WebView* webView, WebInputEvent::Type type, WebCore::IntPoint clientPoint) |
| 286 { | 379 { |
| 287 ASSERT_TRUE(type == WebInputEvent::TouchStart || type == WebInputEvent::Touc hCancel); | 380 ASSERT_TRUE(type == WebInputEvent::TouchStart || type == WebInputEvent::Touc hCancel); |
| 288 | 381 |
| 289 WebTouchEvent webTouchEvent; | 382 WebTouchEvent webTouchEvent; |
| 290 webTouchEvent.type = type; | 383 webTouchEvent.type = type; |
| 291 webTouchEvent.touchesLength = 1; | 384 webTouchEvent.touchesLength = 1; |
| 292 webTouchEvent.touches[0].state = (type == WebInputEvent::TouchStart ? | 385 webTouchEvent.touches[0].state = (type == WebInputEvent::TouchStart ? |
| 293 WebTouchPoint::StatePressed : | 386 WebTouchPoint::StatePressed : |
| 294 WebTouchPoint::StateCancelled); | 387 WebTouchPoint::StateCancelled); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 317 TEST_F(TouchActionTest, ShadowDOM) | 410 TEST_F(TouchActionTest, ShadowDOM) |
| 318 { | 411 { |
| 319 runShadowDOMTest("touch-action-shadow-dom.html"); | 412 runShadowDOMTest("touch-action-shadow-dom.html"); |
| 320 } | 413 } |
| 321 | 414 |
| 322 TEST_F(TouchActionTest, Pan) | 415 TEST_F(TouchActionTest, Pan) |
| 323 { | 416 { |
| 324 runTouchActionTest("touch-action-pan.html"); | 417 runTouchActionTest("touch-action-pan.html"); |
| 325 } | 418 } |
| 326 | 419 |
| 420 TEST_F(TouchActionTest, HitTest) | |
| 421 { | |
| 422 runTouchActionHitTest("touch-action-hittest.html"); | |
| 327 } | 423 } |
| 424 | |
| 425 } | |
| OLD | NEW |