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

Side by Side Diff: components/minidump_uploader/android/javatests/src/org/chromium/components/minidump_uploader/CrashTestCase.java

Issue 2800833003: Revert of Android: Remove GetApplicationContext part 2 (Closed)
Patch Set: Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.components.minidump_uploader; 5 package org.chromium.components.minidump_uploader;
6 6
7 import android.test.InstrumentationTestCase; 7 import android.test.InstrumentationTestCase;
8 8
9 import org.chromium.base.ContextUtils;
10 import org.chromium.base.Log; 9 import org.chromium.base.Log;
11 import org.chromium.components.minidump_uploader.util.CrashReportingPermissionMa nager; 10 import org.chromium.components.minidump_uploader.util.CrashReportingPermissionMa nager;
12 11
13 import java.io.File; 12 import java.io.File;
14 import java.io.FileWriter; 13 import java.io.FileWriter;
15 import java.io.IOException; 14 import java.io.IOException;
16 import java.io.PrintWriter; 15 import java.io.PrintWriter;
17 16
18 /** 17 /**
19 * Base case for Crash upload related tests. 18 * Base case for Crash upload related tests.
20 */ 19 */
21 public class CrashTestCase extends InstrumentationTestCase { 20 public class CrashTestCase extends InstrumentationTestCase {
22 private static final String TAG = "CrashTestCase"; 21 private static final String TAG = "CrashTestCase";
23 22
24 protected File mCrashDir; 23 protected File mCrashDir;
25 protected File mCacheDir; 24 protected File mCacheDir;
26 25
27 @Override 26 @Override
28 protected void setUp() throws Exception { 27 protected void setUp() throws Exception {
29 super.setUp(); 28 super.setUp();
30 ContextUtils.initApplicationContextForTests(
31 getInstrumentation().getTargetContext().getApplicationContext()) ;
32 mCacheDir = getExistingCacheDir(); 29 mCacheDir = getExistingCacheDir();
33 mCrashDir = new File( 30 mCrashDir = new File(
34 mCacheDir, 31 mCacheDir,
35 CrashFileManager.CRASH_DUMP_DIR); 32 CrashFileManager.CRASH_DUMP_DIR);
36 if (!mCrashDir.isDirectory() && !mCrashDir.mkdir()) { 33 if (!mCrashDir.isDirectory() && !mCrashDir.mkdir()) {
37 throw new Exception("Unable to create directory: " + mCrashDir.getAb solutePath()); 34 throw new Exception("Unable to create directory: " + mCrashDir.getAb solutePath());
38 } 35 }
39 } 36 }
40 37
41 /** 38 /**
42 * Returns the cache directory where we should store minidumps. 39 * Returns the cache directory where we should store minidumps.
43 * Can be overriden by sub-classes to allow for use with different cache dir ectories. 40 * Can be overriden by sub-classes to allow for use with different cache dir ectories.
44 */ 41 */
45 protected File getExistingCacheDir() { 42 protected File getExistingCacheDir() {
46 return ContextUtils.getApplicationContext().getCacheDir(); 43 return getInstrumentation().getTargetContext().getCacheDir();
47 } 44 }
48 45
49 @Override 46 @Override
50 protected void tearDown() throws Exception { 47 protected void tearDown() throws Exception {
51 super.tearDown(); 48 super.tearDown();
52 File[] crashFiles = mCrashDir.listFiles(); 49 File[] crashFiles = mCrashDir.listFiles();
53 if (crashFiles == null) { 50 if (crashFiles == null) {
54 return; 51 return;
55 } 52 }
56 53
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 public boolean isUsageAndCrashReportingPermittedByUser() { 119 public boolean isUsageAndCrashReportingPermittedByUser() {
123 return mIsUserPermitted; 120 return mIsUserPermitted;
124 } 121 }
125 122
126 @Override 123 @Override
127 public boolean isUploadEnabledForTests() { 124 public boolean isUploadEnabledForTests() {
128 return mIsEnabledForTests; 125 return mIsEnabledForTests;
129 } 126 }
130 } 127 }
131 } 128 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698