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

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

Issue 2337983004: [AndroidWebView] Add instrumentation test to catch StrictMode violations (Closed)
Patch Set: Minor changes - class renaming + comment removal. Created 4 years, 2 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
Index: android_webview/javatests/src/org/chromium/android_webview/test/AwTestBase.java
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwTestBase.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwTestBase.java
index cb4e8b096da8030cb36537f2486c02501c585455..bd76a45cad3dffed113ecfabb992c275c37aee93 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/AwTestBase.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwTestBase.java
@@ -10,8 +10,10 @@ import android.app.Instrumentation;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Build;
+import android.util.AndroidRuntimeException;
import android.util.Log;
+
import org.chromium.android_webview.AwBrowserContext;
import org.chromium.android_webview.AwBrowserProcess;
import org.chromium.android_webview.AwContents;
@@ -80,8 +82,9 @@ public class AwTestBase
@Override
protected void setUp() throws Exception {
- Context appContext = getInstrumentation().getTargetContext().getApplicationContext();
- mBrowserContext = new AwBrowserContext(new InMemorySharedPreferences(), appContext);
+ if (needsAwBrowserContextCreated()) {
+ createAwBrowserContext();
+ }
super.setUp();
if (needsBrowserProcessStarted()) {
@@ -89,6 +92,14 @@ public class AwTestBase
}
}
+ protected void createAwBrowserContext() {
+ if (mBrowserContext != null) {
+ throw new AndroidRuntimeException("There should only be one browser context.");
+ }
+ Context appContext = getInstrumentation().getTargetContext().getApplicationContext();
+ mBrowserContext = new AwBrowserContext(new InMemorySharedPreferences(), appContext);
+ }
+
protected void startBrowserProcess() throws Exception {
// The activity must be launched in order for proper webview statics to be setup.
getActivity();
@@ -101,6 +112,14 @@ public class AwTestBase
}
/**
+ * Override this to return false if the test doesn't want to create an AwBrowserContext
+ * automatically.
+ */
+ protected boolean needsAwBrowserContextCreated() {
+ return true;
+ }
+
+ /**
* Override this to return false if the test doesn't want the browser startup sequence to
* be run automatically.
* @return Whether the instrumentation test requires the browser process to already be started.
« no previous file with comments | « android_webview/javatests/src/org/chromium/android_webview/test/AwStrictModeTest.java ('k') | android_webview/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698