Enforce that the image is visible prior to poking it.
Bug 6299115
The test now requires that the image is visible before poking
its spot and testing the requestImageRef. This fixes the
intermittent failures.
Change-Id: I6a59ef43e97fb734e07d803a3264750e535cddfb
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
index 0a8cc30..3f7ea78 100755
--- a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
@@ -1167,6 +1167,20 @@
}
public void testRequestImageRef() throws Exception, Throwable {
+ final class ImageLoaded {
+ public boolean mImageLoaded;
+
+ public void loaded() {
+ mImageLoaded = true;
+ }
+ }
+ final ImageLoaded imageLoaded = new ImageLoaded();
+ runTestOnUiThread(new Runnable() {
+ public void run() {
+ 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();
@@ -1175,9 +1189,24 @@
startWebServer(false);
final String imgUrl = mWebServer.getAssetUrl(TestHtmlConstants.LARGE_IMG_URL);
mOnUiThread.loadDataAndWaitForCompletion(
- "<html><title>Title</title><body><img src=\"" + imgUrl
+ "<html><head><title>Title</title><style type=\"text/css\">"
+ + "#imgElement { -webkit-transform: translate3d(0,0,1); }"
+ + "#imgElement.finish { -webkit-transform: translate3d(0,0,0);"
+ + " -webkit-transition-duration: 1ms; }</style>"
+ + "<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
- + "\"/></body></html>", "text/html", null);
+ + "\" onLoad=\"imgLoad()\"/></body></html>", "text/html", null);
+ new PollingCheck() {
+ @Override
+ protected boolean check() {
+ return imageLoaded.mImageLoaded;
+ }
+ }.run();
getInstrumentation().waitForIdleSync();
final HrefCheckHandler handler = new HrefCheckHandler(mWebView.getHandler().getLooper());