Add checks about the status of recording, pause and not in recording. Add method findTextView and sleep to help current and following tests.

This commit is contained in:
youtaol
2012-09-04 15:04:11 +08:00
parent 9505ba9a23
commit 7b025443c1
4 changed files with 117 additions and 27 deletions
@@ -105,16 +105,15 @@ public class DeleteTest extends ActivityInstrumentationTestCase2<TrackListActivi
* Deletes a track which is under recording. * Deletes a track which is under recording.
*/ */
public void testDeleteOneTrackUnderRecording() { public void testDeleteOneTrackUnderRecording() {
assertFalse(EndToEndTestUtils.SOLO.getCurrentActivity().findViewById(R.id.track_controller_stop).isEnabled());
EndToEndTestUtils.startRecording(); EndToEndTestUtils.startRecording();
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
assertTrue(EndToEndTestUtils.SOLO.getCurrentActivity().findViewById(R.id.track_controller_stop).isEnabled()); PauseRecordingTest.checkUnderRecording();
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_delete), true); EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_delete), true);
EndToEndTestUtils EndToEndTestUtils
.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true); .getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
assertFalse(EndToEndTestUtils.SOLO.getCurrentActivity().findViewById(R.id.track_controller_stop).isEnabled()); PauseRecordingTest.checkNotRecording();
} }
@Override @Override
@@ -726,13 +726,13 @@ public class EndToEndTestUtils {
} }
/** /**
* Finds a text view with specified test in a view. * Finds a displayed text view with specified text in a view.
* *
* @param findText text to find * @param findText text to find
* @param parent which text view in in * @param parent which text view in in
* @return the text view, null means can not find it * @return the text view, null means can not find it
*/ */
static TextView findTextView(String findText, View parent) { static TextView findTextViewInView(String findText, View parent) {
ArrayList<TextView> textViews = SOLO.getCurrentTextViews(parent); ArrayList<TextView> textViews = SOLO.getCurrentTextViews(parent);
for (TextView textView : textViews) { for (TextView textView : textViews) {
String text = (String) textView.getText(); String text = (String) textView.getText();
@@ -742,6 +742,26 @@ public class EndToEndTestUtils {
} }
return null; return null;
} }
/**
* Finds a displayed text view with specified text.
*
* @param findText text to find
* @return the text view, null means can not find it
*/
static TextView findTextView(String findText) {
ArrayList<View> allViews = SOLO.getViews();
for (View view : allViews) {
if (view instanceof TextView) {
TextView textView = (TextView) view;
String text = (String) textView.getText();
if (textView.isShown() && text.endsWith(findText)) {
return textView;
}
}
}
return null;
}
/** /**
* Gets the ChartView. * Gets the ChartView.
@@ -788,5 +808,18 @@ public class EndToEndTestUtils {
imm.hideSoftInputFromWindow(editText.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY); imm.hideSoftInputFromWindow(editText.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
SOLO.enterText(editText, text); SOLO.enterText(editText, text);
} }
/**
* Waits n milliseconds.
*
* @param milliseconds time to sleep
*/
public static void sleep(long milliseconds) {
try {
Thread.sleep(milliseconds);
} catch (InterruptedException e) {
Log.e(EndToEndTestUtils.LOG_TAG, "Unable to sleep " + milliseconds, e);
}
}
} }
@@ -19,12 +19,14 @@ import com.google.android.apps.mytracks.TrackListActivity;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils.LocationIterator; import com.google.android.apps.mytracks.content.MyTracksProviderUtils.LocationIterator;
import com.google.android.apps.mytracks.services.TrackRecordingService; import com.google.android.apps.mytracks.services.TrackRecordingService;
import com.google.android.apps.mytracks.util.StringUtils;
import com.google.android.maps.mytracks.R; import com.google.android.maps.mytracks.R;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.Instrumentation; import android.app.Instrumentation;
import android.location.Location; import android.location.Location;
import android.test.ActivityInstrumentationTestCase2; import android.test.ActivityInstrumentationTestCase2;
import android.widget.TextView;
/** /**
* Tests the pause and resume of recording. * Tests the pause and resume of recording.
@@ -55,21 +57,22 @@ public class PauseRecordingTest extends ActivityInstrumentationTestCase2<TrackLi
public void testPauseRecording_stopAfterPause() { public void testPauseRecording_stopAfterPause() {
int gpsSignalNumber = 3; int gpsSignalNumber = 3;
checkNotRecording();
// Start recording // Start recording
EndToEndTestUtils.startRecording(); EndToEndTestUtils.startRecording();
assertTrue(EndToEndTestUtils.SOLO.getCurrentActivity().findViewById(R.id.track_controller_stop).isEnabled()); checkUnderRecording();
EndToEndTestUtils.sendGps(gpsSignalNumber); EndToEndTestUtils.sendGps(gpsSignalNumber);
// Pause // Pause
EndToEndTestUtils.pauseRecording(); EndToEndTestUtils.pauseRecording();
assertTrue(EndToEndTestUtils.SOLO.getCurrentActivity().findViewById(R.id.track_controller_stop).isEnabled()); checkUnderPaused();
EndToEndTestUtils.sendGps(gpsSignalNumber, gpsSignalNumber); EndToEndTestUtils.sendGps(gpsSignalNumber, gpsSignalNumber);
// Stop // Stop
EndToEndTestUtils.stopRecording(true); EndToEndTestUtils.stopRecording(true);
checkPointsInPausedTrack(gpsSignalNumber, 1, 0); checkPointsInPausedTrack(gpsSignalNumber, 1, 0);
EndToEndTestUtils.SOLO.goBack();
checkNotRecording();
} }
/** /**
@@ -78,29 +81,30 @@ public class PauseRecordingTest extends ActivityInstrumentationTestCase2<TrackLi
public void testPauseRecording_stopAfterResume() { public void testPauseRecording_stopAfterResume() {
int gpsSignalNumber = 3; int gpsSignalNumber = 3;
checkNotRecording();
// Start recording // Start recording
EndToEndTestUtils.startRecording(); EndToEndTestUtils.startRecording();
assertTrue(EndToEndTestUtils.SOLO.getCurrentActivity().findViewById(R.id.track_controller_stop).isEnabled()); checkUnderRecording();
EndToEndTestUtils.sendGps(gpsSignalNumber); EndToEndTestUtils.sendGps(gpsSignalNumber);
// Pause // Pause
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_pause_track), true); EndToEndTestUtils.pauseRecording();
assertTrue(EndToEndTestUtils.SOLO.getCurrentActivity().findViewById(R.id.track_controller_stop).isEnabled()); checkUnderPaused();
// Send Gps signal after pause. // Send Gps signal after pause.
// Add 10 to make these signals are apparently different. // Add 10 to make these signals are apparently different.
EndToEndTestUtils.sendGps(gpsSignalNumber, gpsSignalNumber + 10, 10); EndToEndTestUtils.sendGps(gpsSignalNumber, gpsSignalNumber + 10, 10);
// Resume // Resume
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_record_track), true); EndToEndTestUtils.resumeRecording();
assertTrue(EndToEndTestUtils.SOLO.getCurrentActivity().findViewById(R.id.track_controller_stop).isEnabled()); checkUnderRecording();
EndToEndTestUtils.sendGps(gpsSignalNumber, gpsSignalNumber); EndToEndTestUtils.sendGps(gpsSignalNumber, gpsSignalNumber);
// Stop // Stop
EndToEndTestUtils.stopRecording(true); EndToEndTestUtils.stopRecording(true);
checkPointsInPausedTrack(gpsSignalNumber * 2, 1, 1); checkPointsInPausedTrack(gpsSignalNumber * 2, 1, 1);
EndToEndTestUtils.SOLO.goBack();
checkNotRecording();
} }
/** /**
@@ -131,12 +135,10 @@ public class PauseRecordingTest extends ActivityInstrumentationTestCase2<TrackLi
} else if (latitude == TrackRecordingService.RESUME_LATITUDE) { } else if (latitude == TrackRecordingService.RESUME_LATITUDE) {
numberOfResumePoint++; numberOfResumePoint++;
} else { } else {
assertEquals( assertEquals(numberOfPoints, (int) ((latitude - EndToEndTestUtils.START_LATITUDE)
numberOfPoints, / EndToEndTestUtils.DELTA_LADITUDE + 0.5));
(int) ((latitude - EndToEndTestUtils.START_LATITUDE) / EndToEndTestUtils.DELTA_LADITUDE + 0.5)); assertEquals(numberOfPoints, (int) ((longitude - EndToEndTestUtils.START_LONGITUDE)
assertEquals( / EndToEndTestUtils.DELTA_LONGITUDE + 0.5));
numberOfPoints,
(int) ((longitude - EndToEndTestUtils.START_LONGITUDE) / EndToEndTestUtils.DELTA_LONGITUDE + 0.5));
numberOfPoints++; numberOfPoints++;
} }
} }
@@ -146,12 +148,68 @@ public class PauseRecordingTest extends ActivityInstrumentationTestCase2<TrackLi
assertEquals(expectResumeNumber, numberOfResumePoint); assertEquals(expectResumeNumber, numberOfResumePoint);
} }
} }
/**
* Checks whether the recording is not started.
*/
static void checkNotRecording() {
EndToEndTestUtils.instrumentation.waitForIdleSync();
assertFalse(EndToEndTestUtils.SOLO.getCurrentActivity()
.findViewById(R.id.track_controller_stop).isEnabled());
assertNull(EndToEndTestUtils.findTextView(EndToEndTestUtils.activityMytracks
.getString(R.string.generic_recording)));
assertNull(EndToEndTestUtils.findTextView(EndToEndTestUtils.activityMytracks
.getString(R.string.generic_paused)));
TextView totalTime = (TextView) EndToEndTestUtils.activityMytracks
.findViewById(R.id.track_controller_total_time);
assertEquals(StringUtils.formatElapsedTimeWithHour(0), totalTime.getText().toString());
}
/**
* Checks whether the MyTracks is under recording.
*/
static void checkUnderRecording() {
EndToEndTestUtils.instrumentation.waitForIdleSync();
assertTrue(EndToEndTestUtils.SOLO.getCurrentActivity().findViewById(R.id.track_controller_stop)
.isEnabled());
assertNotNull(EndToEndTestUtils.findTextView(EndToEndTestUtils.activityMytracks
.getString(R.string.generic_recording)));
assertNull(EndToEndTestUtils.findTextView(EndToEndTestUtils.activityMytracks
.getString(R.string.generic_paused)));
String totalTimeOld = ((TextView) EndToEndTestUtils.SOLO.getCurrentActivity().findViewById(
R.id.track_controller_total_time)).getText().toString();
EndToEndTestUtils.sleep(2000);
String totalTimeNew = ((TextView) EndToEndTestUtils.SOLO.getCurrentActivity().findViewById(
R.id.track_controller_total_time)).getText().toString();
assertFalse(totalTimeOld.equalsIgnoreCase(totalTimeNew));
}
/**
* Checks whether the recording is paused.
*/
static void checkUnderPaused() {
EndToEndTestUtils.instrumentation.waitForIdleSync();
assertTrue(EndToEndTestUtils.SOLO.getCurrentActivity().findViewById(R.id.track_controller_stop)
.isEnabled());
assertNull(EndToEndTestUtils.findTextView(EndToEndTestUtils.activityMytracks
.getString(R.string.generic_recording)));
assertNotNull(EndToEndTestUtils.findTextView(EndToEndTestUtils.activityMytracks
.getString(R.string.generic_paused)));
String totalTimeOld = ((TextView) EndToEndTestUtils.activityMytracks
.findViewById(R.id.track_controller_total_time)).getText().toString();
EndToEndTestUtils.sleep(2000);
String totalTimeNew = ((TextView) EndToEndTestUtils.activityMytracks
.findViewById(R.id.track_controller_total_time)).getText().toString();
assertTrue(totalTimeOld.equalsIgnoreCase(totalTimeNew));
}
@Override @Override
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
// In normally, the activities of MyTracks should be closed after every test is // In normally, the activities of MyTracks should be closed after every test
// completed. But this case is different, send two go back event to make it will // is completed. But this case is different, send two go back event to make
// not block following tests. // it will not block following tests.
EndToEndTestUtils.SOLO.goBack(); EndToEndTestUtils.SOLO.goBack();
EndToEndTestUtils.SOLO.goBack(); EndToEndTestUtils.SOLO.goBack();
super.tearDown(); super.tearDown();
@@ -214,7 +214,7 @@ public class SettingTest extends ActivityInstrumentationTestCase2<TrackListActiv
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks
.getString(R.string.settings_stats_units_title))); .getString(R.string.settings_stats_units_title)));
boolean isImperial = EndToEndTestUtils.findTextView(activityMyTracks boolean isImperial = EndToEndTestUtils.findTextViewInView(activityMyTracks
.getString(R.string.settings_stats_units_imperial), EndToEndTestUtils.SOLO .getString(R.string.settings_stats_units_imperial), EndToEndTestUtils.SOLO
.getCurrentListViews().get(0)) != null; .getCurrentListViews().get(0)) != null;