Fix WebView test testSetPictureListener() to call WebView methods on UI thread
Bug: 4340864
Change-Id: Icc58e90032c499fd01b9585f4b3cba81bcd57f86
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
index 046f469..737f1e7e 100755
--- a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
@@ -713,12 +713,28 @@
method = "setPictureListener",
args = {PictureListener.class}
)
- public void testSetPictureListener() throws Exception {
+ public void testSetPictureListener() throws Exception, Throwable {
+ final class MyPictureListener implements PictureListener {
+ public int callCount;
+ public WebView webView;
+ public Picture picture;
+
+ public void onNewPicture(WebView view, Picture picture) {
+ this.callCount += 1;
+ this.webView = view;
+ this.picture = picture;
+ }
+ }
+
final MyPictureListener listener = new MyPictureListener();
- mWebView.setPictureListener(listener);
startWebServer(false);
- String url = mWebServer.getAssetUrl(TestHtmlConstants.HELLO_WORLD_URL);
- assertLoadUrlSuccessfully(url);
+ final String url = mWebServer.getAssetUrl(TestHtmlConstants.HELLO_WORLD_URL);
+ runTestOnUiThread(new Runnable() {
+ public void run() {
+ mWebView.setPictureListener(listener);
+ assertLoadUrlSuccessfully(url);
+ }
+ });
new DelayedCheck(TEST_TIMEOUT) {
protected boolean check() {
return listener.callCount > 0;
@@ -728,8 +744,12 @@
assertNotNull(listener.picture);
final int oldCallCount = listener.callCount;
- url = mWebServer.getAssetUrl(TestHtmlConstants.SMALL_IMG_URL);
- assertLoadUrlSuccessfully(url);
+ final String newUrl = mWebServer.getAssetUrl(TestHtmlConstants.SMALL_IMG_URL);
+ runTestOnUiThread(new Runnable() {
+ public void run() {
+ assertLoadUrlSuccessfully(newUrl);
+ }
+ });
new DelayedCheck(TEST_TIMEOUT) {
protected boolean check() {
return listener.callCount > oldCallCount;
@@ -2230,16 +2250,4 @@
this.contentDisposition = contentDisposition;
}
}
-
- private static class MyPictureListener implements PictureListener {
- public int callCount;
- public WebView webView;
- public Picture picture;
-
- public void onNewPicture(WebView view, Picture picture) {
- this.callCount += 1;
- this.webView = view;
- this.picture = picture;
- }
- }
}