Fix EmojiTest threading issue.

WebView methods should be called on the UI thread. We are now
enforcing this with an exception. Update the test to use the
WebViewOnUiThread helper.

BUG=8657875

Change-Id: I9ba0530bcc096cb7279823070a6c873a09bb8344
diff --git a/tests/src/android/webkit/cts/WebViewOnUiThread.java b/tests/src/android/webkit/cts/WebViewOnUiThread.java
index aef4374..5133653 100644
--- a/tests/src/android/webkit/cts/WebViewOnUiThread.java
+++ b/tests/src/android/webkit/cts/WebViewOnUiThread.java
@@ -618,6 +618,15 @@
         });
     }
 
+    public Picture capturePicture() {
+        return getValue(new ValueGetter<Picture>() {
+            @Override
+            public Picture capture() {
+                return mWebView.capturePicture();
+            }
+        });
+    }
+
     /**
      * Helper for running code on the UI thread where an exception is
      * a test failure. If this is already the UI thread then it runs
diff --git a/tests/tests/text/src/android/text/cts/EmojiTest.java b/tests/tests/text/src/android/text/cts/EmojiTest.java
index 867cb8d..a8d8d2d 100755
--- a/tests/tests/text/src/android/text/cts/EmojiTest.java
+++ b/tests/tests/text/src/android/text/cts/EmojiTest.java
@@ -25,7 +25,7 @@
 import android.view.KeyEvent;
 import android.view.Menu;
 import android.view.View;
-import android.webkit.WebView;
+import android.webkit.cts.WebViewOnUiThread;
 import android.widget.TextView;
 import android.widget.EditText;
 
@@ -212,24 +212,18 @@
 
     private class CaptureWebView {
 
-        WebView view;
+        WebViewOnUiThread webViewOnUiThread;
         Bitmap bitmap;
         CaptureWebView(Context context) {
-            view = getActivity().getWebView();
+            webViewOnUiThread = new WebViewOnUiThread(EmojiTest.this, getActivity().getWebView());
         }
 
         Bitmap capture(char c[]) {
 
-            view.loadData("<html><body>" + String.valueOf(c) + "</body></html>",
+            webViewOnUiThread.loadDataAndWaitForCompletion("<html><body>" + String.valueOf(c) + "</body></html>",
                     "text/html; charset=utf-8", "utf-8");
 
-            try {
-                Thread.sleep(200);
-            } catch (InterruptedException ie) {
-                return null;
-            }
-
-            Picture picture = view.capturePicture();
+            Picture picture = webViewOnUiThread.capturePicture();
             if (picture == null || picture.getHeight() <= 0 || picture.getWidth() <= 0) {
                 return null;
             } else {