diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/drive/SendDriveAsyncTask.java b/MyTracks/src/com/google/android/apps/mytracks/io/drive/SendDriveAsyncTask.java index 63238f587..70c809d9c 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/drive/SendDriveAsyncTask.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/drive/SendDriveAsyncTask.java @@ -76,7 +76,7 @@ public class SendDriveAsyncTask extends AbstractSendAsyncTask { return false; } Drive drive = SyncUtils.getDriveService(credential); - String folderId = SyncUtils.getMyTracksFolder(context, drive); + String folderId = SyncUtils.getMyTracksFolder(context, drive).getId(); if (folderId == null) { return false; } diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/sync/SyncAdapter.java b/MyTracks/src/com/google/android/apps/mytracks/io/sync/SyncAdapter.java index fdfc18701..6d4a39024 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/sync/SyncAdapter.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/sync/SyncAdapter.java @@ -113,7 +113,7 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter { driveAccountName = account.name; } - String folderId = SyncUtils.getMyTracksFolder(context, drive); + String folderId = SyncUtils.getMyTracksFolder(context, drive).getId(); if (folderId == null) { return; } 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 b3aebd075..f6bd217f4 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 @@ -153,20 +153,20 @@ public class SyncUtils { * @param context the context * @param drive the drive */ - public static String getMyTracksFolder(Context context, Drive drive) throws IOException { + public static File getMyTracksFolder(Context context, Drive drive) throws IOException { String folderName = context.getString(R.string.my_tracks_app_name); List list = drive.files() .list().setQ(String.format(Locale.US, MY_TRACKS_FOLDER_QUERY, folderName)); FileList result = list.execute(); for (File file : result.getItems()) { if (file.getSharedWithMeDate() == null) { - return file.getId(); + return file; } } File file = new File(); file.setTitle(folderName); file.setMimeType(FOLDER_MIME_TYPE); - return drive.files().insert(file).execute().getId(); + return drive.files().insert(file).execute(); } /** diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestRunner.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestRunner.java index cc1831208..0ee2d9b9f 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestRunner.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestRunner.java @@ -15,7 +15,6 @@ */ package com.google.android.apps.mytracks.endtoendtest; -import com.google.android.apps.mytracks.endtoendtest.others.BigTestUtils; import android.os.Bundle; import android.test.InstrumentationTestRunner; @@ -43,14 +42,14 @@ public class EndToEndTestRunner extends InstrumentationTestRunner { } } - BigTestUtils.runStressTest = "true".equalsIgnoreCase(arguments.getString("stress")); - BigTestUtils.runSensorTest = "true".equalsIgnoreCase(arguments.getString("sensor")); - BigTestUtils.runResourceUsageTest = "true".equalsIgnoreCase(arguments.getString("resource")); + RunConfiguration.runStressTest = "true".equalsIgnoreCase(arguments.getString("stress")); + RunConfiguration.runSensorTest = "true".equalsIgnoreCase(arguments.getString("sensor")); + RunConfiguration.runResourceUsageTest = "true".equalsIgnoreCase(arguments.getString("resource")); Log.d(EndToEndTestUtils.LOG_TAG, "Use port number when run test on emulator:" + EndToEndTestUtils.emulatorPort); - Log.i(EndToEndTestUtils.LOG_TAG, "Run stress test:" + BigTestUtils.runStressTest); - Log.i(EndToEndTestUtils.LOG_TAG, "Run sensor test:" + BigTestUtils.runSensorTest); + Log.i(EndToEndTestUtils.LOG_TAG, "Run stress test:" + RunConfiguration.runStressTest); + Log.i(EndToEndTestUtils.LOG_TAG, "Run sensor test:" + RunConfiguration.runSensorTest); super.onCreate(arguments); } 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 632468304..8768fc652 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 @@ -136,6 +136,8 @@ public class EndToEndTestUtils { public static boolean isCheckedFirstLaunch = false; public static boolean isGooglePlayServicesLatest = true; + private EndToEndTestUtils() {}; + /** * Checks the language, then sets the fields with right string. */ diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/RunConfiguration.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/RunConfiguration.java new file mode 100644 index 000000000..6ece55d4e --- /dev/null +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/RunConfiguration.java @@ -0,0 +1,70 @@ +/* + * 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; + +import com.google.android.maps.mytracks.R; + +/** + * Places all the test configuration in this class. + * + * @author Youtao Liu + */ +public class RunConfiguration { + private static RunConfiguration instance = null; + + /** + * Set to false as default. True to run the test. Default to false since this + * test can take a long time. + */ + public static boolean runStressTest = true; + public static boolean runResourceUsageTest = true; + public static boolean runSensorTest = true; + public boolean runSyncTest = false; + + private RunConfiguration() { + runSyncTest = canRunSyncTest(); + } + + public static RunConfiguration getInstance() { + if (instance == null) { + instance = new RunConfiguration(); + } + return instance; + } + + /** + * 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; + } +} diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/BigTestUtils.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/BigTestUtils.java index 3d42117c6..ab326ea26 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/BigTestUtils.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/BigTestUtils.java @@ -30,13 +30,6 @@ import junit.framework.Assert; */ public class BigTestUtils { - /** - * Set to false as default. True to run the test. Default to false since this - * test can take a long time. - */ - public static boolean runStressTest = true; - public static boolean runSensorTest = true; - public static boolean runResourceUsageTest = true; public static final String DISABLE_MESSAGE = "This test is disabled"; public static final String MYTRACKS_PROCESS_NAME = "com.google.android.maps.mytracks"; public static final String MYTRACKS_TEST_INFO_FILE = "MyTracksTestInfo.txt"; diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/ResourceUsageTest.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/ResourceUsageTest.java index 763357506..a68714695 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/ResourceUsageTest.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/ResourceUsageTest.java @@ -17,6 +17,7 @@ package com.google.android.apps.mytracks.endtoendtest.others; import com.google.android.apps.mytracks.TrackListActivity; import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils; +import com.google.android.apps.mytracks.endtoendtest.RunConfiguration; import com.google.android.maps.mytracks.R; import android.app.AlertDialog; @@ -54,7 +55,7 @@ public class ResourceUsageTest extends ActivityInstrumentationTestCase2 */ public void testSyncTracksWithMultiAccounts() throws Exception { - if (!SyncTestUtils.runSyncTest) { + if (!RunConfiguration.getInstance().runSyncTest) { return; } SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_1); @@ -106,7 +107,7 @@ public class MultiAccountsSyncTest extends ActivityInstrumentationTestCase2 */ public void testDeleteTracksWithMultiAccounts() throws Exception { - if (!SyncTestUtils.runSyncTest) { + if (!RunConfiguration.getInstance().runSyncTest) { return; } EndToEndTestUtils.createSimpleTrack(0, true); diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncDriveWithMyTracksTest.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncDriveWithMyTracksTest.java index a10273236..497d83922 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncDriveWithMyTracksTest.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncDriveWithMyTracksTest.java @@ -17,6 +17,7 @@ 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.RunConfiguration; import com.google.android.maps.mytracks.R; import com.google.api.services.drive.Drive; @@ -27,7 +28,8 @@ import android.view.KeyEvent; import java.io.IOException; /** - * Tests making changes on Google Drive when syncing My Tracks with Google Drive. + * Tests making changes on Google Drive when syncing My Tracks with Google + * Drive. * * @author Youtao Liu */ @@ -55,7 +57,7 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2< * @throws IOException */ public void testDeleteAllTracksInMyTracks() throws IOException { - if (!SyncTestUtils.runSyncTest) { + if (!RunConfiguration.getInstance().runSyncTest) { return; } EndToEndTestUtils.deleteAllTracks(); @@ -70,7 +72,7 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2< * @throws IOException */ public void testDeleteOneTracksInMyTracks() throws IOException { - if (!SyncTestUtils.runSyncTest) { + if (!RunConfiguration.getInstance().runSyncTest) { return; } EndToEndTestUtils.createTrackIfEmpty(2, false); @@ -90,7 +92,7 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2< * @throws IOException */ public void testCreateTracksInMyTracks() throws IOException { - if (!SyncTestUtils.runSyncTest) { + if (!RunConfiguration.getInstance().runSyncTest) { return; } EndToEndTestUtils.deleteAllTracks(); @@ -107,7 +109,7 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2< * @throws IOException */ public void testEditTrackInMyTracks() throws IOException { - if (!SyncTestUtils.runSyncTest) { + if (!RunConfiguration.getInstance().runSyncTest) { return; } EndToEndTestUtils.createTrackIfEmpty(3, true); @@ -152,7 +154,7 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2< assertTrue(newTrack.indexOf(newType) > 0); assertTrue(newTrack.indexOf(newDesc) > 0); } - + @Override protected void tearDown() throws Exception { super.tearDown(); diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncMyTracksWithDriveTest.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncMyTracksWithDriveTest.java index 3b2f1652a..f6ceb334e 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncMyTracksWithDriveTest.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncMyTracksWithDriveTest.java @@ -17,6 +17,8 @@ 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.RunConfiguration; +import com.google.android.apps.mytracks.io.sync.SyncUtils; import com.google.android.maps.mytracks.R; import com.google.api.services.drive.Drive; import com.google.api.services.drive.model.File; @@ -55,7 +57,7 @@ public class SyncMyTracksWithDriveTest extends ActivityInstrumentationTestCase2< * @throws IOException */ public void testDeleteAllTracksOnDrive() throws IOException { - if (!SyncTestUtils.runSyncTest) { + if (!RunConfiguration.getInstance().runSyncTest) { return; } EndToEndTestUtils.createTrackIfEmpty(0, true); @@ -75,7 +77,7 @@ public class SyncMyTracksWithDriveTest extends ActivityInstrumentationTestCase2< * @throws IOException */ public void testDeleteOneFileOnDrive() throws IOException { - if (!SyncTestUtils.runSyncTest) { + if (!RunConfiguration.getInstance().runSyncTest) { return; } instrumentation.waitForIdleSync(); @@ -100,7 +102,7 @@ public class SyncMyTracksWithDriveTest extends ActivityInstrumentationTestCase2< * @throws IOException */ public void testCreateMyTracksOnDrive() throws IOException { - if (!SyncTestUtils.runSyncTest) { + if (!RunConfiguration.getInstance().runSyncTest) { return; } instrumentation.waitForIdleSync(); @@ -110,7 +112,7 @@ public class SyncMyTracksWithDriveTest extends ActivityInstrumentationTestCase2< EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_now), true); instrumentation.waitForIdleSync(); SyncTestUtils.checkFilesNumber(drive); - File folder = SyncTestUtils.getMyTracksFolder(trackListActivity.getApplicationContext(), drive); + File folder = SyncUtils.getMyTracksFolder(trackListActivity.getApplicationContext(), drive); assertNotNull(folder); SyncTestUtils.removeFile(folder, drive); diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncTestUtils.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncTestUtils.java index 4f7041242..3e27d62b3 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncTestUtils.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncTestUtils.java @@ -18,6 +18,7 @@ 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.endtoendtest.RunConfiguration; import com.google.android.apps.mytracks.io.sendtogoogle.SendToGoogleUtils; import com.google.android.apps.mytracks.io.sync.SyncUtils; import com.google.android.apps.mytracks.util.PreferencesUtils; @@ -29,11 +30,9 @@ 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; @@ -53,7 +52,6 @@ import junit.framework.Assert; 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; @@ -66,14 +64,13 @@ public class SyncTestUtils { */ public static Drive setUpForSyncTest(Instrumentation instrumentation, TrackListActivity trackListActivity) throws IOException, GoogleAuthException { - if (runSyncTest || !isCheckedRunSyncTest) { + if (RunConfiguration.getInstance().runSyncTest || !isCheckedRunSyncTest) { EndToEndTestUtils.setupForAllTest(instrumentation, trackListActivity); } if (!isCheckedRunSyncTest) { - runSyncTest = canRunSyncTest(); isCheckedRunSyncTest = true; } - if (runSyncTest) { + if (RunConfiguration.getInstance().runSyncTest) { EndToEndTestUtils.deleteAllTracks(); SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_1); Drive drive1 = SyncTestUtils.getGoogleDrive(EndToEndTestUtils.activityMytracks @@ -88,29 +85,6 @@ public class SyncTestUtils { 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. * @@ -118,10 +92,10 @@ public class SyncTestUtils { * @return a Google Drive object */ public static Drive getGoogleDrive(Context context) throws IOException, GoogleAuthException { - String googleAccount = PreferencesUtils.getString( - context, R.string.google_account_key, PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT); - GoogleAccountCredential credential = SendToGoogleUtils.getGoogleAccountCredential( - context, googleAccount, SendToGoogleUtils.DRIVE_SCOPE); + String googleAccount = PreferencesUtils.getString(context, R.string.google_account_key, + PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT); + GoogleAccountCredential credential = SendToGoogleUtils.getGoogleAccountCredential(context, + googleAccount, SendToGoogleUtils.DRIVE_SCOPE); return SyncUtils.getDriveService(credential); } @@ -134,7 +108,7 @@ public class SyncTestUtils { * @throws IOException */ public static List getDriveFiles(Context context, Drive drive) throws IOException { - File folder = SyncTestUtils.getMyTracksFolder(context, drive); + File folder = SyncUtils.getMyTracksFolder(context, drive); if (folder == null) { return new ArrayList(); } @@ -320,28 +294,4 @@ public class SyncTestUtils { 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.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; - } }