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

Unified Diff: android_webview/junit/src/org/chromium/android_webview/crash/CrashReceiverServiceUnitTest.java

Issue 2628863004: [Android WebView] Ensure we have user consent before uploading minidumps (Closed)
Patch Set: Check user consent before copying minidumps, delete minidumps in app dir if no consent, add unit te… Created 3 years, 11 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/junit/src/org/chromium/android_webview/crash/CrashReceiverServiceUnitTest.java
diff --git a/android_webview/junit/src/org/chromium/android_webview/crash/CrashReceiverServiceUnitTest.java b/android_webview/junit/src/org/chromium/android_webview/crash/CrashReceiverServiceUnitTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..3e74bee92c5a95fc0521d69b52e12a9001d66b56
--- /dev/null
+++ b/android_webview/junit/src/org/chromium/android_webview/crash/CrashReceiverServiceUnitTest.java
@@ -0,0 +1,108 @@
+// Copyright 2017 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.crash;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.webkit.ValueCallback;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.Robolectric;
+import org.robolectric.annotation.Config;
+import org.robolectric.util.ServiceController;
+
+import org.chromium.android_webview.PlatformServiceBridge;
+import org.chromium.android_webview.command_line.CommandLineUtil;
+import org.chromium.testing.local.LocalRobolectricTestRunner;
+
+/** Unit tests for {@link CrashReceiverServiceUnit}. */
+@RunWith(LocalRobolectricTestRunner.class)
+@Config(manifest = Config.NONE)
+public class CrashReceiverServiceUnitTest {
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private Context mContext;
+
+ private CrashReceiverService mCrashReceiverService;
+
+ @Mock
+ SynchronizedWebViewCommandLine mWebViewCommandLine;
+
+ @Mock
+ PlatformServiceBridge mPlatformServiceBridge;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ ServiceController<CrashReceiverService> controller =
+ Robolectric.buildService(CrashReceiverService.class);
+ mCrashReceiverService = spy(controller.get());
+ }
+
+ private static enum UserConsentSetup {
+ USER_CONSENT_INTERFACE_NOT_AVAILABLE,
+ NO_USER_CONSENT,
+ USER_CONSENT_OK
+ }
+
+ @Test
+ public void testCrashCopyingEnabledForTesting() {
+ ensureCrashCopyingEnabledCorrectly(
+ true, UserConsentSetup.USER_CONSENT_INTERFACE_NOT_AVAILABLE, true);
+ }
+
+ @Test
+ public void testCrashCopyingEnabledIfUserConsent() {
+ ensureCrashCopyingEnabledCorrectly(false, UserConsentSetup.USER_CONSENT_OK, true);
+ }
+
+ @Test
+ public void testCrashCopyingDisabledCorrectly() {
+ ensureCrashCopyingEnabledCorrectly(false, UserConsentSetup.NO_USER_CONSENT, false);
+ }
+
+ private static class TestPlatformServiceBridge extends PlatformServiceBridge {
+ private boolean mCanUseGms;
+ private boolean mUserConsent;
+
+ TestPlatformServiceBridge(boolean canUseGms, boolean userConsent) {
+ mCanUseGms = canUseGms;
+ mUserConsent = userConsent;
+ }
+
+ @Override
+ public boolean canUseGms() {
+ return mCanUseGms;
+ }
+
+ @Override
+ public void queryMetricsSetting(ValueCallback<Boolean> callback) {
+ callback.onReceiveValue(mUserConsent);
+ }
+ }
+
+ private void ensureCrashCopyingEnabledCorrectly(
+ boolean enabledForTesting, UserConsentSetup userConsentSetup, boolean expectEnabled) {
+ when(mWebViewCommandLine.hasSwitch(
+ eq(CommandLineUtil.CRASH_UPLOADS_ENABLED_FOR_TESTING_SWITCH)))
+ .thenReturn(enabledForTesting);
+ when(mCrashReceiverService.getSynchronizedWebViewCommandLine())
+ .thenReturn(mWebViewCommandLine);
+ when(mCrashReceiverService.getPlaformServiceBridge())
+ .thenReturn(new TestPlatformServiceBridge(
+ userConsentSetup != UserConsentSetup.USER_CONSENT_INTERFACE_NOT_AVAILABLE,
+ userConsentSetup == UserConsentSetup.USER_CONSENT_OK));
+ mCrashReceiverService.onCreate();
+ assertEquals(expectEnabled, mCrashReceiverService.isCrashCopyingEnabled());
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698