merge heads

This commit is contained in:
Jimmy Shih
2012-09-07 10:46:57 -07:00
3 changed files with 70 additions and 82 deletions
@@ -107,13 +107,13 @@ public class DeleteTest extends ActivityInstrumentationTestCase2<TrackListActivi
public void testDeleteOneTrackUnderRecording() { public void testDeleteOneTrackUnderRecording() {
EndToEndTestUtils.startRecording(); EndToEndTestUtils.startRecording();
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
PauseRecordingTest.checkUnderRecording(); EndToEndTestUtils.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();
PauseRecordingTest.checkNotRecording(); EndToEndTestUtils.checkNotRecording();
} }
@Override @Override
@@ -18,6 +18,7 @@ package com.google.android.apps.mytracks.endtoendtest;
import com.google.android.apps.mytracks.ChartView; import com.google.android.apps.mytracks.ChartView;
import com.google.android.apps.mytracks.TrackListActivity; import com.google.android.apps.mytracks.TrackListActivity;
import com.google.android.apps.mytracks.util.FileUtils; import com.google.android.apps.mytracks.util.FileUtils;
import com.google.android.apps.mytracks.util.StringUtils;
import com.google.android.maps.mytracks.R; import com.google.android.maps.mytracks.R;
import com.jayway.android.robotium.solo.Solo; import com.jayway.android.robotium.solo.Solo;
@@ -44,6 +45,8 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
import junit.framework.Assert;
/** /**
* Provides utilities to smoke test. * Provides utilities to smoke test.
* *
@@ -804,6 +807,61 @@ public class EndToEndTestUtils {
} catch (InterruptedException e) { } catch (InterruptedException e) {
Log.e(LOG_TAG, "Unable to sleep " + milliseconds, e); Log.e(LOG_TAG, "Unable to sleep " + milliseconds, e);
} }
}
/**
* Checks whether the recording is not started.
*/
static void checkNotRecording() {
instrumentation.waitForIdleSync();
Assert.assertEquals(activityMytracks.getString(R.string.icon_record_track), (String) SOLO
.getCurrentActivity().findViewById(R.id.track_controller_record).getContentDescription());
Assert.assertFalse(SOLO.getCurrentActivity().findViewById(R.id.track_controller_stop)
.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);
Assert.assertEquals(StringUtils.formatElapsedTimeWithHour(0), totalTime.getText().toString());
}
/**
* Checks whether the MyTracks is under recording.
*/
static void checkUnderRecording() {
instrumentation.waitForIdleSync();
Assert.assertEquals(activityMytracks.getString(R.string.icon_pause_recording), (String) SOLO
.getCurrentActivity().findViewById(R.id.track_controller_record).getContentDescription());
Assert.assertTrue(SOLO.getCurrentActivity().findViewById(R.id.track_controller_stop)
.isEnabled());
Assert.assertNotNull(findTextView(activityMytracks.getString(R.string.generic_recording)));
Assert.assertNull(findTextView(activityMytracks.getString(R.string.generic_paused)));
String totalTimeOld = ((TextView) SOLO.getCurrentActivity().findViewById(
R.id.track_controller_total_time)).getText().toString();
sleep(2000);
String totalTimeNew = ((TextView) SOLO.getCurrentActivity().findViewById(
R.id.track_controller_total_time)).getText().toString();
Assert.assertFalse(totalTimeOld.equalsIgnoreCase(totalTimeNew));
}
/**
* Checks whether the recording is paused.
*/
static void checkUnderPaused() {
instrumentation.waitForIdleSync();
Assert.assertEquals(activityMytracks.getString(R.string.icon_record_track), (String) SOLO
.getCurrentActivity().findViewById(R.id.track_controller_record).getContentDescription());
Assert.assertTrue(SOLO.getCurrentActivity().findViewById(R.id.track_controller_stop)
.isEnabled());
Assert.assertNull(findTextView(activityMytracks.getString(R.string.generic_recording)));
Assert.assertNotNull(findTextView(activityMytracks.getString(R.string.generic_paused)));
String totalTimeOld = ((TextView) activityMytracks
.findViewById(R.id.track_controller_total_time)).getText().toString();
sleep(2000);
String totalTimeNew = ((TextView) activityMytracks
.findViewById(R.id.track_controller_total_time)).getText().toString();
Assert.assertTrue(totalTimeOld.equalsIgnoreCase(totalTimeNew));
} }
} }
@@ -19,14 +19,12 @@ 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 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.
@@ -57,22 +55,22 @@ public class PauseRecordingTest extends ActivityInstrumentationTestCase2<TrackLi
public void testPauseRecording_stopAfterPause() { public void testPauseRecording_stopAfterPause() {
int gpsSignalNumber = 3; int gpsSignalNumber = 3;
checkNotRecording(); EndToEndTestUtils.checkNotRecording();
// Start recording // Start recording
EndToEndTestUtils.startRecording(); EndToEndTestUtils.startRecording();
checkUnderRecording(); EndToEndTestUtils.checkUnderRecording();
EndToEndTestUtils.sendGps(gpsSignalNumber); EndToEndTestUtils.sendGps(gpsSignalNumber);
// Pause // Pause
EndToEndTestUtils.pauseRecording(); EndToEndTestUtils.pauseRecording();
checkUnderPaused(); EndToEndTestUtils.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(); EndToEndTestUtils.SOLO.goBack();
checkNotRecording(); EndToEndTestUtils.checkNotRecording();
} }
/** /**
@@ -81,15 +79,15 @@ public class PauseRecordingTest extends ActivityInstrumentationTestCase2<TrackLi
public void testPauseRecording_stopAfterResume() { public void testPauseRecording_stopAfterResume() {
int gpsSignalNumber = 3; int gpsSignalNumber = 3;
checkNotRecording(); EndToEndTestUtils.checkNotRecording();
// Start recording // Start recording
EndToEndTestUtils.startRecording(); EndToEndTestUtils.startRecording();
checkUnderRecording(); EndToEndTestUtils.checkUnderRecording();
EndToEndTestUtils.sendGps(gpsSignalNumber); EndToEndTestUtils.sendGps(gpsSignalNumber);
// Pause // Pause
EndToEndTestUtils.pauseRecording(); EndToEndTestUtils.pauseRecording();
checkUnderPaused(); EndToEndTestUtils.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.
@@ -97,14 +95,14 @@ public class PauseRecordingTest extends ActivityInstrumentationTestCase2<TrackLi
// Resume // Resume
EndToEndTestUtils.resumeRecording(); EndToEndTestUtils.resumeRecording();
checkUnderRecording(); EndToEndTestUtils.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(); EndToEndTestUtils.SOLO.goBack();
checkNotRecording(); EndToEndTestUtils.checkNotRecording();
} }
/** /**
@@ -149,72 +147,4 @@ public class PauseRecordingTest extends ActivityInstrumentationTestCase2<TrackLi
} }
} }
/**
* Checks whether the recording is not started.
*/
static void checkNotRecording() {
EndToEndTestUtils.instrumentation.waitForIdleSync();
assertEquals(
EndToEndTestUtils.activityMytracks.getString(R.string.icon_record_track),
(String) EndToEndTestUtils.SOLO.getCurrentActivity()
.findViewById(R.id.track_controller_record).getContentDescription());
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();
assertEquals(
EndToEndTestUtils.activityMytracks.getString(R.string.icon_pause_recording),
(String) EndToEndTestUtils.SOLO.getCurrentActivity()
.findViewById(R.id.track_controller_record).getContentDescription());
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();
assertEquals(
EndToEndTestUtils.activityMytracks.getString(R.string.icon_record_track),
(String) EndToEndTestUtils.SOLO.getCurrentActivity()
.findViewById(R.id.track_controller_record).getContentDescription());
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));
}
} }