Commit 9cea744e authored by gsennton's avatar gsennton Committed by Commit bot

Make minidump uploading test logic more useful to WebView.

Make minidump uploading test utility more useful/accessible to WebView
to allow for testing the WebView-implementation of minidump uploading.

BUG=665448

Review-Url: https://codereview.chromium.org/2532133002
Cr-Commit-Position: refs/heads/master@{#434933}
parent 884d7a03
......@@ -7,6 +7,7 @@ package org.chromium.components.minidump_uploader;
import android.test.InstrumentationTestCase;
import org.chromium.base.Log;
import org.chromium.components.minidump_uploader.util.CrashReportingPermissionManager;
import java.io.File;
import java.io.FileWriter;
......@@ -25,7 +26,7 @@ public class CrashTestCase extends InstrumentationTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
mCacheDir = getInstrumentation().getTargetContext().getCacheDir();
mCacheDir = getExistingCacheDir();
mCrashDir = new File(
mCacheDir,
CrashFileManager.CRASH_DUMP_DIR);
......@@ -34,6 +35,14 @@ public class CrashTestCase extends InstrumentationTestCase {
}
}
/**
* Returns the cache directory where we should store minidumps.
* Can be overriden by sub-classes to allow for use with different cache directories.
*/
protected File getExistingCacheDir() {
return getInstrumentation().getTargetContext().getCacheDir();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
......@@ -82,4 +91,50 @@ public class CrashTestCase extends InstrumentationTestCase {
}
}
}
/**
* A utility instantiation of CrashReportingPermissionManager providing a compact way of
* overriding different permission settings.
*/
public static class MockCrashReportingPermissionManager
implements CrashReportingPermissionManager {
protected boolean mIsInSample;
protected boolean mIsPermitted;
protected boolean mIsUserPermitted;
protected boolean mIsCommandLineDisabled;
protected boolean mIsNetworkAvailable;
protected boolean mIsEnabledForTests;
MockCrashReportingPermissionManager() {}
@Override
public boolean isClientInMetricsSample() {
return mIsInSample;
}
@Override
public boolean isNetworkAvailableForCrashUploads() {
return mIsNetworkAvailable;
}
@Override
public boolean isMetricsUploadPermitted() {
return mIsPermitted;
}
@Override
public boolean isUsageAndCrashReportingPermittedByUser() {
return mIsUserPermitted;
}
@Override
public boolean isCrashUploadDisabledByCommandLine() {
return mIsCommandLineDisabled;
}
@Override
public boolean isUploadEnabledForTests() {
return mIsEnabledForTests;
}
}
}
......@@ -111,48 +111,6 @@ public class MinidumpUploadCallableTest extends CrashTestCase {
}
}
private static class MockCrashReportingPermissionManager
implements CrashReportingPermissionManager {
protected boolean mIsInSample;
protected boolean mIsPermitted;
protected boolean mIsUserPermitted;
protected boolean mIsCommandLineDisabled;
protected boolean mIsNetworkAvailable;
protected boolean mIsEnabledForTests;
MockCrashReportingPermissionManager() {}
@Override
public boolean isClientInMetricsSample() {
return mIsInSample;
}
@Override
public boolean isNetworkAvailableForCrashUploads() {
return mIsNetworkAvailable;
}
@Override
public boolean isMetricsUploadPermitted() {
return mIsPermitted;
}
@Override
public boolean isUsageAndCrashReportingPermittedByUser() {
return mIsUserPermitted;
}
@Override
public boolean isCrashUploadDisabledByCommandLine() {
return mIsCommandLineDisabled;
}
@Override
public boolean isUploadEnabledForTests() {
return mIsEnabledForTests;
}
}
/**
* This class calls |getInstrumentation| which cannot be done in a static context.
*/
......
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