mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 938821 - Part 10: Remove reflection from ContentProviderTest. r=mcomella
This commit is contained in:
parent
0989610d5f
commit
3ea16e5ebd
@ -22,8 +22,10 @@ import android.test.mock.MockContext;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.mozilla.gecko.db.BrowserContract;
|
||||
import org.mozilla.gecko.db.BrowserProvider;
|
||||
|
||||
/*
|
||||
* ContentProviderTest provides the infrastructure to run content provider
|
||||
@ -47,10 +49,8 @@ import org.mozilla.gecko.db.BrowserContract;
|
||||
abstract class ContentProviderTest extends BaseTest {
|
||||
protected ContentProvider mProvider;
|
||||
protected ChangeRecordingMockContentResolver mResolver;
|
||||
protected ClassLoader mClassLoader;
|
||||
protected ArrayList<Runnable> mTests;
|
||||
protected String mDatabaseName;
|
||||
protected Class mProviderClass;
|
||||
protected String mProviderAuthority;
|
||||
protected IsolatedContext mProviderContext;
|
||||
|
||||
@ -171,7 +171,20 @@ abstract class ContentProviderTest extends BaseTest {
|
||||
}
|
||||
}
|
||||
|
||||
private void setUpContentProvider() throws Exception {
|
||||
/**
|
||||
* Factory function that makes new ContentProvider instances.
|
||||
* <p>
|
||||
* We want a fresh provider each test, so this should be invoked in
|
||||
* <code>setUp</code> before each individual test.
|
||||
*/
|
||||
protected static Callable<ContentProvider> sBrowserProviderCallable = new Callable<ContentProvider>() {
|
||||
@Override
|
||||
public ContentProvider call() {
|
||||
return new BrowserProvider();
|
||||
}
|
||||
};
|
||||
|
||||
private void setUpContentProvider(ContentProvider targetProvider) throws Exception {
|
||||
mResolver = new ChangeRecordingMockContentResolver();
|
||||
|
||||
final String filenamePrefix = this.getClass().getSimpleName() + ".";
|
||||
@ -183,7 +196,6 @@ abstract class ContentProviderTest extends BaseTest {
|
||||
|
||||
mProviderContext = new IsolatedContext(mResolver, targetContextWrapper);
|
||||
|
||||
ContentProvider targetProvider = (ContentProvider) mProviderClass.newInstance();
|
||||
targetProvider.attachInfo(mProviderContext, null);
|
||||
|
||||
mProvider = new DelegatingTestContentProvider(targetProvider);
|
||||
@ -202,21 +214,18 @@ abstract class ContentProviderTest extends BaseTest {
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
throw new Exception("You should call setUp(providerClassName, authorityUriField, databaseName) instead");
|
||||
throw new UnsupportedOperationException("You should call setUp(authority, databaseName) instead");
|
||||
}
|
||||
|
||||
// TODO: Take the actual class as an arg.
|
||||
public void setUp(String providerClassName, String authority, String databaseName) throws Exception {
|
||||
public void setUp(Callable<ContentProvider> contentProviderFactory, String authority, String databaseName) throws Exception {
|
||||
super.setUp();
|
||||
|
||||
mClassLoader = getInstrumentation().getContext().getClassLoader();
|
||||
mTests = new ArrayList<Runnable>();
|
||||
mDatabaseName = databaseName;
|
||||
|
||||
mProviderAuthority = authority;
|
||||
mProviderClass = mClassLoader.loadClass(providerClassName);
|
||||
|
||||
setUpContentProvider();
|
||||
setUpContentProvider(contentProviderFactory.call());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -202,7 +202,7 @@ public class testBrowserProvider extends ContentProviderTest {
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp("org.mozilla.gecko.db.BrowserProvider", BrowserContract.AUTHORITY, "browser.db");
|
||||
super.setUp(sBrowserProviderCallable, BrowserContract.AUTHORITY, "browser.db");
|
||||
|
||||
mTests.add(new TestSpecialFolders());
|
||||
|
||||
|
@ -10,6 +10,7 @@ import java.util.Random;
|
||||
import org.mozilla.gecko.GeckoProfile;
|
||||
import org.mozilla.gecko.db.BrowserContract;
|
||||
import org.mozilla.gecko.db.BrowserDB;
|
||||
import org.mozilla.gecko.db.BrowserProvider;
|
||||
|
||||
/*
|
||||
* This test is meant to exercise the performance of Fennec's
|
||||
@ -182,7 +183,7 @@ public class testBrowserProviderPerf extends ContentProviderTest {
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp("org.mozilla.gecko.db.BrowserProvider", BrowserContract.AUTHORITY, "browser.db");
|
||||
super.setUp(sBrowserProviderCallable, BrowserContract.AUTHORITY, "browser.db");
|
||||
|
||||
mGenerator = new Random(19580427);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package org.mozilla.gecko.tests;
|
||||
|
||||
import org.mozilla.gecko.*;
|
||||
import org.mozilla.gecko.db.BrowserContract;
|
||||
import org.mozilla.gecko.db.BrowserProvider;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
|
||||
import android.app.Activity;
|
||||
@ -304,7 +305,7 @@ public class testDistribution extends ContentProviderTest {
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
// TODO: Set up the content provider after setting the distribution.
|
||||
super.setUp("org.mozilla.gecko.db.BrowserProvider", BrowserContract.AUTHORITY, "browser.db");
|
||||
super.setUp(sBrowserProviderCallable, BrowserContract.AUTHORITY, "browser.db");
|
||||
}
|
||||
|
||||
private void delete(File file) throws Exception {
|
||||
|
Loading…
Reference in New Issue
Block a user