diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestUtils.java b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestUtils.java index a615e3bdd..58897d0a7 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestUtils.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestUtils.java @@ -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. diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/SensorTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/others/SensorTest.java similarity index 93% rename from MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/SensorTest.java rename to MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/others/SensorTest.java index 9d200c6f2..712472140 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/SensorTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/others/SensorTest.java @@ -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 { + + /** + * 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!"); + } + +}