2012-01-05 15:20:22 +00:00
|
|
|
#filter substitution
|
|
|
|
package @ANDROID_PACKAGE_NAME@.tests;
|
|
|
|
|
|
|
|
import com.jayway.android.robotium.solo.Solo;
|
|
|
|
import @ANDROID_PACKAGE_NAME@.*;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
2012-01-06 02:36:17 +00:00
|
|
|
import android.app.Instrumentation;
|
2012-01-05 15:20:22 +00:00
|
|
|
import android.test.ActivityInstrumentationTestCase2;
|
|
|
|
import android.content.Intent;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
|
|
|
|
private static final String TARGET_PACKAGE_ID = "org.mozilla.gecko";
|
|
|
|
private static final String LAUNCH_ACTIVITY_FULL_CLASSNAME="@ANDROID_PACKAGE_NAME@.App";
|
|
|
|
|
|
|
|
private static Class<Activity> mLauncherActivityClass;
|
|
|
|
private Activity mActivity;
|
|
|
|
private Solo mSolo;
|
|
|
|
protected Driver mDriver;
|
|
|
|
protected Assert mAsserter;
|
|
|
|
protected Actions mActions;
|
|
|
|
|
|
|
|
static {
|
|
|
|
try {
|
|
|
|
mLauncherActivityClass = (Class<Activity>)Class.forName(LAUNCH_ACTIVITY_FULL_CLASSNAME);
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public BaseTest() {
|
|
|
|
super(TARGET_PACKAGE_ID, mLauncherActivityClass);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void setUp() throws Exception {
|
|
|
|
// Load config file from sdcard (setup by python script)
|
|
|
|
String configFile = FennecNativeDriver.getFile("/mnt/sdcard/robotium.config");
|
|
|
|
HashMap config = FennecNativeDriver.convertTextToTable(configFile);
|
|
|
|
|
|
|
|
// Create the intent to be used with all the important arguments.
|
|
|
|
Intent i = new Intent(Intent.ACTION_MAIN);
|
|
|
|
i.putExtra("args", "-no-remote -profile " + (String)config.get("profile"));
|
|
|
|
|
|
|
|
// Start the activity
|
|
|
|
setActivityIntent(i);
|
|
|
|
mActivity = getActivity();
|
|
|
|
|
|
|
|
// Set up Robotium.solo and Driver objects
|
2012-01-06 02:36:17 +00:00
|
|
|
mSolo = new Solo(getInstrumentation());
|
2012-01-05 15:20:22 +00:00
|
|
|
mDriver = new FennecNativeDriver(mActivity, mSolo);
|
|
|
|
mActions = new FennecNativeActions(mActivity, mSolo, getInstrumentation());
|
|
|
|
|
|
|
|
mAsserter = new FennecNativeAssert();
|
|
|
|
mAsserter.setLogFile((String)config.get("logfile"));
|
2012-01-07 23:41:08 +00:00
|
|
|
mAsserter.setTestName(this.getClass().getName());
|
2012-01-05 15:20:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void tearDown() throws Exception {
|
|
|
|
try {
|
2012-01-07 23:41:08 +00:00
|
|
|
mAsserter.finalize();
|
2012-01-05 15:20:22 +00:00
|
|
|
mSolo.finalize();
|
|
|
|
} catch (Throwable e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
getActivity().finish();
|
|
|
|
super.tearDown();
|
|
|
|
}
|
2012-01-05 15:20:22 +00:00
|
|
|
|
2012-01-06 02:36:17 +00:00
|
|
|
protected final Activity getActivityFromClick(Element element) {
|
|
|
|
Instrumentation inst = getInstrumentation();
|
|
|
|
Instrumentation.ActivityMonitor monitor = inst.addMonitor((String)null, null, false);
|
|
|
|
element.click();
|
|
|
|
return inst.waitForMonitor(monitor);
|
|
|
|
}
|
|
|
|
|
2012-01-05 15:20:22 +00:00
|
|
|
protected final void enterUrl(String url) {
|
2012-01-06 02:36:17 +00:00
|
|
|
mActions.expectGeckoEvent("Gecko:Ready").blockForEvent();
|
2012-01-06 02:36:17 +00:00
|
|
|
Element awesomebar = mDriver.findElement(mActivity, "awesome_bar");
|
|
|
|
Activity awesomeBarActivity = getActivityFromClick(awesomebar);
|
2012-01-05 15:20:22 +00:00
|
|
|
getInstrumentation().waitForIdleSync();
|
|
|
|
|
2012-01-06 02:36:17 +00:00
|
|
|
Element urlbar = mDriver.findElement(awesomeBarActivity, "awesomebar_text");
|
2012-01-05 15:20:22 +00:00
|
|
|
mActions.sendKeys(url);
|
|
|
|
mAsserter.is(urlbar.getText(), url, "Awesomebar URL typed properly");
|
|
|
|
}
|
|
|
|
|
2012-01-06 02:36:17 +00:00
|
|
|
protected final void hitEnterAndWait() {
|
|
|
|
Actions.EventExpecter contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded");
|
2012-01-05 15:20:22 +00:00
|
|
|
mActions.sendSpecialKey(Actions.SpecialKey.ENTER);
|
|
|
|
// wait for screen to load
|
2012-01-06 02:36:17 +00:00
|
|
|
contentEventExpecter.blockForEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected final void loadUrl(String url) {
|
|
|
|
enterUrl(url);
|
|
|
|
hitEnterAndWait();
|
2012-01-05 15:20:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected final void verifyUrl(String url) {
|
2012-01-06 02:36:17 +00:00
|
|
|
Element awesomebar = mDriver.findElement(mActivity, "awesome_bar");
|
|
|
|
Activity awesomeBarActivity = getActivityFromClick(awesomebar);
|
2012-01-05 15:20:22 +00:00
|
|
|
getInstrumentation().waitForIdleSync();
|
2012-01-06 02:36:17 +00:00
|
|
|
|
|
|
|
Element urlbar = mDriver.findElement(awesomeBarActivity, "awesomebar_text");
|
2012-01-05 15:20:22 +00:00
|
|
|
mAsserter.is(urlbar.getText(), url, "Awesomebar URL stayed the same");
|
|
|
|
}
|
2012-01-05 15:20:22 +00:00
|
|
|
}
|