2012-01-05 07:20:22 -08:00
|
|
|
#filter substitution
|
|
|
|
package @ANDROID_PACKAGE_NAME@.tests;
|
|
|
|
|
|
|
|
import com.jayway.android.robotium.solo.Solo;
|
|
|
|
import @ANDROID_PACKAGE_NAME@.*;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
2012-12-03 04:14:27 -08:00
|
|
|
import android.content.pm.ActivityInfo;
|
2012-01-05 18:36:17 -08:00
|
|
|
import android.app.Instrumentation;
|
2013-01-19 08:49:47 -08:00
|
|
|
import android.content.ContentResolver;
|
2012-03-08 10:25:44 -08:00
|
|
|
import android.content.ContentValues;
|
2013-01-19 08:49:47 -08:00
|
|
|
import android.content.ContentUris;
|
2012-01-05 07:20:22 -08:00
|
|
|
import android.content.Intent;
|
2012-03-27 13:16:13 -07:00
|
|
|
import android.content.res.AssetManager;
|
|
|
|
import android.database.Cursor;
|
2013-01-19 08:49:47 -08:00
|
|
|
import android.net.Uri;
|
2012-02-22 18:26:04 -08:00
|
|
|
import android.os.SystemClock;
|
|
|
|
import android.test.ActivityInstrumentationTestCase2;
|
2012-03-08 10:25:44 -08:00
|
|
|
import java.io.File;
|
2012-03-27 13:16:13 -07:00
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.IOException;
|
2012-10-25 12:41:26 -07:00
|
|
|
import java.lang.reflect.Method;
|
2012-01-05 07:20:22 -08:00
|
|
|
import java.util.HashMap;
|
2012-11-15 04:54:46 -08:00
|
|
|
import android.view.View;
|
2012-12-03 04:14:27 -08:00
|
|
|
import android.os.Build;
|
|
|
|
import android.util.DisplayMetrics;
|
2013-01-19 08:49:47 -08:00
|
|
|
import android.widget.ListView;
|
|
|
|
import java.util.ArrayList;
|
2012-01-05 07:20:22 -08:00
|
|
|
|
2012-05-22 16:25:30 -07:00
|
|
|
/**
|
|
|
|
* A convenient base class suitable for most Robocop tests.
|
|
|
|
*/
|
2012-01-05 07:20:22 -08:00
|
|
|
abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
|
2012-06-27 16:56:49 -07:00
|
|
|
public static final int TEST_MOCHITEST = 0;
|
|
|
|
public static final int TEST_TALOS = 1;
|
|
|
|
|
2012-01-05 07:20:22 -08:00
|
|
|
private static final String TARGET_PACKAGE_ID = "org.mozilla.gecko";
|
|
|
|
private static final String LAUNCH_ACTIVITY_FULL_CLASSNAME="@ANDROID_PACKAGE_NAME@.App";
|
2012-07-17 20:05:38 -07:00
|
|
|
private static final int VERIFY_URL_TIMEOUT = 2000;
|
2012-12-28 15:06:50 -08:00
|
|
|
public static final int MAX_WAIT_MS = 3000;
|
2012-01-05 07:20:22 -08:00
|
|
|
|
|
|
|
private static Class<Activity> mLauncherActivityClass;
|
|
|
|
private Activity mActivity;
|
2012-01-18 10:44:47 -08:00
|
|
|
protected Solo mSolo;
|
2012-01-05 07:20:22 -08:00
|
|
|
protected Driver mDriver;
|
|
|
|
protected Assert mAsserter;
|
|
|
|
protected Actions mActions;
|
2012-02-02 07:09:26 -08:00
|
|
|
protected String mBaseUrl;
|
2012-06-05 14:07:14 -07:00
|
|
|
protected String mRawBaseUrl;
|
2012-02-02 07:47:17 -08:00
|
|
|
private String mLogFile;
|
2012-03-08 10:25:44 -08:00
|
|
|
protected String mProfile;
|
2013-01-19 08:49:47 -08:00
|
|
|
private static ListView bookmarkList;
|
2012-01-05 07:20:22 -08:00
|
|
|
|
2012-10-25 12:41:26 -07:00
|
|
|
protected void blockForGeckoReady() {
|
|
|
|
try {
|
|
|
|
Actions.EventExpecter geckoReadyExpector = mActions.expectGeckoEvent("Gecko:Ready");
|
|
|
|
ClassLoader classLoader = getActivity().getClassLoader();
|
2013-01-23 06:38:57 -08:00
|
|
|
Class appsCls = classLoader.loadClass("org.mozilla.gecko.GeckoThread");
|
|
|
|
Class launchStateCls = classLoader.loadClass("org.mozilla.gecko.GeckoThread$LaunchState");
|
2012-10-25 12:41:26 -07:00
|
|
|
Method checkLaunchState = appsCls.getMethod("checkLaunchState", launchStateCls);
|
|
|
|
Object states[] = launchStateCls.getEnumConstants();
|
|
|
|
Boolean ret = (Boolean)checkLaunchState.invoke(null, states[3]);
|
|
|
|
if (!ret.booleanValue()) {
|
2013-01-23 06:38:57 -08:00
|
|
|
geckoReadyExpector.blockForEvent();
|
2012-10-25 12:41:26 -07:00
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
mAsserter.dumpLog("Exception in blockForGeckoReady", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-05 07:20:22 -08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-06-27 16:56:49 -07:00
|
|
|
protected abstract int getTestType();
|
|
|
|
|
2012-01-05 07:20:22 -08:00
|
|
|
@Override
|
|
|
|
protected void setUp() throws Exception {
|
2012-09-12 04:56:31 -07:00
|
|
|
// Load config file from root path (setup by python script)
|
|
|
|
String rootPath = FennecInstrumentationTestRunner.getArguments().getString("deviceroot");
|
|
|
|
String configFile = FennecNativeDriver.getFile(rootPath + "/robotium.config");
|
2012-01-05 07:20:22 -08:00
|
|
|
HashMap config = FennecNativeDriver.convertTextToTable(configFile);
|
|
|
|
|
|
|
|
// Create the intent to be used with all the important arguments.
|
|
|
|
Intent i = new Intent(Intent.ACTION_MAIN);
|
2012-03-08 10:25:44 -08:00
|
|
|
mProfile = (String)config.get("profile");
|
|
|
|
i.putExtra("args", "-no-remote -profile " + mProfile);
|
2012-01-05 07:20:22 -08:00
|
|
|
|
2012-10-16 10:25:23 -07:00
|
|
|
String envString = (String)config.get("envvars");
|
|
|
|
if (envString != "") {
|
|
|
|
String[] envStrings = envString.split(",");
|
|
|
|
for (int iter = 0; iter < envStrings.length; iter++) {
|
|
|
|
i.putExtra("env" + iter, envStrings[iter]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-05 07:20:22 -08:00
|
|
|
// Start the activity
|
|
|
|
setActivityIntent(i);
|
|
|
|
mActivity = getActivity();
|
|
|
|
|
2012-02-02 07:09:26 -08:00
|
|
|
mLogFile = (String)config.get("logfile");
|
|
|
|
mBaseUrl = ((String)config.get("host")).replaceAll("(/$)", "");
|
2012-06-05 14:07:14 -07:00
|
|
|
mRawBaseUrl = ((String)config.get("rawhost")).replaceAll("(/$)", "");
|
2012-06-27 16:56:49 -07:00
|
|
|
|
|
|
|
// Initialize the asserter
|
|
|
|
if (getTestType() == TEST_TALOS) {
|
|
|
|
mAsserter = new FennecTalosAssert();
|
|
|
|
} else {
|
|
|
|
mAsserter = new FennecMochitestAssert();
|
|
|
|
}
|
|
|
|
mAsserter.setLogFile(mLogFile);
|
|
|
|
mAsserter.setTestName(this.getClass().getName());
|
2012-06-28 11:20:15 -07:00
|
|
|
|
|
|
|
// Set up Robotium.solo and Driver objects
|
2012-08-14 07:49:59 -07:00
|
|
|
mSolo = new Solo(getInstrumentation(), mActivity);
|
2012-09-12 04:56:31 -07:00
|
|
|
mDriver = new FennecNativeDriver(mActivity, mSolo, rootPath);
|
2012-06-28 11:20:15 -07:00
|
|
|
mActions = new FennecNativeActions(mActivity, mSolo, getInstrumentation(), mAsserter);
|
2012-05-25 23:18:19 -07:00
|
|
|
}
|
|
|
|
|
2012-06-13 13:31:01 -07:00
|
|
|
@Override
|
|
|
|
protected void runTest() throws Throwable {
|
|
|
|
try {
|
|
|
|
super.runTest();
|
|
|
|
} catch (Throwable t) {
|
|
|
|
if (mAsserter != null) {
|
|
|
|
mAsserter.dumpLog("Exception caught during test!", t);
|
|
|
|
mAsserter.ok(false, "Exception caught", t.toString());
|
|
|
|
}
|
|
|
|
// re-throw to continue bail-out
|
|
|
|
throw t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-05 07:20:22 -08:00
|
|
|
@Override
|
|
|
|
public void tearDown() throws Exception {
|
|
|
|
try {
|
2012-08-09 06:06:19 -07:00
|
|
|
mAsserter.endTest();
|
2012-08-14 07:49:59 -07:00
|
|
|
mSolo.finishOpenedActivities();
|
2012-01-05 07:20:22 -08:00
|
|
|
} catch (Throwable e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
super.tearDown();
|
|
|
|
}
|
2012-01-05 07:20:22 -08:00
|
|
|
|
2012-06-08 11:43:23 -07:00
|
|
|
public void assertMatches(String value, String regex, String name) {
|
|
|
|
if (value == null) {
|
|
|
|
mAsserter.ok(false, name, "Expected /" + regex + "/, got null");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mAsserter.ok(value.matches(regex), name, "Expected /" + regex +"/, got \"" + value + "\"");
|
|
|
|
}
|
|
|
|
|
2012-05-22 16:25:30 -07:00
|
|
|
/**
|
|
|
|
* Click on the specified element and return the resulting activity.
|
|
|
|
* @return The created activity, or null if the element cannot be clicked.
|
|
|
|
*/
|
2012-01-05 18:36:17 -08:00
|
|
|
protected final Activity getActivityFromClick(Element element) {
|
|
|
|
Instrumentation inst = getInstrumentation();
|
|
|
|
Instrumentation.ActivityMonitor monitor = inst.addMonitor((String)null, null, false);
|
2012-05-22 16:25:30 -07:00
|
|
|
boolean clicked = element.click();
|
|
|
|
if (!clicked) {
|
|
|
|
mAsserter.ok(clicked != false, "checking that awesome bar clicked", "awesome bar was clicked");
|
|
|
|
return null;
|
|
|
|
}
|
2012-06-09 09:24:57 -07:00
|
|
|
// Wait for click to take effect before waiting for activity
|
|
|
|
// (otherwise we sometimes get the previous activity).
|
|
|
|
// Previously, waitForIdleSync was used here but it was found
|
|
|
|
// to hang very occasionally.
|
|
|
|
mSolo.sleep(2000);
|
2012-01-10 11:15:18 -08:00
|
|
|
Activity activity = inst.waitForMonitor(monitor);
|
2012-06-09 09:24:57 -07:00
|
|
|
// Give the activity time to render itself and initialize views
|
2012-01-24 06:46:36 -08:00
|
|
|
// before continuing, so that views are created before access
|
2012-06-09 09:24:57 -07:00
|
|
|
// attempts are made. Again, waitForIdleSync was used here
|
|
|
|
// previously, but replaced with a sleep to avoid hangs.
|
|
|
|
// TODO: Investigate and document why these pauses are required.
|
|
|
|
mSolo.sleep(2000);
|
2012-01-10 11:15:18 -08:00
|
|
|
return activity;
|
|
|
|
}
|
|
|
|
|
2012-05-22 16:25:30 -07:00
|
|
|
/**
|
|
|
|
* Click on the awesome bar element and return the resulting activity.
|
|
|
|
* @return The created activity, or null if the awesome bar cannot be clicked.
|
|
|
|
*/
|
2012-01-10 11:15:18 -08:00
|
|
|
protected final Activity clickOnAwesomeBar() {
|
2012-05-22 16:25:30 -07:00
|
|
|
Activity activity = null;
|
2012-01-10 11:15:18 -08:00
|
|
|
Element awesomebar = mDriver.findElement(mActivity, "awesome_bar");
|
2012-05-22 16:25:30 -07:00
|
|
|
if (awesomebar != null) {
|
|
|
|
activity = getActivityFromClick(awesomebar);
|
|
|
|
if (activity == null) {
|
|
|
|
mAsserter.dumpLog("failed to click on awesome bar!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return activity;
|
2012-01-05 18:36:17 -08:00
|
|
|
}
|
|
|
|
|
2012-01-05 07:20:22 -08:00
|
|
|
protected final void enterUrl(String url) {
|
2012-01-10 11:15:18 -08:00
|
|
|
Activity awesomeBarActivity = clickOnAwesomeBar();
|
2012-01-05 18:36:17 -08:00
|
|
|
Element urlbar = mDriver.findElement(awesomeBarActivity, "awesomebar_text");
|
2012-01-05 07:20:22 -08:00
|
|
|
mActions.sendKeys(url);
|
2012-05-22 16:25:30 -07:00
|
|
|
String urlbarText = null;
|
|
|
|
if (urlbar != null) {
|
|
|
|
urlbarText = urlbar.getText();
|
|
|
|
}
|
|
|
|
mAsserter.is(urlbarText, url, "Awesomebar URL typed properly");
|
2012-01-05 07:20:22 -08:00
|
|
|
}
|
|
|
|
|
2012-01-05 18:36:17 -08:00
|
|
|
protected final void hitEnterAndWait() {
|
|
|
|
Actions.EventExpecter contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded");
|
2012-01-05 07:20:22 -08:00
|
|
|
mActions.sendSpecialKey(Actions.SpecialKey.ENTER);
|
|
|
|
// wait for screen to load
|
2012-01-05 18:36:17 -08:00
|
|
|
contentEventExpecter.blockForEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected final void loadUrl(String url) {
|
|
|
|
enterUrl(url);
|
|
|
|
hitEnterAndWait();
|
2012-01-05 07:20:22 -08:00
|
|
|
}
|
|
|
|
|
2012-06-18 12:39:13 -07:00
|
|
|
public final void verifyUrl(String url) {
|
2012-01-10 11:15:18 -08:00
|
|
|
Activity awesomeBarActivity = clickOnAwesomeBar();
|
2012-01-05 18:36:17 -08:00
|
|
|
Element urlbar = mDriver.findElement(awesomeBarActivity, "awesomebar_text");
|
2012-05-22 16:25:30 -07:00
|
|
|
String urlbarText = null;
|
|
|
|
if (urlbar != null) {
|
2012-07-17 20:05:38 -07:00
|
|
|
// wait for a short time for the expected text, in case there is a delay
|
|
|
|
// in updating the view
|
|
|
|
waitForTest(new VerifyUrlTest(urlbar, url), VERIFY_URL_TIMEOUT);
|
2012-05-22 16:25:30 -07:00
|
|
|
urlbarText = urlbar.getText();
|
|
|
|
}
|
|
|
|
mAsserter.is(urlbarText, url, "Awesomebar URL stayed the same");
|
2012-01-05 07:20:22 -08:00
|
|
|
}
|
2012-02-02 07:09:26 -08:00
|
|
|
|
2012-07-17 20:05:38 -07:00
|
|
|
class VerifyUrlTest implements BooleanTest {
|
|
|
|
private Element mUrlbar;
|
|
|
|
private String mUrl;
|
|
|
|
public VerifyUrlTest(Element urlbar, String url) {
|
|
|
|
mUrlbar = urlbar;
|
|
|
|
mUrl = url;
|
|
|
|
}
|
|
|
|
public boolean test() {
|
|
|
|
String urlbarText = mUrlbar.getText();
|
|
|
|
if (urlbarText.equals(mUrl)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-02 07:09:26 -08:00
|
|
|
protected final String getAbsoluteUrl(String url) {
|
|
|
|
return mBaseUrl + "/" + url.replaceAll("(^/)", "");
|
|
|
|
}
|
2012-02-22 18:26:04 -08:00
|
|
|
|
2012-06-05 14:07:14 -07:00
|
|
|
protected final String getAbsoluteRawUrl(String url) {
|
|
|
|
return mRawBaseUrl + "/" + url.replaceAll("(^/)", "");
|
|
|
|
}
|
|
|
|
|
2012-02-22 18:26:04 -08:00
|
|
|
protected final boolean waitForTest(BooleanTest t, int timeout) {
|
|
|
|
long end = SystemClock.uptimeMillis() + timeout;
|
|
|
|
while (SystemClock.uptimeMillis() < end) {
|
|
|
|
if (t.test())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
mSolo.sleep(100);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected interface BooleanTest {
|
|
|
|
public boolean test();
|
|
|
|
}
|
2012-03-08 10:25:44 -08:00
|
|
|
|
|
|
|
@SuppressWarnings({"unchecked", "non-varargs"})
|
|
|
|
public void SqliteCompare(String dbName, String sqlCommand, ContentValues[] cvs) {
|
|
|
|
File profile = new File(mProfile);
|
|
|
|
String dbPath = new File(profile, dbName).getPath();
|
|
|
|
|
|
|
|
Cursor c = mActions.querySql(dbPath, sqlCommand);
|
|
|
|
SqliteCompare(c, cvs);
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean CursorMatches(Cursor c, String[] columns, ContentValues cv) {
|
|
|
|
for (int i = 0; i < columns.length; i++) {
|
|
|
|
String column = columns[i];
|
|
|
|
if (cv.containsKey(column)) {
|
2012-04-09 10:47:47 -07:00
|
|
|
mAsserter.info("Comparing", "Column values for: " + column);
|
|
|
|
Object value = cv.get(column);
|
|
|
|
if (value == null) {
|
|
|
|
if (!c.isNull(i))
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
if (c.isNull(i) || !value.toString().equals(c.getString(i)))
|
|
|
|
return false;
|
2012-03-08 10:25:44 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings({"unchecked", "non-varargs"})
|
|
|
|
public void SqliteCompare(Cursor c, ContentValues[] cvs) {
|
|
|
|
mAsserter.is(c.getCount(), cvs.length, "List is correct length");
|
|
|
|
if (c.moveToFirst()) {
|
|
|
|
do {
|
|
|
|
boolean found = false;
|
|
|
|
for (int i = 0; !found && i < cvs.length; i++) {
|
|
|
|
if (CursorMatches(c, cvs[i])) {
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mAsserter.is(found, true, "Password was found");
|
|
|
|
} while(c.moveToNext());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean CursorMatches(Cursor c, ContentValues cv) {
|
|
|
|
for (int i = 0; i < c.getColumnCount(); i++) {
|
|
|
|
String column = c.getColumnName(i);
|
|
|
|
if (cv.containsKey(column)) {
|
2012-04-09 10:47:47 -07:00
|
|
|
mAsserter.info("Comparing", "Column values for: " + column);
|
|
|
|
Object value = cv.get(column);
|
|
|
|
if (value == null) {
|
|
|
|
if (!c.isNull(i))
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
if (c.isNull(i) || !value.toString().equals(c.getString(i)))
|
|
|
|
return false;
|
2012-03-08 10:25:44 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-27 13:16:13 -07:00
|
|
|
|
|
|
|
public InputStream getAsset(String filename) throws IOException {
|
|
|
|
AssetManager assets = getInstrumentation().getContext().getAssets();
|
|
|
|
return assets.open(filename);
|
|
|
|
}
|
2012-10-02 08:24:38 -07:00
|
|
|
|
|
|
|
public final void selectMenuItem(String menuItemName) {
|
|
|
|
//build the item name ready to be used
|
|
|
|
String itemName = "^" + menuItemName + "$";
|
|
|
|
mActions.sendSpecialKey(Actions.SpecialKey.MENU);
|
|
|
|
|
|
|
|
// Look for the 'More' menu if this device/OS uses it
|
|
|
|
if (mSolo.waitForText("^More$")) {
|
|
|
|
mSolo.clickOnText("^More$");
|
|
|
|
}
|
|
|
|
|
|
|
|
mSolo.waitForText(itemName);
|
|
|
|
mSolo.clickOnText(itemName);
|
|
|
|
}
|
|
|
|
|
|
|
|
public final void verifyPageTitle(String title) {
|
|
|
|
Element awesomebar = mDriver.findElement(getActivity(), "awesome_bar_title");
|
2012-12-03 04:14:27 -08:00
|
|
|
String pageTitle = null;
|
|
|
|
if (awesomebar != null) {
|
|
|
|
// Wait for the title to make sure it has been displayed in case the view
|
|
|
|
// does not update fast enough
|
|
|
|
waitForTest(new VerifyTitle(awesomebar, title), MAX_WAIT_MS);
|
|
|
|
pageTitle = awesomebar.getText();
|
|
|
|
}
|
|
|
|
mAsserter.is(pageTitle, title, "Page title is correct");
|
|
|
|
}
|
|
|
|
|
|
|
|
class VerifyTitle implements BooleanTest {
|
|
|
|
private Element mAwesomebar;
|
|
|
|
private String mTitle;
|
|
|
|
public VerifyTitle(Element awesomebar, String title) {
|
|
|
|
mAwesomebar = awesomebar;
|
|
|
|
mTitle = title;
|
|
|
|
}
|
|
|
|
public boolean test() {
|
|
|
|
String pageTitle = mAwesomebar.getText();
|
|
|
|
if (pageTitle.equals(mTitle)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2012-10-02 08:24:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public final void verifyTabCount(int expectedTabCount) {
|
|
|
|
Activity activity = getActivity();
|
|
|
|
Element tabCount = mDriver.findElement(activity, "tabs_count");
|
|
|
|
String tabCountText = tabCount.getText();
|
|
|
|
int tabCountInt = Integer.parseInt(tabCountText);
|
|
|
|
mAsserter.is(tabCountInt, expectedTabCount, "The correct number of tabs are opened");
|
|
|
|
}
|
2012-11-15 04:54:46 -08:00
|
|
|
|
2013-01-19 08:49:47 -08:00
|
|
|
public ListView getBookmarksList() {
|
|
|
|
Activity awesomeBarActivity = clickOnAwesomeBar();
|
|
|
|
mSolo.clickOnText("Bookmarks");
|
|
|
|
|
|
|
|
final ArrayList<ListView> views = mSolo.getCurrentListViews();
|
|
|
|
|
|
|
|
bookmarkList = null;
|
|
|
|
boolean success = waitForTest(new BooleanTest() {
|
|
|
|
public boolean test() {
|
|
|
|
for (ListView view : views) {
|
|
|
|
if (view.getTag().equals("bookmarks")) {
|
|
|
|
bookmarkList = view;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}, MAX_WAIT_MS);
|
|
|
|
return bookmarkList;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long addOrUpdateBookmark(String title, String url, boolean bookmarklet) {
|
|
|
|
ContentResolver resolver = getActivity().getContentResolver();
|
|
|
|
Uri bookmarksUri = Uri.parse("content://@ANDROID_PACKAGE_NAME@.db.browser/bookmarks");
|
|
|
|
bookmarksUri = bookmarksUri.buildUpon().appendQueryParameter("profile", "default").build();
|
|
|
|
long folderId = -1;
|
|
|
|
Cursor c = null;
|
|
|
|
|
|
|
|
// NOTE: this is hardcoded to toolbar/mobile and triggered from bookmarklet because the existing
|
|
|
|
// testcases were written this way
|
|
|
|
String location = "toolbar";
|
|
|
|
if (bookmarklet) {
|
|
|
|
location = "mobile";
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
c = resolver.query(bookmarksUri,
|
|
|
|
new String[] { "_id" },
|
|
|
|
"guid = ?",
|
|
|
|
new String[] { location },
|
|
|
|
null);
|
|
|
|
|
|
|
|
if (c.moveToFirst())
|
|
|
|
folderId = c.getLong(c.getColumnIndexOrThrow("_id"));
|
|
|
|
} finally {
|
|
|
|
if (c != null) {
|
|
|
|
c.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
values.put("title", title);
|
|
|
|
values.put("url", url);
|
|
|
|
values.put("parent", folderId);
|
|
|
|
long now = System.currentTimeMillis();
|
|
|
|
values.put("modified", now);
|
|
|
|
|
|
|
|
if (!bookmarklet) {
|
|
|
|
values.put("type", 1);
|
|
|
|
values.put("guid", url);
|
|
|
|
values.put("position", 10);
|
|
|
|
values.put("created", now);
|
|
|
|
}
|
|
|
|
|
|
|
|
int updated = resolver.update(bookmarksUri,
|
|
|
|
values,
|
|
|
|
"url = ?",
|
|
|
|
new String[] { url });
|
|
|
|
if (updated == 0) {
|
|
|
|
Uri uri = resolver.insert(bookmarksUri, values);
|
|
|
|
mAsserter.ok(true, "Inserted at: ", uri.toString());
|
|
|
|
return ContentUris.parseId(uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ContentUris.parseId(bookmarksUri);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void deleteBookmark(String title) {
|
|
|
|
|
|
|
|
ContentResolver resolver = getActivity().getContentResolver();
|
|
|
|
Uri uri = Uri.parse("content://@ANDROID_PACKAGE_NAME@.db.browser/bookmarks");
|
|
|
|
uri = uri.buildUpon().appendQueryParameter("profile", "default")
|
|
|
|
.appendQueryParameter("sync", "true").build();
|
|
|
|
resolver.delete(uri, "title = ?", new String[] { title });
|
|
|
|
}
|
|
|
|
|
2012-11-15 04:54:46 -08:00
|
|
|
public void addTab(String url) {
|
|
|
|
Element tabs = null;
|
|
|
|
Element addTab = null;
|
|
|
|
|
|
|
|
Activity activity = getActivity();
|
|
|
|
tabs = mDriver.findElement(activity, "tabs");
|
|
|
|
addTab = mDriver.findElement(activity, "add_tab");
|
|
|
|
final int addTabId = addTab.getId();
|
|
|
|
mAsserter.ok(tabs.click(), "checking that tabs clicked", "tabs element clicked");
|
|
|
|
|
|
|
|
// wait for addTab to appear (this is usually immediate)
|
|
|
|
boolean success = waitForTest(new BooleanTest() {
|
|
|
|
public boolean test() {
|
|
|
|
View addTabView = getActivity().findViewById(addTabId);
|
|
|
|
if (addTabView == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}, MAX_WAIT_MS);
|
|
|
|
mAsserter.ok(success, "waiting for add tab view", "add tab view available");
|
|
|
|
|
|
|
|
mAsserter.ok(addTab.click(), "checking that add_tab clicked", "add_tab element clicked");
|
|
|
|
|
|
|
|
// must pause before sending keys, until awesome bar is displayed; waiting for known text is simple
|
|
|
|
mSolo.waitForText("History");
|
|
|
|
|
|
|
|
// cannot use loadUrl(): getText fails because we are using a different urlbar
|
|
|
|
mActions.sendKeys(url);
|
|
|
|
hitEnterAndWait();
|
|
|
|
}
|
2012-12-03 04:14:27 -08:00
|
|
|
|
|
|
|
class Device {
|
|
|
|
Build.VERSION mBuildVersion;
|
|
|
|
public String version; // 2.x or 3.x or 4.x
|
|
|
|
public String type; // tablet or phone
|
|
|
|
public int width;
|
|
|
|
public int height;
|
|
|
|
|
|
|
|
public Device() {
|
|
|
|
detectDevice();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void detectDevice() {
|
|
|
|
// Determine device version
|
|
|
|
mBuildVersion = new Build.VERSION();
|
|
|
|
int mSDK = mBuildVersion.SDK_INT;
|
|
|
|
if (mSDK < Build.VERSION_CODES.HONEYCOMB) {
|
|
|
|
version = "2.x";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (mSDK > Build.VERSION_CODES.HONEYCOMB_MR2) {
|
|
|
|
version = "4.x";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
version = "3.x";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Determine with and height
|
|
|
|
DisplayMetrics dm = new DisplayMetrics();
|
|
|
|
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
|
|
|
|
height = dm.heightPixels;
|
|
|
|
width = dm.widthPixels;
|
|
|
|
|
|
|
|
// Determine device type
|
|
|
|
if (width > 480 && height > 480) {
|
|
|
|
type = "tablet";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
type = "phone";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void rotate() {
|
|
|
|
if (getActivity().getRequestedOrientation () == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
|
|
|
|
mSolo.setActivityOrientation(Solo.PORTRAIT);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mSolo.setActivityOrientation(Solo.LANDSCAPE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Navigation {
|
|
|
|
private String devType;
|
|
|
|
private String osVersion;
|
|
|
|
|
|
|
|
public Navigation(Device mDevice) {
|
|
|
|
devType = mDevice.type;
|
|
|
|
osVersion = mDevice.version;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void back() {
|
|
|
|
if (devType == "tablet"){
|
|
|
|
Element backBtn = mDriver.findElement(getActivity(), "back");
|
|
|
|
backBtn.click();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mActions.sendSpecialKey(Actions.SpecialKey.BACK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void forward() {
|
|
|
|
if (devType == "tablet"){
|
|
|
|
Element fwdBtn = mDriver.findElement(getActivity(), "forward");
|
|
|
|
fwdBtn.click();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mActions.sendSpecialKey(Actions.SpecialKey.MENU);
|
|
|
|
mSolo.waitForText("^New Tab$");
|
|
|
|
if (osVersion != "2.x") {
|
|
|
|
Element fwdBtn = mDriver.findElement(getActivity(), "forward");
|
|
|
|
fwdBtn.click();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mSolo.clickOnText("^Forward$");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void reload() {
|
|
|
|
if (devType == "tablet"){
|
|
|
|
Element reloadBtn = mDriver.findElement(getActivity(), "reload");
|
|
|
|
reloadBtn.click();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mActions.sendSpecialKey(Actions.SpecialKey.MENU);
|
|
|
|
mSolo.waitForText("^New Tab$");
|
|
|
|
if (osVersion != "2.x") {
|
|
|
|
Element reloadBtn = mDriver.findElement(getActivity(), "reload");
|
|
|
|
reloadBtn.click();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mSolo.clickOnText("^Forward$");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-05 07:20:22 -08:00
|
|
|
}
|