webview: deflake testRequestImageRef. On devices with gesture navigation, the point on the screen where WebViewTest#testRequestImageRef was tapping was very close to the edge and sometimes overlapped with the region used for gesture recognition, causing an event injection failure since the test doesn't own the gesture recognition window. Make the image we're trying to tap on the full width and height of the WebView (since its size/location doesn't really matter for this test) and send the tap event to the center of the view instead, where it should avoid any special edge gesture regions. Fixes: 174245348 Test: atest android.webkit.cts.WebViewTest#testRequestImageRef Change-Id: Ia437a1e649710ee91bf6d7dfb9c51e17096ea0cf
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java index 06cc5d2..3069e6a 100755 --- a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java +++ b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
@@ -23,10 +23,8 @@ import android.content.ContentResolver; import android.content.Context; import android.content.ContextWrapper; -import android.content.res.AssetManager; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; -import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Picture; @@ -1798,26 +1796,22 @@ final ImageLoaded imageLoaded = new ImageLoaded(); mOnUiThread.getSettings().setJavaScriptEnabled(true); mOnUiThread.addJavascriptInterface(imageLoaded, "imageLoaded"); - AssetManager assets = getActivity().getAssets(); - Bitmap bitmap = BitmapFactory.decodeStream(assets.open(TestHtmlConstants.LARGE_IMG_URL)); - int imgWidth = bitmap.getWidth(); - int imgHeight = bitmap.getHeight(); startWebServer(false); final String imgUrl = mWebServer.getAssetUrl(TestHtmlConstants.LARGE_IMG_URL); mOnUiThread.loadDataAndWaitForCompletion( - "<html><head><title>Title</title><style type=\"text/css\">" + "<html><head><title>Title</title><style type='text/css'>" + "%23imgElement { -webkit-transform: translate3d(0,0,1); }" + "%23imgElement.finish { -webkit-transform: translate3d(0,0,0);" + " -webkit-transition-duration: 1ms; }</style>" - + "<script type=\"text/javascript\">function imgLoad() {" + + "<script type='text/javascript'>function imgLoad() {" + "imgElement = document.getElementById('imgElement');" + "imgElement.addEventListener('webkitTransitionEnd'," + "function(e) { imageLoaded.loaded(); });" + "imgElement.className = 'finish';}</script>" - + "</head><body><img id=\"imgElement\" src=\"" + imgUrl - + "\" width=\"" + imgWidth + "\" height=\"" + imgHeight - + "\" onLoad=\"imgLoad()\"/></body></html>", "text/html", null); + + "</head><body><img id='imgElement' src='" + imgUrl + + "' width='100%' height='100%' onLoad='imgLoad()'/>" + + "</body></html>", "text/html", null); WebkitUtils.waitForFuture(imageLoaded.future()); getInstrumentation().waitForIdleSync(); @@ -1828,12 +1822,13 @@ // touch the image handler.reset(); int[] location = mOnUiThread.getLocationOnScreen(); + int middleX = location[0] + mOnUiThread.getWebView().getWidth() / 2; + int middleY = location[1] + mOnUiThread.getWebView().getHeight() / 2; long time = SystemClock.uptimeMillis(); getInstrumentation().sendPointerSync( MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, - location[0] + imgWidth / 2, - location[1] + imgHeight / 2, 0)); + middleX, middleY, 0)); getInstrumentation().waitForIdleSync(); mOnUiThread.requestImageRef(msg); new PollingCheck() {