Commit 63e3af96 authored by Changwan Ryu's avatar Changwan Ryu Committed by Commit Bot

WPT for WebView: destroy webview better

Also, this CL fixes settings and a typo.

Bug: 994939
Change-Id: Ied967e8a15f6c1a83ca5947d5a569d0c66a8191c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1797325Reviewed-by: default avatarAndrew Luo <aluo@chromium.org>
Commit-Queue: Changwan Ryu <changwan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695772}
parent 4088baba
...@@ -27,7 +27,7 @@ import org.chromium.base.VisibleForTesting; ...@@ -27,7 +27,7 @@ import org.chromium.base.VisibleForTesting;
* A main activity to handle WPT requests. * A main activity to handle WPT requests.
* *
* This is currently implemented to support minimum viable implementation such that * This is currently implemented to support minimum viable implementation such that
* Multi-window and JavaScript are enabled by default. * multi-window and JavaScript are enabled by default.
* *
* TODO(crbug.com/994939): It is currently implemented to support only a single child. Although not * TODO(crbug.com/994939): It is currently implemented to support only a single child. Although not
* explicitly stated, there may be some WPT tests that require more than one * explicitly stated, there may be some WPT tests that require more than one
...@@ -58,13 +58,11 @@ public class WebPlatformTestsActivity extends Activity { ...@@ -58,13 +58,11 @@ public class WebPlatformTestsActivity extends Activity {
@Override @Override
public boolean onCreateWindow( public boolean onCreateWindow(
WebView webView, boolean isDialog, boolean isUserGesture, Message resultMsg) { WebView webView, boolean isDialog, boolean isUserGesture, Message resultMsg) {
removeAndDestroyChildWebView(); removeAndDestroyWebView(mChildWebView);
// Note that WebView is not inflated but created programmatically // Note that WebView is not inflated but created programmatically
// such that it can be destroyed separately. // such that it can be destroyed separately.
mChildWebView = new WebView(WebPlatformTestsActivity.this); mChildWebView = new WebView(WebPlatformTestsActivity.this);
WebSettings settings = mChildWebView.getSettings(); setUpWebSettings(mChildWebView.getSettings());
setUpWebSettings(settings);
settings.setUseWideViewPort(false);
mChildWebView.setWebViewClient(new WebViewClient() { mChildWebView.setWebViewClient(new WebViewClient() {
@Override @Override
public void onPageFinished(WebView childWebView, String url) { public void onPageFinished(WebView childWebView, String url) {
...@@ -101,13 +99,12 @@ public class WebPlatformTestsActivity extends Activity { ...@@ -101,13 +99,12 @@ public class WebPlatformTestsActivity extends Activity {
} }
} }
/** Remove and destroy a child webview if it exists. */ /** Remove and destroy a webview if it exists. */
private void removeAndDestroyChildWebView() { private void removeAndDestroyWebView(WebView webView) {
if (mChildWebView == null) return; if (webView == null) return;
ViewGroup parent = (ViewGroup) mChildWebView.getParent(); ViewGroup parent = (ViewGroup) webView.getParent();
if (parent != null) parent.removeView(mChildWebView); if (parent != null) parent.removeView(webView);
mChildWebView.destroy(); webView.destroy();
mChildWebView = null;
} }
private String getUrlFromIntent() { private String getUrlFromIntent() {
...@@ -137,6 +134,15 @@ public class WebPlatformTestsActivity extends Activity { ...@@ -137,6 +134,15 @@ public class WebPlatformTestsActivity extends Activity {
} }
} }
@Override
protected void onDestroy() {
super.onDestroy();
removeAndDestroyWebView(mWebView);
mWebView = null;
removeAndDestroyWebView(mChildWebView);
mChildWebView = null;
}
private LinearLayout createChildLayout() { private LinearLayout createChildLayout() {
// Provide parent such that MATCH_PARENT layout params can work. Ignore the return value // Provide parent such that MATCH_PARENT layout params can work. Ignore the return value
// which is mRootLayout. // which is mRootLayout.
...@@ -151,10 +157,13 @@ public class WebPlatformTestsActivity extends Activity { ...@@ -151,10 +157,13 @@ public class WebPlatformTestsActivity extends Activity {
} }
private void setUpWebSettings(WebSettings settings) { private void setUpWebSettings(WebSettings settings) {
// Required by WPT.
settings.setJavaScriptEnabled(true); settings.setJavaScriptEnabled(true);
// Enable multi-window. // Enable multi-window.
settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setSupportMultipleWindows(true); settings.setSupportMultipleWindows(true);
// Respect "viewport" HTML meta tag. This is false by default, but set to false to be clear.
settings.setUseWideViewPort(false);
} }
private void setUpMainWebView(String url) { private void setUpMainWebView(String url) {
...@@ -167,7 +176,8 @@ public class WebPlatformTestsActivity extends Activity { ...@@ -167,7 +176,8 @@ public class WebPlatformTestsActivity extends Activity {
TextView childTitleText = mChildLayout.findViewById(R.id.childTitleText); TextView childTitleText = mChildLayout.findViewById(R.id.childTitleText);
childTitleText.setText(""); childTitleText.setText("");
mChildLayout.setVisibility(View.INVISIBLE); mChildLayout.setVisibility(View.INVISIBLE);
removeAndDestroyChildWebView(); removeAndDestroyWebView(mChildWebView);
mChildWebView = null;
if (mTestCallback != null) mTestCallback.onChildLayoutInvisible(); if (mTestCallback != null) mTestCallback.onChildLayoutInvisible();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment