diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/sync/SyncUtils.java b/MyTracks/src/com/google/android/apps/mytracks/io/sync/SyncUtils.java index 40aa84998..fb2d2b966 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/sync/SyncUtils.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/sync/SyncUtils.java @@ -76,9 +76,6 @@ public class SyncUtils { public static final String GET_KML_FILES_QUERY = "'%s' in parents and mimeType = '" + KML_MIME_TYPE + "' and trashed = false"; - public static final String GET_MYTRACKS_FOLDER_QUERY = "'%s' in parents and mimeType = '" - + KML_MIME_TYPE + "' and trashed = false"; - private static final String FOLDER_MIME_TYPE = "application/vnd.google-apps.folder"; @VisibleForTesting public static final String GET_MY_TRACKS_FOLDER_QUERY = diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestUtils.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestUtils.java index d458c9119..632468304 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestUtils.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestUtils.java @@ -312,6 +312,8 @@ public class EndToEndTestUtils { } 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(); } diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/MultiAccountsSyncTest.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/MultiAccountsSyncTest.java index 0153f727d..c075222a8 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/MultiAccountsSyncTest.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/MultiAccountsSyncTest.java @@ -50,7 +50,19 @@ public class MultiAccountsSyncTest extends ActivityInstrumentationTestCase2 + *
  • 1. Enable sync with account1.
  • + *
  • 2. Create a track.
  • + *
  • 3. Enable sync with account2.
  • + *
  • 4. Create a track.
  • + *
  • 5. Sync and check
  • + *
  • 6. Enable sync with account1.
  • + *
  • 7. Sync and check
  • + *
  • 8. Enable sync with account2.
  • + *
  • 9. Check
  • + * * * @throws IOException */ @@ -78,12 +90,24 @@ public class MultiAccountsSyncTest extends ActivityInstrumentationTestCase2 + *
  • 1. Create 3 tracks.
  • + *
  • 2. Delete 1 track.
  • + *
  • 3. Sync with account2(account2 should have 2 files).
  • + *
  • 4. Delete 1 track (account2 should have 1 file).
  • + *
  • 5. Sync with account 1 (account 1 should have 1 file, account2 should + * also have 1 file).
  • + * * * @throws IOException */ @@ -132,5 +156,4 @@ public class MultiAccountsSyncTest extends ActivityInstrumentationTestCase2 updateDriveFiles(Context context, Drive drive) throws IOException { + public static List getDriveFiles(Context context, Drive drive) throws IOException { File folder = SyncTestUtils.getMyTracksFolder(context, drive); if (folder == null) { return new ArrayList(); @@ -147,12 +146,12 @@ public class SyncTestUtils { * Finds whether a file is existed by the name of track. * * @param trackName name of track - * @param drive drive object of Google Drive + * @param drive a Google Drive object * @return the file be found * @throws IOException */ public static File getFile(String trackName, Drive drive) throws IOException { - List files = updateDriveFiles(EndToEndTestUtils.activityMytracks.getApplicationContext(), + List files = getDriveFiles(EndToEndTestUtils.activityMytracks.getApplicationContext(), drive); for (int i = 0; i < files.size(); i++) { File file = files.get(i); @@ -167,11 +166,11 @@ public class SyncTestUtils { /** * Removes all KML files on Google Drive. * - * @param drive drive object of Google Drive + * @param drive a Google Drive object * @throws IOException */ public static void removeKMLFiles(Drive drive) throws IOException { - List files = SyncTestUtils.updateDriveFiles( + List files = SyncTestUtils.getDriveFiles( EndToEndTestUtils.activityMytracks.getApplicationContext(), drive); for (int i = 0; i < files.size(); i++) { File file = files.get(i); @@ -183,7 +182,7 @@ public class SyncTestUtils { * Removes one file on Google Drive. * * @param file the file to remove - * @param drive drive object of Google Drive + * @param drive a Google Drive object * @throws IOException */ public static void removeFile(File file, Drive drive) throws IOException { @@ -240,7 +239,7 @@ public class SyncTestUtils { /** * Checks the files number on Google Drive * - * @param drive drive object of Google Drive + * @param drive a Google Drive object * @throws IOException */ public static void checkFilesNumber(Drive drive) throws IOException { @@ -248,7 +247,7 @@ public class SyncTestUtils { while (System.currentTimeMillis() - startTime < MAX_TIME_TO_WAIT_SYNC) { try { int trackNumber = EndToEndTestUtils.SOLO.getCurrentListViews().get(0).getCount(); - List files = updateDriveFiles( + List files = getDriveFiles( EndToEndTestUtils.activityMytracks.getApplicationContext(), drive); if (files.size() == trackNumber) { return; @@ -281,7 +280,7 @@ public class SyncTestUtils { * * @param trackName the name of track * @param shouldExist true means this track should be existed - * @param drive drive object of Google Drive + * @param drive a Google Drive object * @return true means the actual result is same as expectation * @throws IOException */ @@ -289,7 +288,8 @@ public class SyncTestUtils { throws IOException { long startTime = System.currentTimeMillis(); while (System.currentTimeMillis() - startTime < MAX_TIME_TO_WAIT_SYNC) { - if ((getFile(trackName, drive) != null) == shouldExist) { + boolean exist = getFile(trackName, drive) != null; + if (exist == shouldExist) { return true; } } @@ -301,15 +301,14 @@ public class SyncTestUtils { * Gets the content of a file on Google Drive. * * @param file file to read - * @param drive drive object of Google Drive + * @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(); - InputStream response = resp.getContent(); - BufferedReader br = new BufferedReader(new InputStreamReader(response)); + BufferedReader br = new BufferedReader(new InputStreamReader(resp.getContent())); StringBuilder sb = new StringBuilder(); String line; while ((line = br.readLine()) != null) { @@ -324,7 +323,7 @@ public class SyncTestUtils { * Gets the MyTracks folder on Google Drive. * * @param context context of application - * @param drive drive object of Google Drive + * @param drive a Google Drive object * @return the MyTracks folder on Google Drive */ public static File getMyTracksFolder(Context context, Drive drive) {