Merge changes from topic "am-159e2a29-1b2a-4aa4-b12e-080f0d31a514" into nyc-mr2-dev

* changes:
  [automerger] CTS test for Android Security b/32589224 b/72461500 am: b2509874c4 am: 9e8d60b34f am: 5b529105de am: bc632a0f6f
  [automerger] CTS test for Android Security b/32589224 b/72461500 am: b2509874c4 am: 9e8d60b34f am: 5b529105de
  [automerger] CTS test for Android Security b/32589224 b/72461500 am: b2509874c4 am: 9e8d60b34f
  [automerger] CTS test for Android Security b/32589224 b/72461500 am: b2509874c4
  CTS test for Android Security b/32589224 b/72461500
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java b/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java
index d0fffae..a3a7279 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java
@@ -21,11 +21,13 @@
 import android.graphics.Bitmap;
 import android.net.http.SslError;
 import android.os.Build;
+import android.os.Message;
 import android.test.ActivityInstrumentationTestCase2;
 import android.util.Base64;
 import android.util.Log;
 import android.webkit.ConsoleMessage;
 import android.webkit.SslErrorHandler;
+import android.webkit.WebChromeClient;
 import android.webkit.WebIconDatabase;
 import android.webkit.WebResourceResponse;
 import android.webkit.WebResourceRequest;
@@ -41,6 +43,8 @@
 import java.io.FileOutputStream;
 import java.nio.charset.StandardCharsets;
 import java.util.Locale;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -408,26 +412,38 @@
             return;
         }
         mSettings.setJavaScriptEnabled(true);
+        mSettings.setSupportMultipleWindows(true);
+        startWebServer();
+
+        final WebView childWebView = mOnUiThread.createWebView();
+        final CountDownLatch latch = new CountDownLatch(1);
+        mOnUiThread.setWebChromeClient(new WebChromeClient() {
+            @Override
+            public boolean onCreateWindow(
+                WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
+                WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
+                transport.setWebView(childWebView);
+                resultMsg.sendToTarget();
+                latch.countDown();
+                return true;
+            }
+        });
 
         mSettings.setJavaScriptCanOpenWindowsAutomatically(false);
         assertFalse(mSettings.getJavaScriptCanOpenWindowsAutomatically());
-        loadAssetUrl(TestHtmlConstants.POPUP_URL);
+        mOnUiThread.loadUrl(mWebServer.getAssetUrl(TestHtmlConstants.POPUP_URL));
         new PollingCheck(WEBVIEW_TIMEOUT) {
             @Override
             protected boolean check() {
                 return "Popup blocked".equals(mOnUiThread.getTitle());
             }
         }.run();
+        assertEquals(1, latch.getCount());
 
         mSettings.setJavaScriptCanOpenWindowsAutomatically(true);
         assertTrue(mSettings.getJavaScriptCanOpenWindowsAutomatically());
-        loadAssetUrl(TestHtmlConstants.POPUP_URL);
-        new PollingCheck(WEBVIEW_TIMEOUT) {
-            @Override
-            protected boolean check() {
-                return "Popup allowed".equals(mOnUiThread.getTitle());
-            }
-        }.run();
+        mOnUiThread.loadUrl(mWebServer.getAssetUrl(TestHtmlConstants.POPUP_URL));
+        assertTrue(latch.await(WEBVIEW_TIMEOUT, TimeUnit.MILLISECONDS));
     }
 
     public void testAccessJavaScriptEnabled() throws Exception {