Merge changes from topic "am-10d7afb6-3af4-4441-ba2b-ee79a6b00d71" into nyc-mr2-dev
* changes:
[automerger] Android Security CTS/STS Oom Catcher App update am: 5ab7cfe8fd am: 09282d1c92 am: 39811fd750 am: 27719db9c9
[automerger] Android Security CTS/STS Oom Catcher App update am: 5ab7cfe8fd am: 09282d1c92 am: 39811fd750
[automerger] Android Security CTS/STS Oom Catcher App update am: 5ab7cfe8fd am: 09282d1c92
[automerger] Android Security CTS/STS Oom Catcher App update am: 5ab7cfe8fd
Android Security CTS/STS Oom Catcher App update
diff --git a/tests/tests/webkit/assets/webkit/jsunload.html b/tests/tests/webkit/assets/webkit/jsunload.html
index 9932ae1..593ecc9 100644
--- a/tests/tests/webkit/assets/webkit/jsunload.html
+++ b/tests/tests/webkit/assets/webkit/jsunload.html
@@ -23,11 +23,8 @@
}
window.onbeforeunload = fireUnload;
window.onload = function() {
- document.addEventListener("touchend", function() {
- setTimeout(() => {
- document.title = "touch received";
- }, 0);
- }, false);
+ document.addEventListener("click", () => document.title = "touch received", false);
+ document.title = "listener added";
}
</script>
<body>
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java b/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java
index 94ebe66..5e133ea 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java
@@ -33,12 +33,16 @@
import com.google.common.util.concurrent.SettableFuture;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
public class WebChromeClientTest extends ActivityInstrumentationTestCase2<WebViewCtsActivity> {
private static final long TEST_TIMEOUT = 5000L;
+ private static final String JAVASCRIPT_UNLOAD = "javascript unload";
+ private static final String LISTENER_ADDED = "listener added";
private static final String TOUCH_RECEIVED = "touch received";
private CtsTestServer mWebServer;
@@ -213,26 +217,17 @@
return;
}
- // Use a default WebChromeClient to listen first page title change.
- final MockWebChromeClient webChromeClient = new MockWebChromeClient();
- mOnUiThread.setWebChromeClient(webChromeClient);
-
final WebSettings settings = mOnUiThread.getSettings();
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
- assertFalse(webChromeClient.hadOnJsBeforeUnload());
-
- mOnUiThread.loadUrlAndWaitForCompletion(
- mWebServer.getAssetUrl(TestHtmlConstants.JS_UNLOAD_URL));
-
- final SettableFuture<String> pageTitleFuture = SettableFuture.create();
+ final BlockingQueue<String> pageTitleQueue = new ArrayBlockingQueue<>(3);
final SettableFuture<Void> onJsBeforeUnloadFuture = SettableFuture.create();
final MockWebChromeClient webChromeClientWaitTitle = new MockWebChromeClient() {
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
- pageTitleFuture.set(title);
+ pageTitleQueue.add(title);
}
@Override
@@ -245,9 +240,14 @@
};
mOnUiThread.setWebChromeClient(webChromeClientWaitTitle);
+ mOnUiThread.loadUrlAndWaitForCompletion(
+ mWebServer.getAssetUrl(TestHtmlConstants.JS_UNLOAD_URL));
+
+ assertEquals(JAVASCRIPT_UNLOAD, pageTitleQueue.poll(TEST_TIMEOUT, TimeUnit.MILLISECONDS));
+ assertEquals(LISTENER_ADDED, pageTitleQueue.poll(TEST_TIMEOUT, TimeUnit.MILLISECONDS));
// Send a user gesture, required for unload to execute since WebView version 60.
tapWebView();
- assertEquals(TOUCH_RECEIVED, waitForFuture(pageTitleFuture));
+ assertEquals(TOUCH_RECEIVED, pageTitleQueue.poll(TEST_TIMEOUT, TimeUnit.MILLISECONDS));
// unload should trigger when we try to navigate away
mOnUiThread.loadUrlAndWaitForCompletion(