mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-07 20:03:06 +02:00
My Tracks 2.0.1. Add support for Google location settings.
This commit is contained in:
+265
@@ -0,0 +1,265 @@
|
||||
/*
|
||||
* 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 com.google.android.apps.mytracks.TrackListActivity;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Instrumentation;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.view.KeyEvent;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Tests creating a track with markers, and editing and sending send a track.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
||||
|
||||
private static final String WAYPOINT_NAME = "testWaypoint";
|
||||
private Instrumentation instrumentation;
|
||||
private TrackListActivity activityMyTracks;
|
||||
|
||||
@TargetApi(8)
|
||||
public CreateAndSendTrackTest() {
|
||||
super(TrackListActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
instrumentation = getInstrumentation();
|
||||
activityMyTracks = getActivity();
|
||||
EndToEndTestUtils.setupForAllTest(instrumentation, activityMyTracks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does not check any service and try to send to google.
|
||||
*/
|
||||
public void testCreateAndSendTrack_notSend() {
|
||||
EndToEndTestUtils.createTrackIfEmpty(1, false);
|
||||
instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_send_google), true);
|
||||
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.send_google_title));
|
||||
EndToEndTestUtils.rotateCurrentActivity();
|
||||
instrumentation.waitForIdleSync();
|
||||
|
||||
ArrayList<CheckBox> checkBoxs = EndToEndTestUtils.SOLO.getCurrentCheckBoxes();
|
||||
for (int i = 0; i < checkBoxs.size(); i++) {
|
||||
if (checkBoxs.get(i).isChecked()) {
|
||||
EndToEndTestUtils.SOLO.clickOnCheckBox(i);
|
||||
}
|
||||
}
|
||||
|
||||
if (checkBoxs.size() < 3) {
|
||||
EndToEndTestUtils.SOLO.scrollDown();
|
||||
checkBoxs = EndToEndTestUtils.SOLO.getCurrentCheckBoxes();
|
||||
for (int i = 0; i < checkBoxs.size(); i++) {
|
||||
if (checkBoxs.get(i).isChecked()) {
|
||||
EndToEndTestUtils.SOLO.clickOnCheckBox(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.send_google_send_now));
|
||||
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks
|
||||
.getString(R.string.send_google_no_service_selected)));
|
||||
// Stop here for do not really send.
|
||||
}
|
||||
|
||||
/**
|
||||
* Check all services and send to google.
|
||||
*/
|
||||
public void testCreateAndSendTrack_Send() {
|
||||
EndToEndTestUtils.createTrackIfEmpty(1, false);
|
||||
instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_send_google), true);
|
||||
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.send_google_title));
|
||||
ArrayList<CheckBox> checkBoxs = EndToEndTestUtils.SOLO.getCurrentCheckBoxes();
|
||||
for (int i = 0; i < checkBoxs.size(); i++) {
|
||||
if (!checkBoxs.get(i).isChecked()) {
|
||||
EndToEndTestUtils.SOLO.clickOnCheckBox(i);
|
||||
}
|
||||
}
|
||||
|
||||
if (checkBoxs.size() < 3) {
|
||||
EndToEndTestUtils.SOLO.scrollDown();
|
||||
checkBoxs = EndToEndTestUtils.SOLO.getCurrentCheckBoxes();
|
||||
for (int i = 0; i < checkBoxs.size(); i++) {
|
||||
if (!checkBoxs.get(i).isChecked()) {
|
||||
EndToEndTestUtils.SOLO.clickOnCheckBox(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.send_google_send_now));
|
||||
|
||||
// If no account is binded with this device.
|
||||
if (EndToEndTestUtils.SOLO.waitForText(activityMyTracks
|
||||
.getString(R.string.send_google_no_account_title), 1, 10000)) {
|
||||
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
|
||||
} else {
|
||||
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks
|
||||
.getString(R.string.generic_progress_title)));
|
||||
// Waiting the send is finish.
|
||||
while (EndToEndTestUtils.SOLO.waitForText(activityMyTracks
|
||||
.getString(R.string.generic_progress_title), 1, 500)) {
|
||||
}
|
||||
|
||||
// For we not sure the send will be successful, just check whether the result dialog is display.
|
||||
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks
|
||||
.getString(R.string.share_track_share_url)));
|
||||
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests editing a track.
|
||||
*/
|
||||
public void testEditTrack() {
|
||||
EndToEndTestUtils.createTrackIfEmpty(1, false);
|
||||
instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_edit), true);
|
||||
|
||||
String newTrackName = EndToEndTestUtils.TRACK_NAME_PREFIX + "_new" + System.currentTimeMillis();
|
||||
String newType = "type" + newTrackName;
|
||||
String newDesc = "desc" + newTrackName;
|
||||
|
||||
instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.rotateAllActivities();
|
||||
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.generic_save));
|
||||
sendKeys(KeyEvent.KEYCODE_DEL);
|
||||
ArrayList<EditText> editTexts = EndToEndTestUtils.SOLO.getCurrentEditTexts();
|
||||
|
||||
EndToEndTestUtils.SOLO.enterText(editTexts.get(0), newTrackName);
|
||||
EndToEndTestUtils.SOLO.enterText(editTexts.get(1), newType);
|
||||
// In landscape, there are only two visible edit texts.
|
||||
if (editTexts.size() > 2) {
|
||||
EndToEndTestUtils.SOLO.enterText(editTexts.get(2), newDesc);
|
||||
} else {
|
||||
EndToEndTestUtils.SOLO.scrollDown();
|
||||
editTexts = EndToEndTestUtils.SOLO.getCurrentEditTexts();
|
||||
EndToEndTestUtils.SOLO.enterText(editTexts.get(editTexts.size() - 1), newDesc);
|
||||
}
|
||||
EndToEndTestUtils.SOLO.clickOnButton(activityMyTracks.getString(R.string.generic_save));
|
||||
instrumentation.waitForIdleSync();
|
||||
// Go back to track list.
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
instrumentation.waitForIdleSync();
|
||||
assertTrue(EndToEndTestUtils.SOLO.searchText(newTrackName));
|
||||
assertTrue(EndToEndTestUtils.SOLO.searchText(newDesc));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates one track with a two locations, a way point and a statistics point.
|
||||
*/
|
||||
public void testCreateTrackWithMarkers() {
|
||||
EndToEndTestUtils.startRecording();
|
||||
instrumentation.waitForIdleSync();
|
||||
// Send Gps before send marker.
|
||||
EndToEndTestUtils.sendGps(2);
|
||||
if (EndToEndTestUtils.hasActionBar) {
|
||||
// Check the title is Recording.
|
||||
assertTrue(EndToEndTestUtils.SOLO.searchText(activityMyTracks
|
||||
.getString(R.string.icon_recording)));
|
||||
}
|
||||
createWaypoint();
|
||||
EndToEndTestUtils.sendGps(2);
|
||||
// Back to tracks list.
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.rotateAllActivities();
|
||||
EndToEndTestUtils.stopRecording(false);
|
||||
EndToEndTestUtils.trackName = EndToEndTestUtils.TRACK_NAME_PREFIX + System.currentTimeMillis();
|
||||
EndToEndTestUtils.SOLO.enterText(0, EndToEndTestUtils.trackName);
|
||||
if(!EndToEndTestUtils.isEmulator) {
|
||||
// Close soft keyboard.
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
}
|
||||
EndToEndTestUtils.SOLO.clickOnButton(activityMyTracks.getString(R.string.generic_save));
|
||||
|
||||
instrumentation.waitForIdleSync();
|
||||
// Check the new track
|
||||
assertTrue(EndToEndTestUtils.SOLO.waitForText(EndToEndTestUtils.trackName, 1, 5000, true,
|
||||
false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the display of track start time. Use relative time (x mins ago) for
|
||||
* the start time if it is within the past week. But only show the start time
|
||||
* if it is different from the track name.
|
||||
*/
|
||||
public void testTrackStartTime() {
|
||||
// Delete all track first.
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_delete_all), true);
|
||||
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
|
||||
|
||||
// Reset all settings.
|
||||
EndToEndTestUtils.resetAllSettings(activityMyTracks, false);
|
||||
|
||||
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.track_list_empty_message)));
|
||||
// Test should not show relative time.
|
||||
EndToEndTestUtils.startRecording();
|
||||
instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.stopRecording(false);
|
||||
instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.generic_save));
|
||||
instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
instrumentation.waitForIdleSync();
|
||||
assertFalse(EndToEndTestUtils.SOLO.waitForText(EndToEndTestUtils.RELATIVE_STARTTIME_POSTFIX, 1, 5000));
|
||||
|
||||
// Test should show relative time for createSimpleTrack would save a track
|
||||
// name that is different with the start time.
|
||||
EndToEndTestUtils.createSimpleTrack(2);
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
assertTrue(EndToEndTestUtils.SOLO.waitForText(EndToEndTestUtils.RELATIVE_STARTTIME_POSTFIX, 1, 5000));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a way point and a split maker during track recording.
|
||||
*/
|
||||
private void createWaypoint() {
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_markers), true);
|
||||
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.marker_list_empty_message));
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_insert_marker), true);
|
||||
// Rotate when show insert page.
|
||||
EndToEndTestUtils.rotateAllActivities();
|
||||
EndToEndTestUtils.SOLO.enterText(0, WAYPOINT_NAME);
|
||||
if(!EndToEndTestUtils.isEmulator) {
|
||||
// Close soft keyboard.
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
}
|
||||
EndToEndTestUtils.SOLO.clickOnButton(activityMyTracks.getString(R.string.generic_add));
|
||||
assertTrue(EndToEndTestUtils.SOLO.searchText(WAYPOINT_NAME));
|
||||
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
EndToEndTestUtils.SOLO.finishOpenedActivities();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* 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 com.google.android.apps.mytracks.TrackListActivity;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Instrumentation;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.widget.ListView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Tests the delete of MyTracks.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class DeleteTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
||||
|
||||
private Instrumentation instrumentation;
|
||||
private TrackListActivity activityMyTracks;
|
||||
|
||||
@TargetApi(8)
|
||||
public DeleteTest() {
|
||||
super(TrackListActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
instrumentation = getInstrumentation();
|
||||
activityMyTracks = getActivity();
|
||||
EndToEndTestUtils.setupForAllTest(instrumentation, activityMyTracks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all tracks.
|
||||
*/
|
||||
public void testDeleteAllTracks() {
|
||||
EndToEndTestUtils.createTrackIfEmpty(1, true);
|
||||
instrumentation.waitForIdleSync();
|
||||
// There is at least one track.
|
||||
ArrayList<ListView> trackListView = EndToEndTestUtils.SOLO.getCurrentListViews();
|
||||
assertTrue(trackListView.size() > 0);
|
||||
assertTrue(trackListView.get(0).getCount() > 0);
|
||||
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_delete_all), true);
|
||||
instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.rotateAllActivities();
|
||||
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
|
||||
instrumentation.waitForIdleSync();
|
||||
// There is no track now.
|
||||
trackListView = EndToEndTestUtils.SOLO.getCurrentListViews();
|
||||
assertEquals(0, trackListView.get(0).getCount());
|
||||
// Export when there is no track.
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_save_all), true);
|
||||
EndToEndTestUtils.SOLO
|
||||
.clickOnText(String.format(activityMyTracks.getString(R.string.menu_save_format),
|
||||
EndToEndTestUtils.GPX.toUpperCase()));
|
||||
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks
|
||||
.getString(R.string.sd_card_save_error_no_track)));
|
||||
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes only one track.
|
||||
*/
|
||||
public void testDeleteSingleTrack() {
|
||||
EndToEndTestUtils.createTrackIfEmpty(1, true);
|
||||
instrumentation.waitForIdleSync();
|
||||
// Get the number of track( or tracks)
|
||||
ArrayList<ListView> trackListView = EndToEndTestUtils.SOLO.getCurrentListViews();
|
||||
int trackNumberOld = trackListView.get(0).getCount();
|
||||
|
||||
EndToEndTestUtils.SOLO.clickOnView(trackListView.get(0).getChildAt(0));
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_delete), true);
|
||||
EndToEndTestUtils
|
||||
.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
|
||||
instrumentation.waitForIdleSync();
|
||||
trackListView = EndToEndTestUtils.SOLO.getCurrentListViews();
|
||||
int trackNumberNew = trackListView.get(0).getCount();
|
||||
assertEquals(trackNumberOld - 1, trackNumberNew);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a track which is under recording.
|
||||
*/
|
||||
public void testDeleteOneTrackUnderRecording() {
|
||||
EndToEndTestUtils.startRecording();
|
||||
instrumentation.waitForIdleSync();
|
||||
assertTrue(EndToEndTestUtils.findMenuItem(
|
||||
activityMyTracks.getString(R.string.menu_stop_recording), false));
|
||||
instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_delete), true);
|
||||
EndToEndTestUtils
|
||||
.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
|
||||
instrumentation.waitForIdleSync();
|
||||
assertTrue(EndToEndTestUtils.findMenuItem(
|
||||
activityMyTracks.getString(R.string.menu_record_track), false));
|
||||
instrumentation.waitForIdleSync();
|
||||
assertTrue(EndToEndTestUtils.findMenuItem(
|
||||
activityMyTracks.getString(R.string.menu_record_track), false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
EndToEndTestUtils.SOLO.finishOpenedActivities();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
||||
+603
@@ -0,0 +1,603 @@
|
||||
/*
|
||||
* 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 com.google.android.apps.mytracks.ChartView;
|
||||
import com.google.android.apps.mytracks.TrackListActivity;
|
||||
import com.google.android.apps.mytracks.util.FileUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
import com.jayway.android.robotium.solo.Solo;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Instrumentation;
|
||||
import android.content.res.Configuration;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.net.Socket;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Provides utilities to smoke test.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class EndToEndTestUtils {
|
||||
private static final String ANDROID_LOCAL_IP = "10.0.2.2";
|
||||
// usually 5554.
|
||||
private static final int ANDROID_LOCAL_PORT = 5554;
|
||||
|
||||
private static final int ORIENTATION_PORTRAIT = 1;
|
||||
private static final int ORIENTATION_LANDSCAPE = 0;
|
||||
// Pause 200ms between each send.
|
||||
static int PAUSE = 200;
|
||||
private static final float START_LONGITUDE = 51;
|
||||
private static final float START_LATITUDE = -1.3f;
|
||||
private static final float DELTA_LONGITUDE = 0.0005f;
|
||||
private static final float DELTA_LADITUDE = 0.0005f;
|
||||
|
||||
private static final String MOREOPTION_CLASSNAME = "com.android.internal.view.menu.ActionMenuPresenter$OverflowMenuButton";
|
||||
|
||||
static final String TRACK_NAME_PREFIX = "testTrackName";
|
||||
static final String GPX = "gpx";
|
||||
static final String KML = "kml";
|
||||
static final String CSV = "csv";
|
||||
static final String TCX = "tcx";
|
||||
static final String BACKUPS = "backups";
|
||||
static final String MENU_MORE = "More";
|
||||
static String trackName;
|
||||
|
||||
// Following is some check strings in English and Chinese
|
||||
private static final HashMap<String, String> RELATIVE_STARTTIME_POSTFIX_MULTILINGUAL = new HashMap<String, String>();
|
||||
private static final HashMap<String, String> VIEW_MODE_ENGLISH_MULTILINGUAL = new HashMap<String, String>();
|
||||
public static String RELATIVE_STARTTIME_POSTFIX = "";
|
||||
public static String VIEW_MODE = "";
|
||||
|
||||
static Solo SOLO;
|
||||
static Instrumentation instrumentation;
|
||||
static TrackListActivity activityMytracks;
|
||||
// Check whether the UI has an action bar which is related with the version of
|
||||
// Android OS.
|
||||
static boolean hasActionBar = false;
|
||||
static boolean isEmulator = true;
|
||||
static boolean isCheckedFirstLaunch = false;
|
||||
|
||||
private EndToEndTestUtils() {}
|
||||
|
||||
private static void checkLanguage() {
|
||||
RELATIVE_STARTTIME_POSTFIX_MULTILINGUAL.put("es", "mins ago");
|
||||
RELATIVE_STARTTIME_POSTFIX_MULTILINGUAL.put("de", "Minuten");
|
||||
RELATIVE_STARTTIME_POSTFIX_MULTILINGUAL.put("fr", "minute");
|
||||
RELATIVE_STARTTIME_POSTFIX_MULTILINGUAL.put("ar", "دقيقة");
|
||||
RELATIVE_STARTTIME_POSTFIX_MULTILINGUAL.put("zh", "分钟前");
|
||||
|
||||
VIEW_MODE_ENGLISH_MULTILINGUAL.put("es", "mode");
|
||||
VIEW_MODE_ENGLISH_MULTILINGUAL.put("de", "modus");
|
||||
VIEW_MODE_ENGLISH_MULTILINGUAL.put("fr", "Mode");
|
||||
VIEW_MODE_ENGLISH_MULTILINGUAL.put("ar", "وضع");
|
||||
VIEW_MODE_ENGLISH_MULTILINGUAL.put("zh", "模式");
|
||||
|
||||
|
||||
// Check the language, test in Chinese or English.
|
||||
String deviceLanguage = instrumentation.getContext().getResources().getConfiguration().locale.getLanguage();
|
||||
if (RELATIVE_STARTTIME_POSTFIX_MULTILINGUAL.get(deviceLanguage) != null) {
|
||||
RELATIVE_STARTTIME_POSTFIX = RELATIVE_STARTTIME_POSTFIX_MULTILINGUAL.get(deviceLanguage);
|
||||
VIEW_MODE = VIEW_MODE_ENGLISH_MULTILINGUAL.get(deviceLanguage);
|
||||
} else {
|
||||
RELATIVE_STARTTIME_POSTFIX = RELATIVE_STARTTIME_POSTFIX_MULTILINGUAL.get("es");
|
||||
VIEW_MODE = VIEW_MODE_ENGLISH_MULTILINGUAL.get("es");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends Gps data to emulator.
|
||||
*
|
||||
* @param number send times
|
||||
*/
|
||||
public static void sendGps(int number) {
|
||||
if (number < 1) {
|
||||
return;
|
||||
}
|
||||
// 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, ANDROID_LOCAL_PORT);
|
||||
out = new PrintStream(socket.getOutputStream());
|
||||
float longitude = START_LONGITUDE;
|
||||
float latitude = START_LATITUDE;
|
||||
for (int i = 0; i < number; i++) {
|
||||
Thread.sleep(PAUSE);
|
||||
out.println("geo fix " + latitude + " " + longitude);
|
||||
longitude += DELTA_LONGITUDE;
|
||||
latitude += DELTA_LADITUDE;
|
||||
}
|
||||
} catch (UnknownHostException e) {
|
||||
System.exit(-1);
|
||||
} catch (IOException e) {
|
||||
System.exit(-1);
|
||||
} catch (InterruptedException e) {
|
||||
System.exit(-1);
|
||||
} finally {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the status whether the test is run on an emulator or not.
|
||||
*/
|
||||
static void setIsEmulator() {
|
||||
isEmulator = android.os.Build.MODEL.equals("google_sdk");
|
||||
}
|
||||
|
||||
/**
|
||||
* A setup for all end-to-end tests.
|
||||
*
|
||||
* @param instrumentation the instrumentation is used for test
|
||||
* @param activityMyTracks the startup activity
|
||||
*/
|
||||
static void setupForAllTest(Instrumentation instrumentation, TrackListActivity activityMyTracks) {
|
||||
setIsEmulator();
|
||||
EndToEndTestUtils.instrumentation = instrumentation;
|
||||
EndToEndTestUtils.activityMytracks = activityMyTracks;
|
||||
EndToEndTestUtils.SOLO = new Solo(EndToEndTestUtils.instrumentation,
|
||||
EndToEndTestUtils.activityMytracks);
|
||||
// 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 (!EndToEndTestUtils.isCheckedFirstLaunch) {
|
||||
if ((EndToEndTestUtils.getButtonOnScreen(EndToEndTestUtils.activityMytracks
|
||||
.getString(R.string.eula_accept), false, false) != null)) {
|
||||
EndToEndTestUtils.verifyFirstLaunch();
|
||||
} else if (EndToEndTestUtils.SOLO.waitForText(
|
||||
// After reset setting, welcome page will show again.
|
||||
activityMytracks.getString(R.string.welcome_title), 0, 500)) {
|
||||
resetPreferredUnits();
|
||||
}
|
||||
checkLanguage();
|
||||
EndToEndTestUtils.isCheckedFirstLaunch = true;
|
||||
EndToEndTestUtils.setHasActionBar();
|
||||
} else if (EndToEndTestUtils.SOLO.waitForText(
|
||||
// After reset setting, welcome page will show again.
|
||||
activityMytracks.getString(R.string.welcome_title), 0, 500)) {
|
||||
resetPreferredUnits();
|
||||
}
|
||||
|
||||
// Check whether is under recording. If previous test failed, the recording
|
||||
// may not be recording.
|
||||
if (isUnderRecording()) {
|
||||
stopRecording(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if need reset preferred units.
|
||||
*/
|
||||
private static void resetPreferredUnits() {
|
||||
getButtonOnScreen(activityMytracks.getString(R.string.generic_ok), true, true);
|
||||
SOLO.waitForText(activityMytracks.getString(R.string.settings_stats_units_title));
|
||||
getButtonOnScreen(activityMytracks.getString(R.string.generic_ok), true, true);
|
||||
instrumentation.waitForIdleSync();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Rotates the given activity.
|
||||
*
|
||||
* @param activity a given activity
|
||||
*/
|
||||
static void rotateActivity(Activity activity) {
|
||||
activity
|
||||
.setRequestedOrientation(activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT ? ORIENTATION_LANDSCAPE
|
||||
: ORIENTATION_PORTRAIT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts terms and configures units.
|
||||
*/
|
||||
static void verifyFirstLaunch() {
|
||||
getButtonOnScreen(activityMytracks.getString(R.string.eula_accept), true, true);
|
||||
if (SOLO.waitForText(activityMytracks.getString(R.string.generic_ok))) {
|
||||
// Click for welcome.
|
||||
getButtonOnScreen(activityMytracks.getString(R.string.generic_ok), true, true);
|
||||
// Click for choose units.
|
||||
getButtonOnScreen(activityMytracks.getString(R.string.generic_ok), true, true);
|
||||
instrumentation.waitForIdleSync();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
static void createSimpleTrack(int numberOfGpsData) {
|
||||
startRecording();
|
||||
EndToEndTestUtils.sendGps(numberOfGpsData);
|
||||
instrumentation.waitForIdleSync();
|
||||
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
|
||||
*/
|
||||
static boolean isTrackListEmpty(boolean isClick) {
|
||||
int trackNumber = SOLO.getCurrentListViews().get(0).getCount();
|
||||
if(trackNumber <= 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
View oneTrack = SOLO.getCurrentListViews().get(0).getChildAt(0);
|
||||
trackName = (String) ((TextView) oneTrack.findViewById(R.id.list_item_name)).getText();
|
||||
if (isClick) {
|
||||
SOLO.scrollUp();
|
||||
SOLO.clickOnView(oneTrack);
|
||||
}
|
||||
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
|
||||
*/
|
||||
static void createTrackIfEmpty(int gpsNumber, boolean showTrackList) {
|
||||
if (EndToEndTestUtils.isTrackListEmpty(!showTrackList)) {
|
||||
// Create a simple track.
|
||||
EndToEndTestUtils.createSimpleTrack(gpsNumber);
|
||||
if (showTrackList) {
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts recoding track.
|
||||
*/
|
||||
static void startRecording() {
|
||||
if (hasActionBar) {
|
||||
Button startButton = getButtonOnScreen(activityMytracks.getString(R.string.menu_record_track), false, false);
|
||||
// In case a track is recording.
|
||||
if (startButton == null) {
|
||||
stopRecording(true);
|
||||
startButton = getButtonOnScreen(activityMytracks.getString(R.string.menu_record_track), false, false);
|
||||
}
|
||||
SOLO.clickOnView(startButton);
|
||||
} else {
|
||||
showMoreMenuItem();
|
||||
if (!SOLO.searchText(activityMytracks.getString(R.string.menu_record_track))) {
|
||||
// Check if in TrackDetailActivity.
|
||||
if (SOLO.searchText(activityMytracks.getString(R.string.menu_play))) {
|
||||
SOLO.goBack();
|
||||
} else {
|
||||
// In case a track is recording.
|
||||
stopRecording(true);
|
||||
showMoreMenuItem();
|
||||
}
|
||||
}
|
||||
instrumentation.waitForIdleSync();
|
||||
SOLO.clickOnText(activityMytracks.getString(R.string.menu_record_track));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the MyTracks is under recording.
|
||||
*
|
||||
* @return true if it is under recording.
|
||||
*/
|
||||
static boolean isUnderRecording() {
|
||||
if (hasActionBar) {
|
||||
return getButtonOnScreen(activityMytracks
|
||||
.getString(R.string.menu_record_track), false, false) == null;
|
||||
}
|
||||
showMoreMenuItem();
|
||||
if (SOLO.searchText(activityMytracks.getString(R.string.menu_record_track))
|
||||
|| SOLO.searchText(activityMytracks.getString(R.string.menu_play))) {
|
||||
SOLO.goBack();
|
||||
return false;
|
||||
}
|
||||
SOLO.goBack();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops recoding track.
|
||||
*
|
||||
* @param isSave true means should save this track
|
||||
*/
|
||||
static void stopRecording(boolean isSave) {
|
||||
if (hasActionBar) {
|
||||
getButtonOnScreen(activityMytracks.getString(R.string.menu_stop_recording), false, true);
|
||||
} else {
|
||||
showMoreMenuItem();
|
||||
instrumentation.waitForIdleSync();
|
||||
SOLO.clickOnText(activityMytracks.getString(R.string.menu_stop_recording));
|
||||
}
|
||||
if (isSave) {
|
||||
EndToEndTestUtils.SOLO.waitForText(activityMytracks.getString(R.string.generic_save), 1, 5000);
|
||||
// Make every track name is unique to make sure every check can be
|
||||
// trusted.
|
||||
EndToEndTestUtils.trackName = EndToEndTestUtils.TRACK_NAME_PREFIX
|
||||
+ System.currentTimeMillis();
|
||||
SOLO.enterText(0, trackName);
|
||||
if(!EndToEndTestUtils.isEmulator) {
|
||||
// Close soft keyboard.
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
}
|
||||
SOLO.clickLongOnText(activityMytracks.getString(R.string.generic_save));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a kind of track in MyTracks folder.
|
||||
*
|
||||
* @param trackKind the kind of track
|
||||
*/
|
||||
static void deleteExportedFiles(String trackKind) {
|
||||
File[] allFiles = (new File(FileUtils.buildExternalDirectoryPath(trackKind.toLowerCase())))
|
||||
.listFiles();
|
||||
if (allFiles != null) {
|
||||
for (File oneFile : allFiles) {
|
||||
oneFile.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a kind of exported files.
|
||||
*
|
||||
* @param trackKind the kind of track
|
||||
* @return files array of such kind of exported tracks
|
||||
*/
|
||||
static File[] getExportedFiles(final String trackKind) {
|
||||
String filePath = FileUtils.buildExternalDirectoryPath(trackKind);
|
||||
FileFilter filter = new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File pathname) {
|
||||
return pathname.getName().indexOf("." + trackKind) > 0;
|
||||
}
|
||||
};
|
||||
return (new File(filePath)).listFiles(filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a track to a kind of file in SD card.
|
||||
*
|
||||
* @param trackKind the kind of track
|
||||
*/
|
||||
static void saveTrackToSdCard(String trackKind) {
|
||||
deleteExportedFiles(trackKind);
|
||||
instrumentation.waitForIdleSync();
|
||||
findMenuItem(activityMytracks.getString(R.string.menu_save), true);
|
||||
instrumentation.waitForIdleSync();
|
||||
SOLO.clickOnText(trackKind.toUpperCase());
|
||||
// rotateAllActivities();
|
||||
SOLO.waitForText(activityMytracks.getString(R.string.generic_success_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
|
||||
*/
|
||||
static Button getButtonOnScreen(String buttonName, boolean isWait,boolean isClick) {
|
||||
instrumentation.waitForIdleSync();
|
||||
if (isWait) {
|
||||
SOLO.waitForText(buttonName);
|
||||
}
|
||||
ArrayList<Button> currentButtons = SOLO.getCurrentButtons();
|
||||
for (Button button : currentButtons) {
|
||||
String title = (String) button.getText();
|
||||
if (title.equalsIgnoreCase(buttonName)) {
|
||||
if(isClick) {
|
||||
SOLO.clickOnView(button);
|
||||
}
|
||||
return button;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether an action bar is shown.
|
||||
*
|
||||
* @return false means can not check failed.
|
||||
*/
|
||||
static boolean setHasActionBar() {
|
||||
instrumentation.waitForIdleSync();
|
||||
// If can find record button without pressing Menu, it should be an action
|
||||
// bar.
|
||||
Button startButton = getButtonOnScreen(activityMytracks.getString(R.string.menu_record_track), false, false);
|
||||
Button stopButton = getButtonOnScreen(activityMytracks.getString(R.string.menu_stop_recording), false, false);
|
||||
if (startButton != null || stopButton != null) {
|
||||
hasActionBar = true;
|
||||
} else {
|
||||
showMoreMenuItem();
|
||||
if (SOLO.searchText(activityMytracks.getString(R.string.menu_record_track))
|
||||
|| SOLO.searchText(activityMytracks.getString(R.string.menu_stop_recording))) {
|
||||
hasActionBar = false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
SOLO.goBack();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates the current activity.
|
||||
*/
|
||||
static void rotateCurrentActivity() {
|
||||
EndToEndTestUtils.rotateActivity(SOLO.getCurrentActivity());
|
||||
instrumentation.waitForIdleSync();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates all activities.
|
||||
*/
|
||||
static void rotateAllActivities() {
|
||||
ArrayList<Activity> allActivities = SOLO.getAllOpenedActivities();
|
||||
for (Activity activity : allActivities) {
|
||||
EndToEndTestUtils.rotateActivity(activity);
|
||||
}
|
||||
|
||||
instrumentation.waitForIdleSync();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds an item in the menu with the option to click the item.
|
||||
*
|
||||
* @param menuName the name of item
|
||||
* @param click true means need click this menu
|
||||
* @return true if find this menu
|
||||
*/
|
||||
static boolean findMenuItem(String menuName, boolean click) {
|
||||
boolean findResult = false;
|
||||
|
||||
// Firstly find in action bar.
|
||||
Button button = getButtonOnScreen(menuName, false, false);
|
||||
if (button != null) {
|
||||
findResult = true;
|
||||
if (click) {
|
||||
SOLO.clickOnView(button);
|
||||
instrumentation.waitForIdleSync();
|
||||
}
|
||||
return findResult;
|
||||
}
|
||||
|
||||
showMoreMenuItem();
|
||||
if (SOLO.searchText(menuName)) {
|
||||
findResult = true;
|
||||
} else if (SOLO.searchText(MENU_MORE)) {
|
||||
SOLO.clickOnText(MENU_MORE);
|
||||
findResult = SOLO.searchText(menuName);
|
||||
}
|
||||
|
||||
if (findResult && click) {
|
||||
SOLO.clickOnText(menuName);
|
||||
instrumentation.waitForIdleSync();
|
||||
} else {
|
||||
SOLO.goBack();
|
||||
}
|
||||
return findResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get more menu items operation is different for different Android OS.
|
||||
*/
|
||||
public static void showMoreMenuItem() {
|
||||
if (hasActionBar) {
|
||||
View moreButton = getMoreOptionView();
|
||||
if (moreButton != null) {
|
||||
SOLO.clickOnView(moreButton);
|
||||
return;
|
||||
}
|
||||
}
|
||||
SOLO.sendKey(KeyEvent.KEYCODE_MENU);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the more option menu. It should match following conditions:
|
||||
* <ul>
|
||||
* <li>The view extends ImageButton.</li>
|
||||
* <li>The view name equals {@link EndToEndTestUtils#MOREOPTION_CLASSNAME}.</li>
|
||||
* </ul>
|
||||
* @return the more option view. Null means can not find it.
|
||||
*/
|
||||
private static View getMoreOptionView() {
|
||||
ArrayList<View> allViews = SOLO.getViews();
|
||||
for (View view : allViews) {
|
||||
if (view instanceof ImageButton && view.getClass().getName().equals(MOREOPTION_CLASSNAME)) {
|
||||
return view;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a text view with specified test in a view.
|
||||
*
|
||||
* @param findText text to find
|
||||
* @param parent which text view in in
|
||||
* @return the text view, null means can not find it
|
||||
*/
|
||||
static TextView findTextView(String findText, View parent) {
|
||||
ArrayList<TextView> textViews = EndToEndTestUtils.SOLO.getCurrentTextViews(parent);
|
||||
for (TextView textView : textViews) {
|
||||
String text = (String) textView.getText();
|
||||
if (textView.isShown() && text.endsWith(findText)) {
|
||||
return textView;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ChartView.
|
||||
*
|
||||
* @return the ChartView or null if not find
|
||||
*/
|
||||
static ChartView getChartView() {
|
||||
ArrayList<View> views = EndToEndTestUtils.SOLO.getViews();
|
||||
for (View view : views) {
|
||||
if (view instanceof ChartView) {
|
||||
return (ChartView) view;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets all settings of MyTracks.
|
||||
*
|
||||
* @param activityMyTracks current activity
|
||||
* @param keepInSettingList whether keep in setting list or not
|
||||
*/
|
||||
public static void resetAllSettings(Activity activityMyTracks, boolean keepInSettingList) {
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true);
|
||||
SOLO.waitForText(activityMyTracks.getString(R.string.settings_reset));
|
||||
SOLO.clickOnText(activityMyTracks.getString(R.string.settings_reset));
|
||||
getButtonOnScreen(activityMytracks.getString(R.string.generic_ok), true, true);
|
||||
instrumentation.waitForIdleSync();
|
||||
if (!keepInSettingList) {
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
}
|
||||
}
|
||||
}
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* 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 com.google.android.apps.mytracks.TrackListActivity;
|
||||
import com.google.android.apps.mytracks.util.FileUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Instrumentation;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Tests the import and export of MyTracks.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class ExportAndImportTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
||||
|
||||
private Instrumentation instrumentation;
|
||||
private TrackListActivity activityMyTracks;
|
||||
|
||||
@TargetApi(8)
|
||||
public ExportAndImportTest() {
|
||||
super(TrackListActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
instrumentation = getInstrumentation();
|
||||
activityMyTracks = getActivity();
|
||||
EndToEndTestUtils.setupForAllTest(instrumentation, activityMyTracks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests export and import tracks.
|
||||
* <ul>
|
||||
* <li>Create two tracks, one of them is empty(Have no Gps data).</li>
|
||||
* <li>Tests import when there is no track file.</li>
|
||||
* <li>Tests export tracks to Gpx files.</li>
|
||||
* <li>Tests import files to tracks.</li>
|
||||
* <li>Tests export tracks to Kml files.</li>
|
||||
* </ul>
|
||||
*/
|
||||
public void testExportAndImportTracks() {
|
||||
// Create a new track with 3 gps data.
|
||||
EndToEndTestUtils.createTrackIfEmpty(3, true);
|
||||
instrumentation.waitForIdleSync();
|
||||
// Create a empty track.
|
||||
EndToEndTestUtils.createSimpleTrack(0);
|
||||
instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
instrumentation.waitForIdleSync();
|
||||
// Delete all exported gpx and kml tracks.
|
||||
EndToEndTestUtils.deleteExportedFiles(EndToEndTestUtils.GPX);
|
||||
EndToEndTestUtils.deleteExportedFiles(EndToEndTestUtils.KML);
|
||||
int gpxFilesNumber = 0;
|
||||
File[] allGpxFiles = EndToEndTestUtils.getExportedFiles(EndToEndTestUtils.GPX);
|
||||
// For the first export, there is no MyTracks folder.
|
||||
if (allGpxFiles != null) {
|
||||
gpxFilesNumber = EndToEndTestUtils.getExportedFiles(EndToEndTestUtils.GPX).length;
|
||||
}
|
||||
|
||||
// Get track number in current track list of MyTracks.
|
||||
int trackNumber = EndToEndTestUtils.SOLO.getCurrentListViews().get(0).getCount();
|
||||
|
||||
// No file to imported.
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_import), true);
|
||||
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.sd_card_import_error_no_file,
|
||||
FileUtils.buildExternalDirectoryPath(EndToEndTestUtils.GPX)));
|
||||
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
|
||||
|
||||
// Click to export tracks(At least one track) to Gpx files.
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_save_all), true);
|
||||
EndToEndTestUtils.SOLO
|
||||
.clickOnText(String.format(activityMyTracks.getString(R.string.menu_save_format),
|
||||
EndToEndTestUtils.GPX.toUpperCase()));
|
||||
EndToEndTestUtils.rotateAllActivities();
|
||||
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.sd_card_save_success));
|
||||
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
|
||||
// Check export file.
|
||||
assertEquals(gpxFilesNumber + trackNumber,
|
||||
EndToEndTestUtils.getExportedFiles(EndToEndTestUtils.GPX).length);
|
||||
instrumentation.waitForIdleSync();
|
||||
|
||||
// Click to import track.
|
||||
gpxFilesNumber = EndToEndTestUtils.getExportedFiles(EndToEndTestUtils.GPX).length;
|
||||
trackNumber = EndToEndTestUtils.SOLO.getCurrentListViews().get(0).getCount();
|
||||
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_import), true);
|
||||
EndToEndTestUtils.rotateAllActivities();
|
||||
// Wait for the prefix of import success string is much faster than wait
|
||||
// the whole string.
|
||||
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.sd_card_import_success_count).split(
|
||||
"%")[0]);
|
||||
// Check import tracks should be equal with the sum of trackNumber and
|
||||
// gpxFilesNumber;
|
||||
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
|
||||
instrumentation.waitForIdleSync();
|
||||
assertEquals(trackNumber + gpxFilesNumber, EndToEndTestUtils.SOLO.getCurrentListViews().get(0)
|
||||
.getCount());
|
||||
|
||||
// Click to export tracks(At least two tracks) to KML files.
|
||||
gpxFilesNumber = EndToEndTestUtils.getExportedFiles(EndToEndTestUtils.GPX).length;
|
||||
trackNumber = EndToEndTestUtils.SOLO.getCurrentListViews().get(0).getCount();
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_save_all), true);
|
||||
EndToEndTestUtils.SOLO
|
||||
.clickOnText(String.format(activityMyTracks.getString(R.string.menu_save_format),
|
||||
EndToEndTestUtils.KML.toUpperCase()));
|
||||
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.sd_card_save_success));
|
||||
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
|
||||
// Check export files.
|
||||
assertEquals(gpxFilesNumber, EndToEndTestUtils.getExportedFiles(EndToEndTestUtils.GPX).length);
|
||||
assertEquals(trackNumber, EndToEndTestUtils.getExportedFiles(EndToEndTestUtils.KML).length);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
EndToEndTestUtils.SOLO.finishOpenedActivities();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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 com.google.android.apps.mytracks.TrackListActivity;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Instrumentation;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.view.View;
|
||||
|
||||
/**
|
||||
* Tests the function of go to my location.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class GoToMyLocationTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
||||
|
||||
private Instrumentation instrumentation;
|
||||
private TrackListActivity activityMyTracks;
|
||||
|
||||
@TargetApi(8)
|
||||
public GoToMyLocationTest() {
|
||||
super(TrackListActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
instrumentation = getInstrumentation();
|
||||
activityMyTracks = getActivity();
|
||||
EndToEndTestUtils.setupForAllTest(instrumentation, activityMyTracks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the menu My Location.
|
||||
*/
|
||||
public void testGotoMyLocation() {
|
||||
EndToEndTestUtils.createTrackIfEmpty(1, false);
|
||||
EndToEndTestUtils.sendGps(30);
|
||||
instrumentation.waitForIdleSync();
|
||||
View myLocation = EndToEndTestUtils.SOLO.getCurrentActivity()
|
||||
.findViewById(R.id.map_my_location);
|
||||
EndToEndTestUtils.SOLO.clickOnView(myLocation);
|
||||
if (EndToEndTestUtils.isEmulator) {
|
||||
EndToEndTestUtils.SOLO.waitForText(
|
||||
activityMyTracks.getString(R.string.my_location_no_location), 1, 1000);
|
||||
} else {
|
||||
// TODO How to verify the location is shown on the map.
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
EndToEndTestUtils.SOLO.finishOpenedActivities();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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 com.google.android.apps.mytracks.TrackListActivity;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Instrumentation;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.view.KeyEvent;
|
||||
import android.widget.EditText;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Tests some menu items of MyTracks.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class MenuItemsTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
||||
|
||||
private Instrumentation instrumentation;
|
||||
private TrackListActivity activityMyTracks;
|
||||
|
||||
@TargetApi(8)
|
||||
public MenuItemsTest() {
|
||||
super(TrackListActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
instrumentation = getInstrumentation();
|
||||
activityMyTracks = getActivity();
|
||||
EndToEndTestUtils.setupForAllTest(instrumentation, activityMyTracks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests following items in More menu.
|
||||
* <ul>
|
||||
* <li>Tests the aggregated statistics activity.</li>
|
||||
* <li>Tests the Sensor state activity.</li>
|
||||
* <li>Tests the help menu.</li>
|
||||
* </ul>
|
||||
*/
|
||||
public void testSomeMenuItems() {
|
||||
// Menu in TrackListActivity.
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_aggregated_statistics),
|
||||
true);
|
||||
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.stats_total_distance));
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.createTrackIfEmpty(1, false);
|
||||
instrumentation.waitForIdleSync();
|
||||
// Menu in TrackDetailActivity.
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_sensor_state), true);
|
||||
EndToEndTestUtils.SOLO.waitForText(activityMyTracks
|
||||
.getString(R.string.sensor_state_last_sensor_time));
|
||||
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_help), true);
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.help_about));
|
||||
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
|
||||
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests search menu item.
|
||||
*/
|
||||
public void testSearch() {
|
||||
EndToEndTestUtils.createSimpleTrack(1);
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_search), true);
|
||||
ArrayList<EditText> editTexts = EndToEndTestUtils.SOLO.getCurrentEditTexts();
|
||||
EndToEndTestUtils.SOLO.enterText(editTexts.get(0), EndToEndTestUtils.trackName);
|
||||
sendKeys(KeyEvent.KEYCODE_ENTER);
|
||||
instrumentation.waitForIdleSync();
|
||||
assertEquals(1, EndToEndTestUtils.SOLO.getCurrentListViews().size());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
EndToEndTestUtils.SOLO.finishOpenedActivities();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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 com.google.android.apps.mytracks.TrackListActivity;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Instrumentation;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
|
||||
/**
|
||||
* Tests sending a track to SD card.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class SaveToSdCardTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
||||
|
||||
private Instrumentation instrumentation;
|
||||
private TrackListActivity activityMyTracks;
|
||||
|
||||
@TargetApi(8)
|
||||
public SaveToSdCardTest() {
|
||||
super(TrackListActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
instrumentation = getInstrumentation();
|
||||
activityMyTracks = getActivity();
|
||||
EndToEndTestUtils.setupForAllTest(instrumentation, activityMyTracks);
|
||||
EndToEndTestUtils.createTrackIfEmpty(1, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests saving a track to SD card as a GPX file.
|
||||
*/
|
||||
public void testSaveToSdCard_GPX() {
|
||||
EndToEndTestUtils.saveTrackToSdCard(EndToEndTestUtils.GPX);
|
||||
assertEquals(1, EndToEndTestUtils.getExportedFiles(EndToEndTestUtils.GPX).length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests saving a track to SD card as a KML file.
|
||||
*/
|
||||
public void testSaveToSdCard_KML() {
|
||||
EndToEndTestUtils.saveTrackToSdCard(EndToEndTestUtils.KML);
|
||||
assertEquals(1, EndToEndTestUtils.getExportedFiles(EndToEndTestUtils.KML).length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests saving a track to SD card as a CSV file.
|
||||
*/
|
||||
public void testSaveToSdCard_CSV() {
|
||||
EndToEndTestUtils.saveTrackToSdCard(EndToEndTestUtils.CSV);
|
||||
assertEquals(1, EndToEndTestUtils.getExportedFiles(EndToEndTestUtils.CSV).length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests saving a track to SD card as a TCX file.
|
||||
*/
|
||||
public void testSaveToSdCard_TCX() {
|
||||
EndToEndTestUtils.saveTrackToSdCard(EndToEndTestUtils.TCX);
|
||||
assertEquals(1, EndToEndTestUtils.getExportedFiles(EndToEndTestUtils.TCX).length);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
EndToEndTestUtils.SOLO.finishOpenedActivities();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,311 @@
|
||||
/*
|
||||
* 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 com.google.android.apps.mytracks.ChartView;
|
||||
import com.google.android.apps.mytracks.TrackListActivity;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Instrumentation;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.widget.CheckBox;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Tests the setting of MyTracks.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class SettingTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
||||
|
||||
private final String DEFAULTACTIVITY = "TestActivity";
|
||||
|
||||
private Instrumentation instrumentation;
|
||||
private TrackListActivity activityMyTracks;
|
||||
|
||||
@TargetApi(8)
|
||||
public SettingTest() {
|
||||
super(TrackListActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
instrumentation = getInstrumentation();
|
||||
activityMyTracks = getActivity();
|
||||
EndToEndTestUtils.setupForAllTest(instrumentation, activityMyTracks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes some settings and then reset them. This test case tests three
|
||||
* points:
|
||||
* <ul>
|
||||
* <li>Resets all settings.</li>
|
||||
* <li>Changes the setting of Display.</li>
|
||||
* <li>Changes the setting of Sharing.</li>
|
||||
* </ul>
|
||||
*/
|
||||
public void testChangeAndReset() {
|
||||
// Reset all settings.
|
||||
EndToEndTestUtils.resetAllSettings(activityMyTracks, true);
|
||||
// Change a setting of Map.
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_stats_tab));
|
||||
instrumentation.waitForIdleSync();
|
||||
// Rotate on a sub setting page.
|
||||
EndToEndTestUtils.rotateAllActivities();
|
||||
EndToEndTestUtils.SOLO.waitForText(activityMyTracks
|
||||
.getString(R.string.settings_stats_units_title));
|
||||
ArrayList<CheckBox> displayCheckBoxs = EndToEndTestUtils.SOLO.getCurrentCheckBoxes();
|
||||
boolean useMetric = displayCheckBoxs.get(0).isChecked();
|
||||
EndToEndTestUtils.SOLO.clickOnCheckBox(0);
|
||||
instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
// Change a setting of sharing.
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_sharing));
|
||||
assertTrue(EndToEndTestUtils.SOLO.waitForText(
|
||||
activityMyTracks.getString(R.string.settings_sharing_allow_access), 1, 5000));
|
||||
ArrayList<CheckBox> sharingCheckBoxs = EndToEndTestUtils.SOLO.getCurrentCheckBoxes();
|
||||
boolean newMapsPublic = sharingCheckBoxs.get(0).isChecked();
|
||||
EndToEndTestUtils.SOLO.clickOnCheckBox(0);
|
||||
instrumentation.waitForIdleSync();
|
||||
assertTrue(EndToEndTestUtils.SOLO.waitForText(
|
||||
activityMyTracks.getString(R.string.settings_sharing_allow_access), 1, 5000));
|
||||
assertEquals(!newMapsPublic, sharingCheckBoxs.get(0).isChecked());
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
|
||||
// Reset all settings.
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_reset));
|
||||
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
|
||||
|
||||
// Check settings.
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_stats_tab));
|
||||
EndToEndTestUtils.SOLO.waitForText(activityMyTracks
|
||||
.getString(R.string.settings_stats_units_title), 1, 20000);
|
||||
displayCheckBoxs = EndToEndTestUtils.SOLO.getCurrentCheckBoxes();
|
||||
assertEquals(useMetric, displayCheckBoxs.get(0).isChecked());
|
||||
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_sharing));
|
||||
EndToEndTestUtils.SOLO.waitForText(activityMyTracks
|
||||
.getString(R.string.settings_sharing_allow_access));
|
||||
sharingCheckBoxs = EndToEndTestUtils.SOLO.getCurrentCheckBoxes();
|
||||
assertEquals(newMapsPublic, sharingCheckBoxs.get(0).isChecked());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the change of preferred units.
|
||||
*/
|
||||
public void testChangePreferredUnits() {
|
||||
EndToEndTestUtils.createTrackIfEmpty(5, false);
|
||||
// Change it and verify it.
|
||||
ChangePreferredUnits();
|
||||
// Change it back and verify it.
|
||||
ChangePreferredUnits();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the change of stats settings during recording on chart view.
|
||||
*/
|
||||
public void testChangeStatsSettings_underRecording_chart() {
|
||||
EndToEndTestUtils.startRecording();
|
||||
// Test just change preferred units when display CHART tab.
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_chart_tab));
|
||||
EndToEndTestUtils.sendGps(3);
|
||||
ChangeStatsSettings(true, false, false, false, false);
|
||||
EndToEndTestUtils.sendGps(3);
|
||||
EndToEndTestUtils.stopRecording(true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the change of stats settings during recording on stats tab.
|
||||
*/
|
||||
public void testChangeStatsSettings_underRecording_stats() {
|
||||
EndToEndTestUtils.startRecording();
|
||||
// Test change preferred units and preferred rate when display STATS tab.
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_stats_tab));
|
||||
EndToEndTestUtils.sendGps(3);
|
||||
ChangeStatsSettings(true, true, false, false, false);
|
||||
EndToEndTestUtils.sendGps(3);
|
||||
EndToEndTestUtils.stopRecording(true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests displaying elevation, grade and latitude and longitude information in Stats tab.
|
||||
*/
|
||||
public void testChangeStatsSettings_showExtraInfos() {
|
||||
EndToEndTestUtils.createTrackIfEmpty(5, false);
|
||||
EndToEndTestUtils.resetAllSettings(activityMyTracks, true);
|
||||
ChangeStatsSettings(false, false, true, true, true);
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_stats_tab));
|
||||
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks
|
||||
.getString(R.string.stats_min_elevation)));
|
||||
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks
|
||||
.getString(R.string.stats_min_grade)));
|
||||
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks
|
||||
.getString(R.string.stats_latitude)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes settings of preferred units and preferred rate.
|
||||
*
|
||||
* @param changeUnits is change the preferred unit
|
||||
* @param changeRate is change the preferred rate
|
||||
* @param changeElevation is change the elevation
|
||||
* @param changeGrade is change the grade
|
||||
* @param changeLatLong is change the latitude and longitude
|
||||
*/
|
||||
private void ChangeStatsSettings(boolean changeUnits, boolean changeRate,
|
||||
boolean changeElevation, boolean changeGrade, boolean changeLatLong) {
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true);
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_stats_tab));
|
||||
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks
|
||||
.getString(R.string.settings_stats_units_title)));
|
||||
|
||||
// Change preferred units.
|
||||
if (changeUnits) {
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
|
||||
.getString(R.string.settings_stats_units_title));
|
||||
}
|
||||
if (changeRate) {
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
|
||||
.getString(R.string.settings_stats_rate_title));
|
||||
}
|
||||
if (changeElevation) {
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
|
||||
.getString(R.string.stats_elevation));
|
||||
}
|
||||
if (changeGrade) {
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
|
||||
.getString(R.string.settings_stats_grade));
|
||||
}
|
||||
if (changeLatLong) {
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
|
||||
.getString(R.string.settings_stats_coordinate));
|
||||
}
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes PreferredUnits and verifies the change.
|
||||
*/
|
||||
private void ChangePreferredUnits() {
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true);
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_stats_tab));
|
||||
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks
|
||||
.getString(R.string.settings_stats_units_title)));
|
||||
|
||||
boolean isImperial = EndToEndTestUtils.findTextView(activityMyTracks
|
||||
.getString(R.string.settings_stats_units_imperial), EndToEndTestUtils.SOLO
|
||||
.getCurrentListViews().get(0)) != null;
|
||||
|
||||
// Change preferred units.
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
|
||||
.getString(R.string.settings_stats_units_title));
|
||||
isImperial = !isImperial;
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_chart_tab));
|
||||
instrumentation.waitForIdleSync();
|
||||
ChartView chartView = EndToEndTestUtils.getChartView();
|
||||
assertEquals(!isImperial, chartView.isMetricUnits());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the backup.
|
||||
*/
|
||||
public void testBackup() {
|
||||
// Delete all backup at first.
|
||||
EndToEndTestUtils.deleteExportedFiles(EndToEndTestUtils.BACKUPS);
|
||||
EndToEndTestUtils.createTrackIfEmpty(3, true);
|
||||
|
||||
assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.trackName));
|
||||
|
||||
// Write to SD card.
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true);
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_backup));
|
||||
EndToEndTestUtils.SOLO
|
||||
.clickOnText(activityMyTracks.getString(R.string.settings_backup_now));
|
||||
assertTrue(EndToEndTestUtils.SOLO.waitForText(
|
||||
activityMyTracks.getString(R.string.sd_card_save_success), 0, 100000));
|
||||
instrumentation.waitForIdleSync();
|
||||
|
||||
// Delete all tracks.
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_delete_all), true);
|
||||
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
|
||||
instrumentation.waitForIdleSync();
|
||||
|
||||
// Read from SD card.
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true);
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_backup));
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
|
||||
.getString(R.string.settings_backup_restore));
|
||||
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
|
||||
assertTrue(EndToEndTestUtils.SOLO.waitForText(
|
||||
activityMyTracks.getString(R.string.sd_card_import_success), 0, 10000));
|
||||
// Check restore track.
|
||||
assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.trackName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the setting of recording. This test changes the default name and
|
||||
* activity of tracks, and the creates a new track to check it.
|
||||
*/
|
||||
public void testRecording() {
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true);
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_recording));
|
||||
// Changes the setting of recording name.
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
|
||||
.getString(R.string.settings_recording_track_name));
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
|
||||
.getString(R.string.settings_recording_track_name_number_option));
|
||||
// Changes the setting of default activity.
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
|
||||
.getString(R.string.settings_recording_default_activity));
|
||||
EndToEndTestUtils.SOLO.enterText(0, DEFAULTACTIVITY);
|
||||
if(!EndToEndTestUtils.isEmulator) {
|
||||
// Close soft keyboard.
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
}
|
||||
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
|
||||
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
|
||||
EndToEndTestUtils.startRecording();
|
||||
instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.stopRecording(false);
|
||||
instrumentation.waitForIdleSync();
|
||||
assertTrue(EndToEndTestUtils.SOLO.searchText(activityMyTracks.getString(
|
||||
R.string.track_name_format).split(" ")[0]));
|
||||
assertTrue(EndToEndTestUtils.SOLO.searchText(DEFAULTACTIVITY));
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.generic_save));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
EndToEndTestUtils.SOLO.finishOpenedActivities();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* 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 com.google.android.apps.mytracks.TrackListActivity;
|
||||
import com.google.android.apps.mytracks.fragments.MapFragment;
|
||||
import com.google.android.maps.MapView;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Instrumentation;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Tests switching views and the menu list of each view.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class ViewsTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
||||
|
||||
private Instrumentation instrumentation;
|
||||
private TrackListActivity activityMyTracks;
|
||||
|
||||
@TargetApi(8)
|
||||
public ViewsTest() {
|
||||
super(TrackListActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
instrumentation = getInstrumentation();
|
||||
activityMyTracks = getActivity();
|
||||
EndToEndTestUtils.setupForAllTest(instrumentation, activityMyTracks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Switches view from {@link MapFragment} to @ ChartFragment} , then changes
|
||||
* to @ StatsFragment} . Finally back to {@link MapFragment}. And check some
|
||||
* menus in these views.
|
||||
*/
|
||||
public void testSwitchViewsAndMenusOfView() {
|
||||
EndToEndTestUtils.createTrackIfEmpty(3, false);
|
||||
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.trackName);
|
||||
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_chart_tab));
|
||||
EndToEndTestUtils.rotateAllActivities();
|
||||
|
||||
EndToEndTestUtils.showMoreMenuItem();
|
||||
assertTrue(EndToEndTestUtils.SOLO.waitForText(
|
||||
activityMyTracks.getString(R.string.menu_settings), 1, 3000));
|
||||
assertFalse(EndToEndTestUtils.SOLO.waitForText(
|
||||
activityMyTracks.getString(R.string.menu_satellite_mode), 1, 0));
|
||||
assertFalse(EndToEndTestUtils.SOLO.waitForText(
|
||||
activityMyTracks.getString(R.string.menu_map_mode), 1, 0));
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_stats_tab));
|
||||
EndToEndTestUtils.SOLO.sendKey(KeyEvent.KEYCODE_MENU);
|
||||
assertTrue(EndToEndTestUtils.SOLO.waitForText(
|
||||
activityMyTracks.getString(R.string.menu_settings), 1, 3000));
|
||||
assertFalse(EndToEndTestUtils.SOLO.waitForText(
|
||||
activityMyTracks.getString(R.string.menu_satellite_mode), 1, 0));
|
||||
assertFalse(EndToEndTestUtils.SOLO.waitForText(
|
||||
activityMyTracks.getString(R.string.menu_map_mode), 1, 0));
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_map_tab));
|
||||
EndToEndTestUtils.showMoreMenuItem();
|
||||
assertTrue(EndToEndTestUtils.SOLO.waitForText(
|
||||
activityMyTracks.getString(R.string.menu_settings), 1, 3000));
|
||||
assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.VIEW_MODE, 1, true, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the switch between satellite mode and map mode.
|
||||
*/
|
||||
public void testSatelliteAndMapView() {
|
||||
instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.createTrackIfEmpty(1, false);
|
||||
instrumentation.waitForIdleSync();
|
||||
// Check current mode.
|
||||
boolean isMapMode = true;
|
||||
// If can not find switch menu in top menu, click More menu.
|
||||
if (!EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_satellite_mode),
|
||||
false)) {
|
||||
isMapMode = false;
|
||||
}
|
||||
EndToEndTestUtils.showMoreMenuItem();
|
||||
// Switch to satellite mode if it's map mode now..
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
|
||||
.getString(isMapMode ? R.string.menu_satellite_mode : R.string.menu_map_mode));
|
||||
|
||||
isMapMode = !isMapMode;
|
||||
|
||||
ArrayList<View> allViews = EndToEndTestUtils.SOLO.getViews();
|
||||
for (View view : allViews) {
|
||||
if (view instanceof MapView) {
|
||||
assertEquals(isMapMode, !((MapView) view).isSatellite());
|
||||
}
|
||||
}
|
||||
instrumentation.waitForIdleSync();
|
||||
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_help), false);
|
||||
instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.rotateAllActivities();
|
||||
|
||||
// Switch back.
|
||||
EndToEndTestUtils.showMoreMenuItem();
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
|
||||
.getString(isMapMode ? R.string.menu_satellite_mode : R.string.menu_map_mode));
|
||||
isMapMode = !isMapMode;
|
||||
allViews = EndToEndTestUtils.SOLO.getViews();
|
||||
for (View view : allViews) {
|
||||
if (view instanceof MapView) {
|
||||
assertEquals(isMapMode, !((MapView) view).isSatellite());
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for the TrackDetailActivity, or the stop button will can not be
|
||||
// found in next step.
|
||||
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.track_detail_chart_tab),
|
||||
0, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
EndToEndTestUtils.SOLO.finishOpenedActivities();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user