Add code to drop the maps data, fusion table table of a track after send it Google. Change some code to make end-to-end tests run more stable.

This commit is contained in:
youtaol
2012-07-05 18:49:58 +08:00
parent 72273b7a85
commit 453dd01928
4 changed files with 69 additions and 6 deletions
@@ -124,7 +124,7 @@ public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2<Tra
.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(activityMyTracks
.getString(R.string.generic_progress_title), 1, 500)) { .getString(R.string.generic_progress_title), 1, 2000)) {
} }
// Check whether the result dialog is display. // Check whether the result dialog is display.
@@ -136,6 +136,8 @@ public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2<Tra
assertTrue(GoogleUtils.searchMapByTitle(EndToEndTestUtils.trackName, activityMyTracks)); assertTrue(GoogleUtils.searchMapByTitle(EndToEndTestUtils.trackName, activityMyTracks));
assertTrue(GoogleUtils.searchFusionTableByTitle(EndToEndTestUtils.TRACK_NAME_PREFIX, activityMyTracks)); assertTrue(GoogleUtils.searchFusionTableByTitle(EndToEndTestUtils.TRACK_NAME_PREFIX, activityMyTracks));
assertTrue(GoogleUtils.searchTrackTitleInSpreadsheet(EndToEndTestUtils.trackName, activityMyTracks, "My Tracks-" + EndToEndTestUtils.DEFAULTACTIVITY)); assertTrue(GoogleUtils.searchTrackTitleInSpreadsheet(EndToEndTestUtils.trackName, activityMyTracks, "My Tracks-" + EndToEndTestUtils.DEFAULTACTIVITY));
GoogleUtils.dropMaps(EndToEndTestUtils.trackName, activityMyTracks);
GoogleUtils.dropFusionTables(EndToEndTestUtils.trackName, activityMyTracks);
} }
} }
@@ -359,12 +359,15 @@ public class EndToEndTestUtils {
+ System.currentTimeMillis(); + System.currentTimeMillis();
SOLO.sendKey(KeyEvent.KEYCODE_DEL); SOLO.sendKey(KeyEvent.KEYCODE_DEL);
SOLO.enterText(0, trackName); SOLO.enterText(0, trackName);
SOLO.clickOnEditText(1);
SOLO.sendKey(KeyEvent.KEYCODE_DEL);
SOLO.enterText(1, DEFAULTACTIVITY); SOLO.enterText(1, DEFAULTACTIVITY);
if(!EndToEndTestUtils.isEmulator) { if(!EndToEndTestUtils.isEmulator) {
// Close soft keyboard. // Close soft keyboard.
EndToEndTestUtils.SOLO.goBack(); EndToEndTestUtils.SOLO.goBack();
} }
SOLO.clickLongOnText(activityMytracks.getString(R.string.generic_save)); SOLO.clickLongOnText(activityMytracks.getString(R.string.generic_save));
instrumentation.waitForIdleSync();
} }
} }
@@ -50,6 +50,7 @@ import android.content.Context;
import android.util.Log; import android.util.Log;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Locale; import java.util.Locale;
@@ -74,6 +75,9 @@ public class GoogleUtils {
* @return true means set successfully * @return true means set successfully
*/ */
private static boolean getMaps(Context context) { private static boolean getMaps(Context context) {
account = AccountManager.get(context).getAccountsByType(
Constants.ACCOUNT_TYPE)[0];
// Reset the per request states // Reset the per request states
authToken = null; authToken = null;
mapIds = new ArrayList<String>(); mapIds = new ArrayList<String>();
@@ -118,8 +122,6 @@ public class GoogleUtils {
* @return true means find the map * @return true means find the map
*/ */
static boolean searchMapByTitle(String title, Activity activity) { static boolean searchMapByTitle(String title, Activity activity) {
account = AccountManager.get(activity.getApplicationContext()).getAccountsByType(
Constants.ACCOUNT_TYPE)[0];
if (getMaps(activity.getApplicationContext())) { if (getMaps(activity.getApplicationContext())) {
for (MapsMapMetadata oneData : mapData) { for (MapsMapMetadata oneData : mapData) {
if (oneData.getTitle().indexOf(title) > -1) { if (oneData.getTitle().indexOf(title) > -1) {
@@ -129,6 +131,36 @@ public class GoogleUtils {
} }
return false; return false;
} }
/**
* Drops map which contain the string in title and is created by My Tracks on Google Maps.
*
* @param title the title of track to drop
* @param activity activity to get context
*/
static void dropMaps(String title, Activity activity) {
Context context = activity.getApplicationContext();
// Get all maps at first.
getMaps(context);
// Drop maps.
MapsClient mapsClient = new MapsClient(GDataClientFactory.getGDataClient(context),
new XmlMapsGDataParserFactory(new AndroidXmlParserFactory()));
for (MapsMapMetadata oneData : mapData) {
// Only drop maps created by My Tracks.
if (oneData.getDescription().indexOf("My Tracks") > -1 && oneData.getTitle().indexOf(title) > -1) {
try {
account = AccountManager.get(context).getAccountsByType(Constants.ACCOUNT_TYPE)[0];
authToken = AccountManager.get(context).blockingGetAuthToken(account,
MapsConstants.SERVICE_NAME, false);
mapsClient.deleteEntry(oneData.getGDataEditUri(), authToken);
} catch (Exception e) {
Log.d(LOG_TAG, "Unable to drop map", e);
}
}
}
}
/** /**
* Searches a doc in user's Google Documents. * Searches a doc in user's Google Documents.
@@ -217,7 +249,6 @@ public class GoogleUtils {
*/ */
static boolean searchFusionTableByTitle(String title, Activity activity) { static boolean searchFusionTableByTitle(String title, Activity activity) {
Context context = activity.getApplicationContext(); Context context = activity.getApplicationContext();
account = AccountManager.get(context).getAccountsByType(Constants.ACCOUNT_TYPE)[0];
try { try {
HttpResponse response = sendFusionTableQuery("SHOW TABLES", context); HttpResponse response = sendFusionTableQuery("SHOW TABLES", context);
// We can use index of method to check new table for every track name is unique. // We can use index of method to check new table for every track name is unique.
@@ -230,6 +261,31 @@ public class GoogleUtils {
return false; return false;
} }
/**
* Remove one fusion table which contain the string in title of current user.
*
* @param title the title of a track to drop
* @param activity to get context
*/
static void dropFusionTables(String title, Activity activity) {
Context context = activity.getApplicationContext();
HttpResponse response = sendFusionTableQuery("SHOW TABLES", context);
String[] rowsTable;
try {
rowsTable = response.parseAsString().split("\n");
for (String string : rowsTable) {
// If the first column is all figure, it is the table id.
String regularExpression = "^[0-9]*$";
if (string.split(",")[0].matches(regularExpression) && string.indexOf(title) > -1) {
sendFusionTableQuery("DROP TABLE " + string.split(",")[0], context);
}
}
} catch (IOException e) {
Log.d(LOG_TAG, "Failed when delete all fusion tables.", e);
}
}
/** /**
* Sends query to operate fusion tables. * Sends query to operate fusion tables.
* *
@@ -91,9 +91,11 @@ public class SettingTest extends ActivityInstrumentationTestCase2<TrackListActiv
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true); EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
// Check settings. // Check settings.
// Add following scroll up for a bug of Robotium.
EndToEndTestUtils.SOLO.scrollUp();
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_stats_tab)); EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_stats_tab));
EndToEndTestUtils.SOLO.waitForText(activityMyTracks assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks
.getString(R.string.settings_stats_units_title), 1, 20000); .getString(R.string.settings_stats_units_title), 1, 20000));
displayCheckBoxs = EndToEndTestUtils.SOLO.getCurrentCheckBoxes(); displayCheckBoxs = EndToEndTestUtils.SOLO.getCurrentCheckBoxes();
assertEquals(useMetric, displayCheckBoxs.get(0).isChecked()); assertEquals(useMetric, displayCheckBoxs.get(0).isChecked());