summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2011-08-09 10:54:46 -0700
committerJohn Reck <jreck@google.com>2011-08-09 10:54:46 -0700
commitdb78cd054b0344e67a18dc9e1d1a154d3814dc77 (patch)
tree415c8d6cac5c34e5a68c9bf26e1526bcf93ab2f1
parente28b347fcc1df6e6bd41cb294d521a4f1e7c5c75 (diff)
downloadpackages_apps_Browser-db78cd054b0344e67a18dc9e1d1a154d3814dc77.zip
packages_apps_Browser-db78cd054b0344e67a18dc9e1d1a154d3814dc77.tar.gz
packages_apps_Browser-db78cd054b0344e67a18dc9e1d1a154d3814dc77.tar.bz2
Tests fixup
Bug: 5113381 Fix case of using the wrong context (BP1 would use the app context explicitly, bypassing the mock context) Clean up test databases after runs Change-Id: Ibac09d08d4ab7235d5763c209d84be2562e6fae3
-rw-r--r--src/com/android/browser/provider/BrowserProvider.java2
-rw-r--r--tests/src/com/android/browser/tests/utils/BP2TestCaseHelper.java21
-rw-r--r--tests/src/com/android/browser/tests/utils/ProviderTestCase3.java5
3 files changed, 25 insertions, 3 deletions
diff --git a/src/com/android/browser/provider/BrowserProvider.java b/src/com/android/browser/provider/BrowserProvider.java
index fabf57e..b55b84a 100644
--- a/src/com/android/browser/provider/BrowserProvider.java
+++ b/src/com/android/browser/provider/BrowserProvider.java
@@ -251,7 +251,7 @@ public class BrowserProvider extends ContentProvider {
public DatabaseHelper(Context context) {
super(context, sDatabaseName, null, DATABASE_VERSION);
- mContext = context.getApplicationContext();
+ mContext = context;
}
@Override
diff --git a/tests/src/com/android/browser/tests/utils/BP2TestCaseHelper.java b/tests/src/com/android/browser/tests/utils/BP2TestCaseHelper.java
index 18c1c10..e341c6a 100644
--- a/tests/src/com/android/browser/tests/utils/BP2TestCaseHelper.java
+++ b/tests/src/com/android/browser/tests/utils/BP2TestCaseHelper.java
@@ -18,6 +18,9 @@ package com.android.browser.tests.utils;
import com.android.browser.provider.BrowserProvider2;
+import java.io.File;
+import java.io.FilenameFilter;
+
import android.content.ContentValues;
import android.database.ContentObserver;
import android.net.Uri;
@@ -208,4 +211,22 @@ public abstract class BP2TestCaseHelper extends ProviderTestCase3<BrowserProvide
perfIdeallyUntriggered(mBookmarksObserver, mWidgetObserver);
return updated;
}
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ // Delete the test databases so that subsequent runs have a clean slate
+ File f = getMockContext().getDatabasePath("test");
+ File dir = f.getParentFile();
+ File testFiles[] = dir.listFiles(new FilenameFilter() {
+
+ @Override
+ public boolean accept(File dir, String filename) {
+ return filename.startsWith(ProviderTestCase3.FILENAME_PREFIX);
+ }
+ });
+ for (File testFile : testFiles) {
+ testFile.delete();
+ }
+ }
}
diff --git a/tests/src/com/android/browser/tests/utils/ProviderTestCase3.java b/tests/src/com/android/browser/tests/utils/ProviderTestCase3.java
index 536163a..75bc052 100644
--- a/tests/src/com/android/browser/tests/utils/ProviderTestCase3.java
+++ b/tests/src/com/android/browser/tests/utils/ProviderTestCase3.java
@@ -35,6 +35,8 @@ import java.io.File;
*/
public abstract class ProviderTestCase3<T extends ContentProvider> extends AndroidTestCase {
+ public static final String FILENAME_PREFIX = "test.";
+
Class<T> mProviderClass;
String[] mProviderAuthority;
@@ -112,13 +114,12 @@ public abstract class ProviderTestCase3<T extends ContentProvider> extends Andro
super.setUp();
mResolver = new MockContentResolver2();
- final String filenamePrefix = "test.";
RenamingDelegatingContext targetContextWrapper = new
RenamingDelegatingContext(
new MockContext2(), // The context that most methods are
//delegated to
getContext(), // The context that file methods are delegated to
- filenamePrefix);
+ FILENAME_PREFIX);
// The default IsolatedContext has a mock AccountManager that doesn't
// work for us, so override getSystemService to always return null
mProviderContext = new IsolatedContext(mResolver, targetContextWrapper) {