merge heads

This commit is contained in:
Jimmy Shih
2012-07-25 11:10:51 -07:00
5 changed files with 177 additions and 125 deletions
@@ -113,33 +113,38 @@ public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2<Tra
} }
} }
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.send_google_send_now), true, true); EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.send_google_send_now),
true, true);
// If no account is binded with this device. // If no account is binded with this device.
if (EndToEndTestUtils.SOLO.waitForText(activityMyTracks if (EndToEndTestUtils.SOLO.waitForText(
.getString(R.string.send_google_no_account_title), 1, EndToEndTestUtils.SHORT_WAIT_TIME)) { activityMyTracks.getString(R.string.send_google_no_account_title), 1,
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true); EndToEndTestUtils.SHORT_WAIT_TIME)) {
} else if (EndToEndTestUtils.SOLO.waitForText(activityMyTracks EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true,
.getString(R.string.send_google_no_account_permission), 1, EndToEndTestUtils.SHORT_WAIT_TIME)) { true);
} else { } else if (EndToEndTestUtils.SOLO.waitForText(
activityMyTracks.getString(R.string.send_google_no_account_permission), 1,
EndToEndTestUtils.SHORT_WAIT_TIME)) {} else {
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks
.getString(R.string.generic_progress_title))); .getString(R.string.generic_progress_title)));
// Waiting the send is finish. // Waiting the send is finish.
while (EndToEndTestUtils.SOLO.waitForText(activityMyTracks while (EndToEndTestUtils.SOLO.waitForText(
.getString(R.string.generic_progress_title), 1, EndToEndTestUtils.SHORT_WAIT_TIME)) { activityMyTracks.getString(R.string.generic_progress_title), 1,
} EndToEndTestUtils.SHORT_WAIT_TIME)) {}
// Check whether the result dialog is display. // Check whether the result dialog is display.
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks
.getString(R.string.share_track_share_url))); .getString(R.string.share_track_share_url)));
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true); EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true,
true);
// Check whether all data is correct on Google Map, Documents, and Spreadsheet. // Check whether all data is correct on Google Map, Documents, and
// Spreadsheet.
assertTrue(GoogleUtils.deleteMap(EndToEndTestUtils.trackName, activityMyTracks)); assertTrue(GoogleUtils.deleteMap(EndToEndTestUtils.trackName, activityMyTracks));
assertTrue(GoogleUtils.searchFusionTableByTitle(EndToEndTestUtils.TRACK_NAME_PREFIX, assertTrue(GoogleUtils.searchFusionTableByTitle(EndToEndTestUtils.TRACK_NAME_PREFIX,
activityMyTracks)); activityMyTracks));
assertTrue(GoogleUtils.searchTrackTitleInSpreadsheet(EndToEndTestUtils.trackName, assertTrue(GoogleUtils
activityMyTracks, GoogleUtils.SPREADSHEET_NAME, true)); .deleteTrackInSpreadSheet(EndToEndTestUtils.trackName, activityMyTracks));
assertTrue(GoogleUtils.dropFusionTables(EndToEndTestUtils.trackName, activityMyTracks)); assertTrue(GoogleUtils.dropFusionTables(EndToEndTestUtils.trackName, activityMyTracks));
} }
@@ -182,6 +187,23 @@ public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2<Tra
assertTrue(EndToEndTestUtils.SOLO.searchText(newDesc)); assertTrue(EndToEndTestUtils.SOLO.searchText(newDesc));
} }
/**
* Checks the voice frequency and split frequency menus.
*/
public void testFrequencyMenu() {
EndToEndTestUtils.startRecording();
assertTrue(EndToEndTestUtils.findMenuItem(
activityMyTracks.getString(R.string.menu_voice_frequency), false));
assertTrue(EndToEndTestUtils.findMenuItem(
activityMyTracks.getString(R.string.menu_split_frequency), false));
EndToEndTestUtils.stopRecording(true);
assertFalse(EndToEndTestUtils.findMenuItem(
activityMyTracks.getString(R.string.menu_voice_frequency), false));
assertFalse(EndToEndTestUtils.findMenuItem(
activityMyTracks.getString(R.string.menu_split_frequency), false));
}
/** /**
* Creates one track with a two locations, a way point and a statistics point. * Creates one track with a two locations, a way point and a statistics point.
*/ */
@@ -195,6 +217,7 @@ public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2<Tra
assertTrue(EndToEndTestUtils.SOLO.searchText(activityMyTracks assertTrue(EndToEndTestUtils.SOLO.searchText(activityMyTracks
.getString(R.string.icon_recording))); .getString(R.string.icon_recording)));
} }
createWaypoint(); createWaypoint();
EndToEndTestUtils.sendGps(2); EndToEndTestUtils.sendGps(2);
// Back to tracks list. // Back to tracks list.
@@ -204,17 +227,15 @@ public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2<Tra
EndToEndTestUtils.stopRecording(false); EndToEndTestUtils.stopRecording(false);
EndToEndTestUtils.trackName = EndToEndTestUtils.TRACK_NAME_PREFIX + System.currentTimeMillis(); EndToEndTestUtils.trackName = EndToEndTestUtils.TRACK_NAME_PREFIX + System.currentTimeMillis();
EndToEndTestUtils.SOLO.enterText(0, EndToEndTestUtils.trackName); EndToEndTestUtils.SOLO.enterText(0, EndToEndTestUtils.trackName);
EndToEndTestUtils.SOLO.enterText(0, EndToEndTestUtils.DEFAULTACTIVITY); EndToEndTestUtils.SOLO.enterText(1, EndToEndTestUtils.DEFAULTACTIVITY);
if(!EndToEndTestUtils.isEmulator) {
// Close soft keyboard.
EndToEndTestUtils.SOLO.goBack();
}
EndToEndTestUtils.SOLO.clickOnButton(activityMyTracks.getString(R.string.generic_save)); EndToEndTestUtils.SOLO.clickOnButton(activityMyTracks.getString(R.string.generic_save));
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
// Check the new track // Check the new track
assertTrue(EndToEndTestUtils.SOLO.waitForText(EndToEndTestUtils.trackName, 1, 5000, true, EndToEndTestUtils.SOLO.scrollUp();
false)); assertTrue(EndToEndTestUtils.SOLO.waitForText(EndToEndTestUtils.trackName, 1,
EndToEndTestUtils.NORMAL_WAIT_TIME, true, false));
} }
/** /**
@@ -283,10 +304,6 @@ public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2<Tra
// Rotate when show insert page. // Rotate when show insert page.
EndToEndTestUtils.rotateAllActivities(); EndToEndTestUtils.rotateAllActivities();
EndToEndTestUtils.SOLO.enterText(0, WAYPOINT_NAME); EndToEndTestUtils.SOLO.enterText(0, WAYPOINT_NAME);
if(!EndToEndTestUtils.isEmulator) {
// Close soft keyboard.
EndToEndTestUtils.SOLO.goBack();
}
EndToEndTestUtils.SOLO.clickOnButton(activityMyTracks.getString(R.string.generic_add)); EndToEndTestUtils.SOLO.clickOnButton(activityMyTracks.getString(R.string.generic_add));
if (!EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.marker_add_error), if (!EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.marker_add_error),
1, EndToEndTestUtils.SHORT_WAIT_TIME)) { 1, EndToEndTestUtils.SHORT_WAIT_TIME)) {
@@ -62,9 +62,11 @@ public class DeleteTest extends ActivityInstrumentationTestCase2<TrackListActivi
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_delete_all), true); EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_delete_all), true);
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
EndToEndTestUtils.rotateAllActivities(); EndToEndTestUtils.rotateAllActivities();
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true); EndToEndTestUtils
.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.track_list_empty_message))); assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks
.getString(R.string.track_list_empty_message)));
// There is no track now. // There is no track now.
trackListView = EndToEndTestUtils.SOLO.getCurrentListViews(); trackListView = EndToEndTestUtils.SOLO.getCurrentListViews();
assertEquals(0, trackListView.get(0).getCount()); assertEquals(0, trackListView.get(0).getCount());
@@ -75,7 +77,8 @@ public class DeleteTest extends ActivityInstrumentationTestCase2<TrackListActivi
EndToEndTestUtils.GPX.toUpperCase())); EndToEndTestUtils.GPX.toUpperCase()));
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks
.getString(R.string.sd_card_save_error_no_track))); .getString(R.string.sd_card_save_error_no_track)));
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true); EndToEndTestUtils
.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
} }
/** /**
@@ -91,7 +94,7 @@ public class DeleteTest extends ActivityInstrumentationTestCase2<TrackListActivi
EndToEndTestUtils.SOLO.clickOnView(trackListView.get(0).getChildAt(0)); EndToEndTestUtils.SOLO.clickOnView(trackListView.get(0).getChildAt(0));
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_delete), true); EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_delete), true);
EndToEndTestUtils EndToEndTestUtils
.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true); .getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
trackListView = EndToEndTestUtils.SOLO.getCurrentListViews(); trackListView = EndToEndTestUtils.SOLO.getCurrentListViews();
int trackNumberNew = trackListView.get(0).getCount(); int trackNumberNew = trackListView.get(0).getCount();
@@ -23,10 +23,13 @@ import com.jayway.android.robotium.solo.Solo;
import android.app.Activity; import android.app.Activity;
import android.app.Instrumentation; import android.app.Instrumentation;
import android.content.Context;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.TextView; import android.widget.TextView;
@@ -198,28 +201,27 @@ public class EndToEndTestUtils {
setIsEmulator(); setIsEmulator();
EndToEndTestUtils.instrumentation = instrumentation; EndToEndTestUtils.instrumentation = instrumentation;
EndToEndTestUtils.activityMytracks = activityMyTracks; EndToEndTestUtils.activityMytracks = activityMyTracks;
EndToEndTestUtils.SOLO = new Solo(EndToEndTestUtils.instrumentation, SOLO = new Solo(EndToEndTestUtils.instrumentation,
EndToEndTestUtils.activityMytracks); EndToEndTestUtils.activityMytracks);
// Check if open MyTracks first time after install. If so, there would be a // Check if open MyTracks first time after install. If so, there would be a
// welcome view with accept buttons. And makes sure only check once. // welcome view with accept buttons. And makes sure only check once.
if (!EndToEndTestUtils.isCheckedFirstLaunch) { if (!isCheckedFirstLaunch) {
if ((EndToEndTestUtils.getButtonOnScreen(EndToEndTestUtils.activityMytracks if ((getButtonOnScreen(EndToEndTestUtils.activityMytracks
.getString(R.string.eula_accept), false, false) != null)) { .getString(R.string.eula_accept), false, false) != null)) {
EndToEndTestUtils.verifyFirstLaunch(); verifyFirstLaunch();
} else if (EndToEndTestUtils.SOLO.waitForText( } else if (SOLO.waitForText(
// After reset setting, welcome page will show again. // After reset setting, welcome page will show again.
activityMytracks.getString(R.string.welcome_title), 0, EndToEndTestUtils.SHORT_WAIT_TIME)) { activityMytracks.getString(R.string.welcome_title), 0, SHORT_WAIT_TIME)) {
resetPreferredUnits(); resetPreferredUnits();
} }
checkLanguage(); checkLanguage();
EndToEndTestUtils.isCheckedFirstLaunch = true; isCheckedFirstLaunch = true;
EndToEndTestUtils.setHasActionBar(); setHasActionBar();
// Make the test is totally new. deleteAllTracks();
EndToEndTestUtils.deleteAllTracks(); resetAllSettings(activityMyTracks, false);
EndToEndTestUtils.resetAllSettings(activityMyTracks, false); } else if (SOLO.waitForText(
} else if (EndToEndTestUtils.SOLO.waitForText(
// After reset setting, welcome page will show again. // After reset setting, welcome page will show again.
activityMytracks.getString(R.string.welcome_title), 0, EndToEndTestUtils.SHORT_WAIT_TIME)) { activityMytracks.getString(R.string.welcome_title), 0, SHORT_WAIT_TIME)) {
resetPreferredUnits(); resetPreferredUnits();
} }
@@ -274,7 +276,7 @@ public class EndToEndTestUtils {
*/ */
static void createSimpleTrack(int numberOfGpsData) { static void createSimpleTrack(int numberOfGpsData) {
startRecording(); startRecording();
EndToEndTestUtils.sendGps(numberOfGpsData); sendGps(numberOfGpsData);
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
stopRecording(true); stopRecording(true);
} }
@@ -309,12 +311,12 @@ public class EndToEndTestUtils {
* activity * activity
*/ */
static void createTrackIfEmpty(int gpsNumber, boolean showTrackList) { static void createTrackIfEmpty(int gpsNumber, boolean showTrackList) {
if (EndToEndTestUtils.isTrackListEmpty(!showTrackList)) { if (isTrackListEmpty(!showTrackList)) {
// Create a simple track. // Create a simple track.
EndToEndTestUtils.createSimpleTrack(gpsNumber); createSimpleTrack(gpsNumber);
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
if (showTrackList) { if (showTrackList) {
EndToEndTestUtils.SOLO.goBack(); SOLO.goBack();
} }
} }
} }
@@ -383,19 +385,15 @@ public class EndToEndTestUtils {
SOLO.clickOnText(activityMytracks.getString(R.string.menu_stop_recording)); SOLO.clickOnText(activityMytracks.getString(R.string.menu_stop_recording));
} }
if (isSave) { if (isSave) {
EndToEndTestUtils.SOLO.waitForText(activityMytracks.getString(R.string.generic_save), 1, EndToEndTestUtils.NORMAL_WAIT_TIME); SOLO.waitForText(activityMytracks.getString(R.string.generic_save), 1, 5000);
// Make every track name is unique to make sure every check can be // Make every track name is unique to make sure every check can be
// trusted. // trusted.
EndToEndTestUtils.trackName = EndToEndTestUtils.TRACK_NAME_PREFIX trackName = TRACK_NAME_PREFIX
+ System.currentTimeMillis(); + System.currentTimeMillis();
SOLO.sendKey(KeyEvent.KEYCODE_DEL); SOLO.sendKey(KeyEvent.KEYCODE_DEL);
SOLO.enterText(0, trackName); SOLO.enterText(0, trackName);
SOLO.enterText(1, DEFAULTACTIVITY); SOLO.enterText(1, DEFAULTACTIVITY);
if(!EndToEndTestUtils.isEmulator) { SOLO.clickOnText(activityMytracks.getString(R.string.generic_save));
// Close soft keyboard.
EndToEndTestUtils.SOLO.goBack();
}
SOLO.clickLongOnText(activityMytracks.getString(R.string.generic_save));
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
} }
} }
@@ -416,11 +414,13 @@ public class EndToEndTestUtils {
} }
/** /**
* Deletes all tracks. This method should be call when the TracksListActivity is shown. * Deletes all tracks. This method should be call when the TracksListActivity
* is shown.
*/ */
static void deleteAllTracks() { static void deleteAllTracks() {
EndToEndTestUtils.findMenuItem(activityMytracks.getString(R.string.menu_delete_all), true); EndToEndTestUtils.findMenuItem(activityMytracks.getString(R.string.menu_delete_all), true);
EndToEndTestUtils.getButtonOnScreen(activityMytracks.getString(R.string.generic_ok), true, true); EndToEndTestUtils
.getButtonOnScreen(activityMytracks.getString(R.string.generic_ok), true, true);
} }
/** /**
@@ -511,7 +511,7 @@ public class EndToEndTestUtils {
* Rotates the current activity. * Rotates the current activity.
*/ */
static void rotateCurrentActivity() { static void rotateCurrentActivity() {
EndToEndTestUtils.rotateActivity(SOLO.getCurrentActivity()); rotateActivity(SOLO.getCurrentActivity());
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
} }
@@ -519,14 +519,13 @@ public class EndToEndTestUtils {
* Rotates all activities. * Rotates all activities.
*/ */
static void rotateAllActivities() { static void rotateAllActivities() {
if(hasActionBar) { if (hasActionBar) {
ArrayList<Activity> allActivities = SOLO.getAllOpenedActivities(); ArrayList<Activity> allActivities = SOLO.getAllOpenedActivities();
for (Activity activity : allActivities) { for (Activity activity : allActivities) {
EndToEndTestUtils.rotateActivity(activity); rotateActivity(activity);
} }
instrumentation.waitForIdleSync();
} }
instrumentation.waitForIdleSync();
} }
/** /**
@@ -536,49 +535,48 @@ public class EndToEndTestUtils {
* @param click true means need click this menu * @param click true means need click this menu
* @return true if find this menu * @return true if find this menu
*/ */
static boolean findMenuItem(String menuName, boolean click) { static boolean findMenuItem(String menuName, boolean click) {boolean findResult = false;
boolean findResult = false; boolean isMoreMenuOpened = false;
boolean isMoreMenuOpened = false;
// ICS phone. // ICS phone.
if(hasActionBar) { if(hasActionBar) {
// Firstly find in action bar. // Firstly find in action bar.
Button button = getButtonOnScreen(menuName, false, false); Button button = getButtonOnScreen(menuName, false, false);
if (button != null) { if (button != null) {
findResult = true; findResult = true;
if (click) { if (click) {
SOLO.clickOnView(button); SOLO.clickOnView(button);
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
}
return findResult;
}
showMenuItem();
findResult = SOLO.searchText(menuName);
} else {
// Non-ICS phone.
SOLO.sendKey(KeyEvent.KEYCODE_MENU);
if (SOLO.searchText(menuName)) {
findResult = true;
} else if (SOLO.searchText(MENU_MORE)) {
SOLO.clickOnText(MENU_MORE);
findResult = SOLO.searchText(menuName);
isMoreMenuOpened = true;
} }
return findResult;
} }
showMenuItem();
findResult = SOLO.searchText(menuName);
} else {
// Non-ICS phone.
SOLO.sendKey(KeyEvent.KEYCODE_MENU);
if (SOLO.searchText(menuName)) {
findResult = true;
} else if (SOLO.searchText(MENU_MORE)) {
SOLO.clickOnText(MENU_MORE);
findResult = SOLO.searchText(menuName);
isMoreMenuOpened = true;
}
}
if (findResult && click) { if (findResult && click) {
SOLO.clickOnText(menuName); SOLO.clickOnText(menuName);
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
} else { } else {
// Quit more menu list if opened. // Quit more menu list if opened.
if (isMoreMenuOpened) { if (isMoreMenuOpened) {
SOLO.goBack();
}
// Quit menu list.
SOLO.goBack(); SOLO.goBack();
} }
return findResult; // Quit menu list.
SOLO.goBack();
} }
return findResult;
}
/** /**
* Show menu item list. * Show menu item list.
@@ -586,6 +584,7 @@ public class EndToEndTestUtils {
public static void showMenuItem() { public static void showMenuItem() {
showMenuItem(0); showMenuItem(0);
} }
/** /**
* Gets more menu items operation is different for different Android OS. When * Gets more menu items operation is different for different Android OS. When
* get overflow button view on action, it usually be able to click. But in * get overflow button view on action, it usually be able to click. But in
@@ -645,7 +644,7 @@ public class EndToEndTestUtils {
* @return the text view, null means can not find it * @return the text view, null means can not find it
*/ */
static TextView findTextView(String findText, View parent) { static TextView findTextView(String findText, View parent) {
ArrayList<TextView> textViews = EndToEndTestUtils.SOLO.getCurrentTextViews(parent); ArrayList<TextView> textViews = SOLO.getCurrentTextViews(parent);
for (TextView textView : textViews) { for (TextView textView : textViews) {
String text = (String) textView.getText(); String text = (String) textView.getText();
if (textView.isShown() && text.endsWith(findText)) { if (textView.isShown() && text.endsWith(findText)) {
@@ -661,7 +660,7 @@ public class EndToEndTestUtils {
* @return the ChartView or null if not find * @return the ChartView or null if not find
*/ */
static ChartView getChartView() { static ChartView getChartView() {
ArrayList<View> views = EndToEndTestUtils.SOLO.getViews(); ArrayList<View> views = SOLO.getViews();
for (View view : views) { for (View view : views) {
if (view instanceof ChartView) { if (view instanceof ChartView) {
return (ChartView) view; return (ChartView) view;
@@ -677,14 +676,24 @@ public class EndToEndTestUtils {
* @param keepInSettingList whether keep in setting list or not * @param keepInSettingList whether keep in setting list or not
*/ */
public static void resetAllSettings(Activity activityMyTracks, boolean keepInSettingList) { public static void resetAllSettings(Activity activityMyTracks, boolean keepInSettingList) {
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true); findMenuItem(activityMyTracks.getString(R.string.menu_settings), true);
SOLO.waitForText(activityMyTracks.getString(R.string.settings_reset)); SOLO.waitForText(activityMyTracks.getString(R.string.settings_reset));
SOLO.clickOnText(activityMyTracks.getString(R.string.settings_reset)); SOLO.clickOnText(activityMyTracks.getString(R.string.settings_reset));
getButtonOnScreen(activityMytracks.getString(R.string.generic_ok), true, true); getButtonOnScreen(activityMytracks.getString(R.string.generic_ok), true, true);
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
if (!keepInSettingList) { if (!keepInSettingList) {
EndToEndTestUtils.SOLO.goBack(); SOLO.goBack();
} }
} }
/**
* Hides soft key board when input text in an exit text.
* @param myEditText
* @param context
*/
public static void hideSoftKeyBoard(EditText myEditText, Context context) {
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
}
} }
@@ -62,17 +62,20 @@ import java.util.Locale;
* @author Youtao Liu * @author Youtao Liu
*/ */
public class GoogleUtils { public class GoogleUtils {
private static Account account;
public static final String LOG_TAG = "MyTracksTest"; public static final String LOG_TAG = "MyTracksTest";
public static final String DOCUMENT_NAME_PREFIX = "My Tracks"; public static final String DOCUMENT_NAME_PREFIX = "My Tracks";
public static final String SPREADSHEET_NAME = DOCUMENT_NAME_PREFIX + "-" + EndToEndTestUtils.DEFAULTACTIVITY; public static final String SPREADSHEET_NAME = DOCUMENT_NAME_PREFIX + "-" + EndToEndTestUtils.DEFAULTACTIVITY;
/**
* Gets the account to access Google Services.
*
* @param context context used to get account
* @return the first account which is bound with current device
*/
private static Account getAccount(Context context) { private static Account getAccount(Context context) {
return account == null ? account = AccountManager.get(context).getAccountsByType( return AccountManager.get(context).getAccountsByType(Constants.ACCOUNT_TYPE)[0];
Constants.ACCOUNT_TYPE)[0] : account;
} }
/** /**
* Gets Google maps of a user. * Gets Google maps of a user.
* *
@@ -81,7 +84,6 @@ public class GoogleUtils {
* @return true means set successfully * @return true means set successfully
*/ */
private static ArrayList<MapsMapMetadata> getMaps(Context context, MapsClient mapsClient) { private static ArrayList<MapsMapMetadata> getMaps(Context context, MapsClient mapsClient) {
// Reset the per request states
String authToken = null; String authToken = null;
ArrayList<String> mapIds = new ArrayList<String>(); ArrayList<String> mapIds = new ArrayList<String>();
ArrayList<MapsMapMetadata> mapData = new ArrayList<MapsMapMetadata>(); ArrayList<MapsMapMetadata> mapData = new ArrayList<MapsMapMetadata>();
@@ -176,7 +178,7 @@ public class GoogleUtils {
* @param activity to get context * @param activity to get context
* @return the entry of the document, null means can not find the spreadsheet. * @return the entry of the document, null means can not find the spreadsheet.
*/ */
private static Entry searchSepeadsheetByTitle(String title, Activity activity) { private static Entry searchSpreadsheetByTitle(String title, Activity activity) {
Context context = activity.getApplicationContext(); Context context = activity.getApplicationContext();
DocumentsClient documentsClient = new DocumentsClient( DocumentsClient documentsClient = new DocumentsClient(
GDataClientFactory.getGDataClient(context), GDataClientFactory.getGDataClient(context),
@@ -214,8 +216,8 @@ public class GoogleUtils {
* @param isDelete whether delete the information of this track in the document * @param isDelete whether delete the information of this track in the document
* @return true means find the track name in the spreadsheet * @return true means find the track name in the spreadsheet
*/ */
public static boolean searchTrackTitleInSpreadsheet(String title, Activity activity, String spreadsheetTitle, boolean isDelete) { private static boolean searchTrackTitleInSpreadsheet(String title, Activity activity, String spreadsheetTitle, boolean isDelete) {
String spreadsheetId = searchSepeadsheetByTitle(spreadsheetTitle, activity).getId().replace(SendDocsUtils.SPREADSHEET_ID_PREFIX, ""); String spreadsheetId = searchSpreadsheetByTitle(spreadsheetTitle, activity).getId().replace(SendDocsUtils.SPREADSHEET_ID_PREFIX, "");
if(spreadsheetId == null) { if(spreadsheetId == null) {
Log.d(LOG_TAG, "Unable to find the spreadsheet -- " + spreadsheetTitle); Log.d(LOG_TAG, "Unable to find the spreadsheet -- " + spreadsheetTitle);
return false; return false;
@@ -250,6 +252,28 @@ public class GoogleUtils {
return false; return false;
} }
/**
* Searches a track in spreadsheet.
*
* @param title the track name to search
* @param activity to get context
* @return true means find the track name in the spreadsheet
*/
public static boolean searchTrackInSpreadSheet(String title, Activity activity) {
return searchTrackTitleInSpreadsheet(title, activity, GoogleUtils.SPREADSHEET_NAME, false);
}
/**
* Searches and deletes a track in spreadsheet.
*
* @param title the track name to search
* @param activity to get context
* @return true means find and delete successfully
*/
public static boolean deleteTrackInSpreadSheet(String title, Activity activity) {
return searchTrackTitleInSpreadsheet(title, activity, GoogleUtils.SPREADSHEET_NAME, true);
}
/** /**
* Searches a fusion table in user's Google tables. * Searches a fusion table in user's Google tables.
* *
@@ -276,6 +300,7 @@ public class GoogleUtils {
* *
* @param title the title of a track to drop * @param title the title of a track to drop
* @param activity to get context * @param activity to get context
* @return the result of drop
*/ */
public static boolean dropFusionTables(String title, Activity activity) { public static boolean dropFusionTables(String title, Activity activity) {
Context context = activity.getApplicationContext(); Context context = activity.getApplicationContext();
@@ -280,12 +280,11 @@ public class SettingTest extends ActivityInstrumentationTestCase2<TrackListActiv
// Changes the setting of default activity. // Changes the setting of default activity.
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
.getString(R.string.settings_recording_default_activity)); .getString(R.string.settings_recording_default_activity));
EndToEndTestUtils.hideSoftKeyBoard(EndToEndTestUtils.SOLO.getEditText(0),
activityMyTracks.getApplicationContext());
EndToEndTestUtils.SOLO.enterText(0, EndToEndTestUtils.DEFAULTACTIVITY); EndToEndTestUtils.SOLO.enterText(0, EndToEndTestUtils.DEFAULTACTIVITY);
if(!EndToEndTestUtils.isEmulator) { EndToEndTestUtils
// Close soft keyboard. .getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
EndToEndTestUtils.SOLO.goBack();
}
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
EndToEndTestUtils.SOLO.goBack(); EndToEndTestUtils.SOLO.goBack();
EndToEndTestUtils.SOLO.goBack(); EndToEndTestUtils.SOLO.goBack();
@@ -298,7 +297,6 @@ public class SettingTest extends ActivityInstrumentationTestCase2<TrackListActiv
R.string.track_name_format).split(" ")[0])); R.string.track_name_format).split(" ")[0]));
assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.DEFAULTACTIVITY)); assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.DEFAULTACTIVITY));
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.generic_save)); EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.generic_save));
} }
@Override @Override