forked from upstream-mirrors/OpenTracks
Split the CreateAndSendTrackTest to two files. Add a test case to test the send same track(the activity string of this track contains special character) to Google twice.
This commit is contained in:
+6
-81
@@ -30,13 +30,13 @@ import java.util.ArrayList;
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
||||
public class CreateTrackTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
||||
|
||||
private static final String WAYPOINT_NAME = "testWaypoint";
|
||||
private Instrumentation instrumentation;
|
||||
private TrackListActivity activityMyTracks;
|
||||
|
||||
public CreateAndSendTrackTest() {
|
||||
public CreateTrackTest() {
|
||||
super(TrackListActivity.class);
|
||||
}
|
||||
|
||||
@@ -83,25 +83,6 @@ public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2<Tra
|
||||
// Stop here for do not really send.
|
||||
}
|
||||
|
||||
/**
|
||||
* Check all services and send to google.
|
||||
*/
|
||||
public void testCreateAndSendTrack_send() {
|
||||
EndToEndTestUtils.createTrackIfEmpty(1, false);
|
||||
instrumentation.waitForIdleSync();
|
||||
checkSendTrackToGoogle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check all services and send to google.
|
||||
*/
|
||||
public void testCreateAndSendTrack_sendPausedTrack() {
|
||||
EndToEndTestUtils.deleteAllTracks();
|
||||
EndToEndTestUtils.createTrackWithPause(3);
|
||||
instrumentation.waitForIdleSync();
|
||||
checkSendTrackToGoogle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests editing a track.
|
||||
*/
|
||||
@@ -111,7 +92,7 @@ public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2<Tra
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_edit), true);
|
||||
|
||||
String newTrackName = EndToEndTestUtils.TRACK_NAME_PREFIX + "_new" + System.currentTimeMillis();
|
||||
String newType = EndToEndTestUtils.DEFAULTACTIVITY;
|
||||
String newType = EndToEndTestUtils.activityType;
|
||||
String newDesc = "desc" + newTrackName;
|
||||
|
||||
instrumentation.waitForIdleSync();
|
||||
@@ -154,7 +135,7 @@ public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2<Tra
|
||||
EndToEndTestUtils.stopRecording(false);
|
||||
EndToEndTestUtils.trackName = EndToEndTestUtils.TRACK_NAME_PREFIX + System.currentTimeMillis();
|
||||
EndToEndTestUtils.SOLO.enterText(0, EndToEndTestUtils.trackName);
|
||||
EndToEndTestUtils.SOLO.enterText(1, EndToEndTestUtils.DEFAULTACTIVITY);
|
||||
EndToEndTestUtils.SOLO.enterText(1, EndToEndTestUtils.activityType);
|
||||
|
||||
EndToEndTestUtils.SOLO.clickOnButton(activityMyTracks.getString(R.string.generic_save));
|
||||
|
||||
@@ -191,8 +172,7 @@ public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2<Tra
|
||||
|
||||
// Test should show relative time for createSimpleTrack would save a track
|
||||
// name that is different with the start time.
|
||||
EndToEndTestUtils.createSimpleTrack(2);
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
EndToEndTestUtils.createSimpleTrack(2, true);
|
||||
assertTrue(EndToEndTestUtils.SOLO.waitForText(EndToEndTestUtils.RELATIVE_STARTTIME_POSTFIX, 1, EndToEndTestUtils.NORMAL_WAIT_TIME));
|
||||
}
|
||||
|
||||
@@ -227,61 +207,6 @@ public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2<Tra
|
||||
EndToEndTestUtils.stopRecording(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the process of sending track to google.
|
||||
*/
|
||||
private void checkSendTrackToGoogle() {
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_send_google), true);
|
||||
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.send_google_title));
|
||||
ArrayList<CheckBox> checkBoxs = EndToEndTestUtils.SOLO.getCurrentCheckBoxes();
|
||||
for (int i = 0; i < checkBoxs.size(); i++) {
|
||||
if (!checkBoxs.get(i).isChecked()) {
|
||||
EndToEndTestUtils.SOLO.clickOnCheckBox(i);
|
||||
}
|
||||
}
|
||||
|
||||
if (checkBoxs.size() < 3) {
|
||||
EndToEndTestUtils.SOLO.scrollDown();
|
||||
checkBoxs = EndToEndTestUtils.SOLO.getCurrentCheckBoxes();
|
||||
|
||||
// Choose all Google service.
|
||||
for (int i = 0; i < checkBoxs.size(); i++) {
|
||||
if (!checkBoxs.get(i).isChecked()) {
|
||||
EndToEndTestUtils.SOLO.clickOnCheckBox(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.send_google_send_now),
|
||||
true, true);
|
||||
|
||||
if(!GoogleUtils.isAccountAvailable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Following check the process of "Send to Google".
|
||||
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks
|
||||
.getString(R.string.generic_progress_title)));
|
||||
// Waiting the send is finish.
|
||||
while (EndToEndTestUtils.SOLO.waitForText(
|
||||
activityMyTracks.getString(R.string.generic_progress_title), 1,
|
||||
EndToEndTestUtils.SHORT_WAIT_TIME)) {}
|
||||
|
||||
// Check whether the result dialog is display.
|
||||
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks
|
||||
.getString(R.string.share_track_share_url)));
|
||||
EndToEndTestUtils
|
||||
.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
|
||||
|
||||
// Check whether all data is correct on Google Map, Documents, and
|
||||
// Spreadsheet.
|
||||
assertTrue(GoogleUtils.deleteMap(EndToEndTestUtils.trackName, activityMyTracks));
|
||||
assertTrue(GoogleUtils.searchFusionTableByTitle(EndToEndTestUtils.TRACK_NAME_PREFIX,
|
||||
activityMyTracks));
|
||||
assertTrue(GoogleUtils.deleteTrackInSpreadSheet(EndToEndTestUtils.trackName, activityMyTracks));
|
||||
assertTrue(GoogleUtils.dropFusionTables(EndToEndTestUtils.trackName, activityMyTracks));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a way point and a split maker during track recording.
|
||||
*/
|
||||
@@ -305,4 +230,4 @@ public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2<Tra
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+13
-9
@@ -70,7 +70,8 @@ public class EndToEndTestUtils {
|
||||
|
||||
private static final String MOREOPTION_CLASSNAME = "com.android.internal.view.menu.ActionMenuPresenter$OverflowMenuButton";
|
||||
|
||||
static final String DEFAULTACTIVITY = "TestActivity";
|
||||
static final String DEFAULTACTIVITYTYPE = "TestActivity";
|
||||
public static String activityType = DEFAULTACTIVITYTYPE;
|
||||
static final String TRACK_NAME_PREFIX = "testTrackName";
|
||||
static final String GPX = "gpx";
|
||||
static final String KML = "kml";
|
||||
@@ -319,12 +320,20 @@ public class EndToEndTestUtils {
|
||||
* will save a customized track name.
|
||||
*
|
||||
* @param numberOfGpsData number of simulated Gps data
|
||||
* @param showTrackList whether stay on track list activity or track detail
|
||||
* activity
|
||||
*/
|
||||
public static void createSimpleTrack(int numberOfGpsData) {
|
||||
public static void createSimpleTrack(int numberOfGpsData, boolean showTrackList) {
|
||||
startRecording();
|
||||
sendGps(numberOfGpsData);
|
||||
instrumentation.waitForIdleSync();
|
||||
stopRecording(true);
|
||||
|
||||
instrumentation.waitForIdleSync();
|
||||
if (showTrackList) {
|
||||
SOLO.goBack();
|
||||
}
|
||||
instrumentation.waitForIdleSync();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -374,12 +383,7 @@ public class EndToEndTestUtils {
|
||||
public static void createTrackIfEmpty(int gpsNumber, boolean showTrackList) {
|
||||
if (isTrackListEmpty(!showTrackList)) {
|
||||
// Create a simple track.
|
||||
createSimpleTrack(gpsNumber);
|
||||
instrumentation.waitForIdleSync();
|
||||
if (showTrackList) {
|
||||
SOLO.goBack();
|
||||
}
|
||||
instrumentation.waitForIdleSync();
|
||||
createSimpleTrack(gpsNumber, showTrackList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -442,7 +446,7 @@ public class EndToEndTestUtils {
|
||||
+ System.currentTimeMillis();
|
||||
SOLO.sendKey(KeyEvent.KEYCODE_DEL);
|
||||
enterTextAvoidSoftKeyBoard(0, trackName);
|
||||
enterTextAvoidSoftKeyBoard(1, DEFAULTACTIVITY);
|
||||
enterTextAvoidSoftKeyBoard(1, activityType);
|
||||
SOLO.clickOnText(activityMytracks.getString(R.string.generic_save));
|
||||
instrumentation.waitForIdleSync();
|
||||
}
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ public class ExportAndImportTest extends ActivityInstrumentationTestCase2<TrackL
|
||||
EndToEndTestUtils.createTrackIfEmpty(3, true);
|
||||
instrumentation.waitForIdleSync();
|
||||
// Create a empty track.
|
||||
EndToEndTestUtils.createSimpleTrack(0);
|
||||
EndToEndTestUtils.createSimpleTrack(0, true);
|
||||
instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
instrumentation.waitForIdleSync();
|
||||
|
||||
@@ -54,6 +54,7 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
@@ -64,7 +65,7 @@ import java.util.Locale;
|
||||
*/
|
||||
public class GoogleUtils {
|
||||
public static final String DOCUMENT_NAME_PREFIX = "My Tracks";
|
||||
public static final String SPREADSHEET_NAME = DOCUMENT_NAME_PREFIX + "-" + EndToEndTestUtils.DEFAULTACTIVITY;
|
||||
public static final String SPREADSHEET_NAME = DOCUMENT_NAME_PREFIX + "-" + EndToEndTestUtils.activityType;
|
||||
|
||||
/**
|
||||
* Gets the account to access Google Services.
|
||||
@@ -178,7 +179,7 @@ public class GoogleUtils {
|
||||
* @param activity to get context
|
||||
* @return the entry of the document, null means can not find the spreadsheet.
|
||||
*/
|
||||
private static Entry searchSpreadsheetByTitle(String title, Activity activity) {
|
||||
public static Entry searchSpreadsheetByTitle(String title, Activity activity) {
|
||||
Context context = activity.getApplicationContext();
|
||||
DocumentsClient documentsClient = new DocumentsClient(
|
||||
GDataClientFactory.getGDataClient(context),
|
||||
@@ -206,6 +207,42 @@ public class GoogleUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches docs in user's Google Documents.
|
||||
*
|
||||
* @param title the title of doc
|
||||
* @param activity to get context
|
||||
* @return the entry of the document, null means can not find the spreadsheet.
|
||||
*/
|
||||
public static List<Entry> searchAllSpreadsheetByTitle(String title, Activity activity) {
|
||||
List<Entry> docs = new ArrayList<Entry>();
|
||||
Context context = activity.getApplicationContext();
|
||||
DocumentsClient documentsClient = new DocumentsClient(
|
||||
GDataClientFactory.getGDataClient(context),
|
||||
new XmlDocsGDataParserFactory(new AndroidXmlParserFactory()));
|
||||
|
||||
try {
|
||||
String documentsAuthToken = AccountManager.get(context)
|
||||
.blockingGetAuthToken(getAccount(context), documentsClient.getServiceName(), false);
|
||||
String uri = String.format(Locale.US, SendDocsUtils.GET_SPREADSHEET_BY_TITLE_URI,
|
||||
URLEncoder.encode(title, "utf-8"));
|
||||
GDataParser gDataParser = documentsClient.getParserForFeed(Entry.class, uri,
|
||||
documentsAuthToken);
|
||||
gDataParser.init();
|
||||
|
||||
while (gDataParser.hasMoreData()) {
|
||||
Entry entry = gDataParser.readNextEntry(null);
|
||||
String entryTitle = entry.getTitle();
|
||||
if (entryTitle.equals(title)) {
|
||||
docs.add(entry);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.d(EndToEndTestUtils.LOG_TAG, "Unable to fetch spreadsheet.", e);
|
||||
}
|
||||
return docs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Searches a track title in a spreadsheet.
|
||||
@@ -396,4 +433,4 @@ public class GoogleUtils {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,7 @@ public class MenuItemsTest extends ActivityInstrumentationTestCase2<TrackListAct
|
||||
* Tests search menu item.
|
||||
*/
|
||||
public void testSearch() {
|
||||
EndToEndTestUtils.createSimpleTrack(1);
|
||||
EndToEndTestUtils.createSimpleTrack(0, true);
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_search), true);
|
||||
EndToEndTestUtils.enterTextAvoidSoftKeyBoard(0, EndToEndTestUtils.trackName);
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Copyright 2012 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.apps.mytracks.TrackListActivity;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
import com.google.wireless.gdata.data.Entry;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Instrumentation;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.widget.CheckBox;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Tests the logic of send track to Google.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class SendToGoogleTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
||||
|
||||
private Instrumentation instrumentation;
|
||||
private TrackListActivity activityMyTracks;
|
||||
|
||||
@TargetApi(15)
|
||||
public SendToGoogleTest() {
|
||||
super(TrackListActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
instrumentation = getInstrumentation();
|
||||
activityMyTracks = getActivity();
|
||||
EndToEndTestUtils.setupForAllTest(instrumentation, activityMyTracks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check all services and send to google.
|
||||
*/
|
||||
public void testCreateAndSendTrack_send() {
|
||||
EndToEndTestUtils.createTrackIfEmpty(1, false);
|
||||
instrumentation.waitForIdleSync();
|
||||
checkSendTrackToGoogle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check all services and send to google.
|
||||
*/
|
||||
public void testCreateAndSendTrack_sendPausedTrack() {
|
||||
EndToEndTestUtils.deleteAllTracks();
|
||||
EndToEndTestUtils.createTrackWithPause(3);
|
||||
instrumentation.waitForIdleSync();
|
||||
checkSendTrackToGoogle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends two tracks with same activity. Two tracks should be in the same
|
||||
* spreadsheet.
|
||||
*/
|
||||
public void testSendTwoTracksWithSameActivity() {
|
||||
String testActivity = "(TestActivity)";
|
||||
EndToEndTestUtils.activityType = testActivity;
|
||||
EndToEndTestUtils.createSimpleTrack(1, false);
|
||||
sendToGoogle();
|
||||
sendToGoogle();
|
||||
|
||||
List<Entry> spreadsheetEntry = GoogleUtils.searchAllSpreadsheetByTitle(GoogleUtils.DOCUMENT_NAME_PREFIX + "-"
|
||||
+ EndToEndTestUtils.activityType, activityMyTracks);
|
||||
assertEquals(1, spreadsheetEntry.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the process of sending track to google.
|
||||
*/
|
||||
private void checkSendTrackToGoogle() {
|
||||
if (!sendToGoogle()) {
|
||||
return;
|
||||
}
|
||||
// Check whether all data is correct on Google Map, Documents, and
|
||||
// Spreadsheet.
|
||||
assertTrue(GoogleUtils.deleteMap(EndToEndTestUtils.trackName, activityMyTracks));
|
||||
assertTrue(GoogleUtils.searchFusionTableByTitle(EndToEndTestUtils.TRACK_NAME_PREFIX,
|
||||
activityMyTracks));
|
||||
assertTrue(GoogleUtils.deleteTrackInSpreadSheet(EndToEndTestUtils.trackName, activityMyTracks));
|
||||
assertTrue(GoogleUtils.dropFusionTables(EndToEndTestUtils.trackName, activityMyTracks));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a track to Google.
|
||||
*
|
||||
* @return true means send successfully
|
||||
*/
|
||||
private boolean sendToGoogle() {
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_send_google), true);
|
||||
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.send_google_title));
|
||||
ArrayList<CheckBox> checkBoxs = EndToEndTestUtils.SOLO.getCurrentCheckBoxes();
|
||||
for (int i = 0; i < checkBoxs.size(); i++) {
|
||||
if (!checkBoxs.get(i).isChecked()) {
|
||||
EndToEndTestUtils.SOLO.clickOnCheckBox(i);
|
||||
}
|
||||
}
|
||||
|
||||
if (checkBoxs.size() < 3) {
|
||||
EndToEndTestUtils.SOLO.scrollDown();
|
||||
checkBoxs = EndToEndTestUtils.SOLO.getCurrentCheckBoxes();
|
||||
|
||||
// Choose all Google service.
|
||||
for (int i = 0; i < checkBoxs.size(); i++) {
|
||||
if (!checkBoxs.get(i).isChecked()) {
|
||||
EndToEndTestUtils.SOLO.clickOnCheckBox(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.send_google_send_now),
|
||||
true, true);
|
||||
|
||||
if (!GoogleUtils.isAccountAvailable()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Following check the process of "Send to Google".
|
||||
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks
|
||||
.getString(R.string.generic_progress_title)));
|
||||
// Waiting the send is finish.
|
||||
while (EndToEndTestUtils.SOLO.waitForText(
|
||||
activityMyTracks.getString(R.string.generic_progress_title), 1,
|
||||
EndToEndTestUtils.SHORT_WAIT_TIME)) {}
|
||||
|
||||
// Check whether the result dialog is display.
|
||||
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks
|
||||
.getString(R.string.share_track_share_url)));
|
||||
EndToEndTestUtils
|
||||
.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
EndToEndTestUtils.activityType = EndToEndTestUtils.DEFAULTACTIVITYTYPE;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -280,7 +280,7 @@ public class SettingTest extends ActivityInstrumentationTestCase2<TrackListActiv
|
||||
// Changes the setting of default activity.
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
|
||||
.getString(R.string.settings_recording_default_activity_title));
|
||||
EndToEndTestUtils.enterTextAvoidSoftKeyBoard(0, EndToEndTestUtils.DEFAULTACTIVITY);
|
||||
EndToEndTestUtils.enterTextAvoidSoftKeyBoard(0, EndToEndTestUtils.activityType);
|
||||
EndToEndTestUtils
|
||||
.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
|
||||
|
||||
@@ -293,7 +293,7 @@ public class SettingTest extends ActivityInstrumentationTestCase2<TrackListActiv
|
||||
instrumentation.waitForIdleSync();
|
||||
assertTrue(EndToEndTestUtils.SOLO.searchText(activityMyTracks.getString(
|
||||
R.string.track_name_format).split(" ")[0]));
|
||||
assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.DEFAULTACTIVITY));
|
||||
assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.activityType));
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.generic_save));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user