Bug 1171566 - Part 2: Remove BrowserTestCase. rs=mcomella

This was just a remnant from earlier days.  This launched the Fennec
activity, which is absolutely *not* something we want to do during
these browser JUnit 3 tests.  That is, these should be pure
instrumentation tests that just run Java code in the correct package
and Java classloader context.  They shouldn't interact with the App
lifecycle at all.

Not all the tests pass; I took a shot at fixing one but don't care to
dig deeply right now.

--HG--
extra : rebase_source : cc512347c2adfb5cd59f641893ed8a8edaf5ba94
extra : histedit_source : 4c14f269054ad98e0fbcb9eb6595247f285058df
This commit is contained in:
Nick Alexander 2015-06-04 10:41:48 -07:00
Родитель 3f6c59b27c
Коммит 2b5fe7b1a4
13 изменённых файлов: 92 добавлений и 139 удалений

Просмотреть файл

@ -8,7 +8,6 @@ DEFINES['ANDROID_PACKAGE_NAME'] = CONFIG['ANDROID_PACKAGE_NAME']
jar = add_java_jar('browser-junit3')
jar.sources += [
'src/org/mozilla/tests/browser/junit3/BrowserTestCase.java',
'src/org/mozilla/tests/browser/junit3/harness/BrowserInstrumentationTestRunner.java',
'src/org/mozilla/tests/browser/junit3/harness/BrowserTestListener.java',
'src/org/mozilla/tests/browser/junit3/TestDistribution.java',

Просмотреть файл

@ -1,48 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
package org.mozilla.tests.browser.junit3;
import org.mozilla.gecko.AppConstants;
import android.app.Activity;
import android.content.Context;
import android.test.ActivityInstrumentationTestCase2;
/**
* BrowserTestCase provides helper methods for testing.
*/
@SuppressWarnings("unchecked")
public class BrowserTestCase extends ActivityInstrumentationTestCase2<Activity> {
@SuppressWarnings("unused")
private static String LOG_TAG = "BrowserTestCase";
/**
* The Java Class instance that launches the browser.
* <p>
* This should always agree with {@link AppConstants#MOZ_ANDROID_BROWSER_INTENT_CLASS}.
*/
public static final Class<? extends Activity> BROWSER_INTENT_CLASS;
// Use reflection here so we don't have to either (a) preprocess this
// file, or (b) get access to Robocop's TestConstants class from these
// instrumentation tests.
static {
Class<? extends Activity> cl;
try {
cl = (Class<? extends Activity>) Class.forName(AppConstants.MOZ_ANDROID_BROWSER_INTENT_CLASS);
} catch (ClassNotFoundException e) {
// Oh well.
cl = Activity.class;
}
BROWSER_INTENT_CLASS = cl;
}
public BrowserTestCase() {
super((Class<Activity>) BROWSER_INTENT_CLASS);
}
public Context getApplicationContext() {
return this.getInstrumentation().getTargetContext().getApplicationContext();
}
}

Просмотреть файл

@ -4,9 +4,10 @@
package org.mozilla.tests.browser.junit3;
import android.test.InstrumentationTestCase;
import org.mozilla.gecko.distribution.ReferrerDescriptor;
public class TestDistribution extends BrowserTestCase {
public class TestDistribution extends InstrumentationTestCase {
private static final String TEST_REFERRER_STRING = "utm_source=campsource&utm_medium=campmed&utm_term=term%2Bhere&utm_content=content&utm_campaign=name";
private static final String TEST_MALFORMED_REFERRER_STRING = "utm_source=campsource&utm_medium=campmed&utm_term=term%2";

Просмотреть файл

@ -4,9 +4,10 @@
package org.mozilla.tests.browser.junit3;
import android.test.InstrumentationTestCase;
import org.mozilla.gecko.util.ThreadUtils;
public class TestGeckoBackgroundThread extends BrowserTestCase {
public class TestGeckoBackgroundThread extends InstrumentationTestCase {
private boolean finishedTest;
private boolean ranFirstRunnable;

Просмотреть файл

@ -4,11 +4,12 @@
package org.mozilla.tests.browser.junit3;
import android.test.InstrumentationTestCase;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.menu.GeckoMenu;
import org.mozilla.gecko.util.ThreadUtils;
public class TestGeckoMenu extends BrowserTestCase {
public class TestGeckoMenu extends InstrumentationTestCase {
private volatile Exception exception;
private void setException(Exception e) {
@ -16,7 +17,7 @@ public class TestGeckoMenu extends BrowserTestCase {
}
public void testMenuThreading() throws InterruptedException {
final GeckoMenu menu = new GeckoMenu(getActivity());
final GeckoMenu menu = new GeckoMenu(getInstrumentation().getTargetContext());
final Object semaphore = new Object();
ThreadUtils.postToUiThread(new Runnable() {

Просмотреть файл

@ -4,25 +4,25 @@
package org.mozilla.tests.browser.junit3;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import org.mozilla.gecko.db.BrowserContract;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.os.RemoteException;
import android.test.InstrumentationTestCase;
import org.mozilla.gecko.db.BrowserContract;
public class TestGeckoProfilesProvider extends BrowserTestCase {
import java.io.File;
import java.util.HashMap;
import java.util.Map;
public class TestGeckoProfilesProvider extends InstrumentationTestCase {
private static final String[] NAME_AND_PATH = new String[] { BrowserContract.Profiles.NAME, BrowserContract.Profiles.PATH };
/**
* Ensure that the default profile is found in the results from the provider.
*/
public void testQueryDefault() throws RemoteException {
final ContentResolver contentResolver = getActivity().getContentResolver();
final ContentResolver contentResolver = getInstrumentation().getContext().getContentResolver();
final Uri uri = BrowserContract.PROFILES_AUTHORITY_URI.buildUpon().appendPath("profiles").build();
final Cursor c = contentResolver.query(uri, NAME_AND_PATH, null, null, null);
assertNotNull(c);

Просмотреть файл

@ -3,26 +3,26 @@
package org.mozilla.tests.browser.junit3;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
import android.test.InstrumentationTestCase;
import android.test.RenamingDelegatingContext;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.GeckoSharedPrefs;
import org.mozilla.gecko.GeckoSharedPrefs.Flags;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.GeckoSharedPrefs;
import org.mozilla.gecko.GeckoSharedPrefs.Flags;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
import android.test.RenamingDelegatingContext;
/**
* Test GeckoSharedPrefs migrations.
*/
public class TestGeckoSharedPrefs extends BrowserTestCase {
public class TestGeckoSharedPrefs extends InstrumentationTestCase {
private static class TestContext extends RenamingDelegatingContext {
private static final String PREFIX = "TestGeckoSharedPrefs-";
@ -54,7 +54,7 @@ public class TestGeckoSharedPrefs extends BrowserTestCase {
private TestContext context;
protected void setUp() {
context = new TestContext(getApplicationContext());
context = new TestContext(getInstrumentation().getTargetContext());
}
protected void tearDown() {

Просмотреть файл

@ -4,12 +4,15 @@
package org.mozilla.tests.browser.junit3;
import android.content.Context;
import android.content.res.Resources;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.net.Uri;
import android.test.mock.MockResources;
import android.test.InstrumentationTestCase;
import android.test.RenamingDelegatingContext;
import android.test.mock.MockResources;
import android.util.DisplayMetrics;
import org.mozilla.gecko.distribution.Distribution;
import org.mozilla.gecko.home.ImageLoader.ImageDownloader;
import java.io.File;
import java.io.IOException;
@ -19,10 +22,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.mozilla.gecko.distribution.Distribution;
import org.mozilla.gecko.home.ImageLoader.ImageDownloader;
public class TestImageDownloader extends BrowserTestCase {
public class TestImageDownloader extends InstrumentationTestCase {
private static class TestContext extends RenamingDelegatingContext {
private static final String PREFIX = "TestImageDownloader-";
@ -104,7 +104,7 @@ public class TestImageDownloader extends BrowserTestCase {
private ImageDownloader downloader;
protected void setUp() {
context = new TestContext(getApplicationContext());
context = new TestContext(getInstrumentation().getTargetContext());
resources = (TestResources) context.getResources();
distribution = new TestDistribution(context);
downloader = new ImageDownloader(context, distribution);

Просмотреть файл

@ -5,6 +5,7 @@ package org.mozilla.tests.browser.junit3;
import java.io.InputStream;
import android.test.InstrumentationTestCase;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.util.GeckoJarReader;
@ -12,9 +13,9 @@ import org.mozilla.gecko.util.GeckoJarReader;
* A basic jar reader test. Tests reading a png from fennec's apk, as well as
* loading some invalid jar urls.
*/
public class TestJarReader extends BrowserTestCase {
public class TestJarReader extends InstrumentationTestCase {
public void testJarReader() {
String appPath = getActivity().getApplication().getPackageResourcePath();
String appPath = getInstrumentation().getTargetContext().getPackageResourcePath();
assertNotNull(appPath);
// Test reading a file from a jar url that looks correct.

Просмотреть файл

@ -3,22 +3,22 @@
package org.mozilla.tests.browser.junit3;
import android.content.Context;
import android.content.res.Resources;
import android.test.InstrumentationTestCase;
import android.test.mock.MockContext;
import android.test.mock.MockResources;
import org.mozilla.gecko.util.RawResource;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.mozilla.gecko.util.RawResource;
import android.content.Context;
import android.content.res.Resources;
import android.test.mock.MockContext;
import android.test.mock.MockResources;
/**
* Tests whether RawResource.getAsString() produces the right String
* result after reading the returned raw resource's InputStream.
*/
public class TestRawResource extends BrowserTestCase {
public class TestRawResource extends InstrumentationTestCase {
private static final int RAW_RESOURCE_ID = 1;
private static final String RAW_CONTENTS = "RAW";

Просмотреть файл

@ -3,6 +3,27 @@
package org.mozilla.tests.browser.junit3;
import android.content.ContentResolver;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.database.Cursor;
import android.net.Uri;
import android.os.SystemClock;
import android.test.InstrumentationTestCase;
import android.test.RenamingDelegatingContext;
import android.test.mock.MockResources;
import org.json.JSONArray;
import org.json.JSONObject;
import org.mozilla.gecko.R;
import org.mozilla.gecko.GeckoSharedPrefs;
import org.mozilla.gecko.Locales;
import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.db.SuggestedSites;
import org.mozilla.gecko.distribution.Distribution;
import org.mozilla.gecko.preferences.GeckoPreferences;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
@ -16,29 +37,10 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.json.JSONArray;
import org.json.JSONObject;
import org.mozilla.gecko.R;
import org.mozilla.gecko.GeckoSharedPrefs;
import org.mozilla.gecko.Locales;
import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.db.SuggestedSites;
import org.mozilla.gecko.distribution.Distribution;
import org.mozilla.gecko.preferences.GeckoPreferences;
import android.content.ContentResolver;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.database.Cursor;
import android.net.Uri;
import android.os.SystemClock;
import android.test.RenamingDelegatingContext;
import android.test.mock.MockResources;
public class TestSuggestedSites extends BrowserTestCase {
public class TestSuggestedSites extends InstrumentationTestCase {
private static class TestContext extends RenamingDelegatingContext {
private static final String PREFIX = "TestSuggestedSites-";
@ -122,18 +124,16 @@ public class TestSuggestedSites extends BrowserTestCase {
}
class TestObserver extends ContentObserver {
private final Object changeLock;
private final CountDownLatch changeLatch;
public TestObserver(Object changeLock) {
public TestObserver(CountDownLatch changeLatch) {
super(null);
this.changeLock = changeLock;
this.changeLatch = changeLatch;
}
@Override
public void onChange(boolean selfChange) {
synchronized(changeLock) {
changeLock.notifyAll();
}
changeLatch.countDown();
}
}
@ -214,7 +214,7 @@ public class TestSuggestedSites extends BrowserTestCase {
}
protected void setUp() {
context = new TestContext(getApplicationContext());
context = new TestContext(getInstrumentation().getTargetContext());
resources = (TestResources) context.getResources();
tempFiles = new ArrayList<File>();
}
@ -452,6 +452,14 @@ public class TestSuggestedSites extends BrowserTestCase {
tempFiles.add(distFile);
assertTrue(distFile.exists());
final CountDownLatch changeLatch = new CountDownLatch(1);
// Watch for change notifications on suggested sites.
ContentResolver cr = context.getContentResolver();
ContentObserver observer = new TestObserver(changeLatch);
cr.registerContentObserver(BrowserContract.SuggestedSites.CONTENT_URI,
false, observer);
// Init distribution with the mock file.
TestDistribution distribution = new TestDistribution(context);
distribution.setFileForLocale(Locale.getDefault(), distFile);
@ -462,14 +470,6 @@ public class TestSuggestedSites extends BrowserTestCase {
SuggestedSites suggestedSites =
new SuggestedSites(context, distribution, sitesFile);
Object changeLock = new Object();
// Watch for change notifications on suggested sites.
ContentResolver cr = context.getContentResolver();
ContentObserver observer = new TestObserver(changeLock);
cr.registerContentObserver(BrowserContract.SuggestedSites.CONTENT_URI,
false, observer);
// The initial query will not contain the distribution sites
// yet. This will happen asynchronously once the distribution
// is installed.
@ -483,12 +483,10 @@ public class TestSuggestedSites extends BrowserTestCase {
}
}
synchronized(changeLock) {
try {
changeLock.wait(5000);
} catch (InterruptedException ie) {
fail("No change notification after fetching distribution file");
}
try {
assertTrue(changeLatch.await(5, TimeUnit.SECONDS));
} catch (InterruptedException ie) {
fail("No change notification after fetching distribution file");
}
// Target file should exist after distribution is deployed.

Просмотреть файл

@ -6,18 +6,18 @@ package org.mozilla.tests.browser.junit3;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.database.MatrixCursor.RowBuilder;
import android.test.InstrumentationTestCase;
import android.text.TextUtils;
import java.util.Arrays;
import java.util.List;
import org.mozilla.gecko.db.BrowserContract.Bookmarks;
import org.mozilla.gecko.db.BrowserContract.Combined;
import org.mozilla.gecko.db.BrowserContract.SuggestedSites;
import org.mozilla.gecko.db.BrowserContract.TopSites;
import org.mozilla.gecko.db.TopSitesCursorWrapper;
public class TestTopSitesCursorWrapper extends BrowserTestCase {
import java.util.Arrays;
import java.util.List;
public class TestTopSitesCursorWrapper extends InstrumentationTestCase {
private String[] TOP_SITES_COLUMNS = new String[] { Combined._ID,
Combined.URL,

Просмотреть файл

@ -3,10 +3,10 @@
package org.mozilla.tests.browser.junit3.harness;
import android.util.Log;
import junit.framework.AssertionFailedError;
import junit.framework.Test;
import junit.framework.TestListener;
import android.util.Log;
/**
* BrowserTestListener turns JUnit 3 test events into log messages in the format