Index: android_webview/javatests/src/org/chromium/android_webview/test/crash/CrashReceiverServiceTest.java |
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/crash/CrashReceiverServiceTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/crash/CrashReceiverServiceTest.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..63f4048745fb2a21ef696a5c344e4e8a56cb275c |
--- /dev/null |
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/crash/CrashReceiverServiceTest.java |
@@ -0,0 +1,55 @@ |
+// 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.test.crash; |
+ |
+import android.content.Context; |
+import android.os.ParcelFileDescriptor; |
+import android.support.test.filters.MediumTest; |
+import android.test.InstrumentationTestCase; |
+ |
+import org.chromium.android_webview.crash.CrashReceiverService; |
+ |
+import java.io.File; |
+import java.io.FileNotFoundException; |
+import java.io.IOException; |
+ |
+/** |
+ * Instrumentation tests for CrashReceiverService. |
+ */ |
+public class CrashReceiverServiceTest extends InstrumentationTestCase { |
+ /** |
+ * Ensure that the minidump copying doesn't trigger when we pass it invalid file descriptors. |
+ */ |
+ @MediumTest |
+ public void testCopyingAbortsForInvalidFds() throws FileNotFoundException, IOException { |
+ assertFalse(CrashReceiverService.copyMinidumps( |
+ getInstrumentation().getTargetContext(), 0 /* uid */, null)); |
+ assertFalse(CrashReceiverService.copyMinidumps(getInstrumentation().getTargetContext(), |
+ 0 /* uid */, new ParcelFileDescriptor[] {null, null})); |
+ assertFalse(CrashReceiverService.copyMinidumps( |
+ getInstrumentation().getTargetContext(), 0 /* uid */, new ParcelFileDescriptor[0])); |
+ } |
+ |
+ /** |
+ * Ensure deleting temporary files used when copying minidumps works correctly. |
+ */ |
+ @MediumTest |
+ public void testDeleteFilesInDir() throws IOException { |
+ Context context = getInstrumentation().getTargetContext(); |
+ File webviewTmpDir = CrashReceiverService.getWebViewTmpCrashDir(context); |
+ if (!webviewTmpDir.isDirectory()) { |
+ assertTrue(webviewTmpDir.mkdir()); |
+ } |
+ File testFile1 = new File(webviewTmpDir, "testFile1"); |
+ File testFile2 = new File(webviewTmpDir, "testFile2"); |
+ assertTrue(testFile1.createNewFile()); |
+ assertTrue(testFile2.createNewFile()); |
+ assertTrue(testFile1.exists()); |
+ assertTrue(testFile2.exists()); |
+ CrashReceiverService.deleteFilesInWebViewTmpDirIfExists(context); |
+ assertFalse(testFile1.exists()); |
+ assertFalse(testFile2.exists()); |
+ } |
+} |