merge heads

This commit is contained in:
Jimmy Shih
2012-11-09 16:42:44 -08:00
5 changed files with 180 additions and 9 deletions
@@ -116,8 +116,8 @@ public class EndToEndTestUtils {
MILE_MULTILINGUAL.put("zh", "英里");
}
static Solo SOLO;
static Instrumentation instrumentation;
public static Solo SOLO;
public static Instrumentation instrumentation;
static TrackListActivity activityMytracks;
// Check whether the UI has an action bar which is related with the version of
// Android OS.
@@ -848,7 +848,7 @@ public class EndToEndTestUtils {
.isEnabled());
Assert.assertNull(findTextView(activityMytracks.getString(R.string.generic_recording)));
Assert.assertNull(findTextView(activityMytracks.getString(R.string.generic_paused)));
TextView totalTime = (TextView) activityMytracks.findViewById(R.id.track_controller_total_time);
TextView totalTime = (TextView) SOLO.getCurrentActivity().findViewById(R.id.track_controller_total_time);
Assert.assertEquals(StringUtils.formatElapsedTimeWithHour(0), totalTime.getText().toString());
}
@@ -884,10 +884,10 @@ public class EndToEndTestUtils {
Assert.assertNull(findTextView(activityMytracks.getString(R.string.generic_recording)));
Assert.assertNotNull(findTextView(activityMytracks.getString(R.string.generic_paused)));
String totalTimeOld = ((TextView) activityMytracks
String totalTimeOld = ((TextView) SOLO.getCurrentActivity()
.findViewById(R.id.track_controller_total_time)).getText().toString();
sleep(2000);
String totalTimeNew = ((TextView) activityMytracks
String totalTimeNew = ((TextView) SOLO.getCurrentActivity()
.findViewById(R.id.track_controller_total_time)).getText().toString();
Assert.assertTrue(totalTimeOld.equalsIgnoreCase(totalTimeNew));
}
@@ -207,6 +207,40 @@ public class GoogleUtils {
return null;
}
/**
* Delete spreadsheet which name is title.
*
* @param title the name of spreadsheet
* @param activity to get context
*/
public static void deleteSpreadsheetByTitle(String title, Activity activity) {
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)) {
documentsClient.deleteEntry(entry.getEditUri(), documentsAuthToken);
Log.d(EndToEndTestUtils.LOG_TAG, "Delete one spreadsheet.");
}
}
} catch (Exception e) {
Log.e(EndToEndTestUtils.LOG_TAG, "Unable to fetch spreadsheet.", e);
}
}
/**
* Searches docs in user's Google Documents.
*
@@ -76,6 +76,8 @@ public class SendToGoogleTest extends ActivityInstrumentationTestCase2<TrackList
public void testSendTwoTracksWithSameActivity() {
String testActivity = "(TestActivity)";
EndToEndTestUtils.activityType = testActivity;
GoogleUtils.deleteSpreadsheetByTitle("My Tracks-" + EndToEndTestUtils.activityType,
EndToEndTestUtils.activityMytracks);
EndToEndTestUtils.createSimpleTrack(1, false);
boolean result = sendToGoogle();
result = result && sendToGoogle();
@@ -13,9 +13,10 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.endtoendtest;
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.maps.mytracks.R;
import android.app.Instrumentation;
@@ -43,7 +44,7 @@ public class SensorTest extends ActivityInstrumentationTestCase2<TrackListActivi
private Instrumentation instrumentation;
private TrackListActivity activityMyTracks;
private final String disableMessage= "Sensor test is disabled";
public static final String DISABLE_MESSAGE = "This test is disabled";
@Override
protected void setUp() throws Exception {
@@ -59,7 +60,7 @@ public class SensorTest extends ActivityInstrumentationTestCase2<TrackListActivi
*/
public void testConnectZephyrBluetoothSensor() {
if (!testSensor) {
Log.i(EndToEndTestUtils.LOG_TAG, disableMessage);
Log.i(EndToEndTestUtils.LOG_TAG, DISABLE_MESSAGE);
return;
}
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true);
@@ -82,7 +83,7 @@ public class SensorTest extends ActivityInstrumentationTestCase2<TrackListActivi
*/
public void testConnectPolarBluetoothSensor() {
if (!testSensor) {
Log.i(EndToEndTestUtils.LOG_TAG, disableMessage);
Log.i(EndToEndTestUtils.LOG_TAG, DISABLE_MESSAGE);
return;
}
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true);
@@ -0,0 +1,134 @@
/*
* 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.others;
import com.google.android.apps.mytracks.TrackListActivity;
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils;
import com.google.android.maps.mytracks.R;
import android.app.Instrumentation;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
/**
* Tests Rotation of MyTracks.
*
* @author Youtao Liu
*/
public class StressTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
/**
* Set to false as default.
*/
public static boolean testStress = false;
public static final int MINUTES_FOR_EACH_TEST = 30;
public static final int MILLI_SECOND_IN_ONE_MINUTE = 60 * 1000;
long startTime = 0;
int trackNumber;
public StressTest() {
super(TrackListActivity.class);
}
private Instrumentation instrumentation;
private TrackListActivity activityMyTracks;
@Override
protected void setUp() throws Exception {
super.setUp();
instrumentation = getInstrumentation();
activityMyTracks = getActivity();
EndToEndTestUtils.setupForDebug(instrumentation, activityMyTracks);
startTime = System.currentTimeMillis();
EndToEndTestUtils.emulatorPort = 5568;
}
/**
* Records tracks and delete them when there are more than 30 tracks..
*/
public void testRecordAndDeleteTracks() {
if (!testStress) {
Log.i(EndToEndTestUtils.LOG_TAG, SensorTest.DISABLE_MESSAGE);
return;
}
for (int i = 0; (System.currentTimeMillis() - startTime) / MILLI_SECOND_IN_ONE_MINUTE < MINUTES_FOR_EACH_TEST; i++) {
EndToEndTestUtils.startRecording();
// Points in a tracks keep increasing.
EndToEndTestUtils.sendGps(i * 10, 0, 10);
EndToEndTestUtils.stopRecording(true);
EndToEndTestUtils.SOLO.goBack();
EndToEndTestUtils.instrumentation.waitForIdleSync();
trackNumber = EndToEndTestUtils.SOLO.getCurrentListViews().get(0).getCount();
if (trackNumber > 30) {
EndToEndTestUtils.deleteAllTracks();
}
logStatus(i);
}
}
/**
* Rotates screen when display map view.
*/
public void testRotateMapViewInTrackDetailActivity() {
if (!testStress) {
Log.i(EndToEndTestUtils.LOG_TAG, SensorTest.DISABLE_MESSAGE);
return;
}
EndToEndTestUtils.startRecording();
for (int i = 0; (System.currentTimeMillis() - startTime) / MILLI_SECOND_IN_ONE_MINUTE < MINUTES_FOR_EACH_TEST; i++) {
EndToEndTestUtils.sendGps(10, i * 10);
EndToEndTestUtils.rotateCurrentActivity();
}
}
/**
* Switches view between CHART, MAP and STAT.
*/
public void testSwitchTabs() {
if (!testStress) {
Log.i(EndToEndTestUtils.LOG_TAG, SensorTest.DISABLE_MESSAGE);
return;
}
EndToEndTestUtils.startRecording();
int i = 0;
while ((System.currentTimeMillis() - startTime) / MILLI_SECOND_IN_ONE_MINUTE < MINUTES_FOR_EACH_TEST) {
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_map_tab));
instrumentation.waitForIdleSync();
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
.getString(R.string.track_detail_chart_tab));
instrumentation.waitForIdleSync();
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
.getString(R.string.track_detail_stats_tab));
instrumentation.waitForIdleSync();
logStatus(++i);
}
}
/**
* Displays log message.
*
* @param times this test has been run
*/
private void logStatus(int times) {
Log.i(EndToEndTestUtils.LOG_TAG, "This test has run "
+ times
+ " times and will be finished in "
+ (MINUTES_FOR_EACH_TEST - (System.currentTimeMillis() - startTime)
/ MILLI_SECOND_IN_ONE_MINUTE) + " minutes!");
Log.i(EndToEndTestUtils.LOG_TAG, "There are " + trackNumber + " tracks!");
}
}