| Index: android_webview/javatests/src/org/chromium/android_webview/test/crash/MinidumpUploaderTest.java
|
| diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/crash/MinidumpUploaderTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/crash/MinidumpUploaderTest.java
|
| index 0f39c4c4fe377d4cc63311ed13a89026b4cbd9bc..b725dc17a4328e31f4bde3d47c18a5b0d9562d16 100644
|
| --- a/android_webview/javatests/src/org/chromium/android_webview/test/crash/MinidumpUploaderTest.java
|
| +++ b/android_webview/javatests/src/org/chromium/android_webview/test/crash/MinidumpUploaderTest.java
|
| @@ -9,11 +9,14 @@ import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
|
| import android.content.Context;
|
| import android.os.ParcelFileDescriptor;
|
| import android.test.suitebuilder.annotation.MediumTest;
|
| +import android.webkit.ValueCallback;
|
|
|
| +import org.chromium.android_webview.UserConsentInterface;
|
| import org.chromium.android_webview.crash.CrashReceiverService;
|
| import org.chromium.android_webview.crash.MinidumpUploader;
|
| import org.chromium.android_webview.crash.MinidumpUploaderImpl;
|
| import org.chromium.base.FileUtils;
|
| +import org.chromium.base.ThreadUtils;
|
| import org.chromium.components.minidump_uploader.CrashFileManager;
|
| import org.chromium.components.minidump_uploader.CrashTestCase;
|
| import org.chromium.components.minidump_uploader.MinidumpUploadCallable;
|
| @@ -47,6 +50,27 @@ public class MinidumpUploaderTest extends CrashTestCase {
|
| return CrashReceiverService.createWebViewCrashDir(getInstrumentation().getTargetContext());
|
| }
|
|
|
| + private static class TestUserConsentImpl implements UserConsentInterface {
|
| + private boolean mAvailable;
|
| + private boolean mUserConsents;
|
| +
|
| + public TestUserConsentImpl(boolean available, boolean userConsents) {
|
| + mAvailable = available;
|
| + mUserConsents = userConsents;
|
| + }
|
| +
|
| + @Override
|
| + public boolean userConsentInterfaceAvailable() {
|
| + return mAvailable;
|
| + }
|
| +
|
| + @Override
|
| + public void userConsents(ValueCallback<Boolean> callback) {
|
| + ThreadUtils.assertOnUiThread();
|
| + callback.onReceiveValue(mUserConsents);
|
| + }
|
| + }
|
| +
|
| /**
|
| * Test to ensure the minidump uploading mechanism behaves as expected when we fail to upload
|
| * minidumps.
|
| @@ -65,7 +89,8 @@ public class MinidumpUploaderTest extends CrashTestCase {
|
| }
|
| };
|
| MinidumpUploader minidumpUploader = new MinidumpUploaderImpl(
|
| - getInstrumentation().getTargetContext(), false /* cleanOutMinidumps */) {
|
| + getInstrumentation().getTargetContext(), false /* cleanOutMinidumps */,
|
| + new TestUserConsentImpl(true /* available */, true /* userConsent */)) {
|
| @Override
|
| public MinidumpUploadCallable createMinidumpUploadCallable(
|
| File minidumpFile, File logfile) {
|
| @@ -132,7 +157,8 @@ public class MinidumpUploaderTest extends CrashTestCase {
|
| { mIsEnabledForTests = true; }
|
| };
|
| MinidumpUploader minidumpUploader = new MinidumpUploaderImpl(
|
| - getInstrumentation().getTargetContext(), false /* cleanOutMinidumps */) {
|
| + getInstrumentation().getTargetContext(), false /* cleanOutMinidumps */,
|
| + new TestUserConsentImpl(true /* available */, true /* userConsent */)) {
|
| @Override
|
| public MinidumpUploadCallable createMinidumpUploadCallable(
|
| File minidumpFile, File logfile) {
|
| @@ -162,7 +188,8 @@ public class MinidumpUploaderTest extends CrashTestCase {
|
|
|
| private static MinidumpUploaderImpl createCallableListMinidumpUploader(
|
| Context context, final List<MinidumpUploadCallableCreator> callables) {
|
| - return new MinidumpUploaderImpl(context, false /* cleanOutMinidumps */) {
|
| + return new MinidumpUploaderImpl(context, false /* cleanOutMinidumps */,
|
| + new TestUserConsentImpl(true /* available */, true /* userConsent */)) {
|
| private int mIndex = 0;
|
|
|
| @Override
|
| @@ -269,7 +296,8 @@ public class MinidumpUploaderTest extends CrashTestCase {
|
| { mIsEnabledForTests = true; }
|
| };
|
| MinidumpUploader minidumpUploader = new MinidumpUploaderImpl(
|
| - getInstrumentation().getTargetContext(), false /* cleanOutMinidumps */) {
|
| + getInstrumentation().getTargetContext(), false /* cleanOutMinidumps */,
|
| + new TestUserConsentImpl(true /* available */, true /* userConsent */)) {
|
| @Override
|
| public MinidumpUploadCallable createMinidumpUploadCallable(
|
| File minidumpFile, File logfile) {
|
| @@ -412,6 +440,81 @@ public class MinidumpUploaderTest extends CrashTestCase {
|
| }
|
|
|
| /**
|
| + * Ensures that we do not upload minidumps if the user consent interface (GmsCore) isn't
|
| + * available.
|
| + */
|
| + @MediumTest
|
| + public void testUserConsentInterfaceNotAvailable() throws IOException, InterruptedException {
|
| + testUserConsentLogic(UserConsentSetup.USER_CONSENT_INTERFACE_NOT_AVAILABLE);
|
| + }
|
| +
|
| + /**
|
| + * Ensures that we do not upload minidumps if we have no user consent.
|
| + */
|
| + @MediumTest
|
| + public void testNoUserConsent() throws IOException, InterruptedException {
|
| + testUserConsentLogic(UserConsentSetup.NO_USER_CONSENT);
|
| + }
|
| +
|
| + private static enum UserConsentSetup { USER_CONSENT_INTERFACE_NOT_AVAILABLE, NO_USER_CONSENT }
|
| +
|
| + private static UserConsentInterface createUserConsentInterface(UserConsentSetup consentSetup) {
|
| + switch (consentSetup) {
|
| + case USER_CONSENT_INTERFACE_NOT_AVAILABLE:
|
| + return new TestUserConsentImpl(false /* available */, true /* userConsent */);
|
| + case NO_USER_CONSENT:
|
| + return new TestUserConsentImpl(true /* available */, false /* userConsent */);
|
| + default:
|
| + fail();
|
| + return null;
|
| + }
|
| + }
|
| +
|
| + private void testUserConsentLogic(UserConsentSetup consentSetup)
|
| + throws IOException, InterruptedException {
|
| + MinidumpUploader minidumpUploader =
|
| + new MinidumpUploaderImpl(getInstrumentation().getTargetContext(),
|
| + false /* cleanOutMinidumps */, createUserConsentInterface(consentSetup)) {
|
| + @Override
|
| + public MinidumpUploadCallable createMinidumpUploadCallable(
|
| + File minidumpFile, File logfile) {
|
| + // Ensure that we crash if we try to upload a minidump.
|
| + return new UploadsDisallowedCallable(minidumpFile, logfile);
|
| + }
|
| + };
|
| +
|
| + File firstFile = createMinidumpFileInCrashDir("1_abc.dmp0");
|
| + File secondFile = createMinidumpFileInCrashDir("12_abcd.dmp0");
|
| +
|
| + final CountDownLatch uploadsFinishedLatch = new CountDownLatch(1);
|
| + minidumpUploader.uploadAllMinidumps(new MinidumpUploader.UploadsFinishedCallback() {
|
| + @Override
|
| + public void uploadsFinished(boolean reschedule) {
|
| + uploadsFinishedLatch.countDown();
|
| + }
|
| + });
|
| + assertTrue(
|
| + uploadsFinishedLatch.await(scaleTimeout(TIME_OUT_MILLIS), TimeUnit.MILLISECONDS));
|
| + // TODO what do we want to do to the minidumps if we have no user-consent?
|
| + assertTrue(firstFile.exists());
|
| + assertTrue(secondFile.exists());
|
| + }
|
| +
|
| + private static class UploadsDisallowedCallable extends MinidumpUploadCallable {
|
| + public UploadsDisallowedCallable(File fileToUpload, File logFile) {
|
| + super(fileToUpload, logFile, new MockCrashReportingPermissionManager() {
|
| + { mIsEnabledForTests = true; }
|
| + });
|
| + }
|
| +
|
| + @Override
|
| + public Integer call() {
|
| + fail();
|
| + return -1;
|
| + }
|
| + }
|
| +
|
| + /**
|
| * Copy and upload {@param minidumps} by one array at a time - i.e. the minidumps in a single
|
| * array in {@param minidumps} will all be copied in the same call into CrashReceiverService.
|
| * @param fileManager the CrashFileManager to use when copying/renaming minidumps.
|
| @@ -451,7 +554,8 @@ public class MinidumpUploaderTest extends CrashTestCase {
|
| { mIsEnabledForTests = true; }
|
| };
|
| MinidumpUploader minidumpUploader = new MinidumpUploaderImpl(
|
| - getInstrumentation().getTargetContext(), false /* cleanOutMinidumps */) {
|
| + getInstrumentation().getTargetContext(), false /* cleanOutMinidumps */,
|
| + new TestUserConsentImpl(true /* available */, true /* userConsent */)) {
|
| @Override
|
| public MinidumpUploadCallable createMinidumpUploadCallable(
|
| File minidumpFile, File logfile) {
|
|
|