Add a judge about the three dots menu item. Add tests about the relative start time and delete a track during recording.

This commit is contained in:
youtaol
2012-05-16 17:48:29 +08:00
parent 37bfefaa3d
commit 2fe97f55dd
5 changed files with 119 additions and 39 deletions
@@ -33,7 +33,7 @@ import java.util.ArrayList;
public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
private static final String WAYPOINT_NAME = "testWaypoint";
private static final String STATISTICS_NAME = "testStatistics";
private static final String RELATIVE_STARTTIME_POSTFIX = "mins ago";
private Instrumentation instrumentation;
private TrackListActivity activityMyTracks;
@@ -56,6 +56,7 @@ public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2<Tra
if (EndToEndTestUtils.isTrackListEmpty(true)) {
// Create a simple track.
EndToEndTestUtils.createSimpleTrack(1);
assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.TRACK_NAME));
}
instrumentation.waitForIdleSync();
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_send_google), true,
@@ -125,15 +126,16 @@ public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2<Tra
* Creates one track with a two locations, a way point and a statistics point.
*/
public void testCreateTrackWithMarkers() {
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_delete_all), true,
false);
EndToEndTestUtils.SOLO.clickOnButton(activityMyTracks.getString(R.string.generic_ok));
instrumentation.waitForIdleSync();
EndToEndTestUtils.startRecording();
instrumentation.waitForIdleSync();
// Send Gps before send marker.
EndToEndTestUtils.sendGps(2);
createWaypointAndStatistics();
if (EndToEndTestUtils.HAS_ACTIONBAR) {
// Check the title is Recording.
assertTrue(EndToEndTestUtils.SOLO.searchText(activityMyTracks
.getString(R.string.icon_recording)));
}
createWaypointAndSplit();
EndToEndTestUtils.sendGps(2);
// Back to tracks list.
EndToEndTestUtils.SOLO.goBack();
@@ -151,32 +153,49 @@ public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2<Tra
}
/**
* Creates a way point and a statistics during track recording.
* Tests the display of track start time. Use relative time (x mins ago) for
* the start time if it is within the past week. But only show the start time
* if it is different from the track name.
*/
private void createWaypointAndStatistics() {
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_markers), true, true);
public void testTrackStartTime() {
// Delete all track first.
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_delete_all), true,
false);
EndToEndTestUtils.SOLO.clickOnButton(activityMyTracks.getString(R.string.generic_ok));
instrumentation.waitForIdleSync();
// Test should not show relative time.
EndToEndTestUtils.startRecording();
instrumentation.waitForIdleSync();
EndToEndTestUtils.stopRecording(false);
instrumentation.waitForIdleSync();
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.generic_save));
instrumentation.waitForIdleSync();
EndToEndTestUtils.SOLO.goBack();
instrumentation.waitForIdleSync();
assertFalse(EndToEndTestUtils.SOLO.waitForText(RELATIVE_STARTTIME_POSTFIX, 1, 500));
// Test should show relative time.
EndToEndTestUtils.createSimpleTrack(2);
EndToEndTestUtils.SOLO.goBack();
assertTrue(EndToEndTestUtils.SOLO.waitForText(RELATIVE_STARTTIME_POSTFIX, 1, 500));
}
/**
* Creates a way point and a split maker during track recording.
*/
private void createWaypointAndSplit() {
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_markers), true, true);
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.marker_list_empty_message));
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_insert_marker), true,
true);
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.marker_waypoint));
// Rotate when show insert page.
EndToEndTestUtils.rotateAllActivities();
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.generic_more_options));
EndToEndTestUtils.SOLO.enterText(0, WAYPOINT_NAME);
EndToEndTestUtils.SOLO.clickOnButton(activityMyTracks.getString(R.string.generic_add));
assertTrue(EndToEndTestUtils.SOLO.searchText(WAYPOINT_NAME));
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_insert_marker), true,
true);
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.marker_statistics));
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.generic_more_options));
// Rotate when show option page.
EndToEndTestUtils.rotateAllActivities();
EndToEndTestUtils.SOLO.enterText(0, STATISTICS_NAME);
EndToEndTestUtils.SOLO.clickOnButton(activityMyTracks.getString(R.string.generic_add));
instrumentation.waitForIdleSync();
assertTrue(EndToEndTestUtils.SOLO.searchText(STATISTICS_NAME));
// TODO Add test when Split maker feature is finished.
EndToEndTestUtils.SOLO.goBack();
}
@@ -54,7 +54,7 @@ public class DeleteTest extends ActivityInstrumentationTestCase2<TrackListActivi
// Create a simple track.
EndToEndTestUtils.createSimpleTrack(0);
EndToEndTestUtils.SOLO.goBack();
}
}
instrumentation.waitForIdleSync();
// There is at least one track.
ArrayList<ListView> trackListView = EndToEndTestUtils.SOLO.getCurrentListViews();
@@ -80,20 +80,39 @@ public class DeleteTest extends ActivityInstrumentationTestCase2<TrackListActivi
// Create a simple track.
EndToEndTestUtils.createSimpleTrack(0);
EndToEndTestUtils.SOLO.goBack();
}
}
instrumentation.waitForIdleSync();
// Get the number of track( or tracks)
ArrayList<ListView> trackListView = EndToEndTestUtils.SOLO.getCurrentListViews();
int trackNumberOld = trackListView.get(0).getCount();
EndToEndTestUtils.SOLO.clickLongOnText(EndToEndTestUtils.TRACK_NAME);
EndToEndTestUtils.SOLO.clickOnView(trackListView.get(0).getChildAt(0));
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_delete), true, true);
EndToEndTestUtils.SOLO.clickLongOnText(activityMyTracks.getString(R.string.generic_ok));
instrumentation.waitForIdleSync();
trackListView = EndToEndTestUtils.SOLO.getCurrentListViews();
int trackNumberNew = trackListView.get(0).getCount();
assertEquals(trackNumberOld - 1, trackNumberNew);
}
/**
* Deletes a track which is under recording.
*/
public void testDeleteOneTrackUnderRecording() {
EndToEndTestUtils.startRecording();
instrumentation.waitForIdleSync();
assertTrue(EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_stop_recording),
false, true));
instrumentation.waitForIdleSync();
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_delete),
true, false);
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.generic_ok));
instrumentation.waitForIdleSync();
assertTrue(EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_record_track),
false, true));
instrumentation.waitForIdleSync();
assertTrue(EndToEndTestUtils.findMenuItem(
activityMyTracks.getString(R.string.menu_record_track), false, true));
}
@Override
@@ -26,6 +26,7 @@ import android.content.res.Configuration;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
import java.io.File;
@@ -54,6 +55,8 @@ public class EndToEndTestUtils {
private static final float START_LATITUDE = -1.3f;
private static final float DELTA_LONGITUDE = 0.0005f;
private static final float DELTA_LADITUDE = 0.0005f;
private static final String MOREOPTION_CLASSNAME = "com.android.internal.view.menu.ActionMenuPresenter$OverflowMenuButton";
static final String TRACK_NAME_PREFIX = "testTrackName";
static final String GPX = "gpx";
@@ -227,7 +230,7 @@ public class EndToEndTestUtils {
}
SOLO.clickOnView(startButton);
} else {
SOLO.sendKey(KeyEvent.KEYCODE_MENU);
showMoreMenuItem();
if (!SOLO.searchText(ACTIVITYMYTRACKS.getString(R.string.menu_record_track))) {
// Check if in TrackDetailActivity.
if (SOLO.searchText(ACTIVITYMYTRACKS.getString(R.string.menu_play))) {
@@ -235,7 +238,7 @@ public class EndToEndTestUtils {
} else {
// In case a track is recording.
stopRecording(true);
SOLO.sendKey(KeyEvent.KEYCODE_MENU);
showMoreMenuItem();
}
}
INSTRUMENTATION.waitForIdleSync();
@@ -256,7 +259,7 @@ public class EndToEndTestUtils {
return true;
}
} else {
SOLO.sendKey(KeyEvent.KEYCODE_MENU);
showMoreMenuItem();
if (!SOLO.searchText(ACTIVITYMYTRACKS.getString(R.string.menu_record_track))) {
// Check if in TrackDetailActivity.
if (SOLO.searchText(ACTIVITYMYTRACKS.getString(R.string.menu_play))) {
@@ -264,6 +267,8 @@ public class EndToEndTestUtils {
} else {
return true;
}
} else {
SOLO.goBack();
}
}
return false;
@@ -278,7 +283,7 @@ public class EndToEndTestUtils {
if (HAS_ACTIONBAR) {
SOLO.clickOnView(getButtonOnScreen(ACTIVITYMYTRACKS.getString(R.string.menu_stop_recording)));
} else {
SOLO.sendKey(KeyEvent.KEYCODE_MENU);
showMoreMenuItem();
INSTRUMENTATION.waitForIdleSync();
SOLO.clickOnText(ACTIVITYMYTRACKS.getString(R.string.menu_stop_recording));
}
@@ -333,9 +338,8 @@ public class EndToEndTestUtils {
static void saveTrackToSdCard(String trackKind) {
deleteExportedFiles(trackKind);
INSTRUMENTATION.waitForIdleSync();
SOLO.sendKey(KeyEvent.KEYCODE_MENU);
findMenuItem(ACTIVITYMYTRACKS.getString(R.string.menu_save), true, true);
INSTRUMENTATION.waitForIdleSync();
SOLO.clickOnText(ACTIVITYMYTRACKS.getString(R.string.menu_save));
SOLO.clickOnText(trackKind.toUpperCase());
rotateAllActivities();
SOLO.waitForText(ACTIVITYMYTRACKS.getString(R.string.generic_success_title));
@@ -351,7 +355,9 @@ public class EndToEndTestUtils {
ArrayList<Button> currentButtons = SOLO.getCurrentButtons();
for (Button button : currentButtons) {
String title = (String) button.getText();
if (title.equalsIgnoreCase(buttonName)) { return button; }
if (title.equalsIgnoreCase(buttonName)) {
return button;
}
}
return null;
}
@@ -370,7 +376,7 @@ public class EndToEndTestUtils {
if (startButton != null || stopButton != null) {
HAS_ACTIONBAR = true;
} else {
SOLO.sendKey(KeyEvent.KEYCODE_MENU);
showMoreMenuItem();
if (SOLO.searchText(ACTIVITYMYTRACKS.getString(R.string.menu_record_track))
|| SOLO.searchText(ACTIVITYMYTRACKS.getString(R.string.menu_stop_recording))) {
HAS_ACTIONBAR = false;
@@ -425,7 +431,7 @@ public class EndToEndTestUtils {
}
}
SOLO.sendKey(KeyEvent.KEYCODE_MENU);
showMoreMenuItem();
if (SOLO.searchText(menuName)) {
findResult = true;
} else if (SOLO.searchText(MENU_MORE)) {
@@ -435,7 +441,42 @@ public class EndToEndTestUtils {
if (findResult && click) {
SOLO.clickOnText(menuName);
} else {
SOLO.goBack();
}
return findResult;
}
/**
* Get more menu items operation is different for different Android OS.
*/
public static void showMoreMenuItem() {
if (HAS_ACTIONBAR) {
View moreButton = getMoreOptionView();
if (moreButton == null) {
SOLO.sendKey(KeyEvent.KEYCODE_MENU);
} else {
SOLO.clickOnView(moreButton);
}
} else {
SOLO.sendKey(KeyEvent.KEYCODE_MENU);
}
}
/**
* Finds the more option menu. It should match following conditions:
* <ul>
* <li>The view extends ImageButton.</li>
* <li>The view name equals {@link EndToEndTestUtils#MOREOPTION_CLASSNAME}.</li>
* </ul>
* @return the more option view. Null means can not find it.
*/
private static View getMoreOptionView() {
ArrayList<View> allViews = SOLO.getViews();
for (View view : allViews) {
if (view instanceof ImageButton && view.getClass().getName().equals(MOREOPTION_CLASSNAME)) { return view; }
}
return null;
}
}
@@ -16,7 +16,6 @@
package com.google.android.apps.mytracks.endtoendtest;
import com.google.android.apps.mytracks.TrackListActivity;
import com.google.android.maps.mytracks.R;
import android.app.Instrumentation;
import android.test.ActivityInstrumentationTestCase2;
@@ -51,7 +50,7 @@ public class GoToMyLocationTest extends ActivityInstrumentationTestCase2<TrackLi
// Create a simple track.
EndToEndTestUtils.createSimpleTrack(2);
}
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.my_location), true, false);
// TODO How to verify the location is shown on the map.
}
@@ -66,7 +66,7 @@ public class ViewsTest extends ActivityInstrumentationTestCase2<TrackListActivit
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_chart_tab));
EndToEndTestUtils.rotateAllActivities();
EndToEndTestUtils.SOLO.sendKey(KeyEvent.KEYCODE_MENU);
EndToEndTestUtils.showMoreMenuItem();
assertTrue(EndToEndTestUtils.SOLO.waitForText(
activityMyTracks.getString(R.string.menu_settings), 1, 3000));
assertFalse(EndToEndTestUtils.SOLO.waitForText(
@@ -86,7 +86,7 @@ public class ViewsTest extends ActivityInstrumentationTestCase2<TrackListActivit
EndToEndTestUtils.SOLO.goBack();
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_map_tab));
EndToEndTestUtils.SOLO.sendKey(KeyEvent.KEYCODE_MENU);
EndToEndTestUtils.showMoreMenuItem();
assertTrue(EndToEndTestUtils.SOLO.waitForText(
activityMyTracks.getString(R.string.menu_settings), 1, 3000));
assertTrue(EndToEndTestUtils.SOLO.waitForText(
@@ -111,6 +111,7 @@ public class ViewsTest extends ActivityInstrumentationTestCase2<TrackListActivit
false, false)) {
isMapMode = false;
}
EndToEndTestUtils.showMoreMenuItem();
// Switch to satellite mode if it's map mode now..
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
.getString(isMapMode ? R.string.menu_satellite_mode : R.string.menu_map_mode));
@@ -130,6 +131,7 @@ public class ViewsTest extends ActivityInstrumentationTestCase2<TrackListActivit
EndToEndTestUtils.rotateAllActivities();
// Switch back.
EndToEndTestUtils.showMoreMenuItem();
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
.getString(isMapMode ? R.string.menu_satellite_mode : R.string.menu_map_mode));
isMapMode = !isMapMode;