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

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

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

Powered by Google App Engine
This is Rietveld 408576698