2013-11-07 08:18:51 -08:00
|
|
|
package org.mozilla.gecko.tests;
|
2012-01-05 07:20:22 -08:00
|
|
|
|
2013-09-10 18:10:43 -07:00
|
|
|
import com.jayway.android.robotium.solo.Condition;
|
2012-01-05 07:20:22 -08:00
|
|
|
import com.jayway.android.robotium.solo.Solo;
|
2013-11-13 14:53:21 -08:00
|
|
|
|
2013-11-07 08:18:51 -08:00
|
|
|
import org.mozilla.gecko.*;
|
2013-11-13 14:53:21 -08:00
|
|
|
import org.mozilla.gecko.GeckoThread.LaunchState;
|
2012-01-05 07:20:22 -08:00
|
|
|
|
|
|
|
import android.app.Activity;
|
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;
|
2013-02-13 07:54:44 -08:00
|
|
|
import android.content.pm.ActivityInfo;
|
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;
|
2013-02-13 07:54:44 -08:00
|
|
|
import android.os.Build;
|
2012-02-22 18:26:04 -08:00
|
|
|
import android.os.SystemClock;
|
2013-08-14 14:53:34 -07:00
|
|
|
import android.support.v4.app.Fragment;
|
|
|
|
import android.support.v4.app.FragmentActivity;
|
|
|
|
import android.support.v4.app.FragmentManager;
|
2013-10-31 13:50:23 -07:00
|
|
|
import android.text.InputType;
|
2013-11-19 11:57:35 -08:00
|
|
|
import android.text.TextUtils;
|
2012-02-22 18:26:04 -08:00
|
|
|
import android.test.ActivityInstrumentationTestCase2;
|
2013-02-13 07:54:44 -08:00
|
|
|
import android.util.DisplayMetrics;
|
2013-06-04 05:16:07 -07:00
|
|
|
import android.view.inputmethod.InputMethodManager;
|
2013-07-18 16:02:48 -07:00
|
|
|
import android.view.KeyEvent;
|
2013-02-13 07:54:44 -08:00
|
|
|
import android.view.View;
|
2013-11-15 22:59:17 -08:00
|
|
|
import android.widget.AdapterView;
|
2013-06-04 05:16:07 -07:00
|
|
|
import android.widget.Button;
|
2013-07-18 16:02:48 -07:00
|
|
|
import android.widget.EditText;
|
2013-04-18 20:18:11 -07:00
|
|
|
import android.widget.ListAdapter;
|
2013-02-13 07:54:44 -08:00
|
|
|
import android.widget.ListView;
|
2013-06-25 15:33:01 -07:00
|
|
|
import android.widget.TextView;
|
2013-11-15 22:59:17 -08:00
|
|
|
|
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;
|
2013-11-15 22:59:17 -08:00
|
|
|
import java.io.PrintWriter;
|
|
|
|
import java.io.StringWriter;
|
2013-01-19 08:49:47 -08:00
|
|
|
import java.util.ArrayList;
|
2013-02-13 07:54:44 -08:00
|
|
|
import java.util.HashMap;
|
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";
|
2013-11-07 08:18:51 -08:00
|
|
|
private static final String LAUNCH_ACTIVITY_FULL_CLASSNAME = TestConstants.ANDROID_PACKAGE_NAME + ".App";
|
2012-07-17 20:05:38 -07:00
|
|
|
private static final int VERIFY_URL_TIMEOUT = 2000;
|
2013-03-01 16:02:52 -08:00
|
|
|
private static final int MAX_LIST_ATTEMPTS = 3;
|
2013-06-25 15:33:01 -07:00
|
|
|
private static final int MAX_WAIT_ENABLED_TEXT_MS = 10000;
|
2013-09-19 06:37:58 -07:00
|
|
|
private static final int MAX_WAIT_HOME_PAGER_HIDDEN_MS = 15000;
|
2013-09-17 07:05:39 -07:00
|
|
|
public static final int MAX_WAIT_MS = 4500;
|
2013-08-20 00:26:55 -07:00
|
|
|
public static final int LONG_PRESS_TIME = 6000;
|
2012-01-05 07:20:22 -08:00
|
|
|
|
2013-07-18 16:02:48 -07:00
|
|
|
// IDs for UI views
|
|
|
|
private static final String BROWSER_TOOLBAR_ID = "browser_toolbar";
|
|
|
|
protected static final String URL_EDIT_TEXT_ID = "url_edit_text";
|
|
|
|
protected static final String URL_BAR_TITLE_ID = "url_bar_title";
|
|
|
|
|
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-05-08 13:46:36 -07:00
|
|
|
public Device mDevice;
|
2013-08-21 07:11:13 -07:00
|
|
|
protected DatabaseHelper mDatabaseHelper;
|
|
|
|
protected StringHelper mStringHelper;
|
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");
|
2013-11-13 14:53:21 -08:00
|
|
|
if (!GeckoThread.checkLaunchState(LaunchState.GeckoRunning)) {
|
2013-01-23 06:38:57 -08:00
|
|
|
geckoReadyExpector.blockForEvent();
|
2012-10-25 12:41:26 -07:00
|
|
|
}
|
2013-04-18 20:18:09 -07:00
|
|
|
geckoReadyExpector.unregisterListener();
|
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)
|
2013-07-30 08:13:34 -07:00
|
|
|
String rootPath = FennecInstrumentationTestRunner.getFennecArguments().getString("deviceroot");
|
2012-09-12 04:56:31 -07:00
|
|
|
String configFile = FennecNativeDriver.getFile(rootPath + "/robotium.config");
|
2012-01-05 07:20:22 -08:00
|
|
|
HashMap config = FennecNativeDriver.convertTextToTable(configFile);
|
2013-11-15 22:59:17 -08:00
|
|
|
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());
|
2012-01-05 07:20:22 -08:00
|
|
|
// 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-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-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);
|
2013-05-08 13:46:36 -07:00
|
|
|
mDevice = new Device();
|
2013-08-21 07:11:13 -07:00
|
|
|
mDatabaseHelper = new DatabaseHelper(mActivity, mAsserter);
|
|
|
|
mStringHelper = new StringHelper();
|
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) {
|
2013-03-26 10:31:25 -07:00
|
|
|
// save screenshot -- written to /mnt/sdcard/Robotium-Screenshots
|
|
|
|
// as <filename>.jpg
|
|
|
|
mSolo.takeScreenshot("robocop-screenshot");
|
2012-06-13 13:31:01 -07:00
|
|
|
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
|
|
|
/**
|
2013-07-18 16:02:48 -07:00
|
|
|
* Click on the URL bar to focus it and enter editing mode.
|
2012-05-22 16:25:30 -07:00
|
|
|
*/
|
2013-07-18 16:02:48 -07:00
|
|
|
protected final void focusUrlBar() {
|
|
|
|
// Click on the browser toolbar to enter editing mode
|
2013-09-10 18:10:29 -07:00
|
|
|
final View toolbarView = mSolo.getView(BROWSER_TOOLBAR_ID);
|
|
|
|
mSolo.clickOnView(toolbarView);
|
2012-01-10 11:15:18 -08:00
|
|
|
|
2013-07-18 16:02:48 -07:00
|
|
|
// Wait for highlighed text to gain focus
|
2013-09-10 18:10:43 -07:00
|
|
|
boolean success = waitForCondition(new Condition() {
|
2013-05-09 17:42:14 -07:00
|
|
|
@Override
|
2013-09-10 18:10:43 -07:00
|
|
|
public boolean isSatisfied() {
|
2013-07-18 16:02:48 -07:00
|
|
|
EditText urlEditText = mSolo.getEditText(0);
|
2013-08-13 05:37:48 -07:00
|
|
|
if (urlEditText.isInputMethodTarget()) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
mSolo.clickOnEditText(0);
|
|
|
|
return false;
|
|
|
|
}
|
2012-05-22 16:25:30 -07:00
|
|
|
}
|
2013-07-18 16:02:48 -07:00
|
|
|
}, MAX_WAIT_ENABLED_TEXT_MS);
|
2013-05-09 17:42:14 -07:00
|
|
|
|
2013-07-18 16:02:48 -07:00
|
|
|
mAsserter.ok(success, "waiting for urlbar text to gain focus", "urlbar text gained focus");
|
2012-01-05 18:36:17 -08:00
|
|
|
}
|
|
|
|
|
2012-01-05 07:20:22 -08:00
|
|
|
protected final void enterUrl(String url) {
|
2013-10-31 13:50:23 -07:00
|
|
|
final EditText urlEditView = (EditText) mSolo.getView(URL_EDIT_TEXT_ID);
|
|
|
|
|
2013-07-18 16:02:48 -07:00
|
|
|
focusUrlBar();
|
|
|
|
|
|
|
|
// Send the keys for the URL we want to enter
|
2013-10-31 13:50:23 -07:00
|
|
|
mSolo.clearEditText(urlEditView);
|
|
|
|
mSolo.enterText(urlEditView, url);
|
2013-07-18 16:02:48 -07:00
|
|
|
|
|
|
|
// Get the URL text from the URL bar EditText view
|
2013-10-31 13:50:23 -07:00
|
|
|
final String urlBarText = urlEditView.getText().toString();
|
2013-07-18 16:02:48 -07:00
|
|
|
mAsserter.is(url, urlBarText, "URL typed properly");
|
2012-01-05 07:20:22 -08:00
|
|
|
}
|
|
|
|
|
2013-08-14 14:53:34 -07:00
|
|
|
protected final Fragment getBrowserSearch() {
|
|
|
|
final FragmentManager fm = ((FragmentActivity) getActivity()).getSupportFragmentManager();
|
|
|
|
return fm.findFragmentByTag("browser_search");
|
|
|
|
}
|
|
|
|
|
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();
|
2013-04-18 20:18:09 -07:00
|
|
|
contentEventExpecter.unregisterListener();
|
2012-01-05 18:36:17 -08:00
|
|
|
}
|
|
|
|
|
2013-05-10 19:45:58 -07:00
|
|
|
/**
|
2013-07-18 16:02:48 -07:00
|
|
|
* Load <code>url</code> by sending key strokes to the URL bar UI.
|
2013-05-10 19:45:58 -07:00
|
|
|
*
|
|
|
|
* This method waits synchronously for the <code>DOMContentLoaded</code>
|
|
|
|
* message from Gecko before returning.
|
|
|
|
*/
|
2013-08-19 13:33:49 -07:00
|
|
|
protected final void inputAndLoadUrl(String url) {
|
2012-01-05 18:36:17 -08:00
|
|
|
enterUrl(url);
|
|
|
|
hitEnterAndWait();
|
2012-01-05 07:20:22 -08:00
|
|
|
}
|
|
|
|
|
2013-05-10 19:45:58 -07:00
|
|
|
/**
|
|
|
|
* Load <code>url</code> using reflection and the internal
|
|
|
|
* <code>org.mozilla.gecko.Tabs</code> API.
|
|
|
|
*
|
|
|
|
* This method does not wait for any confirmation from Gecko before
|
|
|
|
* returning.
|
|
|
|
*/
|
2013-08-19 13:33:49 -07:00
|
|
|
protected final void loadUrl(final String url) {
|
2013-05-10 19:45:58 -07:00
|
|
|
try {
|
2013-11-13 14:53:21 -08:00
|
|
|
Tabs.getInstance().loadUrl(url);
|
2013-05-10 19:45:58 -07:00
|
|
|
} catch (Exception e) {
|
2013-08-19 13:33:49 -07:00
|
|
|
mAsserter.dumpLog("Exception in loadUrl", e);
|
2013-05-10 19:45:58 -07:00
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-18 12:39:13 -07:00
|
|
|
public final void verifyUrl(String url) {
|
2013-09-10 18:10:29 -07:00
|
|
|
final EditText urlEditText = (EditText) mSolo.getView(URL_EDIT_TEXT_ID);
|
2013-07-18 16:02:48 -07:00
|
|
|
String urlBarText = null;
|
|
|
|
if (urlEditText != 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
|
2013-09-10 18:10:43 -07:00
|
|
|
waitForCondition(new VerifyTextViewText(urlEditText, url), VERIFY_URL_TIMEOUT);
|
2013-09-10 18:10:29 -07:00
|
|
|
urlBarText = urlEditText.getText().toString();
|
|
|
|
|
2012-05-22 16:25:30 -07:00
|
|
|
}
|
2013-07-18 16:02:48 -07:00
|
|
|
mAsserter.is(urlBarText, url, "Browser toolbar URL stayed the same");
|
2012-01-05 07:20:22 -08:00
|
|
|
}
|
2012-02-02 07:09:26 -08:00
|
|
|
|
2013-09-10 18:10:43 -07:00
|
|
|
class VerifyTextViewText implements Condition {
|
2013-09-10 18:10:29 -07:00
|
|
|
private TextView mTextView;
|
|
|
|
private String mExpected;
|
|
|
|
public VerifyTextViewText(TextView textView, String expected) {
|
|
|
|
mTextView = textView;
|
|
|
|
mExpected = expected;
|
2012-07-17 20:05:38 -07:00
|
|
|
}
|
2013-07-18 16:02:48 -07:00
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2013-09-10 18:10:43 -07:00
|
|
|
public boolean isSatisfied() {
|
2013-09-10 18:10:29 -07:00
|
|
|
String textValue = mTextView.getText().toString();
|
|
|
|
return mExpected.equals(textValue);
|
2012-07-17 20:05:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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("(^/)", "");
|
|
|
|
}
|
|
|
|
|
2013-09-10 18:10:43 -07:00
|
|
|
/*
|
|
|
|
* Wrapper method for mSolo.waitForCondition with additional logging.
|
|
|
|
*/
|
|
|
|
protected final boolean waitForCondition(Condition condition, int timeout) {
|
|
|
|
boolean result = mSolo.waitForCondition(condition, timeout);
|
|
|
|
if (!result) {
|
|
|
|
// Log timeout failure for diagnostic purposes only; a failed wait may
|
|
|
|
// be normal and does not necessarily warrant a test asssertion/failure.
|
|
|
|
mAsserter.dumpLog("waitForCondition timeout after " + timeout + " ms.");
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: With Robotium 4.2, we should use Condition and waitForCondition instead.
|
|
|
|
// Future boolean tests should not use this method.
|
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) {
|
2013-02-27 07:21:23 -08:00
|
|
|
if (t.test()) {
|
2012-02-22 18:26:04 -08:00
|
|
|
return true;
|
2013-02-27 07:21:23 -08:00
|
|
|
}
|
2012-02-22 18:26:04 -08:00
|
|
|
mSolo.sleep(100);
|
|
|
|
}
|
2013-02-27 07:21:24 -08:00
|
|
|
// log out wait failure for diagnostic purposes only;
|
|
|
|
// a failed wait may be normal and does not necessarily
|
|
|
|
// warrant a test assertion/failure
|
|
|
|
mAsserter.dumpLog("waitForTest timeout after "+timeout+" ms");
|
2012-02-22 18:26:04 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-10 18:10:43 -07:00
|
|
|
// TODO: With Robotium 4.2, we should use Condition and waitForCondition instead.
|
|
|
|
// Future boolean tests should not implement this interface.
|
2012-02-22 18:26:04 -08:00
|
|
|
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) {
|
2013-02-27 07:21:23 -08:00
|
|
|
if (!c.isNull(i)) {
|
2012-04-09 10:47:47 -07:00
|
|
|
return false;
|
2013-02-27 07:21:23 -08:00
|
|
|
}
|
2012-04-09 10:47:47 -07:00
|
|
|
} else {
|
2013-02-27 07:21:23 -08:00
|
|
|
if (c.isNull(i) || !value.toString().equals(c.getString(i))) {
|
2012-04-09 10:47:47 -07:00
|
|
|
return false;
|
2013-02-27 07:21:23 -08:00
|
|
|
}
|
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);
|
2013-02-27 07:21:23 -08:00
|
|
|
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) {
|
2013-02-27 07:21:23 -08:00
|
|
|
if (!c.isNull(i)) {
|
2012-04-09 10:47:47 -07:00
|
|
|
return false;
|
2013-02-27 07:21:23 -08:00
|
|
|
}
|
2012-04-09 10:47:47 -07:00
|
|
|
} else {
|
2013-02-27 07:21:23 -08:00
|
|
|
if (c.isNull(i) || !value.toString().equals(c.getString(i))) {
|
2012-04-09 10:47:47 -07:00
|
|
|
return false;
|
2013-02-27 07:21:23 -08:00
|
|
|
}
|
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
|
|
|
|
2013-02-27 07:21:24 -08:00
|
|
|
public boolean waitForText(String text) {
|
|
|
|
boolean rc = mSolo.waitForText(text);
|
|
|
|
if (!rc) {
|
|
|
|
// log out failed wait for diagnostic purposes only;
|
|
|
|
// waitForText failures are sometimes expected/normal
|
|
|
|
mAsserter.dumpLog("waitForText timeout on "+text);
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2013-06-26 10:57:52 -07:00
|
|
|
/**
|
|
|
|
* Wait for <text> to be visible and also be enabled/clickable.
|
|
|
|
*/
|
2013-06-25 15:33:01 -07:00
|
|
|
public boolean waitForEnabledText(String text) {
|
|
|
|
final String testText = text;
|
2013-09-10 18:10:43 -07:00
|
|
|
boolean rc = waitForCondition(new Condition() {
|
2013-06-25 15:33:01 -07:00
|
|
|
@Override
|
2013-09-10 18:10:43 -07:00
|
|
|
public boolean isSatisfied() {
|
2013-06-25 15:33:01 -07:00
|
|
|
// Solo.getText() could be used here, except that it sometimes
|
|
|
|
// hits an assertion when the requested text is not found.
|
|
|
|
ArrayList<View> views = mSolo.getCurrentViews();
|
|
|
|
for (View view : views) {
|
|
|
|
if (view instanceof TextView) {
|
|
|
|
TextView tv = (TextView)view;
|
|
|
|
String viewText = tv.getText().toString();
|
|
|
|
if (tv.isEnabled() && viewText != null && viewText.matches(testText)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}, MAX_WAIT_ENABLED_TEXT_MS);
|
|
|
|
if (!rc) {
|
|
|
|
// log out failed wait for diagnostic purposes only;
|
|
|
|
// failures are sometimes expected/normal
|
|
|
|
mAsserter.dumpLog("waitForEnabledText timeout on "+text);
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-08 13:46:36 -07:00
|
|
|
/**
|
2013-07-08 18:34:25 -07:00
|
|
|
* Select <item> from Menu > "Settings" > <section>.
|
2013-05-08 13:46:36 -07:00
|
|
|
*/
|
|
|
|
public void selectSettingsItem(String section, String item) {
|
2013-07-08 18:34:25 -07:00
|
|
|
String[] itemPath = { "Settings", section, item };
|
|
|
|
selectMenuItemByPath(itemPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Traverses the items in listItems in order in the menu.
|
|
|
|
*/
|
|
|
|
public void selectMenuItemByPath(String[] listItems) {
|
|
|
|
int listLength = listItems.length;
|
|
|
|
if (listLength > 0) {
|
|
|
|
selectMenuItem(listItems[0]);
|
|
|
|
}
|
|
|
|
if (listLength > 1) {
|
|
|
|
for (int i = 1; i < listLength; i++) {
|
|
|
|
String itemName = "^" + listItems[i] + "$";
|
|
|
|
if (!waitForEnabledText(itemName)) {
|
|
|
|
mSolo.scrollDown();
|
|
|
|
}
|
|
|
|
mSolo.clickOnText(itemName);
|
|
|
|
}
|
|
|
|
}
|
2013-05-08 13:46:36 -07:00
|
|
|
}
|
|
|
|
|
2012-10-02 08:24:38 -07:00
|
|
|
public final void selectMenuItem(String menuItemName) {
|
2013-02-27 07:21:23 -08:00
|
|
|
// build the item name ready to be used
|
2012-10-02 08:24:38 -07:00
|
|
|
String itemName = "^" + menuItemName + "$";
|
|
|
|
mActions.sendSpecialKey(Actions.SpecialKey.MENU);
|
2013-07-08 18:34:25 -07:00
|
|
|
if (waitForText(itemName)) {
|
2013-01-16 02:34:54 -08:00
|
|
|
mSolo.clickOnText(itemName);
|
2013-02-27 07:21:23 -08:00
|
|
|
} else {
|
2013-07-08 18:34:25 -07:00
|
|
|
// Older versions of Android have additional settings under "More",
|
|
|
|
// including settings that newer versions have under "Tools."
|
2013-02-27 07:21:23 -08:00
|
|
|
if (mSolo.searchText("(^More$|^Tools$)")) {
|
2013-01-16 02:34:54 -08:00
|
|
|
mSolo.clickOnText("(^More$|^Tools$)");
|
2013-02-27 07:21:23 -08:00
|
|
|
}
|
2013-02-27 07:21:24 -08:00
|
|
|
waitForText(itemName);
|
2013-01-16 02:34:54 -08:00
|
|
|
mSolo.clickOnText(itemName);
|
2012-10-02 08:24:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-27 08:38:23 -07:00
|
|
|
public final void verifyHomePagerHidden() {
|
2013-09-10 18:10:29 -07:00
|
|
|
final View homePagerView = mSolo.getView("home_pager");
|
2013-08-27 08:38:23 -07:00
|
|
|
|
2013-09-10 18:10:43 -07:00
|
|
|
boolean rc = waitForCondition(new Condition() {
|
2013-08-27 08:38:23 -07:00
|
|
|
@Override
|
2013-09-10 18:10:43 -07:00
|
|
|
public boolean isSatisfied() {
|
2013-08-27 08:38:23 -07:00
|
|
|
return homePagerView.getVisibility() != View.VISIBLE;
|
|
|
|
}
|
|
|
|
}, MAX_WAIT_HOME_PAGER_HIDDEN_MS);
|
|
|
|
|
|
|
|
if (!rc) {
|
|
|
|
mAsserter.ok(rc, "Verify HomePager is hidden", "HomePager is hidden");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-02 08:24:38 -07:00
|
|
|
public final void verifyPageTitle(String title) {
|
2013-09-10 18:10:29 -07:00
|
|
|
final TextView urlBarTitle = (TextView) mSolo.getView(URL_BAR_TITLE_ID);
|
2012-12-03 04:14:27 -08:00
|
|
|
String pageTitle = null;
|
2013-07-18 16:02:48 -07:00
|
|
|
if (urlBarTitle != null) {
|
2012-12-03 04:14:27 -08:00
|
|
|
// Wait for the title to make sure it has been displayed in case the view
|
|
|
|
// does not update fast enough
|
2013-09-10 18:10:43 -07:00
|
|
|
waitForCondition(new VerifyTextViewText(urlBarTitle, title), MAX_WAIT_MS);
|
2013-09-10 18:10:29 -07:00
|
|
|
pageTitle = urlBarTitle.getText().toString();
|
2012-12-03 04:14:27 -08:00
|
|
|
}
|
|
|
|
mAsserter.is(pageTitle, title, "Page title is correct");
|
|
|
|
}
|
|
|
|
|
2012-10-02 08:24:38 -07:00
|
|
|
public final void verifyTabCount(int expectedTabCount) {
|
|
|
|
Activity activity = getActivity();
|
2013-04-26 16:17:34 -07:00
|
|
|
Element tabCount = mDriver.findElement(activity, "tabs_counter");
|
2012-10-02 08:24:38 -07:00
|
|
|
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-06-04 05:16:07 -07:00
|
|
|
// Used to perform clicks on pop-up buttons without having to close the virtual keyboard
|
|
|
|
public void clickOnButton(String label) {
|
|
|
|
final Button button = mSolo.getButton(label);
|
|
|
|
try {
|
|
|
|
runTestOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
button.performClick();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (Throwable throwable) {
|
|
|
|
mAsserter.ok(false, "Unable to click the button","Was unable to click button ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Used to hide/show the virtual keyboard
|
|
|
|
public void toggleVKB() {
|
|
|
|
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
|
|
|
|
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
|
|
|
|
}
|
|
|
|
|
2013-11-15 22:59:17 -08:00
|
|
|
public void addTab() {
|
2013-09-10 18:10:29 -07:00
|
|
|
mSolo.clickOnView(mSolo.getView("tabs"));
|
2012-11-15 04:54:46 -08:00
|
|
|
// wait for addTab to appear (this is usually immediate)
|
2013-09-10 18:10:43 -07:00
|
|
|
boolean success = waitForCondition(new Condition() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2013-09-10 18:10:43 -07:00
|
|
|
public boolean isSatisfied() {
|
2013-09-10 18:10:29 -07:00
|
|
|
View addTabView = mSolo.getView("add_tab");
|
2012-11-15 04:54:46 -08:00
|
|
|
if (addTabView == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}, MAX_WAIT_MS);
|
|
|
|
mAsserter.ok(success, "waiting for add tab view", "add tab view available");
|
2013-09-10 18:10:29 -07:00
|
|
|
final View addTabView = mSolo.getView("add_tab");
|
|
|
|
mSolo.clickOnView(mSolo.getView("add_tab"));
|
2013-11-15 22:59:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void addTab(String url) {
|
|
|
|
addTab();
|
2013-07-18 16:02:48 -07:00
|
|
|
|
2013-07-23 17:52:39 -07:00
|
|
|
// Adding a new tab opens about:home, so now we just need to load the url in it.
|
2013-08-19 13:33:49 -07:00
|
|
|
inputAndLoadUrl(url);
|
2012-11-15 04:54:46 -08:00
|
|
|
}
|
2012-12-03 04:14:27 -08:00
|
|
|
|
2013-11-15 22:59:17 -08:00
|
|
|
/**
|
|
|
|
* Gets the AdapterView of the tabs list.
|
|
|
|
*
|
|
|
|
* @return List view in the tabs tray
|
|
|
|
*/
|
|
|
|
private final AdapterView<ListAdapter> getTabsList() {
|
|
|
|
Element tabs = mDriver.findElement(getActivity(), "tabs");
|
|
|
|
tabs.click();
|
|
|
|
Element listElem = mDriver.findElement(getActivity(), "normal_tabs");
|
|
|
|
int listId = listElem.getId();
|
|
|
|
return (AdapterView<ListAdapter>) getActivity().findViewById(listId);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the view in the tabs tray at the specified index.
|
|
|
|
*
|
|
|
|
* @return View at index
|
|
|
|
*/
|
|
|
|
private View getTabViewAt(final int index) {
|
|
|
|
final View[] childView = { null };
|
|
|
|
|
|
|
|
final AdapterView<ListAdapter> view = getTabsList();
|
|
|
|
|
|
|
|
runOnUiThreadSync(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
view.setSelection(index);
|
|
|
|
|
|
|
|
// The selection isn't updated synchronously; posting a
|
|
|
|
// runnable to the view's queue guarantees we'll run after the
|
|
|
|
// layout pass.
|
|
|
|
view.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
// getChildAt() is relative to the list of visible
|
|
|
|
// views, but our index is relative to all views in the
|
|
|
|
// list. Subtract the first visible list position for
|
|
|
|
// the correct offset.
|
|
|
|
childView[0] = view.getChildAt(index - view.getFirstVisiblePosition());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
boolean result = waitForCondition(new Condition() {
|
|
|
|
@Override
|
|
|
|
public boolean isSatisfied() {
|
|
|
|
return childView[0] != null;
|
|
|
|
}
|
|
|
|
}, MAX_WAIT_MS);
|
|
|
|
|
|
|
|
mAsserter.ok(result, "list item at index " + index + " exists", null);
|
|
|
|
|
|
|
|
return childView[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Selects the tab at the specified index.
|
|
|
|
*
|
|
|
|
* @param index Index of tab to select
|
|
|
|
*/
|
|
|
|
public void selectTabAt(final int index) {
|
|
|
|
mSolo.clickOnView(getTabViewAt(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Closes the tab at the specified index.
|
|
|
|
*
|
|
|
|
* @param index Index of tab to close
|
|
|
|
*/
|
|
|
|
public void closeTabAt(final int index) {
|
|
|
|
Element close = mDriver.findElement(getActivity(), "close");
|
|
|
|
View closeButton = getTabViewAt(index).findViewById(close.getId());
|
|
|
|
|
|
|
|
mSolo.clickOnView(closeButton);
|
|
|
|
}
|
|
|
|
|
2013-03-21 18:43:04 -07:00
|
|
|
public final void runOnUiThreadSync(Runnable runnable) {
|
|
|
|
RobocopUtils.runOnUiThreadSync(mActivity, runnable);
|
|
|
|
}
|
|
|
|
|
2013-07-25 17:38:10 -07:00
|
|
|
/* Tap the "star" (bookmark) button to bookmark or un-bookmark the current page */
|
|
|
|
public void toggleBookmark() {
|
|
|
|
mActions.sendSpecialKey(Actions.SpecialKey.MENU);
|
|
|
|
waitForText("Settings");
|
|
|
|
|
|
|
|
// On ICS+ phones, there is no button labeled "Bookmarks"
|
|
|
|
// instead we have to just dig through every button on the screen
|
|
|
|
ArrayList<View> images = mSolo.getCurrentViews();
|
|
|
|
for (int i = 0; i < images.size(); i++) {
|
|
|
|
final View view = images.get(i);
|
|
|
|
boolean found = false;
|
|
|
|
found = "Bookmark".equals(view.getContentDescription());
|
|
|
|
|
|
|
|
// on older android versions, try looking at the button's text
|
|
|
|
if (!found) {
|
|
|
|
if (view instanceof TextView) {
|
|
|
|
found = "Bookmark".equals(((TextView)view).getText());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found) {
|
|
|
|
int[] xy = new int[2];
|
|
|
|
view.getLocationOnScreen(xy);
|
|
|
|
|
|
|
|
final int viewWidth = view.getWidth();
|
|
|
|
final int viewHeight = view.getHeight();
|
|
|
|
final float x = xy[0] + (viewWidth / 2.0f);
|
|
|
|
float y = xy[1] + (viewHeight / 2.0f);
|
|
|
|
|
|
|
|
mSolo.clickOnScreen(x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-13 05:37:48 -07:00
|
|
|
public void clearPrivateData() {
|
2013-08-21 07:11:13 -07:00
|
|
|
selectSettingsItem(StringHelper.PRIVACY_SECTION_LABEL, StringHelper.CLEAR_PRIVATE_DATA_LABEL);
|
2013-08-13 05:37:48 -07:00
|
|
|
Actions.EventExpecter clearData = mActions.expectGeckoEvent("Sanitize:Finished");
|
|
|
|
mSolo.clickOnText("Clear data");
|
|
|
|
clearData.blockForEvent();
|
|
|
|
clearData.unregisterListener();
|
2013-03-19 07:12:43 -07:00
|
|
|
}
|
|
|
|
|
2012-12-03 04:14:27 -08:00
|
|
|
class Device {
|
2013-04-22 04:23:20 -07:00
|
|
|
public final String version; // 2.x or 3.x or 4.x
|
2013-02-19 11:02:15 -08:00
|
|
|
public String type; // "tablet" or "phone"
|
2013-04-22 04:23:20 -07:00
|
|
|
public final int width;
|
|
|
|
public final int height;
|
2013-09-20 10:35:29 -07:00
|
|
|
public final float density;
|
2012-12-03 04:14:27 -08:00
|
|
|
|
|
|
|
public Device() {
|
|
|
|
// Determine device version
|
2013-04-22 04:23:20 -07:00
|
|
|
int sdk = Build.VERSION.SDK_INT;
|
|
|
|
if (sdk < Build.VERSION_CODES.HONEYCOMB) {
|
2012-12-03 04:14:27 -08:00
|
|
|
version = "2.x";
|
2013-02-19 11:02:15 -08:00
|
|
|
} else {
|
2013-04-22 04:23:20 -07:00
|
|
|
if (sdk > Build.VERSION_CODES.HONEYCOMB_MR2) {
|
2012-12-03 04:14:27 -08:00
|
|
|
version = "4.x";
|
2013-02-19 11:02:15 -08:00
|
|
|
} else {
|
2012-12-03 04:14:27 -08:00
|
|
|
version = "3.x";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Determine with and height
|
|
|
|
DisplayMetrics dm = new DisplayMetrics();
|
|
|
|
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
|
|
|
|
height = dm.heightPixels;
|
|
|
|
width = dm.widthPixels;
|
2013-09-20 10:35:29 -07:00
|
|
|
density = dm.density;
|
2012-12-03 04:14:27 -08:00
|
|
|
// Determine device type
|
2013-02-19 11:02:15 -08:00
|
|
|
type = "phone";
|
|
|
|
try {
|
2013-11-13 14:53:21 -08:00
|
|
|
if (GeckoAppShell.isTablet()) {
|
2013-02-19 11:02:15 -08:00
|
|
|
type = "tablet";
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
mAsserter.dumpLog("Exception in detectDevice", e);
|
2012-12-03 04:14:27 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void rotate() {
|
|
|
|
if (getActivity().getRequestedOrientation () == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
|
|
|
|
mSolo.setActivityOrientation(Solo.PORTRAIT);
|
2013-02-19 11:02:15 -08:00
|
|
|
} else {
|
2012-12-03 04:14:27 -08:00
|
|
|
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() {
|
2013-11-15 22:59:16 -08:00
|
|
|
Actions.EventExpecter pageShowExpecter = mActions.expectGeckoEvent("Content:PageShow");
|
|
|
|
|
2013-02-19 11:02:15 -08:00
|
|
|
if (devType.equals("tablet")) {
|
2012-12-03 04:14:27 -08:00
|
|
|
Element backBtn = mDriver.findElement(getActivity(), "back");
|
|
|
|
backBtn.click();
|
2013-02-19 11:02:15 -08:00
|
|
|
} else {
|
2012-12-03 04:14:27 -08:00
|
|
|
mActions.sendSpecialKey(Actions.SpecialKey.BACK);
|
|
|
|
}
|
2013-11-15 22:59:16 -08:00
|
|
|
|
|
|
|
pageShowExpecter.blockForEvent();
|
|
|
|
pageShowExpecter.unregisterListener();
|
2012-12-03 04:14:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void forward() {
|
2013-11-15 22:59:16 -08:00
|
|
|
Actions.EventExpecter pageShowExpecter = mActions.expectGeckoEvent("Content:PageShow");
|
|
|
|
|
2013-02-19 11:02:15 -08:00
|
|
|
if (devType.equals("tablet")) {
|
2012-12-03 04:14:27 -08:00
|
|
|
Element fwdBtn = mDriver.findElement(getActivity(), "forward");
|
|
|
|
fwdBtn.click();
|
2013-02-19 11:02:15 -08:00
|
|
|
} else {
|
2012-12-03 04:14:27 -08:00
|
|
|
mActions.sendSpecialKey(Actions.SpecialKey.MENU);
|
2013-02-27 07:21:24 -08:00
|
|
|
waitForText("^New Tab$");
|
2013-02-19 11:02:15 -08:00
|
|
|
if (!osVersion.equals("2.x")) {
|
2012-12-03 04:14:27 -08:00
|
|
|
Element fwdBtn = mDriver.findElement(getActivity(), "forward");
|
|
|
|
fwdBtn.click();
|
2013-02-19 11:02:15 -08:00
|
|
|
} else {
|
2012-12-03 04:14:27 -08:00
|
|
|
mSolo.clickOnText("^Forward$");
|
|
|
|
}
|
2013-11-15 22:59:16 -08:00
|
|
|
ensureMenuClosed();
|
2012-12-03 04:14:27 -08:00
|
|
|
}
|
2013-11-15 22:59:16 -08:00
|
|
|
|
|
|
|
pageShowExpecter.blockForEvent();
|
|
|
|
pageShowExpecter.unregisterListener();
|
2012-12-03 04:14:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void reload() {
|
2013-02-19 11:02:15 -08:00
|
|
|
if (devType.equals("tablet")) {
|
2012-12-03 04:14:27 -08:00
|
|
|
Element reloadBtn = mDriver.findElement(getActivity(), "reload");
|
|
|
|
reloadBtn.click();
|
2013-02-19 11:02:15 -08:00
|
|
|
} else {
|
2012-12-03 04:14:27 -08:00
|
|
|
mActions.sendSpecialKey(Actions.SpecialKey.MENU);
|
2013-02-27 07:21:24 -08:00
|
|
|
waitForText("^New Tab$");
|
2013-02-19 11:02:15 -08:00
|
|
|
if (!osVersion.equals("2.x")) {
|
2012-12-03 04:14:27 -08:00
|
|
|
Element reloadBtn = mDriver.findElement(getActivity(), "reload");
|
|
|
|
reloadBtn.click();
|
2013-02-19 11:02:15 -08:00
|
|
|
} else {
|
|
|
|
mSolo.clickOnText("^Reload$");
|
2012-12-03 04:14:27 -08:00
|
|
|
}
|
2013-11-15 22:59:16 -08:00
|
|
|
ensureMenuClosed();
|
2012-12-03 04:14:27 -08:00
|
|
|
}
|
|
|
|
}
|
2013-02-26 04:46:02 -08:00
|
|
|
|
2013-07-25 17:38:10 -07:00
|
|
|
// DEPRECATED!
|
|
|
|
// Use BaseTest.toggleBookmark() in new code.
|
2013-02-26 04:46:02 -08:00
|
|
|
public void bookmark() {
|
2013-08-19 07:11:09 -07:00
|
|
|
mActions.sendSpecialKey(Actions.SpecialKey.MENU);
|
|
|
|
waitForText("^New Tab$");
|
|
|
|
if (mSolo.searchText("^Bookmark$")) {
|
|
|
|
// This is the Android 2.x so the button has text
|
|
|
|
mSolo.clickOnText("^Bookmark$");
|
|
|
|
} else {
|
|
|
|
Element bookmarkBtn = mDriver.findElement(getActivity(), "bookmark");
|
|
|
|
if (bookmarkBtn != null) {
|
|
|
|
// We are on Android 4.x so the button is an image button
|
2013-02-26 04:46:02 -08:00
|
|
|
bookmarkBtn.click();
|
|
|
|
}
|
|
|
|
}
|
2013-11-15 22:59:16 -08:00
|
|
|
ensureMenuClosed();
|
|
|
|
}
|
|
|
|
|
|
|
|
// On some devices, the menu may not be dismissed after clicking on an
|
|
|
|
// item. Close it here.
|
|
|
|
private void ensureMenuClosed() {
|
|
|
|
if (mSolo.searchText("^New Tab$")) {
|
|
|
|
mActions.sendSpecialKey(Actions.SpecialKey.BACK);
|
|
|
|
}
|
2013-08-19 07:11:09 -07:00
|
|
|
}
|
2012-12-03 04:14:27 -08:00
|
|
|
}
|
2013-11-15 22:59:17 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the string representation of a stack trace.
|
|
|
|
*
|
|
|
|
* @param t Throwable to get stack trace for
|
|
|
|
* @return Stack trace as a string
|
|
|
|
*/
|
|
|
|
public static String getStackTraceString(Throwable t) {
|
|
|
|
StringWriter sw = new StringWriter();
|
|
|
|
t.printStackTrace(new PrintWriter(sw));
|
|
|
|
return sw.toString();
|
|
|
|
}
|
2013-11-19 11:57:35 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Condition class that waits for a view, and allows callers access it when done.
|
|
|
|
*/
|
|
|
|
private class DescriptionCondition<T extends View> implements Condition {
|
|
|
|
public T mView;
|
|
|
|
private String mDescr;
|
|
|
|
private Class<T> mCls;
|
|
|
|
|
|
|
|
public DescriptionCondition(Class<T> cls, String descr) {
|
|
|
|
mDescr = descr;
|
|
|
|
mCls = cls;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isSatisfied() {
|
|
|
|
mView = findViewWithContentDescription(mCls, mDescr);
|
2013-11-22 14:13:23 -08:00
|
|
|
return (mView != null);
|
2013-11-19 11:57:35 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wait for a view with the specified description .
|
|
|
|
*/
|
|
|
|
public <T extends View> T waitForViewWithDescription(Class<T> cls, String description) {
|
|
|
|
DescriptionCondition<T> c = new DescriptionCondition<T>(cls, description);
|
|
|
|
waitForCondition(c, MAX_WAIT_ENABLED_TEXT_MS);
|
|
|
|
return c.mView;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an active view with the specified description .
|
|
|
|
*/
|
|
|
|
public <T extends View> T findViewWithContentDescription(Class<T> cls, String description) {
|
|
|
|
for (T view : mSolo.getCurrentViews(cls)) {
|
|
|
|
final String descr = (String) view.getContentDescription();
|
|
|
|
if (TextUtils.isEmpty(descr)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TextUtils.equals(description, descr)) {
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2012-01-05 07:20:22 -08:00
|
|
|
}
|