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 5b4f88565..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. @@ -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)); } diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/GoogleUtils.java b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/GoogleUtils.java index b3af8ac58..8905535a8 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/GoogleUtils.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/GoogleUtils.java @@ -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. * diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/SendToGoogleTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/SendToGoogleTest.java index 9d6346fc2..f427b7b62 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/SendToGoogleTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/SendToGoogleTest.java @@ -76,6 +76,8 @@ public class SendToGoogleTest 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!"); + } + +}