Merge heads

This commit is contained in:
youtaol
2013-02-01 13:05:31 +08:00
12 changed files with 886 additions and 20 deletions
@@ -38,6 +38,7 @@ import com.google.api.services.drive.DriveScopes;
import com.google.api.services.drive.model.File; import com.google.api.services.drive.model.File;
import com.google.api.services.drive.model.FileList; import com.google.api.services.drive.model.FileList;
import com.google.api.services.drive.model.ParentReference; import com.google.api.services.drive.model.ParentReference;
import com.google.common.annotations.VisibleForTesting;
import android.accounts.Account; import android.accounts.Account;
import android.accounts.AccountManager; import android.accounts.AccountManager;
@@ -76,7 +77,8 @@ public class SyncUtils {
+ KML_MIME_TYPE + "' and trashed = false"; + KML_MIME_TYPE + "' and trashed = false";
private static final String FOLDER_MIME_TYPE = "application/vnd.google-apps.folder"; private static final String FOLDER_MIME_TYPE = "application/vnd.google-apps.folder";
private static final String GET_MY_TRACKS_FOLDER_QUERY = @VisibleForTesting
public static final String GET_MY_TRACKS_FOLDER_QUERY =
"'root' in parents and title = '%s' and mimeType = '" + FOLDER_MIME_TYPE "'root' in parents and title = '%s' and mimeType = '" + FOLDER_MIME_TYPE
+ "' and trashed = false"; + "' and trashed = false";
@@ -141,6 +141,8 @@ public class SendRequestTest extends AndroidTestCase {
parcel.writeLong(2); parcel.writeLong(2);
parcel.writeString(""); parcel.writeString("");
parcel.writeString(""); parcel.writeString("");
parcel.writeString("");
parcel.writeByte((byte) 1);
parcel.writeByte((byte) 1); parcel.writeByte((byte) 1);
parcel.writeByte((byte) 1); parcel.writeByte((byte) 1);
parcel.writeByte((byte) 1); parcel.writeByte((byte) 1);
@@ -151,17 +153,21 @@ public class SendRequestTest extends AndroidTestCase {
parcel.writeByte((byte) 1); parcel.writeByte((byte) 1);
parcel.writeByte((byte) 1); parcel.writeByte((byte) 1);
parcel.writeByte((byte) 1); parcel.writeByte((byte) 1);
parcel.writeByte((byte) 1);
parcel.setDataPosition(0); parcel.setDataPosition(0);
sendRequest = SendRequest.CREATOR.createFromParcel(parcel); sendRequest = SendRequest.CREATOR.createFromParcel(parcel);
assertEquals(2, sendRequest.getTrackId()); assertEquals(2, sendRequest.getTrackId());
assertEquals("", sendRequest.getSharingAppPackageName()); assertEquals("", sendRequest.getSharingAppPackageName());
assertEquals("", sendRequest.getSharingAppClassName()); assertEquals("", sendRequest.getSharingAppClassName());
assertEquals("", sendRequest.getAcl());
assertTrue(sendRequest.isSendDrive());
assertTrue(sendRequest.isSendMaps()); assertTrue(sendRequest.isSendMaps());
assertTrue(sendRequest.isSendFusionTables()); assertTrue(sendRequest.isSendFusionTables());
assertTrue(sendRequest.isSendDocs()); assertTrue(sendRequest.isSendDocs());
assertTrue(sendRequest.isNewMap()); assertTrue(sendRequest.isNewMap());
assertEquals(account, sendRequest.getAccount()); assertEquals(account, sendRequest.getAccount());
assertEquals(MAPID, sendRequest.getMapId()); assertEquals(MAPID, sendRequest.getMapId());
assertTrue(sendRequest.isDriveSuccess());
assertTrue(sendRequest.isMapsSuccess()); assertTrue(sendRequest.isMapsSuccess());
assertTrue(sendRequest.isFusionTablesSuccess()); assertTrue(sendRequest.isFusionTablesSuccess());
assertTrue(sendRequest.isDocsSuccess()); assertTrue(sendRequest.isDocsSuccess());
@@ -176,6 +182,8 @@ public class SendRequestTest extends AndroidTestCase {
parcel.writeLong(4); parcel.writeLong(4);
parcel.writeString(null); parcel.writeString(null);
parcel.writeString(null); parcel.writeString(null);
parcel.writeString(null);
parcel.writeByte((byte) 0);
parcel.writeByte((byte) 0); parcel.writeByte((byte) 0);
parcel.writeByte((byte) 0); parcel.writeByte((byte) 0);
parcel.writeByte((byte) 0); parcel.writeByte((byte) 0);
@@ -186,17 +194,21 @@ public class SendRequestTest extends AndroidTestCase {
parcel.writeByte((byte) 0); parcel.writeByte((byte) 0);
parcel.writeByte((byte) 0); parcel.writeByte((byte) 0);
parcel.writeByte((byte) 0); parcel.writeByte((byte) 0);
parcel.writeByte((byte) 0);
parcel.setDataPosition(0); parcel.setDataPosition(0);
sendRequest = SendRequest.CREATOR.createFromParcel(parcel); sendRequest = SendRequest.CREATOR.createFromParcel(parcel);
assertEquals(4, sendRequest.getTrackId()); assertEquals(4, sendRequest.getTrackId());
assertNull(sendRequest.getSharingAppPackageName()); assertNull(sendRequest.getSharingAppPackageName());
assertNull(sendRequest.getSharingAppClassName()); assertNull(sendRequest.getSharingAppClassName());
assertNull(sendRequest.getAcl());
assertFalse(sendRequest.isSendDrive());
assertFalse(sendRequest.isSendMaps()); assertFalse(sendRequest.isSendMaps());
assertFalse(sendRequest.isSendFusionTables()); assertFalse(sendRequest.isSendFusionTables());
assertFalse(sendRequest.isSendDocs()); assertFalse(sendRequest.isSendDocs());
assertFalse(sendRequest.isNewMap()); assertFalse(sendRequest.isNewMap());
assertEquals(account, sendRequest.getAccount()); assertEquals(account, sendRequest.getAccount());
assertEquals(MAPID, sendRequest.getMapId()); assertEquals(MAPID, sendRequest.getMapId());
assertFalse(sendRequest.isDriveSuccess());
assertFalse(sendRequest.isMapsSuccess()); assertFalse(sendRequest.isMapsSuccess());
assertFalse(sendRequest.isFusionTablesSuccess()); assertFalse(sendRequest.isFusionTablesSuccess());
assertFalse(sendRequest.isDocsSuccess()); assertFalse(sendRequest.isDocsSuccess());
@@ -214,24 +226,30 @@ public class SendRequestTest extends AndroidTestCase {
long trackId = parcel.readLong(); long trackId = parcel.readLong();
String sharingAppPackageName = parcel.readString(); String sharingAppPackageName = parcel.readString();
String sharingAppClassName = parcel.readString(); String sharingAppClassName = parcel.readString();
String acl = parcel.readString();
boolean sendDrive = parcel.readByte() == 1;
boolean sendMaps = parcel.readByte() == 1; boolean sendMaps = parcel.readByte() == 1;
boolean sendFusionTables = parcel.readByte() == 1; boolean sendFusionTables = parcel.readByte() == 1;
boolean sendDocs = parcel.readByte() == 1; boolean sendDocs = parcel.readByte() == 1;
boolean newMap = parcel.readByte() == 1; boolean newMap = parcel.readByte() == 1;
Parcelable account = parcel.readParcelable(null); Parcelable account = parcel.readParcelable(null);
String mapId = parcel.readString(); String mapId = parcel.readString();
boolean driveSuccess = parcel.readByte() == 1;
boolean mapsSuccess = parcel.readByte() == 1; boolean mapsSuccess = parcel.readByte() == 1;
boolean fusionTablesSuccess = parcel.readByte() == 1; boolean fusionTablesSuccess = parcel.readByte() == 1;
boolean docsSuccess = parcel.readByte() == 1; boolean docsSuccess = parcel.readByte() == 1;
assertEquals(1, trackId); assertEquals(1, trackId);
assertNull(sharingAppPackageName); assertNull(sharingAppPackageName);
assertNull(sharingAppClassName); assertNull(sharingAppClassName);
assertNull(acl);
assertFalse(sendDrive);
assertFalse(sendMaps); assertFalse(sendMaps);
assertFalse(sendFusionTables); assertFalse(sendFusionTables);
assertFalse(sendDocs); assertFalse(sendDocs);
assertFalse(newMap); assertFalse(newMap);
assertNull(account); assertNull(account);
assertNull(mapId); assertNull(mapId);
assertFalse(driveSuccess);
assertFalse(mapsSuccess); assertFalse(mapsSuccess);
assertFalse(fusionTablesSuccess); assertFalse(fusionTablesSuccess);
assertFalse(docsSuccess); assertFalse(docsSuccess);
@@ -244,6 +262,8 @@ public class SendRequestTest extends AndroidTestCase {
sendRequest = new SendRequest(4); sendRequest = new SendRequest(4);
sendRequest.setSharingAppPackageName("package"); sendRequest.setSharingAppPackageName("package");
sendRequest.setSharingAppClassName("class"); sendRequest.setSharingAppClassName("class");
sendRequest.setAcl("acl");
sendRequest.setSendDrive(true);
sendRequest.setSendMaps(true); sendRequest.setSendMaps(true);
sendRequest.setSendFusionTables(true); sendRequest.setSendFusionTables(true);
sendRequest.setSendDocs(true); sendRequest.setSendDocs(true);
@@ -252,6 +272,7 @@ public class SendRequestTest extends AndroidTestCase {
sendRequest.setAccount(accountNew); sendRequest.setAccount(accountNew);
sendRequest.setMapId(MAPID); sendRequest.setMapId(MAPID);
sendRequest.setMapsSuccess(true); sendRequest.setMapsSuccess(true);
sendRequest.setDriveSuccess(true);
sendRequest.setFusionTablesSuccess(true); sendRequest.setFusionTablesSuccess(true);
sendRequest.setDocsSuccess(true); sendRequest.setDocsSuccess(true);
Parcel parcel = Parcel.obtain(); Parcel parcel = Parcel.obtain();
@@ -261,24 +282,30 @@ public class SendRequestTest extends AndroidTestCase {
long trackId = parcel.readLong(); long trackId = parcel.readLong();
String sharingAppPackageName = parcel.readString(); String sharingAppPackageName = parcel.readString();
String sharingAppClassName = parcel.readString(); String sharingAppClassName = parcel.readString();
String acl = parcel.readString();
boolean sendDrive = parcel.readByte() == 1;
boolean sendMaps = parcel.readByte() == 1; boolean sendMaps = parcel.readByte() == 1;
boolean sendFusionTables = parcel.readByte() == 1; boolean sendFusionTables = parcel.readByte() == 1;
boolean sendDocs = parcel.readByte() == 1; boolean sendDocs = parcel.readByte() == 1;
boolean newMap = parcel.readByte() == 1; boolean newMap = parcel.readByte() == 1;
Parcelable account = parcel.readParcelable(null); Parcelable account = parcel.readParcelable(null);
String mapId = parcel.readString(); String mapId = parcel.readString();
boolean driveSuccess = parcel.readByte() == 1;
boolean mapsSuccess = parcel.readByte() == 1; boolean mapsSuccess = parcel.readByte() == 1;
boolean fusionTablesSuccess = parcel.readByte() == 1; boolean fusionTablesSuccess = parcel.readByte() == 1;
boolean docsSuccess = parcel.readByte() == 1; boolean docsSuccess = parcel.readByte() == 1;
assertEquals(4, trackId); assertEquals(4, trackId);
assertEquals("package", sharingAppPackageName); assertEquals("package", sharingAppPackageName);
assertEquals("class", sharingAppClassName); assertEquals("class", sharingAppClassName);
assertEquals("acl", acl);
assertTrue(sendDrive);
assertTrue(sendMaps); assertTrue(sendMaps);
assertTrue(sendFusionTables); assertTrue(sendFusionTables);
assertTrue(sendDocs); assertTrue(sendDocs);
assertTrue(newMap); assertTrue(newMap);
assertEquals(accountNew, account); assertEquals(accountNew, account);
assertEquals(MAPID, mapId); assertEquals(MAPID, mapId);
assertTrue(driveSuccess);
assertTrue(mapsSuccess); assertTrue(mapsSuccess);
assertTrue(fusionTablesSuccess); assertTrue(fusionTablesSuccess);
assertTrue(docsSuccess); assertTrue(docsSuccess);
@@ -93,6 +93,7 @@ public class DeleteTest extends ActivityInstrumentationTestCase2<TrackListActivi
int trackNumberOld = trackListView.get(0).getCount(); int trackNumberOld = trackListView.get(0).getCount();
EndToEndTestUtils.SOLO.clickOnView(trackListView.get(0).getChildAt(0)); EndToEndTestUtils.SOLO.clickOnView(trackListView.get(0).getChildAt(0));
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.track_detail_chart_tab));
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);
@@ -136,8 +136,6 @@ public class EndToEndTestUtils {
public static boolean isCheckedFirstLaunch = false; public static boolean isCheckedFirstLaunch = false;
public static boolean isGooglePlayServicesLatest = true; public static boolean isGooglePlayServicesLatest = true;
private EndToEndTestUtils() {}
/** /**
* Checks the language, then sets the fields with right string. * Checks the language, then sets the fields with right string.
*/ */
@@ -299,8 +297,6 @@ public class EndToEndTestUtils {
hasActionBar = setHasActionBar(); hasActionBar = setHasActionBar();
checkLanguage(); checkLanguage();
isCheckedFirstLaunch = true; isCheckedFirstLaunch = true;
deleteAllTracks();
resetAllSettings(activityMyTracks, false);
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
// Check the status of real phone. For emulator, we would fix GPS signal. // Check the status of real phone. For emulator, we would fix GPS signal.
@@ -315,6 +311,16 @@ public class EndToEndTestUtils {
resetPreferredUnits(); resetPreferredUnits();
} }
int trackNumber = SOLO.getCurrentListViews().get(0).getCount();
// Delete all tracks when there are two many tracks which may make some test
// run slowly, such as sync test cases.
if (trackNumber > 3) {
deleteAllTracks();
}
resetAllSettings(activityMyTracks, false);
instrumentation.waitForIdleSync();
// Check whether is under recording. If previous test failed, the recording // Check whether is under recording. If previous test failed, the recording
// may not be recording. // may not be recording.
if (isUnderRecording()) { if (isUnderRecording()) {
@@ -415,6 +421,8 @@ public class EndToEndTestUtils {
if (isClick) { if (isClick) {
SOLO.scrollUp(); SOLO.scrollUp();
SOLO.clickOnView(oneTrack); SOLO.clickOnView(oneTrack);
EndToEndTestUtils.SOLO.waitForText(activityMytracks
.getString(R.string.track_detail_chart_tab));
} }
return false; return false;
} }
@@ -1005,6 +1013,7 @@ public class EndToEndTestUtils {
sendGps(30); sendGps(30);
View myLocation = SOLO.getCurrentActivity().findViewById(R.id.map_my_location); View myLocation = SOLO.getCurrentActivity().findViewById(R.id.map_my_location);
instrumentation.waitForIdleSync();
// Find the My Location button in another if null. // Find the My Location button in another if null.
if (myLocation == null) { if (myLocation == null) {
ArrayList<ImageButton> aa = SOLO.getCurrentImageButtons(); ArrayList<ImageButton> aa = SOLO.getCurrentImageButtons();
@@ -111,6 +111,7 @@ public class ExportAndImportTest extends ActivityInstrumentationTestCase2<TrackL
// Check the track name, activity and description. // Check the track name, activity and description.
assertTrue(EndToEndTestUtils.SOLO.waitForText(EndToEndTestUtils.trackName)); assertTrue(EndToEndTestUtils.SOLO.waitForText(EndToEndTestUtils.trackName));
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.trackName); EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.trackName);
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.track_detail_chart_tab));
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_edit), true); EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_edit), true);
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.trackName)); assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.trackName));
@@ -64,7 +64,8 @@ import java.util.Locale;
*/ */
public class GoogleUtils { public class GoogleUtils {
public static final String DOCUMENT_NAME_PREFIX = "My Tracks"; public static final String DOCUMENT_NAME_PREFIX = "My Tracks";
public static final String ACCOUNT_NAME = "mytrackstest@gmail.com"; public static final String ACCOUNT_NAME_1 = "mytrackstest@gmail.com";
public static final String ACCOUNT_NAME_2 = "mytrackstest2@gmail.com";
public static final String SPREADSHEET_NAME = DOCUMENT_NAME_PREFIX + "-" + EndToEndTestUtils.activityType; public static final String SPREADSHEET_NAME = DOCUMENT_NAME_PREFIX + "-" + EndToEndTestUtils.activityType;
/** /**
@@ -46,7 +46,7 @@ public class SettingTest extends ActivityInstrumentationTestCase2<TrackListActiv
super.setUp(); super.setUp();
instrumentation = getInstrumentation(); instrumentation = getInstrumentation();
activityMyTracks = getActivity(); activityMyTracks = getActivity();
EndToEndTestUtils.setupForDebug(instrumentation, activityMyTracks); EndToEndTestUtils.setupForAllTest(instrumentation, activityMyTracks);
} }
/** /**
@@ -64,6 +64,7 @@ public class SettingTest extends ActivityInstrumentationTestCase2<TrackListActiv
// Change a setting of Map. // Change a setting of Map.
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_stats_tab)); EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_stats_tab));
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
// Rotate on a sub setting page. // Rotate on a sub setting page.
EndToEndTestUtils.rotateAllActivities(); EndToEndTestUtils.rotateAllActivities();
EndToEndTestUtils.SOLO.waitForText(activityMyTracks EndToEndTestUtils.SOLO.waitForText(activityMyTracks
@@ -73,6 +74,7 @@ public class SettingTest extends ActivityInstrumentationTestCase2<TrackListActiv
EndToEndTestUtils.SOLO.clickOnCheckBox(0); EndToEndTestUtils.SOLO.clickOnCheckBox(0);
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
EndToEndTestUtils.SOLO.goBack(); EndToEndTestUtils.SOLO.goBack();
// Change a setting of sharing. // Change a setting of sharing.
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_sharing)); EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_sharing));
assertTrue(EndToEndTestUtils.SOLO.waitForText( assertTrue(EndToEndTestUtils.SOLO.waitForText(
@@ -95,6 +97,7 @@ public class SettingTest extends ActivityInstrumentationTestCase2<TrackListActiv
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_reset)); EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_reset));
EndToEndTestUtils EndToEndTestUtils
.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true); .getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
instrumentation.waitForIdleSync();
EndToEndTestUtils.SOLO.goBack(); EndToEndTestUtils.SOLO.goBack();
// Check settings. // Check settings.
@@ -120,8 +123,10 @@ public class SettingTest extends ActivityInstrumentationTestCase2<TrackListActiv
*/ */
public void testChangePreferredUnits() { public void testChangePreferredUnits() {
EndToEndTestUtils.createTrackIfEmpty(5, false); EndToEndTestUtils.createTrackIfEmpty(5, false);
// Change it and verify it. // Change it and verify it.
ChangePreferredUnits(); ChangePreferredUnits();
// Change it back and verify it. // Change it back and verify it.
ChangePreferredUnits(); ChangePreferredUnits();
} }
@@ -131,6 +136,7 @@ public class SettingTest extends ActivityInstrumentationTestCase2<TrackListActiv
*/ */
public void testChangeStatsSettings_underRecording_chart() { public void testChangeStatsSettings_underRecording_chart() {
EndToEndTestUtils.startRecording(); EndToEndTestUtils.startRecording();
// Test just change preferred units when display CHART tab. // Test just change preferred units when display CHART tab.
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_chart_tab)); EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_chart_tab));
EndToEndTestUtils.sendGps(3); EndToEndTestUtils.sendGps(3);
@@ -248,7 +254,6 @@ public class SettingTest extends ActivityInstrumentationTestCase2<TrackListActiv
// Write to SD card. // Write to SD card.
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true); EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true);
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_backup_reset)); EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_backup_reset));
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_backup));
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_backup_now)); EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_backup_now));
assertTrue(EndToEndTestUtils.SOLO.waitForText( assertTrue(EndToEndTestUtils.SOLO.waitForText(
activityMyTracks.getString(R.string.settings_backup_now_success), 0, activityMyTracks.getString(R.string.settings_backup_now_success), 0,
@@ -258,24 +263,51 @@ public class SettingTest extends ActivityInstrumentationTestCase2<TrackListActiv
// Delete all tracks. // Delete all tracks.
EndToEndTestUtils.SOLO.goBack(); EndToEndTestUtils.SOLO.goBack();
EndToEndTestUtils.SOLO.goBack(); EndToEndTestUtils.SOLO.goBack();
EndToEndTestUtils.SOLO.goBack();
EndToEndTestUtils.deleteAllTracks(); EndToEndTestUtils.deleteAllTracks();
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
// Read from SD card. // Read from SD card.
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true); EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true);
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_backup_reset)); EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_backup_reset));
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_backup)); EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_backup_now));
EndToEndTestUtils.SOLO EndToEndTestUtils.SOLO
.clickOnText(activityMyTracks.getString(R.string.settings_backup_restore)); .clickOnText(activityMyTracks.getString(R.string.settings_backup_restore));
EndToEndTestUtils EndToEndTestUtils
.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true); .getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
// Now there should be 2 backups.
instrumentation.waitForIdleSync();
assertEquals(2, EndToEndTestUtils.SOLO.getCurrentListViews().get(0).getCount());
// Click the first one.
EndToEndTestUtils.SOLO.clickOnView(EndToEndTestUtils.SOLO.getCurrentListViews().get(0)
.getChildAt(0));
assertTrue(EndToEndTestUtils.SOLO.waitForText( assertTrue(EndToEndTestUtils.SOLO.waitForText(
activityMyTracks.getString(R.string.settings_backup_restore_success), 0, activityMyTracks.getString(R.string.settings_backup_restore_success), 0,
EndToEndTestUtils.SUPER_LONG_WAIT_TIME)); EndToEndTestUtils.SUPER_LONG_WAIT_TIME));
EndToEndTestUtils.SOLO.goBack();
// Check restore track. // Check restore track.
assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.trackName)); instrumentation.waitForIdleSync();
boolean isContainTrack = EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.trackName);
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true);
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_backup_reset));
EndToEndTestUtils.SOLO
.clickOnText(activityMyTracks.getString(R.string.settings_backup_restore));
EndToEndTestUtils
.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
instrumentation.waitForIdleSync();
// Click the second one.
EndToEndTestUtils.SOLO.clickOnView(EndToEndTestUtils.SOLO.getCurrentListViews().get(0)
.getChildAt(1));
assertTrue(EndToEndTestUtils.SOLO.waitForText(
activityMyTracks.getString(R.string.settings_backup_restore_success), 0,
EndToEndTestUtils.SUPER_LONG_WAIT_TIME));
// For the older backup contains tracks and the newer backup is empty. The
// search result of twice must be different.
instrumentation.waitForIdleSync();
assertTrue(isContainTrack != EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.trackName));
} }
/** /**
@@ -285,18 +317,19 @@ public class SettingTest extends ActivityInstrumentationTestCase2<TrackListActiv
public void testRecording() { public void testRecording() {
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true); EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true);
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_recording)); EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_recording));
// Changes the setting of recording name. // Changes the setting of recording name.
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
.getString(R.string.settings_recording_track_name_title)); .getString(R.string.settings_recording_track_name_title));
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
.getString(R.string.settings_recording_track_name_number_option)); .getString(R.string.settings_recording_track_name_number_option));
// 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_title)); .getString(R.string.settings_recording_default_activity_title));
EndToEndTestUtils.enterTextAvoidSoftKeyBoard(0, EndToEndTestUtils.activityType); EndToEndTestUtils.enterTextAvoidSoftKeyBoard(0, EndToEndTestUtils.activityType);
EndToEndTestUtils EndToEndTestUtils
.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true); .getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
EndToEndTestUtils.SOLO.goBack(); EndToEndTestUtils.SOLO.goBack();
EndToEndTestUtils.SOLO.goBack(); EndToEndTestUtils.SOLO.goBack();
@@ -379,15 +412,17 @@ public class SettingTest extends ActivityInstrumentationTestCase2<TrackListActiv
.getString(R.string.settings_google_account_title)); .getString(R.string.settings_google_account_title));
// Whether test account is bound. // Whether test account is bound.
if (EndToEndTestUtils.SOLO.waitForText(GoogleUtils.ACCOUNT_NAME, 1, if (EndToEndTestUtils.SOLO.waitForText(GoogleUtils.ACCOUNT_NAME_1, 1,
EndToEndTestUtils.TINY_WAIT_TIME)) { EndToEndTestUtils.TINY_WAIT_TIME)) {
EndToEndTestUtils.SOLO.clickOnText(GoogleUtils.ACCOUNT_NAME); EndToEndTestUtils.SOLO.clickOnText(GoogleUtils.ACCOUNT_NAME_1);
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
assertTrue(EndToEndTestUtils.findTextView( assertTrue(EndToEndTestUtils.findTextView(
activityMyTracks.getString(R.string.settings_google_drive_sync_title)).isEnabled()); activityMyTracks.getString(R.string.settings_google_drive_sync_title)).isEnabled());
} else { } else {
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.value_none)); EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.value_none));
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
EndToEndTestUtils.SOLO.waitForText(activityMyTracks
.getString(R.string.settings_google_drive_sync_title));
assertFalse(EndToEndTestUtils.findTextView( assertFalse(EndToEndTestUtils.findTextView(
activityMyTracks.getString(R.string.settings_google_drive_sync_title)).isEnabled()); activityMyTracks.getString(R.string.settings_google_drive_sync_title)).isEnabled());
return; return;
@@ -397,9 +432,10 @@ public class SettingTest extends ActivityInstrumentationTestCase2<TrackListActiv
.getString(R.string.settings_google_drive_sync_title)); .getString(R.string.settings_google_drive_sync_title));
boolean isSyncChecked = false; boolean isSyncChecked = false;
if (EndToEndTestUtils.SOLO.waitForText( if (EndToEndTestUtils.SOLO
activityMyTracks.getString(R.string.settings_google_drive_sync_confirm_message).split( .waitForText(activityMyTracks
"%")[0], 1, EndToEndTestUtils.SHORT_WAIT_TIME)) { .getString(R.string.settings_google_drive_sync_confirm_message).split("%")[0], 1,
EndToEndTestUtils.SHORT_WAIT_TIME)) {
isSyncChecked = true; isSyncChecked = true;
} else { } else {
isSyncChecked = false; isSyncChecked = false;
@@ -87,12 +87,15 @@ public class ViewsTest extends ActivityInstrumentationTestCase2<TrackListActivit
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
EndToEndTestUtils.createTrackIfEmpty(1, false); EndToEndTestUtils.createTrackIfEmpty(1, false);
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.track_detail_chart_tab));
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_map_layer), true); EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_map_layer), true);
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.menu_terrain)); EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.menu_terrain));
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.track_detail_chart_tab));
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_map_layer), true); EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_map_layer), true);
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.menu_satellite)); EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.menu_satellite));
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.track_detail_chart_tab));
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_map_layer), true); EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_map_layer), true);
// But in some languages only has one match(Such as French). // But in some languages only has one match(Such as French).
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.menu_map)); EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.menu_map));
@@ -0,0 +1,159 @@
/*
* Copyright 2013 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.endtoendtest.sync;
import com.google.android.apps.mytracks.TrackListActivity;
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils;
import com.google.android.apps.mytracks.endtoendtest.GoogleUtils;
import com.google.android.maps.mytracks.R;
import com.google.api.services.drive.Drive;
import android.app.Instrumentation;
import android.test.ActivityInstrumentationTestCase2;
import java.io.IOException;
/**
* Tests the situation when user use multiple account in MyTracks.
*
* @author Youtao Liu
*/
public class MultiAccountsSyncTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
private Drive drive;
private Instrumentation instrumentation;
private TrackListActivity trackListActivity;
public MultiAccountsSyncTest() {
super(TrackListActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
instrumentation = getInstrumentation();
trackListActivity = getActivity();
drive = SyncTestUtils.setUpForSyncTest(instrumentation, trackListActivity);
}
/**
* Tests sync tracks with Google Drive of two accounts with following
* sequence:
* <ul>
* <li>1. Enable sync with account1.</li>
* <li>2. Create a track.</li>
* <li>3. Enable sync with account2.</li>
* <li>4. Create a track.</li>
* <li>5. Sync and check</li>
* <li>6. Enable sync with account1.</li>
* <li>7. Sync and check</li>
* <li>8. Enable sync with account2.</li>
* <li>9. Check</li>
* </ul>
*
* @throws IOException
*/
public void testSyncTracksWithMultiAccounts() throws IOException {
if (!SyncTestUtils.runSyncTest) {
return;
}
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_1);
// Create tracks with first track.
EndToEndTestUtils.createSimpleTrack(0, true);
// Create tracks with second track.
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_2);
EndToEndTestUtils.createSimpleTrack(0, true);
// Sync with Google Drive and then check it of the second account.
EndToEndTestUtils.findMenuItem(
EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_now), true);
drive = SyncTestUtils.getGoogleDrive(trackListActivity.getApplicationContext());
SyncTestUtils.checkFilesNumber(drive);
// Check Google Drive of the first account.
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_1);
EndToEndTestUtils.findMenuItem(
EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_now), true);
drive = SyncTestUtils.getGoogleDrive(trackListActivity.getApplicationContext());
SyncTestUtils.checkFilesNumber(drive);
// Back to account1 change check that files are still existed.
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_2);
drive = SyncTestUtils.getGoogleDrive(trackListActivity.getApplicationContext());
SyncTestUtils.checkFilesNumber(drive);
}
/**
* Tests the behavior of MyTracks about delete operation and switch accounts
* with following sequence.:
* <ul>
* <li>1. Create 3 tracks.</li>
* <li>2. Delete 1 track.</li>
* <li>3. Sync with account2(account2 should have 2 files).</li>
* <li>4. Delete 1 track (account2 should have 1 file).</li>
* <li>5. Sync with account 1 (account 1 should have 1 file, account2 should
* also have 1 file).</li>
* </ul>
*
* @throws IOException
*/
public void testDeleteTracksWithMultiAccounts() throws IOException {
if (!SyncTestUtils.runSyncTest) {
return;
}
EndToEndTestUtils.createSimpleTrack(0, true);
EndToEndTestUtils.createSimpleTrack(0, true);
EndToEndTestUtils.createSimpleTrack(0, true);
// Delete one track.
EndToEndTestUtils.SOLO.clickOnView(EndToEndTestUtils.SOLO.getCurrentListViews().get(0)
.getChildAt(0));
EndToEndTestUtils.SOLO.clickOnMenuItem(EndToEndTestUtils.activityMytracks
.getString(R.string.menu_delete));
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks
.getString(R.string.generic_ok));
// Switch account and delete another track.
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_2);
EndToEndTestUtils.SOLO.clickOnView(EndToEndTestUtils.SOLO.getCurrentListViews().get(0)
.getChildAt(0));
EndToEndTestUtils.SOLO.clickOnMenuItem(EndToEndTestUtils.activityMytracks
.getString(R.string.menu_delete));
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks
.getString(R.string.generic_ok));
// Check Google Drive of the first account.
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_1);
EndToEndTestUtils.findMenuItem(
EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_now), true);
drive = SyncTestUtils.getGoogleDrive(trackListActivity.getApplicationContext());
SyncTestUtils.checkFilesNumber(drive);
// Check Google Drive of the second account.
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_2);
EndToEndTestUtils.findMenuItem(
EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_now), true);
drive = SyncTestUtils.getGoogleDrive(trackListActivity.getApplicationContext());
SyncTestUtils.checkFilesNumber(drive);
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
EndToEndTestUtils.SOLO.finishOpenedActivities();
}
}
@@ -0,0 +1,161 @@
/*
* Copyright 2013 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.endtoendtest.sync;
import com.google.android.apps.mytracks.TrackListActivity;
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils;
import com.google.android.maps.mytracks.R;
import com.google.api.services.drive.Drive;
import android.app.Instrumentation;
import android.test.ActivityInstrumentationTestCase2;
import android.view.KeyEvent;
import java.io.IOException;
/**
* Tests making changes on Google Drive when syncing My Tracks with Google Drive.
*
* @author Youtao Liu
*/
public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
private Drive drive;
private Instrumentation instrumentation;
private TrackListActivity trackListActivity;
public SyncDriveWithMyTracksTest() {
super(TrackListActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
instrumentation = getInstrumentation();
trackListActivity = getActivity();
drive = SyncTestUtils.setUpForSyncTest(instrumentation, trackListActivity);
}
/**
* Deletes all tracks in MyTracks and checks in Google Drive.
*
* @throws IOException
*/
public void testDeleteAllTracksInMyTracks() throws IOException {
if (!SyncTestUtils.runSyncTest) {
return;
}
EndToEndTestUtils.deleteAllTracks();
EndToEndTestUtils.findMenuItem(
EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_now), true);
SyncTestUtils.checkFilesNumber(drive);
}
/**
* Deletes one track in MyTracks and checks it in Google Drive.
*
* @throws IOException
*/
public void testDeleteOneTracksInMyTracks() throws IOException {
if (!SyncTestUtils.runSyncTest) {
return;
}
EndToEndTestUtils.createTrackIfEmpty(2, false);
EndToEndTestUtils.SOLO.clickOnMenuItem(EndToEndTestUtils.activityMytracks
.getString(R.string.menu_delete));
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks
.getString(R.string.generic_ok));
EndToEndTestUtils.findMenuItem(
EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_now), true);
SyncTestUtils.checkFile(EndToEndTestUtils.trackName, false, drive);
}
/**
* Creates one empty track and one non-empty track in MyTracks and then check
* them in Google Drive.
*
* @throws IOException
*/
public void testCreateTracksInMyTracks() throws IOException {
if (!SyncTestUtils.runSyncTest) {
return;
}
EndToEndTestUtils.deleteAllTracks();
EndToEndTestUtils.createSimpleTrack(0, true);
EndToEndTestUtils.createSimpleTrack(3, true);
EndToEndTestUtils.findMenuItem(
EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_now), true);
SyncTestUtils.checkFilesNumber(drive);
}
/**
* Edits a tracks in MyTracks and checks it on Google Drive after sync.
*
* @throws IOException
*/
public void testEditTrackInMyTracks() throws IOException {
if (!SyncTestUtils.runSyncTest) {
return;
}
EndToEndTestUtils.createTrackIfEmpty(3, true);
// Sync this track.
EndToEndTestUtils.findMenuItem(
EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_now), true);
SyncTestUtils.checkFile(EndToEndTestUtils.trackName, true, drive);
String oldTrack = SyncTestUtils.getContentOfFile(
SyncTestUtils.getFile(EndToEndTestUtils.trackName, drive), drive);
String oldTrackName = EndToEndTestUtils.trackName;
// Edit this track.
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.trackName);
EndToEndTestUtils.findMenuItem(trackListActivity.getString(R.string.menu_edit), true);
String newTrackName = EndToEndTestUtils.TRACK_NAME_PREFIX + "_new" + System.currentTimeMillis();
String newType = EndToEndTestUtils.activityType + newTrackName;
String newDesc = "desc" + newTrackName;
instrumentation.waitForIdleSync();
EndToEndTestUtils.SOLO.waitForText(trackListActivity.getString(R.string.generic_save));
sendKeys(KeyEvent.KEYCODE_DEL);
EndToEndTestUtils.enterTextAvoidSoftKeyBoard(0, newTrackName);
EndToEndTestUtils.enterTextAvoidSoftKeyBoard(1, newType);
EndToEndTestUtils.enterTextAvoidSoftKeyBoard(2, newDesc);
EndToEndTestUtils.SOLO.clickOnButton(trackListActivity.getString(R.string.generic_save));
instrumentation.waitForIdleSync();
EndToEndTestUtils.SOLO.goBack();
instrumentation.waitForIdleSync();
// Sync again.
EndToEndTestUtils.findMenuItem(
EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_now), true);
// Check.
SyncTestUtils.checkFile(oldTrackName, false, drive);
SyncTestUtils.checkFile(newTrackName, true, drive);
String newTrack = SyncTestUtils.getContentOfFile(SyncTestUtils.getFile(newTrackName, drive),
drive);
assertNotSame(oldTrack, newTrack);
assertTrue(newTrack.indexOf(newTrackName) > 0);
assertTrue(newTrack.indexOf(newType) > 0);
assertTrue(newTrack.indexOf(newDesc) > 0);
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
EndToEndTestUtils.SOLO.finishOpenedActivities();
}
}
@@ -0,0 +1,121 @@
/*
* Copyright 2013 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.endtoendtest.sync;
import com.google.android.apps.mytracks.TrackListActivity;
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils;
import com.google.android.maps.mytracks.R;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.model.File;
import android.app.Instrumentation;
import android.test.ActivityInstrumentationTestCase2;
import java.io.IOException;
/**
* Tests making changes on My Tracks when syncing My Tracks with Google Drive.
*
* @author Youtao Liu
*/
public class SyncMyTracksWithDriveTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
private Drive drive;
private Instrumentation instrumentation;
private TrackListActivity trackListActivity;
public SyncMyTracksWithDriveTest() {
super(TrackListActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
instrumentation = getInstrumentation();
trackListActivity = getActivity();
drive = SyncTestUtils.setUpForSyncTest(instrumentation, trackListActivity);
}
/**
* Deletes all tracks on Google Drive and checks in MyTracks.
*
* @throws IOException
*/
public void testDeleteAllTracksOnDrive() throws IOException {
if (!SyncTestUtils.runSyncTest) {
return;
}
EndToEndTestUtils.createTrackIfEmpty(0, true);
EndToEndTestUtils.findMenuItem(
EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_now), true);
SyncTestUtils.checkFilesNumber(drive);
SyncTestUtils.removeKMLFiles(drive);
EndToEndTestUtils.findMenuItem(
EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_now), true);
SyncTestUtils.checkTracksNumber(0);
}
/**
* Deletes one file on Google Drive and checks it in MyTracks.
*
* @throws IOException
*/
public void testDeleteOneFileOnDrive() throws IOException {
if (!SyncTestUtils.runSyncTest) {
return;
}
instrumentation.waitForIdleSync();
EndToEndTestUtils.createSimpleTrack(0, true);
EndToEndTestUtils.createSimpleTrack(0, true);
EndToEndTestUtils.findMenuItem(
EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_now), true);
SyncTestUtils.checkFilesNumber(drive);
// Remove one track from Google Drive
File file = SyncTestUtils.getFile(EndToEndTestUtils.trackName, drive);
SyncTestUtils.removeFile(file, drive);
EndToEndTestUtils.findMenuItem(
EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_now), true);
SyncTestUtils.checkFilesNumber(drive);
SyncTestUtils.checkTracksNumber(1);
}
/**
* Tests deleting and creating MyTracks folder on Google Dive by MyTracks.
*
* @throws IOException
*/
public void testCreateMyTracksOnDrive() throws IOException {
if (!SyncTestUtils.runSyncTest) {
return;
}
instrumentation.waitForIdleSync();
EndToEndTestUtils.createSimpleTrack(0, true);
EndToEndTestUtils.createSimpleTrack(0, true);
EndToEndTestUtils.findMenuItem(
EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_now), true);
instrumentation.waitForIdleSync();
SyncTestUtils.checkFilesNumber(drive);
File folder = SyncTestUtils.getMyTracksFolder(trackListActivity.getApplicationContext(), drive);
assertNotNull(folder);
SyncTestUtils.removeFile(folder, drive);
EndToEndTestUtils.findMenuItem(
EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_now), true);
SyncTestUtils.checkFilesNumber(drive);
}
}
@@ -0,0 +1,345 @@
/*
* Copyright 2013 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.endtoendtest.sync;
import com.google.android.apps.mytracks.TrackListActivity;
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils;
import com.google.android.apps.mytracks.endtoendtest.GoogleUtils;
import com.google.android.apps.mytracks.io.sync.SyncUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.maps.mytracks.R;
import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential;
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpResponse;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.model.File;
import com.google.api.services.drive.model.FileList;
import android.app.Instrumentation;
import android.content.Context;
import android.util.Log;
import android.widget.CheckBox;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import junit.framework.Assert;
/**
* Utilites for Google Drive sync endtoend test.
*
* @author Youtao Liu
*/
public class SyncTestUtils {
public static boolean isCheckedRunSyncTest = false;
public static boolean runSyncTest = false;
public static final String KML_FILE_POSTFIX = ".kml";
public static final long MAX_TIME_TO_WAIT_SYNC = 50000;
/**
* Sets up sync tests.
*
* @param instrumentation the instrumentation is used for test
* @param trackListActivity the startup activity
* @return a Google Drive object
* @throws IOException
*/
public static Drive setUpForSyncTest(Instrumentation instrumentation,
TrackListActivity trackListActivity) throws IOException {
if (runSyncTest || !isCheckedRunSyncTest) {
EndToEndTestUtils.setupForAllTest(instrumentation, trackListActivity);
}
if (!isCheckedRunSyncTest) {
runSyncTest = canRunSyncTest();
isCheckedRunSyncTest = true;
}
if (runSyncTest) {
EndToEndTestUtils.deleteAllTracks();
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_1);
Drive drive1 = SyncTestUtils.getGoogleDrive(EndToEndTestUtils.activityMytracks
.getApplicationContext());
removeKMLFiles(drive1);
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_2);
Drive drive2 = SyncTestUtils.getGoogleDrive(EndToEndTestUtils.activityMytracks
.getApplicationContext());
removeKMLFiles(drive2);
return drive2;
}
return null;
}
/**
* Runs sync tests when both test accounts are bound with the devices.
*
* @return true means can run sync tests in this device
*/
public static boolean canRunSyncTest() {
EndToEndTestUtils.findMenuItem(
EndToEndTestUtils.activityMytracks.getString(R.string.menu_settings), true);
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks
.getString(R.string.settings_google));
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks
.getString(R.string.settings_google_account_title));
boolean canRunSyncE2ETest = EndToEndTestUtils.SOLO.waitForText(GoogleUtils.ACCOUNT_NAME_1, 1,
EndToEndTestUtils.SHORT_WAIT_TIME)
&& EndToEndTestUtils.SOLO.waitForText(GoogleUtils.ACCOUNT_NAME_2, 1,
EndToEndTestUtils.TINY_WAIT_TIME);
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks
.getString(R.string.generic_cancel));
EndToEndTestUtils.SOLO.goBack();
EndToEndTestUtils.SOLO.goBack();
return canRunSyncE2ETest;
}
/**
* Gets drive object of Google Drive.
*
* @param context the context of application
* @return a Google Drive object
*/
public static Drive getGoogleDrive(Context context) {
String googleAccount = PreferencesUtils.getString(context, R.string.google_account_key,
PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT);
GoogleAccountCredential credential = SyncUtils.getCredential(context, googleAccount);
return SyncUtils.getDriveService(credential);
}
/**
* Gets KML files from Google Drive of current account.
*
* @param context the context of application
* @param drive a Google Drive object
* @return KML file on Google drive
* @throws IOException
*/
public static List<File> getDriveFiles(Context context, Drive drive) throws IOException {
File folder = SyncTestUtils.getMyTracksFolder(context, drive);
if (folder == null) {
return new ArrayList<File>();
}
String folderId = folder.getId();
return drive.files().list()
.setQ(String.format(Locale.US, SyncUtils.GET_KML_FILES_QUERY, folderId)).execute()
.getItems();
}
/**
* Finds whether a file is existed by the name of track.
*
* @param trackName name of track
* @param drive a Google Drive object
* @return the file be found
* @throws IOException
*/
public static File getFile(String trackName, Drive drive) throws IOException {
List<File> files = getDriveFiles(EndToEndTestUtils.activityMytracks.getApplicationContext(),
drive);
for (int i = 0; i < files.size(); i++) {
File file = files.get(i);
String title = file.getTitle();
if (title.equals(trackName + KML_FILE_POSTFIX)) {
return file;
}
}
return null;
}
/**
* Removes all KML files on Google Drive.
*
* @param drive a Google Drive object
* @throws IOException
*/
public static void removeKMLFiles(Drive drive) throws IOException {
List<File> files = SyncTestUtils.getDriveFiles(
EndToEndTestUtils.activityMytracks.getApplicationContext(), drive);
for (int i = 0; i < files.size(); i++) {
File file = files.get(i);
removeFile(file, drive);
}
}
/**
* Removes one file on Google Drive.
*
* @param file the file to remove
* @param drive a Google Drive object
* @throws IOException
*/
public static void removeFile(File file, Drive drive) throws IOException {
drive.files().trash(file.getId()).execute();
}
/**
* Enables sync feature in MyTracks settings.
*
* @param accountName the account which is used to sync with
*/
public static void enableSync(String accountName) {
EndToEndTestUtils.findMenuItem(
EndToEndTestUtils.activityMytracks.getString(R.string.menu_settings), true);
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks
.getString(R.string.settings_google));
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks
.getString(R.string.settings_google_account_title));
// Whether test account is bound.
if (EndToEndTestUtils.SOLO.waitForText(accountName, 1, EndToEndTestUtils.TINY_WAIT_TIME)) {
EndToEndTestUtils.SOLO.clickOnText(accountName);
EndToEndTestUtils.instrumentation.waitForIdleSync();
if (EndToEndTestUtils.SOLO.waitForText(
EndToEndTestUtils.activityMytracks.getString(
R.string.settings_google_account_confirm_message).split("%")[0], 1,
EndToEndTestUtils.SHORT_WAIT_TIME)) {
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks
.getString(R.string.generic_ok));
}
} else {
Assert.fail();
return;
}
EndToEndTestUtils.instrumentation.waitForIdleSync();
CheckBox syncCheckBox = EndToEndTestUtils.SOLO.getCurrentCheckBoxes().get(0);
if (!syncCheckBox.isChecked()) {
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks
.getString(R.string.settings_google_drive_sync_title));
EndToEndTestUtils.SOLO.waitForText(
EndToEndTestUtils.activityMytracks.getString(
R.string.settings_google_drive_sync_confirm_message).split("%")[0], 1,
EndToEndTestUtils.SHORT_WAIT_TIME);
Assert.assertTrue(EndToEndTestUtils.SOLO.searchText(accountName, true));
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks
.getString(R.string.generic_ok));
}
EndToEndTestUtils.SOLO.goBack();
EndToEndTestUtils.SOLO.goBack();
}
/**
* Checks the files number on Google Drive
*
* @param drive a Google Drive object
* @throws IOException
*/
public static void checkFilesNumber(Drive drive) throws IOException {
long startTime = System.currentTimeMillis();
while (System.currentTimeMillis() - startTime < MAX_TIME_TO_WAIT_SYNC) {
try {
int trackNumber = EndToEndTestUtils.SOLO.getCurrentListViews().get(0).getCount();
List<File> files = getDriveFiles(
EndToEndTestUtils.activityMytracks.getApplicationContext(), drive);
if (files.size() == trackNumber) {
return;
}
} catch (GoogleJsonResponseException e) {
EndToEndTestUtils.sleep(EndToEndTestUtils.SHORT_WAIT_TIME);
}
}
Assert.fail();
}
/**
* Checks the files number on Google Drive
*
* @param number number of files on Google Drive
*/
public static void checkTracksNumber(int number) {
long startTime = System.currentTimeMillis();
while (System.currentTimeMillis() - startTime < MAX_TIME_TO_WAIT_SYNC) {
int trackNumber = EndToEndTestUtils.SOLO.getCurrentListViews().get(0).getCount();
if (trackNumber == number) {
return;
}
}
Assert.fail();
}
/**
* Checks one file on Google Drive
*
* @param trackName the name of track
* @param shouldExist true means this track should be existed
* @param drive a Google Drive object
* @return true means the actual result is same as expectation
* @throws IOException
*/
public static boolean checkFile(String trackName, boolean shouldExist, Drive drive)
throws IOException {
long startTime = System.currentTimeMillis();
while (System.currentTimeMillis() - startTime < MAX_TIME_TO_WAIT_SYNC) {
boolean exist = getFile(trackName, drive) != null;
if (exist == shouldExist) {
return true;
}
}
Assert.fail();
return false;
}
/**
* Gets the content of a file on Google Drive.
*
* @param file file to read
* @param drive a Google Drive object
* @return the string content of the file
* @throws IOException
*/
public static String getContentOfFile(File file, Drive drive) throws IOException {
HttpResponse resp = drive.getRequestFactory()
.buildGetRequest(new GenericUrl(file.getDownloadUrl())).execute();
BufferedReader br = new BufferedReader(new InputStreamReader(resp.getContent()));
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line);
}
String fileContent = sb.toString();
br.close();
return fileContent;
}
/**
* Gets the MyTracks folder on Google Drive.
*
* @param context context of application
* @param drive a Google Drive object
* @return the MyTracks folder on Google Drive
*/
public static File getMyTracksFolder(Context context, Drive drive) {
try {
String folderName = context.getString(R.string.my_tracks_app_name);
com.google.api.services.drive.Drive.Files.List list = drive.files().list()
.setQ(String.format(Locale.US, SyncUtils.GET_MY_TRACKS_FOLDER_QUERY, folderName));
FileList result = list.execute();
for (File file : result.getItems()) {
if (file.getTitle().equals(folderName)) {
return file;
}
}
} catch (IOException e) {
Log.e(EndToEndTestUtils.LOG_TAG, "IOException", e);
}
return null;
}
}