Bug 758392 - Create abstract getTestType() method in BaseTest. r=gbrown

This commit is contained in:
Brian Nicholson 2012-06-27 16:56:49 -07:00
parent 6925f4bb94
commit 4d2d69ae8f
27 changed files with 141 additions and 44 deletions

View File

@ -22,6 +22,9 @@ import java.util.HashMap;
* A convenient base class suitable for most Robocop tests.
*/
abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
public static final int TEST_MOCHITEST = 0;
public static final int TEST_TALOS = 1;
private static final String TARGET_PACKAGE_ID = "org.mozilla.gecko";
private static final String LAUNCH_ACTIVITY_FULL_CLASSNAME="@ANDROID_PACKAGE_NAME@.App";
@ -33,7 +36,6 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
protected Actions mActions;
protected String mBaseUrl;
protected String mRawBaseUrl;
private String mTestType;
private String mLogFile;
protected String mProfile;
@ -49,6 +51,8 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
super(TARGET_PACKAGE_ID, mLauncherActivityClass);
}
protected abstract int getTestType();
@Override
protected void setUp() throws Exception {
// Load config file from sdcard (setup by python script)
@ -72,6 +76,15 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
mLogFile = (String)config.get("logfile");
mBaseUrl = ((String)config.get("host")).replaceAll("(/$)", "");
mRawBaseUrl = ((String)config.get("rawhost")).replaceAll("(/$)", "");
// Initialize the asserter
if (getTestType() == TEST_TALOS) {
mAsserter = new FennecTalosAssert();
} else {
mAsserter = new FennecMochitestAssert();
}
mAsserter.setLogFile(mLogFile);
mAsserter.setTestName(this.getClass().getName());
}
@Override
@ -88,18 +101,6 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
}
}
public void setTestType(String type) {
mTestType = type;
if (mTestType.equals("talos")) {
mAsserter = new FennecTalosAssert();
} else {
mAsserter = new FennecMochitestAssert();
}
mAsserter.setLogFile(mLogFile);
mAsserter.setTestName(this.getClass().getName());
}
@Override
public void tearDown() throws Exception {
try {

View File

@ -3,7 +3,7 @@ package @ANDROID_PACKAGE_NAME@.tests;
import @ANDROID_PACKAGE_NAME@.*;
class PixelTest extends BaseTest {
abstract class PixelTest extends BaseTest {
private static final long PAINT_CLEAR_DELAY = 1000; // milliseconds
protected final PaintedSurface loadAndPaint(String url) {

View File

@ -6,8 +6,12 @@ import android.app.Activity;
import android.util.Log;
public class testAboutPage extends BaseTest {
@Override
protected int getTestType() {
return TEST_MOCHITEST;
}
public void testAboutPage() {
setTestType("mochitest");
mActions.expectGeckoEvent("Gecko:Ready").blockForEvent();
// Load the about: page

View File

@ -4,9 +4,12 @@ package @ANDROID_PACKAGE_NAME@.tests;
import @ANDROID_PACKAGE_NAME@.*;
public class testAwesomebar extends BaseTest {
public void testAwesomebar() {
setTestType("mochitest");
@Override
protected int getTestType() {
return TEST_MOCHITEST;
}
public void testAwesomebar() {
mActions.expectGeckoEvent("Gecko:Ready").blockForEvent();
String url = getAbsoluteUrl("/robocop/robocop_blank_01.html");

View File

@ -13,8 +13,12 @@ import android.app.Instrumentation;
* - Verify that the 45-degree angle was not thrown out and it dragged diagonally
*/
public class testAxisLocking extends PixelTest {
@Override
protected int getTestType() {
return TEST_MOCHITEST;
}
public void testAxisLocking() {
setTestType("mochitest");
String url = getAbsoluteUrl("/robocop/robocop_boxes.html");
MotionEventHelper meh = new MotionEventHelper(getInstrumentation(), mDriver.getGeckoLeft(), mDriver.getGeckoTop());

View File

@ -30,8 +30,12 @@ public class testBookmark extends BaseTest {
"https://addons.mozilla.org/en-US/android/"
};
@Override
protected int getTestType() {
return TEST_MOCHITEST;
}
public void testBookmark() {
setTestType("mochitest");
BOOKMARK_URL = getAbsoluteUrl(BOOKMARK_URL);
mClassLoader = getActivity().getApplicationContext().getClassLoader();

View File

@ -10,13 +10,17 @@ import android.net.Uri;
import android.provider.Browser;
public class testBookmarklets extends BaseTest {
@Override
protected int getTestType() {
return TEST_MOCHITEST;
}
public void testBookmarklets() {
final String url = getAbsoluteUrl("/robocop/robocop_blank_01.html");
final String title = "alertBookmarklet";
final String js = "javascript:alert(12 + .34)";
boolean alerted;
setTestType("mochitest");
mActions.expectGeckoEvent("Gecko:Ready").blockForEvent();
// load a standard page so bookmarklets work

View File

@ -88,6 +88,11 @@ public class testBrowserProvider extends ContentProviderTest {
private int mCombinedDisplayNormal;
private int mCombinedDisplayReader;
@Override
protected int getTestType() {
return TEST_MOCHITEST;
}
private void loadContractInfo() throws Exception {
mBookmarksUri = getContentUri("Bookmarks");
mHistoryUri = getContentUri("History");
@ -320,8 +325,6 @@ public class testBrowserProvider extends ContentProviderTest {
}
public void testBrowserProvider() throws Exception {
setTestType("mochitest");
loadMobileFolderId();
for (int i = 0; i < mTests.size(); i++) {

View File

@ -58,6 +58,11 @@ public class testBrowserProviderPerf extends ContentProviderTest {
private String mHistoryThumbnailCol;
private String mHistoryLastVisitedCol;
@Override
protected int getTestType() {
return TEST_TALOS;
}
private void loadFilterMethod() throws Exception {
Class browserDBClass = mClassLoader.loadClass("org.mozilla.gecko.db.BrowserDB");
@ -232,8 +237,6 @@ public class testBrowserProviderPerf extends ContentProviderTest {
}
public void testBrowserProviderPerf() throws Exception {
setTestType("talos");
initializeBrowserProvider();
loadMobileFolderId();

View File

@ -12,8 +12,12 @@ public class testCheck extends PixelTest {
}
}
@Override
protected int getTestType() {
return TEST_TALOS;
}
public void testCheck() {
setTestType("talos");
String url = getAbsoluteUrl("/startup_test/fennecmark/timecube.html");
mActions.expectGeckoEvent("Gecko:Ready").blockForEvent();

View File

@ -4,8 +4,12 @@ package @ANDROID_PACKAGE_NAME@.tests;
import @ANDROID_PACKAGE_NAME@.*;
public class testCheck2 extends PixelTest {
@Override
protected int getTestType() {
return TEST_TALOS;
}
public void testCheck2() {
setTestType("talos");
String url = getAbsoluteUrl("/startup_test/fennecmark/cnn/cnn.com/index.html");
mActions.expectGeckoEvent("Gecko:Ready").blockForEvent();

View File

@ -5,8 +5,12 @@ import @ANDROID_PACKAGE_NAME@.*;
import java.lang.reflect.Method;
public class testCheck3 extends PixelTest {
@Override
protected int getTestType() {
return TEST_TALOS;
}
public void testCheck3() {
setTestType("talos");
String url = getAbsoluteUrl("/startup_test/fennecmark/cnn/cnn.com/index.html");
// Disable Fennec's low-res screenshot for the duration of this test;
// this distinguishes this test from testCheck2, which is otherwise

View File

@ -11,8 +11,12 @@ import android.app.Instrumentation;
* - Fling the page downwards so we get back to the top and verify.
*/
public class testFlingCorrectness extends PixelTest {
@Override
protected int getTestType() {
return TEST_MOCHITEST;
}
public void testFlingCorrectness() {
setTestType("mochitest");
String url = getAbsoluteUrl("/robocop/robocop_boxes.html");
MotionEventHelper meh = new MotionEventHelper(getInstrumentation(), mDriver.getGeckoLeft(), mDriver.getGeckoTop());

View File

@ -21,8 +21,13 @@ import java.util.ArrayList;
*/
public class testFormHistory extends BaseTest {
private static final String DB_NAME = "formhistory.sqlite";
@Override
protected int getTestType() {
return TEST_MOCHITEST;
}
public void testFormHistory() {
setTestType("mochitest");
Context context = (Context)getActivity();
ContentResolver cr = context.getContentResolver();
ContentValues[] cvs = new ContentValues[1];

View File

@ -19,8 +19,12 @@ import java.io.StringWriter;
* as loading some invalid jar urls.
*/
public class testJarReader extends BaseTest {
@Override
protected int getTestType() {
return TEST_MOCHITEST;
}
public void testJarReader() {
setTestType("mochitest");
try {
ClassLoader classLoader = getActivity().getClassLoader();
Class gjrClass = classLoader.loadClass("org.mozilla.gecko.GeckoJarReader");

View File

@ -10,8 +10,12 @@ import @ANDROID_PACKAGE_NAME@.*;
* - verifies the displayed url is correct
*/
public class testLoad extends PixelTest {
@Override
protected int getTestType() {
return TEST_MOCHITEST;
}
public void testLoad() {
setTestType("mochitest");
String url = getAbsoluteUrl("/robocop/robocop_boxes.html");
mActions.expectGeckoEvent("Gecko:Ready").blockForEvent();

View File

@ -36,6 +36,11 @@ public class testMigration extends ContentProviderTest {
private static final String ASSET_SUFFIX = ".zip";
private static final String DB_NAME = "places.sqlite";
@Override
protected int getTestType() {
return TEST_MOCHITEST;
}
private File extractAsset(String dbName) {
File oldDbLocation = null;
boolean foundFile = false;
@ -94,8 +99,6 @@ public class testMigration extends ContentProviderTest {
}
public void testMigration() {
setTestType("mochitest");
Context context = (Context)getActivity();
File oldDbLocation = extractAsset(DB_NAME);

View File

@ -14,9 +14,12 @@ public class testNewTab extends BaseTest {
private Element closeTab = null;
private int tabCountInt = 0;
public void testNewTab() {
setTestType("mochitest");
@Override
protected int getTestType() {
return TEST_MOCHITEST;
}
public void testNewTab() {
String url = getAbsoluteUrl("/robocop/robocop_blank_01.html");
String url2 = getAbsoluteUrl("/robocop/robocop_blank_02.html");

View File

@ -11,8 +11,12 @@ import android.app.Instrumentation;
* - Drag page rightwards by 100 pixels into overscroll, verify it snaps back.
*/
public class testOverscroll extends PixelTest {
@Override
protected int getTestType() {
return TEST_MOCHITEST;
}
public void testOverscroll() {
setTestType("mochitest");
String url = getAbsoluteUrl("/robocop/robocop_boxes.html");
MotionEventHelper meh = new MotionEventHelper(getInstrumentation(), mDriver.getGeckoLeft(), mDriver.getGeckoTop());

View File

@ -9,9 +9,12 @@ import @ANDROID_PACKAGE_NAME@.*;
* that fennec draws at.
*/
public class testPan extends PixelTest {
@Override
protected int getTestType() {
return TEST_TALOS;
}
public void testPan() {
setTestType("talos");
String url = getAbsoluteUrl("/startup_test/fennecmark/wikipedia.html");
mActions.expectGeckoEvent("Gecko:Ready").blockForEvent();

View File

@ -11,8 +11,12 @@ import android.app.Instrumentation;
* - drags page leftwards by 100 pixels and verifies it draws
*/
public class testPanCorrectness extends PixelTest {
@Override
protected int getTestType() {
return TEST_MOCHITEST;
}
public void testPanCorrectness() {
setTestType("mochitest");
String url = getAbsoluteUrl("/robocop/robocop_boxes.html");
MotionEventHelper meh = new MotionEventHelper(getInstrumentation(), mDriver.getGeckoLeft(), mDriver.getGeckoTop());

View File

@ -16,8 +16,12 @@ import org.json.JSONException;
import org.json.JSONObject;
public class testPasswordEncrypt extends BaseTest {
@Override
protected int getTestType() {
return TEST_MOCHITEST;
}
public void testPasswordEncrypt() {
setTestType("mochitest");
Context context = (Context)getActivity();
ContentResolver cr = context.getContentResolver();
mAsserter.isnot(cr, null, "Found a content resolver");

View File

@ -19,8 +19,13 @@ import java.io.File;
*/
public class testPasswordProvider extends BaseTest {
private static final String DB_NAME = "signons.sqlite";
@Override
protected int getTestType() {
return TEST_MOCHITEST;
}
public void testPasswordProvider() {
setTestType("mochitest");
Context context = (Context)getActivity();
ContentResolver cr = context.getContentResolver();
ContentValues[] cvs = new ContentValues[1];

View File

@ -10,8 +10,12 @@ public class testPermissions extends PixelTest {
private PaintedSurface mPaintedSurface;
private Actions.RepeatedEventExpecter mPaintExpecter;
@Override
protected int getTestType() {
return TEST_MOCHITEST;
}
public void testPermissions() {
setTestType("mochitest");
mActions.expectGeckoEvent("Gecko:Ready").blockForEvent();
geolocationTest();

View File

@ -26,8 +26,12 @@ public class testSearchSuggestions extends BaseTest {
private static final String TEST_QUERY = "foo barz";
private static final String SUGGESTION_TEMPLATE = "/robocop/robocop_suggestions.sjs?query=__searchTerms__";
@Override
protected int getTestType() {
return TEST_MOCHITEST;
}
public void testSearchSuggestions() {
setTestType("mochitest");
mActions.expectGeckoEvent("Gecko:Ready").blockForEvent();
// Map of expected values. See robocop_suggestions.sjs.

View File

@ -6,8 +6,12 @@ import android.app.Activity;
import android.util.DisplayMetrics;
public class testWebContentContextMenu extends BaseTest {
@Override
protected int getTestType() {
return TEST_MOCHITEST;
}
public void testWebContentContextMenu() {
setTestType("mochitest");
mActions.expectGeckoEvent("Gecko:Ready").blockForEvent();
DisplayMetrics dm = new DisplayMetrics();

View File

@ -5,8 +5,12 @@ import @ANDROID_PACKAGE_NAME@.*;
import android.app.Instrumentation;
public class test_bug720538 extends PixelTest {
@Override
protected int getTestType() {
return TEST_MOCHITEST;
}
public void test_bug720538() {
setTestType("mochitest");
String url = getAbsoluteUrl("/robocop/test_bug720538.html");
mActions.expectGeckoEvent("Gecko:Ready").blockForEvent();