summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShimi Zhang <ctzsm@google.com>2019-02-26 12:47:28 -0800
committerShimi Zhang <ctzsm@google.com>2019-02-26 12:47:28 -0800
commit04d45b0fc0c8b047c6bc9e5a9a0ca3e967cc0d62 (patch)
tree50578f73ed168ee1e27f769165f0d9621c0a1081
parented8ae7dd1222afdb78eec81b0c6dc2b9fefc41de (diff)
parenta00b291c5a4e9ba6058e2fb699ea575fce406574 (diff)
downloadcts-04d45b0fc0c8b047c6bc9e5a9a0ca3e967cc0d62.tar.gz
resolve merge conflicts of a00b291c5a4e9ba6058e2fb699ea575fce406574 to oreo-cts-dev
Bug: None Test: cts-tradefed run cts -m CtsWebkitTestCases Change-Id: I2a6f780b1795d03db0862354313336953b5b67cc
-rw-r--r--tests/tests/webkit/assets/webkit/jsunload.html8
-rw-r--r--tests/tests/webkit/res/layout/webview_layout.xml6
-rw-r--r--tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java55
3 files changed, 57 insertions, 12 deletions
diff --git a/tests/tests/webkit/assets/webkit/jsunload.html b/tests/tests/webkit/assets/webkit/jsunload.html
index f016eb7b744..9932ae10d33 100644
--- a/tests/tests/webkit/assets/webkit/jsunload.html
+++ b/tests/tests/webkit/assets/webkit/jsunload.html
@@ -22,9 +22,15 @@
return "this message will be a hardcoded string in chrome.";
}
window.onbeforeunload = fireUnload;
+ window.onload = function() {
+ document.addEventListener("touchend", function() {
+ setTimeout(() => {
+ document.title = "touch received";
+ }, 0);
+ }, false);
+ }
</script>
<body>
javascript unload test
</body>
</html>
-
diff --git a/tests/tests/webkit/res/layout/webview_layout.xml b/tests/tests/webkit/res/layout/webview_layout.xml
index 7a0ed0d1fa1..d266d21305b 100644
--- a/tests/tests/webkit/res/layout/webview_layout.xml
+++ b/tests/tests/webkit/res/layout/webview_layout.xml
@@ -17,9 +17,9 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
- android:layout_height="wrap_content">
+ android:layout_height="match_parent">
<WebView android:id="@+id/web_page"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" />
</LinearLayout>
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java b/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java
index e3208e49831..a8617c79282 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java
@@ -32,10 +32,16 @@ import android.webkit.cts.WebViewOnUiThread.WaitForProgressClient;
import com.android.compatibility.common.util.CddTest;
import com.android.compatibility.common.util.NullWebViewUtils;
import com.android.compatibility.common.util.PollingCheck;
+import com.google.common.util.concurrent.SettableFuture;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
@CddTest(requirement="3.4.1/H-0-1,T-0-1,A-0-1")
public class WebChromeClientTest extends ActivityInstrumentationTestCase2<WebViewCtsActivity> {
private static final long TEST_TIMEOUT = 5000L;
+ private static final String TOUCH_RECEIVED = "touch received";
private CtsTestServer mWebServer;
private WebIconDatabase mIconDb;
@@ -203,11 +209,13 @@ public class WebChromeClientTest extends ActivityInstrumentationTestCase2<WebVie
runWindowTest(false);
}
+ // Note that test is still a little flaky. See b/119468441.
public void testOnJsBeforeUnloadIsCalled() throws Exception {
if (!NullWebViewUtils.isWebViewAvailable()) {
return;
}
+ // Use a default WebChromeClient to listen first page title change.
final MockWebChromeClient webChromeClient = new MockWebChromeClient();
mOnUiThread.setWebChromeClient(webChromeClient);
@@ -217,20 +225,37 @@ public class WebChromeClientTest extends ActivityInstrumentationTestCase2<WebVie
assertFalse(webChromeClient.hadOnJsBeforeUnload());
- mOnUiThread.loadUrlAndWaitForCompletion(mWebServer.getAssetUrl(TestHtmlConstants.JS_UNLOAD_URL));
+ mOnUiThread.loadUrlAndWaitForCompletion(
+ mWebServer.getAssetUrl(TestHtmlConstants.JS_UNLOAD_URL));
+
+ final SettableFuture<String> pageTitleFuture = SettableFuture.create();
+ 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);
+ }
+
+ @Override
+ public boolean onJsBeforeUnload(
+ WebView view, String url, String message, JsResult result) {
+ boolean ret = super.onJsBeforeUnload(view, url, message, result);
+ onJsBeforeUnloadFuture.set(null);
+ return ret;
+ }
+ };
+ mOnUiThread.setWebChromeClient(webChromeClientWaitTitle);
// Send a user gesture, required for unload to execute since WebView version 60.
tapWebView();
+ assertEquals(TOUCH_RECEIVED, waitForFuture(pageTitleFuture));
// unload should trigger when we try to navigate away
- mOnUiThread.loadUrlAndWaitForCompletion(mWebServer.getAssetUrl(TestHtmlConstants.HELLO_WORLD_URL));
+ mOnUiThread.loadUrlAndWaitForCompletion(
+ mWebServer.getAssetUrl(TestHtmlConstants.HELLO_WORLD_URL));
- new PollingCheck(TEST_TIMEOUT) {
- @Override
- protected boolean check() {
- return webChromeClient.hadOnJsBeforeUnload();
- }
- }.run();
+ waitForFuture(onJsBeforeUnloadFuture);
}
public void testOnJsAlert() throws Exception {
@@ -339,6 +364,20 @@ public class WebChromeClientTest extends ActivityInstrumentationTestCase2<WebVie
getInstrumentation().waitForIdleSync();
}
+ // TODO(ctzsm): Remove this method and replace its usage when we have it in a util class.
+ private static <T> T waitForFuture(Future<T> future) throws Exception {
+ try {
+ return future.get(TEST_TIMEOUT, TimeUnit.MILLISECONDS);
+ } catch (ExecutionException e) {
+ Throwable cause = e.getCause();
+ if (cause instanceof Error)
+ throw(Error) cause;
+ if (cause instanceof RuntimeException)
+ throw(RuntimeException) cause;
+ throw new RuntimeException(cause);
+ }
+ }
+
private class MockWebChromeClient extends WaitForProgressClient {
private boolean mHadOnProgressChanged;
private boolean mHadOnReceivedTitle;