Fix WebView test testRequestChildRectangleOnScreen() to call WebView methods on UI thread

Bug: 4340864
Change-Id: I67ba9c16b3adc7c8d137939a078b0f68f211302f
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
index f80bcf0..3a1f0ee 100755
--- a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
@@ -2012,11 +2012,15 @@
         args = {View.class, Rect.class, boolean.class}
     )
     public void testRequestChildRectangleOnScreen() throws Throwable {
-        DisplayMetrics metrics = mWebView.getContext().getResources().getDisplayMetrics();
-        final int dimension = 2 * Math.max(metrics.widthPixels, metrics.heightPixels);
-        String p = "<p style=\"height:" + dimension + "px;width:" + dimension + "px\">&nbsp;</p>";
-        mWebView.loadData("<html><body>" + p + "</body></html>", "text/html", "UTF-8");
-        waitForLoadComplete();
+        runTestOnUiThread(new Runnable() {
+            public void run() {
+                DisplayMetrics metrics = mWebView.getContext().getResources().getDisplayMetrics();
+                final int dimension = 2 * Math.max(metrics.widthPixels, metrics.heightPixels);
+                String p = "<p style=\"height:" + dimension + "px;width:" + dimension + "px\">&nbsp;</p>";
+                mWebView.loadData("<html><body>" + p + "</body></html>", "text/html", "UTF-8");
+                waitForLoadComplete();
+            }
+        });
         getInstrumentation().waitForIdleSync();
 
         runTestOnUiThread(new Runnable() {
@@ -2024,6 +2028,8 @@
                 int origX = mWebView.getScrollX();
                 int origY = mWebView.getScrollY();
 
+                DisplayMetrics metrics = mWebView.getContext().getResources().getDisplayMetrics();
+                final int dimension = 2 * Math.max(metrics.widthPixels, metrics.heightPixels);
                 int half = dimension / 2;
                 Rect rect = new Rect(half, half, half + 1, half + 1);
                 assertTrue(mWebView.requestChildRectangleOnScreen(mWebView, rect, true));