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

Unified Diff: android_webview/javatests/src/org/chromium/android_webview/test/AwStrictModeTest.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
« no previous file with comments | « no previous file | android_webview/javatests/src/org/chromium/android_webview/test/AwTestBase.java » ('j') | 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/AwStrictModeTest.java
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwStrictModeTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwStrictModeTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..9a0dbe2f2f98a5bd97e0291c4d38ae6f8639871d
--- /dev/null
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwStrictModeTest.java
@@ -0,0 +1,111 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.android_webview.test;
+
+import android.os.StrictMode;
+import android.test.suitebuilder.annotation.LargeTest;
+
+import org.chromium.android_webview.AwBrowserProcess;
+import org.chromium.base.test.util.Feature;
+
+/**
+ * Tests ensuring that starting up WebView does not cause any diskRead StrictMode violations.
+ */
+public class AwStrictModeTest extends AwTestBase {
+ private TestAwContentsClient mContentsClient;
+ private AwTestContainerView mAwTestContainerView;
+
+ private StrictMode.ThreadPolicy mOldThreadPolicy;
+ private StrictMode.VmPolicy mOldVmPolicy;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mContentsClient = new TestAwContentsClient();
+ enableStrictModeOnUiThreadSync();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ disableStrictModeOnUiThreadSync();
+ super.tearDown();
+ }
+
+ @Override
+ protected boolean needsAwBrowserContextCreated() {
+ return false;
+ }
+
+
+ @Override
+ protected boolean needsBrowserProcessStarted() {
+ // Don't start the browser process in AwTestBase - we want to start it ourselves with
+ // strictmode policies turned on.
+ return false;
+ }
+
+ @LargeTest
+ @Feature({"AndroidWebView"})
+ public void testStartup() throws Exception {
+ startEverythingSync();
+ }
+
+ @LargeTest
+ @Feature({"AndroidWebView"})
+ public void testLoadEmptyData() throws Exception {
+ startEverythingSync();
+ loadDataSync(mAwTestContainerView.getAwContents(),
+ mContentsClient.getOnPageFinishedHelper(), "", "text/html", false);
+ }
+
+ @LargeTest
+ @Feature({"AndroidWebView"})
+ public void testSetJavaScriptAndLoadData() throws Exception {
+ startEverythingSync();
+ enableJavaScriptOnUiThread(mAwTestContainerView.getAwContents());
+ loadDataSync(mAwTestContainerView.getAwContents(),
+ mContentsClient.getOnPageFinishedHelper(), "", "text/html", false);
+ }
+
+ private void enableStrictModeOnUiThreadSync() {
+ getInstrumentation().runOnMainSync(new Runnable() {
+ @Override
+ public void run() {
+ mOldThreadPolicy = StrictMode.getThreadPolicy();
+ mOldVmPolicy = StrictMode.getVmPolicy();
+ StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
+ .detectAll()
+ .penaltyLog()
+ .penaltyDeath()
+ .build());
+ StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
+ .detectAll()
+ .penaltyLog()
+ .penaltyDeath()
+ .build());
+ }});
+ }
+
+ private void disableStrictModeOnUiThreadSync() {
+ getInstrumentation().runOnMainSync(new Runnable() {
+ @Override
+ public void run() {
+ StrictMode.setThreadPolicy(mOldThreadPolicy);
+ StrictMode.setVmPolicy(mOldVmPolicy);
+ }});
+ }
+
+ private void startEverythingSync() throws Exception {
+ getActivity();
+ getInstrumentation().runOnMainSync(new Runnable() {
+ @Override
+ public void run() {
+ createAwBrowserContext();
+ AwBrowserProcess.start();
+ mAwTestContainerView = createAwTestContainerView(mContentsClient);
+ }
+ });
+ }
+}
« no previous file with comments | « no previous file | android_webview/javatests/src/org/chromium/android_webview/test/AwTestBase.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698