| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.android_webview.test; | 5 package org.chromium.android_webview.test; |
| 6 | 6 |
| 7 import android.content.res.Configuration; | 7 import android.content.res.Configuration; |
| 8 import android.os.SystemClock; | 8 import android.os.SystemClock; |
| 9 import android.test.FlakyTest; | 9 import android.test.FlakyTest; |
| 10 import android.test.suitebuilder.annotation.LargeTest; | 10 import android.test.suitebuilder.annotation.LargeTest; |
| 11 import android.test.suitebuilder.annotation.SmallTest; | 11 import android.test.suitebuilder.annotation.SmallTest; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 private static String fullPageLink(String href, String anchorText) { | 56 private static String fullPageLink(String href, String anchorText) { |
| 57 return CommonResources.makeHtmlPageFrom("", "<a class=\"full_view\" href
=\"" + | 57 return CommonResources.makeHtmlPageFrom("", "<a class=\"full_view\" href
=\"" + |
| 58 href + "\" " + "onclick=\"return false;\">" + anchorText + "</a>
"); | 58 href + "\" " + "onclick=\"return false;\">" + anchorText + "</a>
"); |
| 59 } | 59 } |
| 60 | 60 |
| 61 private void simulateTouchCenterOfWebViewOnUiThread() throws Throwable { | 61 private void simulateTouchCenterOfWebViewOnUiThread() throws Throwable { |
| 62 runTestOnUiThread(new Runnable() { | 62 runTestOnUiThread(new Runnable() { |
| 63 @Override | 63 @Override |
| 64 public void run() { | 64 public void run() { |
| 65 long eventTime = SystemClock.uptimeMillis(); | 65 long eventTime = SystemClock.uptimeMillis(); |
| 66 float x = (float)(mTestView.getRight() - mTestView.getLeft()) /
2; | 66 float x = (float) (mTestView.getRight() - mTestView.getLeft()) /
2; |
| 67 float y = (float)(mTestView.getBottom() - mTestView.getTop()) /
2; | 67 float y = (float) (mTestView.getBottom() - mTestView.getTop()) /
2; |
| 68 mAwContents.onTouchEvent(MotionEvent.obtain( | 68 mAwContents.onTouchEvent(MotionEvent.obtain( |
| 69 eventTime, eventTime, MotionEvent.ACTION_DOWN, | 69 eventTime, eventTime, MotionEvent.ACTION_DOWN, |
| 70 x, y, 0)); | 70 x, y, 0)); |
| 71 mAwContents.onTouchEvent(MotionEvent.obtain( | 71 mAwContents.onTouchEvent(MotionEvent.obtain( |
| 72 eventTime, eventTime, MotionEvent.ACTION_UP, | 72 eventTime, eventTime, MotionEvent.ACTION_UP, |
| 73 x, y, 0)); | 73 x, y, 0)); |
| 74 } | 74 } |
| 75 }); | 75 }); |
| 76 } | 76 } |
| 77 | 77 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 srcAnchorTypeRelativeUrlTestBody(false); | 193 srcAnchorTypeRelativeUrlTestBody(false); |
| 194 } | 194 } |
| 195 | 195 |
| 196 private void srcEmailTypeTestBody(boolean byTouch) throws Throwable { | 196 private void srcEmailTypeTestBody(boolean byTouch) throws Throwable { |
| 197 String email = "foo@bar.com"; | 197 String email = "foo@bar.com"; |
| 198 String prefix = "mailto:"; | 198 String prefix = "mailto:"; |
| 199 String page = fullPageLink(prefix + email, ANCHOR_TEXT); | 199 String page = fullPageLink(prefix + email, ANCHOR_TEXT); |
| 200 setServerResponseAndLoad(page); | 200 setServerResponseAndLoad(page); |
| 201 simulateInput(byTouch); | 201 simulateInput(byTouch); |
| 202 assertTrue(pollForHitTestDataOnUiThread(HitTestResult.EMAIL_TYPE, email)
); | 202 assertTrue(pollForHitTestDataOnUiThread(HitTestResult.EMAIL_TYPE, email)
); |
| 203 assertTrue(pollForHrefAndImageSrcOnUiThread(prefix+ email, ANCHOR_TEXT,
null)); | 203 assertTrue(pollForHrefAndImageSrcOnUiThread(prefix + email, ANCHOR_TEXT,
null)); |
| 204 } | 204 } |
| 205 | 205 |
| 206 @SmallTest | 206 @SmallTest |
| 207 @Feature({"AndroidWebView", "WebKitHitTest"}) | 207 @Feature({"AndroidWebView", "WebKitHitTest"}) |
| 208 public void testSrcEmailType() throws Throwable { | 208 public void testSrcEmailType() throws Throwable { |
| 209 srcEmailTypeTestBody(true); | 209 srcEmailTypeTestBody(true); |
| 210 } | 210 } |
| 211 | 211 |
| 212 @SmallTest | 212 @SmallTest |
| 213 @Feature({"AndroidWebView", "WebKitHitTest"}) | 213 @Feature({"AndroidWebView", "WebKitHitTest"}) |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 return mAwContents.getContentViewCore().getTitle().equals(title)
; | 364 return mAwContents.getContentViewCore().getTitle().equals(title)
; |
| 365 } | 365 } |
| 366 }); | 366 }); |
| 367 simulateTouchCenterOfWebViewOnUiThread(); | 367 simulateTouchCenterOfWebViewOnUiThread(); |
| 368 assertTrue(pollForHitTestDataOnUiThread(HitTestResult.UNKNOWN_TYPE, null
)); | 368 assertTrue(pollForHitTestDataOnUiThread(HitTestResult.UNKNOWN_TYPE, null
)); |
| 369 } | 369 } |
| 370 | 370 |
| 371 @LargeTest | 371 @LargeTest |
| 372 @Feature({"AndroidWebView", "WebKitHitTest"}) | 372 @Feature({"AndroidWebView", "WebKitHitTest"}) |
| 373 public void testUnfocusedNodeAndTouchRace() throws Throwable { | 373 public void testUnfocusedNodeAndTouchRace() throws Throwable { |
| 374 // Test when the touch and focus paths racing with setting different | 374 // Test when the touch and focus paths racing with setting different |
| 375 // results. | 375 // results. |
| 376 | 376 |
| 377 String relImageSrc = "/nonexistent3.jpg"; | 377 String relImageSrc = "/nonexistent3.jpg"; |
| 378 String fullImageSrc = mWebServer.getResponseUrl(relImageSrc); | 378 String fullImageSrc = mWebServer.getResponseUrl(relImageSrc); |
| 379 String html = CommonResources.makeHtmlPageFrom( | 379 String html = CommonResources.makeHtmlPageFrom( |
| 380 "<meta name=\"viewport\" content=\"width=device-width,height=device-he
ight\" />" + | 380 "<meta name=\"viewport\" content=\"width=device-width,height=dev
ice-height\" />" + |
| 381 "<style type=\"text/css\">" + | 381 "<style type=\"text/css\">" + |
| 382 ".full_width { width:100%; position:absolute; }" + | 382 ".full_width { width:100%; position:absolute; }" + |
| 383 "</style>", | 383 "</style>", |
| 384 "<form><input class=\"full_width\" style=\"height:25%;\" " + | 384 "<form><input class=\"full_width\" style=\"height:25%;\"
" + |
| 385 "type=\"text\" name=\"test\"></form>" + | 385 "type=\"text\" name=\"test\"></form>" + |
| 386 "<img class=\"full_width\" style=\"height:50%;top:25%;\" " + | 386 "<img class=\"full_width\" style=\"height:50%;top:25%;\"
" + |
| 387 "src=\"" + relImageSrc + "\">"); | 387 "src=\"" + relImageSrc + "\">"); |
| 388 setServerResponseAndLoad(html); | 388 setServerResponseAndLoad(html); |
| 389 | 389 |
| 390 // Focus on input element and check the hit test results. | 390 // Focus on input element and check the hit test results. |
| 391 simulateTabDownUpOnUiThread(); | 391 simulateTabDownUpOnUiThread(); |
| 392 assertTrue(pollForHitTestDataOnUiThread( | 392 assertTrue(pollForHitTestDataOnUiThread( |
| 393 HitTestResult.EDIT_TEXT_TYPE, null)); | 393 HitTestResult.EDIT_TEXT_TYPE, null)); |
| 394 assertTrue(pollForHrefAndImageSrcOnUiThread(null, null, null)); | 394 assertTrue(pollForHrefAndImageSrcOnUiThread(null, null, null)); |
| 395 | 395 |
| 396 // Touch image. Now the focus based hit test path will try to null out | 396 // Touch image. Now the focus based hit test path will try to null out |
| 397 // the results and the touch based path will update with the result of | 397 // the results and the touch based path will update with the result of |
| 398 // the image. | 398 // the image. |
| 399 simulateTouchCenterOfWebViewOnUiThread(); | 399 simulateTouchCenterOfWebViewOnUiThread(); |
| 400 | 400 |
| 401 // Make sure the result of image sticks. | 401 // Make sure the result of image sticks. |
| 402 for (int i = 0; i < 2; ++i) { | 402 for (int i = 0; i < 2; ++i) { |
| 403 Thread.sleep(500); | 403 Thread.sleep(500); |
| 404 assertTrue(pollForHitTestDataOnUiThread( | 404 assertTrue(pollForHitTestDataOnUiThread( |
| 405 HitTestResult.IMAGE_TYPE, fullImageSrc)); | 405 HitTestResult.IMAGE_TYPE, fullImageSrc)); |
| 406 assertTrue(pollForHrefAndImageSrcOnUiThread(null, null, fullImageSrc)); | 406 assertTrue(pollForHrefAndImageSrcOnUiThread(null, null, fullImageSrc
)); |
| 407 } | 407 } |
| 408 } | 408 } |
| 409 } | 409 } |
| OLD | NEW |