forked from upstream-mirrors/OpenTracks
merge branches
This commit is contained in:
@@ -76,7 +76,7 @@ public class SendDriveAsyncTask extends AbstractSendAsyncTask {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Drive drive = SyncUtils.getDriveService(credential);
|
Drive drive = SyncUtils.getDriveService(credential);
|
||||||
String folderId = SyncUtils.getMyTracksFolder(context, drive);
|
String folderId = SyncUtils.getMyTracksFolder(context, drive).getId();
|
||||||
if (folderId == null) {
|
if (folderId == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter {
|
|||||||
driveAccountName = account.name;
|
driveAccountName = account.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
String folderId = SyncUtils.getMyTracksFolder(context, drive);
|
String folderId = SyncUtils.getMyTracksFolder(context, drive).getId();
|
||||||
if (folderId == null) {
|
if (folderId == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -153,20 +153,20 @@ public class SyncUtils {
|
|||||||
* @param context the context
|
* @param context the context
|
||||||
* @param drive the drive
|
* @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);
|
String folderName = context.getString(R.string.my_tracks_app_name);
|
||||||
List list = drive.files()
|
List list = drive.files()
|
||||||
.list().setQ(String.format(Locale.US, MY_TRACKS_FOLDER_QUERY, folderName));
|
.list().setQ(String.format(Locale.US, MY_TRACKS_FOLDER_QUERY, folderName));
|
||||||
FileList result = list.execute();
|
FileList result = list.execute();
|
||||||
for (File file : result.getItems()) {
|
for (File file : result.getItems()) {
|
||||||
if (file.getSharedWithMeDate() == null) {
|
if (file.getSharedWithMeDate() == null) {
|
||||||
return file.getId();
|
return file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File file = new File();
|
File file = new File();
|
||||||
file.setTitle(folderName);
|
file.setTitle(folderName);
|
||||||
file.setMimeType(FOLDER_MIME_TYPE);
|
file.setMimeType(FOLDER_MIME_TYPE);
|
||||||
return drive.files().insert(file).execute().getId();
|
return drive.files().insert(file).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+5
-6
@@ -15,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.apps.mytracks.endtoendtest;
|
package com.google.android.apps.mytracks.endtoendtest;
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.endtoendtest.others.BigTestUtils;
|
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.test.InstrumentationTestRunner;
|
import android.test.InstrumentationTestRunner;
|
||||||
@@ -43,14 +42,14 @@ public class EndToEndTestRunner extends InstrumentationTestRunner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BigTestUtils.runStressTest = "true".equalsIgnoreCase(arguments.getString("stress"));
|
RunConfiguration.runStressTest = "true".equalsIgnoreCase(arguments.getString("stress"));
|
||||||
BigTestUtils.runSensorTest = "true".equalsIgnoreCase(arguments.getString("sensor"));
|
RunConfiguration.runSensorTest = "true".equalsIgnoreCase(arguments.getString("sensor"));
|
||||||
BigTestUtils.runResourceUsageTest = "true".equalsIgnoreCase(arguments.getString("resource"));
|
RunConfiguration.runResourceUsageTest = "true".equalsIgnoreCase(arguments.getString("resource"));
|
||||||
|
|
||||||
Log.d(EndToEndTestUtils.LOG_TAG, "Use port number when run test on emulator:"
|
Log.d(EndToEndTestUtils.LOG_TAG, "Use port number when run test on emulator:"
|
||||||
+ EndToEndTestUtils.emulatorPort);
|
+ EndToEndTestUtils.emulatorPort);
|
||||||
Log.i(EndToEndTestUtils.LOG_TAG, "Run stress test:" + BigTestUtils.runStressTest);
|
Log.i(EndToEndTestUtils.LOG_TAG, "Run stress test:" + RunConfiguration.runStressTest);
|
||||||
Log.i(EndToEndTestUtils.LOG_TAG, "Run sensor test:" + BigTestUtils.runSensorTest);
|
Log.i(EndToEndTestUtils.LOG_TAG, "Run sensor test:" + RunConfiguration.runSensorTest);
|
||||||
|
|
||||||
super.onCreate(arguments);
|
super.onCreate(arguments);
|
||||||
}
|
}
|
||||||
|
|||||||
+2
@@ -136,6 +136,8 @@ 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.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+70
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
-7
@@ -30,13 +30,6 @@ import junit.framework.Assert;
|
|||||||
*/
|
*/
|
||||||
public class BigTestUtils {
|
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 DISABLE_MESSAGE = "This test is disabled";
|
||||||
public static final String MYTRACKS_PROCESS_NAME = "com.google.android.maps.mytracks";
|
public static final String MYTRACKS_PROCESS_NAME = "com.google.android.maps.mytracks";
|
||||||
public static final String MYTRACKS_TEST_INFO_FILE = "MyTracksTestInfo.txt";
|
public static final String MYTRACKS_TEST_INFO_FILE = "MyTracksTestInfo.txt";
|
||||||
|
|||||||
+2
-1
@@ -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.TrackListActivity;
|
||||||
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils;
|
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.android.maps.mytracks.R;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
@@ -54,7 +55,7 @@ public class ResourceUsageTest extends ActivityInstrumentationTestCase2<TrackLis
|
|||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
runTest = BigTestUtils.runResourceUsageTest;
|
runTest = RunConfiguration.runResourceUsageTest;
|
||||||
if (!runTest) {
|
if (!runTest) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -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.TrackListActivity;
|
||||||
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils;
|
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.android.maps.mytracks.R;
|
||||||
|
|
||||||
import android.app.Instrumentation;
|
import android.app.Instrumentation;
|
||||||
@@ -46,7 +47,7 @@ public class SensorTest extends ActivityInstrumentationTestCase2<TrackListActivi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
runTest = BigTestUtils.runSensorTest;
|
runTest = RunConfiguration.runSensorTest;
|
||||||
super.setUp();
|
super.setUp();
|
||||||
if (!runTest) {
|
if (!runTest) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
+2
-1
@@ -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.TrackListActivity;
|
||||||
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils;
|
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.android.maps.mytracks.R;
|
||||||
|
|
||||||
import android.app.Instrumentation;
|
import android.app.Instrumentation;
|
||||||
@@ -46,7 +47,7 @@ public class StressTest extends ActivityInstrumentationTestCase2<TrackListActivi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
runTest = BigTestUtils.runStressTest;
|
runTest = RunConfiguration.runStressTest;
|
||||||
super.setUp();
|
super.setUp();
|
||||||
if (!runTest) {
|
if (!runTest) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
+3
-2
@@ -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.TrackListActivity;
|
||||||
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils;
|
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils;
|
||||||
import com.google.android.apps.mytracks.endtoendtest.GoogleUtils;
|
import com.google.android.apps.mytracks.endtoendtest.GoogleUtils;
|
||||||
|
import com.google.android.apps.mytracks.endtoendtest.RunConfiguration;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
import com.google.api.services.drive.Drive;
|
import com.google.api.services.drive.Drive;
|
||||||
|
|
||||||
@@ -63,7 +64,7 @@ public class MultiAccountsSyncTest extends ActivityInstrumentationTestCase2<Trac
|
|||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
public void testSyncTracksWithMultiAccounts() throws Exception {
|
public void testSyncTracksWithMultiAccounts() throws Exception {
|
||||||
if (!SyncTestUtils.runSyncTest) {
|
if (!RunConfiguration.getInstance().runSyncTest) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_1);
|
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_1);
|
||||||
@@ -106,7 +107,7 @@ public class MultiAccountsSyncTest extends ActivityInstrumentationTestCase2<Trac
|
|||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
public void testDeleteTracksWithMultiAccounts() throws Exception {
|
public void testDeleteTracksWithMultiAccounts() throws Exception {
|
||||||
if (!SyncTestUtils.runSyncTest) {
|
if (!RunConfiguration.getInstance().runSyncTest) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EndToEndTestUtils.createSimpleTrack(0, true);
|
EndToEndTestUtils.createSimpleTrack(0, true);
|
||||||
|
|||||||
+8
-6
@@ -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.TrackListActivity;
|
||||||
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils;
|
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.android.maps.mytracks.R;
|
||||||
import com.google.api.services.drive.Drive;
|
import com.google.api.services.drive.Drive;
|
||||||
|
|
||||||
@@ -27,7 +28,8 @@ import android.view.KeyEvent;
|
|||||||
import java.io.IOException;
|
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
|
* @author Youtao Liu
|
||||||
*/
|
*/
|
||||||
@@ -55,7 +57,7 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2<
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void testDeleteAllTracksInMyTracks() throws IOException {
|
public void testDeleteAllTracksInMyTracks() throws IOException {
|
||||||
if (!SyncTestUtils.runSyncTest) {
|
if (!RunConfiguration.getInstance().runSyncTest) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EndToEndTestUtils.deleteAllTracks();
|
EndToEndTestUtils.deleteAllTracks();
|
||||||
@@ -70,7 +72,7 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2<
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void testDeleteOneTracksInMyTracks() throws IOException {
|
public void testDeleteOneTracksInMyTracks() throws IOException {
|
||||||
if (!SyncTestUtils.runSyncTest) {
|
if (!RunConfiguration.getInstance().runSyncTest) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EndToEndTestUtils.createTrackIfEmpty(2, false);
|
EndToEndTestUtils.createTrackIfEmpty(2, false);
|
||||||
@@ -90,7 +92,7 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2<
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void testCreateTracksInMyTracks() throws IOException {
|
public void testCreateTracksInMyTracks() throws IOException {
|
||||||
if (!SyncTestUtils.runSyncTest) {
|
if (!RunConfiguration.getInstance().runSyncTest) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EndToEndTestUtils.deleteAllTracks();
|
EndToEndTestUtils.deleteAllTracks();
|
||||||
@@ -107,7 +109,7 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2<
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void testEditTrackInMyTracks() throws IOException {
|
public void testEditTrackInMyTracks() throws IOException {
|
||||||
if (!SyncTestUtils.runSyncTest) {
|
if (!RunConfiguration.getInstance().runSyncTest) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EndToEndTestUtils.createTrackIfEmpty(3, true);
|
EndToEndTestUtils.createTrackIfEmpty(3, true);
|
||||||
@@ -152,7 +154,7 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2<
|
|||||||
assertTrue(newTrack.indexOf(newType) > 0);
|
assertTrue(newTrack.indexOf(newType) > 0);
|
||||||
assertTrue(newTrack.indexOf(newDesc) > 0);
|
assertTrue(newTrack.indexOf(newDesc) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
|
|||||||
+6
-4
@@ -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.TrackListActivity;
|
||||||
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils;
|
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.android.maps.mytracks.R;
|
||||||
import com.google.api.services.drive.Drive;
|
import com.google.api.services.drive.Drive;
|
||||||
import com.google.api.services.drive.model.File;
|
import com.google.api.services.drive.model.File;
|
||||||
@@ -55,7 +57,7 @@ public class SyncMyTracksWithDriveTest extends ActivityInstrumentationTestCase2<
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void testDeleteAllTracksOnDrive() throws IOException {
|
public void testDeleteAllTracksOnDrive() throws IOException {
|
||||||
if (!SyncTestUtils.runSyncTest) {
|
if (!RunConfiguration.getInstance().runSyncTest) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EndToEndTestUtils.createTrackIfEmpty(0, true);
|
EndToEndTestUtils.createTrackIfEmpty(0, true);
|
||||||
@@ -75,7 +77,7 @@ public class SyncMyTracksWithDriveTest extends ActivityInstrumentationTestCase2<
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void testDeleteOneFileOnDrive() throws IOException {
|
public void testDeleteOneFileOnDrive() throws IOException {
|
||||||
if (!SyncTestUtils.runSyncTest) {
|
if (!RunConfiguration.getInstance().runSyncTest) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
instrumentation.waitForIdleSync();
|
instrumentation.waitForIdleSync();
|
||||||
@@ -100,7 +102,7 @@ public class SyncMyTracksWithDriveTest extends ActivityInstrumentationTestCase2<
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void testCreateMyTracksOnDrive() throws IOException {
|
public void testCreateMyTracksOnDrive() throws IOException {
|
||||||
if (!SyncTestUtils.runSyncTest) {
|
if (!RunConfiguration.getInstance().runSyncTest) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
instrumentation.waitForIdleSync();
|
instrumentation.waitForIdleSync();
|
||||||
@@ -110,7 +112,7 @@ public class SyncMyTracksWithDriveTest extends ActivityInstrumentationTestCase2<
|
|||||||
EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_now), true);
|
EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_now), true);
|
||||||
instrumentation.waitForIdleSync();
|
instrumentation.waitForIdleSync();
|
||||||
SyncTestUtils.checkFilesNumber(drive);
|
SyncTestUtils.checkFilesNumber(drive);
|
||||||
File folder = SyncTestUtils.getMyTracksFolder(trackListActivity.getApplicationContext(), drive);
|
File folder = SyncUtils.getMyTracksFolder(trackListActivity.getApplicationContext(), drive);
|
||||||
assertNotNull(folder);
|
assertNotNull(folder);
|
||||||
|
|
||||||
SyncTestUtils.removeFile(folder, drive);
|
SyncTestUtils.removeFile(folder, drive);
|
||||||
|
|||||||
+8
-58
@@ -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.TrackListActivity;
|
||||||
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils;
|
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils;
|
||||||
import com.google.android.apps.mytracks.endtoendtest.GoogleUtils;
|
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.sendtogoogle.SendToGoogleUtils;
|
||||||
import com.google.android.apps.mytracks.io.sync.SyncUtils;
|
import com.google.android.apps.mytracks.io.sync.SyncUtils;
|
||||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
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.client.http.HttpResponse;
|
||||||
import com.google.api.services.drive.Drive;
|
import com.google.api.services.drive.Drive;
|
||||||
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 android.app.Instrumentation;
|
import android.app.Instrumentation;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
@@ -53,7 +52,6 @@ import junit.framework.Assert;
|
|||||||
public class SyncTestUtils {
|
public class SyncTestUtils {
|
||||||
|
|
||||||
public static boolean isCheckedRunSyncTest = false;
|
public static boolean isCheckedRunSyncTest = false;
|
||||||
public static boolean runSyncTest = false;
|
|
||||||
public static final String KML_FILE_POSTFIX = ".kml";
|
public static final String KML_FILE_POSTFIX = ".kml";
|
||||||
public static final long MAX_TIME_TO_WAIT_SYNC = 50000;
|
public static final long MAX_TIME_TO_WAIT_SYNC = 50000;
|
||||||
|
|
||||||
@@ -66,14 +64,13 @@ public class SyncTestUtils {
|
|||||||
*/
|
*/
|
||||||
public static Drive setUpForSyncTest(Instrumentation instrumentation,
|
public static Drive setUpForSyncTest(Instrumentation instrumentation,
|
||||||
TrackListActivity trackListActivity) throws IOException, GoogleAuthException {
|
TrackListActivity trackListActivity) throws IOException, GoogleAuthException {
|
||||||
if (runSyncTest || !isCheckedRunSyncTest) {
|
if (RunConfiguration.getInstance().runSyncTest || !isCheckedRunSyncTest) {
|
||||||
EndToEndTestUtils.setupForAllTest(instrumentation, trackListActivity);
|
EndToEndTestUtils.setupForAllTest(instrumentation, trackListActivity);
|
||||||
}
|
}
|
||||||
if (!isCheckedRunSyncTest) {
|
if (!isCheckedRunSyncTest) {
|
||||||
runSyncTest = canRunSyncTest();
|
|
||||||
isCheckedRunSyncTest = true;
|
isCheckedRunSyncTest = true;
|
||||||
}
|
}
|
||||||
if (runSyncTest) {
|
if (RunConfiguration.getInstance().runSyncTest) {
|
||||||
EndToEndTestUtils.deleteAllTracks();
|
EndToEndTestUtils.deleteAllTracks();
|
||||||
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_1);
|
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_1);
|
||||||
Drive drive1 = SyncTestUtils.getGoogleDrive(EndToEndTestUtils.activityMytracks
|
Drive drive1 = SyncTestUtils.getGoogleDrive(EndToEndTestUtils.activityMytracks
|
||||||
@@ -88,29 +85,6 @@ public class SyncTestUtils {
|
|||||||
return null;
|
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.
|
* Gets drive object of Google Drive.
|
||||||
*
|
*
|
||||||
@@ -118,10 +92,10 @@ public class SyncTestUtils {
|
|||||||
* @return a Google Drive object
|
* @return a Google Drive object
|
||||||
*/
|
*/
|
||||||
public static Drive getGoogleDrive(Context context) throws IOException, GoogleAuthException {
|
public static Drive getGoogleDrive(Context context) throws IOException, GoogleAuthException {
|
||||||
String googleAccount = PreferencesUtils.getString(
|
String googleAccount = PreferencesUtils.getString(context, R.string.google_account_key,
|
||||||
context, R.string.google_account_key, PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT);
|
PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT);
|
||||||
GoogleAccountCredential credential = SendToGoogleUtils.getGoogleAccountCredential(
|
GoogleAccountCredential credential = SendToGoogleUtils.getGoogleAccountCredential(context,
|
||||||
context, googleAccount, SendToGoogleUtils.DRIVE_SCOPE);
|
googleAccount, SendToGoogleUtils.DRIVE_SCOPE);
|
||||||
return SyncUtils.getDriveService(credential);
|
return SyncUtils.getDriveService(credential);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,7 +108,7 @@ public class SyncTestUtils {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public static List<File> getDriveFiles(Context context, Drive drive) throws IOException {
|
public static List<File> getDriveFiles(Context context, Drive drive) throws IOException {
|
||||||
File folder = SyncTestUtils.getMyTracksFolder(context, drive);
|
File folder = SyncUtils.getMyTracksFolder(context, drive);
|
||||||
if (folder == null) {
|
if (folder == null) {
|
||||||
return new ArrayList<File>();
|
return new ArrayList<File>();
|
||||||
}
|
}
|
||||||
@@ -320,28 +294,4 @@ public class SyncTestUtils {
|
|||||||
br.close();
|
br.close();
|
||||||
return fileContent;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user