diff --git a/myTracks/src/androidTest/java/com/google/android/apps/mytracks/endtoendtest/EndToEndTestRunner.java b/myTracks/src/androidTest/java/com/google/android/apps/mytracks/endtoendtest/EndToEndTestRunner.java deleted file mode 100644 index be762b7d1..000000000 --- a/myTracks/src/androidTest/java/com/google/android/apps/mytracks/endtoendtest/EndToEndTestRunner.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2012 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package com.google.android.apps.mytracks.endtoendtest; - -import android.os.Bundle; -import android.test.InstrumentationTestRunner; -import android.util.Log; - -/** - * End-to-end test test runner. - * - * @author Youtao Liu - */ -public class EndToEndTestRunner extends InstrumentationTestRunner { - - private static final String TAG = EndToEndTestRunner.class.getSimpleName(); - private static final String PORT_KEY = "port"; - private static final String RESOURCE_KEY = "resource"; - private static final String SENSOR_KEY = "sensor"; - private static final String STRESS_KEY = "stress"; - private static final String TRUE_VALUE = "true"; - - @Override - public void onCreate(Bundle bundle) { - - // Get the emulator port parameter for GPS signals - String port = bundle.getString(PORT_KEY); - if (port != null) { - try { - EndToEndTestUtils.emulatorPort = Integer.parseInt(port); - } catch (Exception e) { - Log.e(TAG, "Unable to get emulator port parameter, use the default value.", e); - } - } - Log.d(TAG, "Emulator port: " + EndToEndTestUtils.emulatorPort); - - RunConfiguration runConfiguration = RunConfiguration.getInstance(); - - runConfiguration.setRunResourceTest( - TRUE_VALUE.equalsIgnoreCase(bundle.getString(RESOURCE_KEY))); - Log.d(TAG, "Run resource test: " + runConfiguration.getRunResourceTest()); - - runConfiguration.setRunSensorTest(TRUE_VALUE.equalsIgnoreCase(bundle.getString(SENSOR_KEY))); - Log.d(TAG, "Run sensor test: " + runConfiguration.getRunSensorTest()); - - runConfiguration.setRunStressTest(TRUE_VALUE.equalsIgnoreCase(bundle.getString(STRESS_KEY))); - Log.d(TAG, "Run stress test: " + runConfiguration.getRunStressTest()); - - super.onCreate(bundle); - } -} diff --git a/myTracks/src/androidTest/java/com/google/android/apps/mytracks/endtoendtest/EndToEndTestUtils.java b/myTracks/src/androidTest/java/com/google/android/apps/mytracks/endtoendtest/EndToEndTestUtils.java deleted file mode 100644 index d2efaa637..000000000 --- a/myTracks/src/androidTest/java/com/google/android/apps/mytracks/endtoendtest/EndToEndTestUtils.java +++ /dev/null @@ -1,936 +0,0 @@ -package com.google.android.apps.mytracks.endtoendtest; - -/* - * Copyright 2012 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -import com.google.android.apps.mytracks.TrackListActivity; -import com.google.android.maps.mytracks.R; -import com.robotium.solo.Solo; - -import android.annotation.SuppressLint; -import android.app.Activity; -import android.app.Instrumentation; -import android.content.Context; -import android.content.res.Configuration; -import android.util.Log; -import android.view.KeyEvent; -import android.view.View; -import android.view.inputmethod.InputMethodManager; -import android.widget.Button; -import android.widget.EditText; -import android.widget.ImageButton; -import android.widget.ListView; -import android.widget.TextView; - -import java.io.IOException; -import java.io.PrintStream; -import java.net.Socket; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Locale; - -import junit.framework.Assert; - -/** - * Provides utilities to smoke test. - * - * @author Youtao Liu - */ -public class EndToEndTestUtils { - - public static final int TINY_WAIT_TIME = 200; - public static final int VERY_SHORT_WAIT_TIME = 500; - public static final int SHORT_WAIT_TIME = 2000; - public static final int NORMAL_WAIT_TIME = 8000; - public static final int LONG_WAIT_TIME = 15000; - public static final int SUPER_LONG_WAIT_TIME = 100000; - - // Pause 200ms between each send. - public static final double START_LONGITUDE = 51; - public static final double START_LATITUDE = -1.3f; - public static final double DELTA_LONGITUDE = 0.0005f; - public static final double DELTA_LADITUDE = 0.0005f; - public static final String WAYPOINT_NAME = "testWaypoint"; - public static final String WAYPOINT_TYPE = "testWaypoinType"; - public static final String WAYPOINT_DESCRIPTION = "testWaypointDesc"; - public static final String DEFAULT_ACTIVITY_TYPE = "TestActivity"; - public static final String TRACK_NAME_PREFIX = "testTrackName"; - - private static final String TAG = EndToEndTestUtils.class.getSimpleName(); - private static final String TRACK_DESCRIPTION_PREFIX = "testTrackDesc"; - - private static final int ORIENTATION_PORTRAIT = 1; - private static final int ORIENTATION_LANDSCAPE = 0; - - private static final String ANDROID_LOCAL_IP = "10.0.2.2"; - private static final String NO_GPS_MESSAGE_PREFIX = "GPS is not available"; - private static final String MORE_OPTION_CLASSNAME = "com.android.internal.view.menu.ActionMenuPresenter$OverflowMenuButton"; - private static final String MENUITEM_CLASSNAME = "com.android.internal.view.menu.IconMenuItemView"; - - // Following is some check strings in English and Chinese - private static final HashMap - RELATIVE_START_TIME_SUFFIX_MULTILINGUAL = new HashMap(); - - static { - RELATIVE_START_TIME_SUFFIX_MULTILINGUAL.put("en", "mins ago"); - RELATIVE_START_TIME_SUFFIX_MULTILINGUAL.put("de", "Minuten"); - RELATIVE_START_TIME_SUFFIX_MULTILINGUAL.put("fr", "minute"); - RELATIVE_START_TIME_SUFFIX_MULTILINGUAL.put("ar", "دقيقة"); - RELATIVE_START_TIME_SUFFIX_MULTILINGUAL.put("zh", "分钟前"); - } - - public static int emulatorPort = 5554; // usually 5554. - public static String activityType = DEFAULT_ACTIVITY_TYPE; - public static String trackName; - public static String trackDescription; - public static com.robotium.solo.Solo SOLO; - public static Instrumentation instrumentation; - public static TrackListActivity trackListActivity; - - /* - * Check whether the UI has an action bar which is related with the version of - * Android OS. - */ - public static boolean hasActionBar = false; - public static boolean isEmulator = true; - public static boolean hasGpsSignal = true; - - private static boolean isCheckedFirstLaunch = false; - private static boolean isGooglePlayServicesLatest = true; - private static String language; - - private EndToEndTestUtils() {}; - - /** - * Checks the language, then sets the fields with right string. - */ - private static void checkLanguage() { - Locale locale = new Locale("en"); - Locale.setDefault(locale); - - Configuration configuration = trackListActivity.getBaseContext() - .getResources().getConfiguration(); - configuration.locale = locale; - - language = instrumentation.getContext().getResources().getConfiguration().locale.getLanguage(); - } - - /** - * Sends Gps data to emulator, and the start value has an offset. - * - * @param number send times - * @param offset is used to compute the start latitude and longitude - * @param pause pause interval between each sending - */ - public static void sendGps(int number, int offset, int pause) { - if (number < 1) { - return; - } - - int pauseInterval = TINY_WAIT_TIME; - if (pause != -1) { - pauseInterval = pause; - } - - // If it's a real device, does not send simulated GPS signal. - if (!isEmulator) { - return; - } - - PrintStream out = null; - Socket socket = null; - try { - socket = new Socket(ANDROID_LOCAL_IP, emulatorPort); - out = new PrintStream(socket.getOutputStream()); - double longitude = START_LONGITUDE + offset * DELTA_LONGITUDE; - double latitude = START_LATITUDE + offset * DELTA_LADITUDE; - for (int i = 0; i < number; i++) { - out.println("geo fix " + longitude + " " + latitude); - longitude += DELTA_LONGITUDE; - latitude += DELTA_LADITUDE; - Thread.sleep(pauseInterval); - } - // Wait the GPS signal can be obtained by MyTracks. - Thread.sleep(SHORT_WAIT_TIME); - } catch (UnknownHostException e) { - System.exit(-1); - } catch (IOException e) { - System.exit(-1); - } catch (InterruptedException e) { - System.exit(-1); - } finally { - if (out != null) { - out.close(); - } - } - } - - /** - * Send Gps data to emulator. - * - * @param number number of signals - * @param offset is used to compute the start latitude and longitude - */ - public static void sendGps(int number, int offset) { - sendGps(number, offset, -1); - } - - /** - * Send Gps data to emulator. - * - * @param number number of signals - */ - public static void sendGps(int number) { - sendGps(number, 0, -1); - } - - /** - * Sets the status whether the test is run on an emulator or not. - */ - private static void setIsEmulator() { - isEmulator = android.os.Build.MODEL.equals("google_sdk"); - } - - /** - * Checks whether the Google Play Services need update. - */ - private static boolean isGooglePlayServicesLatest() { - return findTextView("Google Play services") == null; - } - - /** - * A setup for debugging end-to-end tests. - * - * @param inst the instrumentation - * @param activity the track list activity - */ - public static void setupForDebug(Instrumentation inst, TrackListActivity activity) { - instrumentation = inst; - trackListActivity = activity; - SOLO = new Solo(instrumentation, trackListActivity); - setIsEmulator(); - hasActionBar = setHasActionBar(); - checkLanguage(); - } - - /** - * A setup for all end-to-end tests. - * - * @param inst the instrumentation - * @param activity the track list activity - */ - public static void setupForAllTest(Instrumentation inst, TrackListActivity activity) { - instrumentation = inst; - trackListActivity = activity; - SOLO = new Solo(instrumentation, trackListActivity); - - if (!isGooglePlayServicesLatest) { - SOLO.finishOpenedActivities(); - Assert.fail(); - Log.e(TAG, "Need update Google Play Services"); - } - - // Check if open MyTracks first time after install. If so, there would be a - // welcome view with accept buttons. And makes sure only check once. - if (!isCheckedFirstLaunch) { - isGooglePlayServicesLatest = isGooglePlayServicesLatest(); - if (!isGooglePlayServicesLatest) { - SOLO.finishOpenedActivities(); - Assert.fail(); - Log.e(TAG, "Need update Google Play Services"); - } - setIsEmulator(); - - verifyFirstLaunch(); - hasActionBar = setHasActionBar(); - checkLanguage(); - isCheckedFirstLaunch = true; - - inst.waitForIdleSync(); - // Check the status of real phone. For emulator, we would fix GPS signal. - if (!isEmulator) { - findAndClickMyLocation(activity); - hasGpsSignal = !SOLO.waitForText(NO_GPS_MESSAGE_PREFIX, 1, SHORT_WAIT_TIME); - SOLO.goBack(); - } - } - - int trackNumber = SOLO.getCurrentViews(ListView.class).get(0).getCount(); - // Delete all tracks when there are two many tracks which may make some test - // run slowly, such as sync test cases. - if (trackNumber > 3) { - deleteAllTracks(); - } - - // Check whether is under recording. If previous test failed, the recording - // may not be recording. - if (isUnderRecording()) { - stopRecording(true); - } - - resetAllSettings(activity, false); - inst.waitForIdleSync(); - } - - /** - * Rotates the given activity. - * - * @param activity a given activity - */ - private static void rotateActivity(Activity activity) { - activity - .setRequestedOrientation(activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT ? ORIENTATION_LANDSCAPE - : ORIENTATION_PORTRAIT); - } - - /** - * Accepts terms and configures units. - */ - private static void verifyFirstLaunch() { - if ((getButtonOnScreen(trackListActivity.getString(R.string.eula_accept), false, false) != null)) { - getButtonOnScreen(trackListActivity.getString(R.string.eula_accept), true, true); - } - } - - /** - * Creates a simple track which can be used by subsequent test. This method - * will save a customized track name. - * - * @param numberOfGpsData number of simulated Gps data - * @param showTrackList whether stay on track list activity or track detail - * activity - */ - public static void createSimpleTrack(int numberOfGpsData, boolean showTrackList) { - startRecording(); - sendGps(numberOfGpsData); - instrumentation.waitForIdleSync(); - stopRecording(true); - - if (showTrackList) { - SOLO.goBack(); - instrumentation.waitForIdleSync(); - } - } - - /** - * Creates a track which contains pause during recording. - * - * @param numberOfGpsData number of simulated Gps data before pause and after - * resume - */ - public static void createTrackWithPause(int numberOfGpsData) { - startRecording(); - sendGps(numberOfGpsData); - pauseRecording(); - resumeRecording(); - sendGps(numberOfGpsData, numberOfGpsData); - stopRecording(true); - } - - /** - * Checks if there is no track in track list. For some tests need at least one - * track, the method can save time to create a new track. - * - * @param isClick if not empty, true means click any track - * @return return true if the track list is empty - */ - private static boolean isTrackListEmpty(boolean isClick) { - instrumentation.waitForIdleSync(); - int trackNumber = SOLO.getCurrentViews(ListView.class).get(0).getCount(); - if (trackNumber <= 0) { - return true; - } - View oneTrack = SOLO.getCurrentViews(ListView.class).get(0).getChildAt(0); - View aa = oneTrack.findViewById(R.id.list_item_name); - if (aa != null) { - trackName = (String) ((TextView) oneTrack.findViewById(R.id.list_item_name)).getText(); - } - - if (isClick) { - SOLO.scrollUp(); - SOLO.clickOnView(oneTrack); - SOLO.waitForText(trackListActivity.getString(R.string.track_detail_chart_tab)); - } - return false; - } - - /** - * Create a new track if the track is empty. - * - * @param gpsNumber the number of gps signals - * @param showTrackList whether stay on track list activity or track detail - * activity - */ - public static void createTrackIfEmpty(int gpsNumber, boolean showTrackList) { - if (isTrackListEmpty(!showTrackList)) { - // Create a simple track. - createSimpleTrack(gpsNumber, showTrackList); - } - } - - /** - * Starts recoding track. - */ - public static void startRecording() { - View startButton = SOLO.getCurrentActivity().findViewById(R.id.track_controller_record); - if (startButton != null && startButton.isShown()) { - SOLO.clickOnView(startButton); - } - instrumentation.waitForIdleSync(); - } - - /** - * Pauses recoding track. - */ - public static void pauseRecording() { - View pauseButton = SOLO.getCurrentActivity().findViewById(R.id.track_controller_record); - if (pauseButton != null && pauseButton.isShown()) { - SOLO.clickOnView(pauseButton); - } - instrumentation.waitForIdleSync(); - } - - /** - * Resume recoding track. - */ - public static void resumeRecording() { - View startButton = SOLO.getCurrentActivity().findViewById(R.id.track_controller_record); - if (startButton != null && startButton.isShown()) { - SOLO.clickOnView(startButton); - } - instrumentation.waitForIdleSync(); - } - - /** - * Checks if the MyTracks is under recording. - * - * @return true if it is under recording. - */ - private static boolean isUnderRecording() { - instrumentation.waitForIdleSync(); - View view = SOLO.getCurrentActivity().findViewById(R.id.track_controller_stop); - // TODO: understand why view can be null here - return view != null ? view.isEnabled() : false; - } - - /** - * Stops recoding track. - * - * @param isSave true means should save this track - */ - public static void stopRecording(boolean isSave) { - View stopButton = SOLO.getCurrentActivity().findViewById(R.id.track_controller_stop); - if (stopButton != null && stopButton.isShown()) { - SOLO.clickOnView(stopButton); - if (isSave) { - SOLO.waitForText(trackListActivity.getString(R.string.generic_save), 1, 5000); - // Make every track name is unique to make sure every check can be - // trusted. - long currentMillis = System.currentTimeMillis(); - trackName = TRACK_NAME_PREFIX + currentMillis; - trackDescription = TRACK_DESCRIPTION_PREFIX + currentMillis; - SOLO.sendKey(KeyEvent.KEYCODE_DEL); - enterTextAvoidSoftKeyBoard(0, trackName); - enterTextAvoidSoftKeyBoard(1, activityType); - enterTextAvoidSoftKeyBoard(2, trackDescription); - SOLO.clickOnText(trackListActivity.getString(R.string.generic_save)); - instrumentation.waitForIdleSync(); - } else { - instrumentation.waitForIdleSync(); - } - } - } - - /** - * Deletes all tracks. This method should be call when the TracksListActivity - * is shown. - */ - public static void deleteAllTracks() { - if (!isTrackListEmpty(false)) { - findMenuItem(trackListActivity.getString(R.string.menu_delete_all), true); - getButtonOnScreen(trackListActivity.getString(R.string.generic_yes), true, true); - waitTextToDisappear(trackListActivity.getString(R.string.generic_progress_title)); - } - } - - /** - * Checks if a button is existed in the screen. - * - * @param buttonName the name string of the button - * @param isWait whether wait the text - * @param isClick whether click the button if find it - * @return the button to search, and null means can not find the button - */ - public static View getButtonOnScreen(String buttonName, boolean isWait, boolean isClick) { - View button = null; - - instrumentation.waitForIdleSync(); - if (isWait) { - SOLO.waitForText(buttonName); - } - - // Find on action bar. - if (hasActionBar) { - ArrayList allViews = SOLO.getViews(); - for (View view : allViews) { - String className = view.getClass().getName(); - if (className.indexOf("ActionMenuItemView") > 0) { - String menuItemNameString = view.getContentDescription().toString(); - if (menuItemNameString.equalsIgnoreCase(buttonName)) { - button = view; - break; - } - } - } - } - - // Get all buttons and find. - if (button == null) { - ArrayList