Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(503)

Unified Diff: android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java

Issue 581423002: [aw] Ensure that WebView APIs do not crash if called after destruction. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix findbugs warning. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « android_webview/java/src/org/chromium/android_webview/AwContents.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java
index 210bfcebd2dea48994b0289bbec45c5fd2be7428..d2db7ddad7ed322d35ea140b51c35b8ab4bb4211 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java
@@ -6,6 +6,7 @@ package org.chromium.android_webview.test;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
@@ -13,16 +14,18 @@ import android.test.UiThreadTest;
import android.test.suitebuilder.annotation.LargeTest;
import android.test.suitebuilder.annotation.SmallTest;
import android.util.Pair;
+import android.view.KeyEvent;
+import android.view.View;
import org.apache.http.Header;
import org.apache.http.HttpRequest;
-
import org.chromium.android_webview.AwContents;
import org.chromium.android_webview.AwSettings;
import org.chromium.android_webview.test.TestAwContentsClient.OnDownloadStartHelper;
import org.chromium.android_webview.test.util.CommonResources;
import org.chromium.base.test.util.Feature;
import org.chromium.content.browser.test.util.CallbackHelper;
+import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.net.test.util.TestWebServer;
import java.io.InputStream;
@@ -92,6 +95,50 @@ public class AwContentsTest extends AwTestBase {
}
}
+ @SmallTest
+ @Feature({"AndroidWebView"})
+ @UiThreadTest
+ public void testWebViewApisFailGracefullyAfterDestruction() throws Throwable {
+ AwContents awContents =
+ createAwTestContainerView(mContentsClient).getAwContents();
+ awContents.destroy();
+
+ assertNull(awContents.getWebContents());
+ assertNull(awContents.getContentViewCore());
+ assertNull(awContents.getNavigationController());
+
+ // The documentation for WebView#destroy() reads "This method should be called
+ // after this WebView has been removed from the view system. No other methods
+ // may be called on this WebView after destroy".
+ // However, some apps do not respect that restriction so we need to ensure that
+ // we fail gracefully and do not crash when APIs are invoked after destruction.
+ // Due to the large number of APIs we only test a representative selection here.
+ awContents.clearHistory();
+ awContents.loadUrl(new LoadUrlParams("http://www.google.com"));
+ awContents.findAllAsync("search");
+ assertNull(awContents.getUrl());
+ assertNull(awContents.getContentSettings());
+ assertFalse(awContents.canGoBack());
+ awContents.disableJavascriptInterfacesInspection();
+ awContents.invokeZoomPicker();
+ awContents.onResume();
+ awContents.stopLoading();
+ awContents.onWindowVisibilityChanged(View.VISIBLE);
+ awContents.requestFocus();
+ awContents.isMultiTouchZoomSupported();
+ awContents.setOverScrollMode(View.OVER_SCROLL_NEVER);
+ awContents.pauseTimers();
+ awContents.onContainerViewScrollChanged(200, 200, 100, 100);
+ awContents.computeScroll();
+ awContents.onMeasure(100, 100);
+ awContents.onDraw(new Canvas());
+ awContents.getMostRecentProgress();
+ assertEquals(0, awContents.computeHorizontalScrollOffset());
+ assertEquals(0, awContents.getContentWidthCss());
+ awContents.onKeyUp(KeyEvent.KEYCODE_BACK,
+ new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MENU));
+ }
+
@LargeTest
@Feature({"AndroidWebView"})
public void testCreateAndGcManyTimes() throws Throwable {
« no previous file with comments | « android_webview/java/src/org/chromium/android_webview/AwContents.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698