forked from upstream-mirrors/OpenTracks
Changes smoke test to end-to-end test cases.
This commit is contained in:
+183
@@ -0,0 +1,183 @@
|
|||||||
|
/*
|
||||||
|
* 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.app.Instrumentation;
|
||||||
|
import android.test.ActivityInstrumentationTestCase2;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
import android.widget.CheckBox;
|
||||||
|
|
||||||
|
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 static final String STATISTICS_NAME = "testStatistics";
|
||||||
|
private Instrumentation instrumentation;
|
||||||
|
private TrackListActivity activityMyTracks;
|
||||||
|
|
||||||
|
public CreateAndSendTrackTest() {
|
||||||
|
super(TrackListActivity.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
instrumentation = getInstrumentation();
|
||||||
|
activityMyTracks = getActivity();
|
||||||
|
EndToEndTestUtils.setupForAllTest(instrumentation, activityMyTracks);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a track with markers and the setting to send to google.
|
||||||
|
*/
|
||||||
|
public void testCreateAndSendTrack() {
|
||||||
|
// Create a track at first.
|
||||||
|
EndToEndTestUtils.createSimpleTrack(1);
|
||||||
|
instrumentation.waitForIdleSync();
|
||||||
|
sendKeys(KeyEvent.KEYCODE_MENU);
|
||||||
|
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_send_google), true, false);
|
||||||
|
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.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests editing a track.
|
||||||
|
*/
|
||||||
|
public void testEditTrack() {
|
||||||
|
EndToEndTestUtils.createSimpleTrack(0);
|
||||||
|
instrumentation.waitForIdleSync();
|
||||||
|
sendKeys(KeyEvent.KEYCODE_MENU);
|
||||||
|
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_edit), true, false);
|
||||||
|
|
||||||
|
String newTrackName = EndToEndTestUtils.TRACK_NAME_PREFIX + "_new" + System.currentTimeMillis();
|
||||||
|
String newType = "type" + newTrackName;
|
||||||
|
String newDesc = "desc" + newTrackName;
|
||||||
|
|
||||||
|
instrumentation.waitForIdleSync();
|
||||||
|
EndToEndTestUtils.rotateAllActivities();
|
||||||
|
sendKeys(KeyEvent.KEYCODE_DEL);
|
||||||
|
EndToEndTestUtils.SOLO.enterText(0, newTrackName);
|
||||||
|
sendKeys(KeyEvent.KEYCODE_TAB);
|
||||||
|
EndToEndTestUtils.SOLO.enterText(1, newType);
|
||||||
|
sendKeys(KeyEvent.KEYCODE_TAB);
|
||||||
|
EndToEndTestUtils.SOLO.enterText(2, newDesc);
|
||||||
|
|
||||||
|
EndToEndTestUtils.SOLO.clickOnButton(activityMyTracks.getString(R.string.generic_save));
|
||||||
|
instrumentation.waitForIdleSync();
|
||||||
|
// Go back to track list.
|
||||||
|
EndToEndTestUtils.SOLO.goBack();
|
||||||
|
|
||||||
|
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.SOLO.sendKey(KeyEvent.KEYCODE_MENU);
|
||||||
|
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_delete_all), true, false);
|
||||||
|
EndToEndTestUtils.SOLO.clickOnButton(activityMyTracks.getString(R.string.generic_ok));
|
||||||
|
instrumentation.waitForIdleSync();
|
||||||
|
|
||||||
|
EndToEndTestUtils.startRecording();
|
||||||
|
instrumentation.waitForIdleSync();
|
||||||
|
EndToEndTestUtils.sendGps(2);
|
||||||
|
createWaypointAndStatistics();
|
||||||
|
EndToEndTestUtils.sendGps(2);
|
||||||
|
// Back to tracks list.
|
||||||
|
EndToEndTestUtils.SOLO.goBack();
|
||||||
|
instrumentation.waitForIdleSync();
|
||||||
|
EndToEndTestUtils.rotateAllActivities();
|
||||||
|
EndToEndTestUtils.stopRecording(false);
|
||||||
|
EndToEndTestUtils.TRACK_NAME = EndToEndTestUtils.TRACK_NAME_PREFIX + System.currentTimeMillis();
|
||||||
|
EndToEndTestUtils.SOLO.enterText(0, EndToEndTestUtils.TRACK_NAME);
|
||||||
|
EndToEndTestUtils.SOLO.clickOnButton(activityMyTracks.getString(R.string.generic_save));
|
||||||
|
|
||||||
|
instrumentation.waitForIdleSync();
|
||||||
|
// Check the new track
|
||||||
|
assertTrue(EndToEndTestUtils.SOLO.waitForText(EndToEndTestUtils.TRACK_NAME, 1, 5000, true, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a way point and a statistics during track recording.
|
||||||
|
*/
|
||||||
|
private void createWaypointAndStatistics() {
|
||||||
|
sendKeys(KeyEvent.KEYCODE_MENU);
|
||||||
|
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_markers), true, false);
|
||||||
|
|
||||||
|
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.marker_list_empty_message)));
|
||||||
|
|
||||||
|
sendKeys(KeyEvent.KEYCODE_MENU);
|
||||||
|
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_insert_marker), true, true);
|
||||||
|
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.marker_edit_type_waypoint));
|
||||||
|
EndToEndTestUtils.rotateAllActivities();
|
||||||
|
EndToEndTestUtils.SOLO.enterText(0, WAYPOINT_NAME);
|
||||||
|
EndToEndTestUtils.SOLO.clickOnButton(activityMyTracks.getString(R.string.marker_edit_add));
|
||||||
|
assertTrue(EndToEndTestUtils.SOLO.searchText(WAYPOINT_NAME));
|
||||||
|
|
||||||
|
sendKeys(KeyEvent.KEYCODE_MENU);
|
||||||
|
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_insert_marker), true, true);
|
||||||
|
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.marker_edit_type_statistics));
|
||||||
|
EndToEndTestUtils.rotateAllActivities();
|
||||||
|
EndToEndTestUtils.SOLO.enterText(0, STATISTICS_NAME);
|
||||||
|
EndToEndTestUtils.SOLO.clickOnButton(activityMyTracks.getString(R.string.marker_edit_add));
|
||||||
|
instrumentation.waitForIdleSync();
|
||||||
|
assertTrue(EndToEndTestUtils.SOLO.searchText(STATISTICS_NAME));
|
||||||
|
|
||||||
|
EndToEndTestUtils.SOLO.goBack();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void tearDown() throws Exception {
|
||||||
|
EndToEndTestUtils.SOLO.finishOpenedActivities();
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* 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.app.Instrumentation;
|
||||||
|
import android.test.ActivityInstrumentationTestCase2;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
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;
|
||||||
|
|
||||||
|
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.createSimpleTrack(0);
|
||||||
|
EndToEndTestUtils.SOLO.goBack();
|
||||||
|
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.SOLO.sendKey(KeyEvent.KEYCODE_MENU);
|
||||||
|
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_delete_all), true,
|
||||||
|
false);
|
||||||
|
instrumentation.waitForIdleSync();
|
||||||
|
EndToEndTestUtils.rotateAllActivities();
|
||||||
|
EndToEndTestUtils.SOLO.clickOnButton(activityMyTracks.getString(R.string.generic_ok));
|
||||||
|
instrumentation.waitForIdleSync();
|
||||||
|
// There is no track now.
|
||||||
|
trackListView = EndToEndTestUtils.SOLO.getCurrentListViews();
|
||||||
|
assertEquals(0, trackListView.get(0).getCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes only one track.
|
||||||
|
*/
|
||||||
|
public void testDeleteSingleTrack() {
|
||||||
|
EndToEndTestUtils.createSimpleTrack(0);
|
||||||
|
EndToEndTestUtils.SOLO.goBack();
|
||||||
|
// Get the number of track( or tracks)
|
||||||
|
ArrayList<ListView> trackListView = EndToEndTestUtils.SOLO.getCurrentListViews();
|
||||||
|
int trackNumberOld = trackListView.get(0).getCount();
|
||||||
|
|
||||||
|
EndToEndTestUtils.SOLO.clickLongOnText(EndToEndTestUtils.TRACK_NAME);
|
||||||
|
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_delete), true, true);
|
||||||
|
EndToEndTestUtils.SOLO.clickLongOnText(activityMyTracks.getString(R.string.generic_ok));
|
||||||
|
instrumentation.waitForIdleSync();
|
||||||
|
trackListView = EndToEndTestUtils.SOLO.getCurrentListViews();
|
||||||
|
int trackNumberNew = trackListView.get(0).getCount();
|
||||||
|
assertEquals(trackNumberOld - 1, trackNumberNew);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void tearDown() throws Exception {
|
||||||
|
EndToEndTestUtils.SOLO.finishOpenedActivities();
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+362
@@ -0,0 +1,362 @@
|
|||||||
|
/*
|
||||||
|
* 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 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.widget.Button;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
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 MENU_MORE = "More";
|
||||||
|
static String TRACK_NAME;
|
||||||
|
|
||||||
|
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 HAS_ACTIONBAR = false;
|
||||||
|
static boolean CHECKED_FIRSTLAUNCH = false;
|
||||||
|
|
||||||
|
private EndToEndTestUtils() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends Gps data to emulator.
|
||||||
|
*
|
||||||
|
* @param number send times
|
||||||
|
*/
|
||||||
|
public static void sendGps(int number) {
|
||||||
|
if (number < 1) { 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
||||||
|
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.CHECKED_FIRSTLAUNCH) {
|
||||||
|
if ((EndToEndTestUtils.getButtonOnScreen(EndToEndTestUtils.ACTIVITYMYTRACKS
|
||||||
|
.getString(R.string.eula_accept)) != null)) {
|
||||||
|
EndToEndTestUtils.verifyFirstLaunch();
|
||||||
|
}
|
||||||
|
|
||||||
|
EndToEndTestUtils.CHECKED_FIRSTLAUNCH = true;
|
||||||
|
EndToEndTestUtils.setHasActionBar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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() {
|
||||||
|
SOLO.clickOnText(ACTIVITYMYTRACKS.getString(R.string.eula_accept));
|
||||||
|
// Click for welcome.
|
||||||
|
SOLO.clickOnText(ACTIVITYMYTRACKS.getString(R.string.generic_ok));
|
||||||
|
// Click for choose units.
|
||||||
|
SOLO.clickOnText(ACTIVITYMYTRACKS.getString(R.string.generic_ok));
|
||||||
|
INSTRUMENTATION.waitForIdleSync();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a simple track which can be used by subsequent test.
|
||||||
|
*
|
||||||
|
* @param numberOfGpsData number of simulated Gps data
|
||||||
|
*/
|
||||||
|
static void createSimpleTrack(int numberOfGpsData) {
|
||||||
|
startRecording();
|
||||||
|
EndToEndTestUtils.sendGps(numberOfGpsData);
|
||||||
|
stopRecording(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts recoding track.
|
||||||
|
*/
|
||||||
|
static void startRecording() {
|
||||||
|
if (HAS_ACTIONBAR) {
|
||||||
|
Button startButton = getButtonOnScreen(ACTIVITYMYTRACKS.getString(R.string.menu_record_track));
|
||||||
|
// In case a track is recording.
|
||||||
|
if (startButton == null) {
|
||||||
|
stopRecording(true);
|
||||||
|
startButton = getButtonOnScreen(ACTIVITYMYTRACKS.getString(R.string.menu_record_track));
|
||||||
|
}
|
||||||
|
SOLO.clickOnView(startButton);
|
||||||
|
} else {
|
||||||
|
SOLO.sendKey(KeyEvent.KEYCODE_MENU);
|
||||||
|
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);
|
||||||
|
SOLO.sendKey(KeyEvent.KEYCODE_MENU);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
INSTRUMENTATION.waitForIdleSync();
|
||||||
|
SOLO.clickOnText(ACTIVITYMYTRACKS.getString(R.string.menu_record_track));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops recoding track.
|
||||||
|
*
|
||||||
|
* @param isSave ture means should save this track
|
||||||
|
*/
|
||||||
|
static void stopRecording(boolean isSave) {
|
||||||
|
INSTRUMENTATION.waitForIdleSync();
|
||||||
|
if (HAS_ACTIONBAR) {
|
||||||
|
SOLO.clickOnView(getButtonOnScreen(ACTIVITYMYTRACKS.getString(R.string.menu_stop_recording)));
|
||||||
|
} else {
|
||||||
|
SOLO.sendKey(KeyEvent.KEYCODE_MENU);
|
||||||
|
INSTRUMENTATION.waitForIdleSync();
|
||||||
|
SOLO.clickOnText(ACTIVITYMYTRACKS.getString(R.string.menu_stop_recording));
|
||||||
|
}
|
||||||
|
if (isSave) {
|
||||||
|
INSTRUMENTATION.waitForIdleSync();
|
||||||
|
// Make every track name is unique to make sure every check can be
|
||||||
|
// trusted.
|
||||||
|
EndToEndTestUtils.TRACK_NAME = EndToEndTestUtils.TRACK_NAME_PREFIX
|
||||||
|
+ System.currentTimeMillis();
|
||||||
|
SOLO.enterText(0, TRACK_NAME);
|
||||||
|
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();
|
||||||
|
SOLO.sendKey(KeyEvent.KEYCODE_MENU);
|
||||||
|
INSTRUMENTATION.waitForIdleSync();
|
||||||
|
SOLO.clickOnText(ACTIVITYMYTRACKS.getString(R.string.menu_save));
|
||||||
|
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
|
||||||
|
* @return the button to search, and null means can not find the button
|
||||||
|
*/
|
||||||
|
static Button getButtonOnScreen(String buttonName) {
|
||||||
|
ArrayList<Button> currentButtons = SOLO.getCurrentButtons();
|
||||||
|
for (Button button : currentButtons) {
|
||||||
|
String title = (String) button.getText();
|
||||||
|
if (title.equalsIgnoreCase(buttonName)) { return button; }
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether an action bar is shown.
|
||||||
|
*
|
||||||
|
* @return false means can not check failed.
|
||||||
|
*/
|
||||||
|
static boolean setHasActionBar() {
|
||||||
|
// If can find record button without pressing Menu, it should be an action
|
||||||
|
// bar.
|
||||||
|
Button startButton = getButtonOnScreen(ACTIVITYMYTRACKS.getString(R.string.menu_record_track));
|
||||||
|
Button stopButton = getButtonOnScreen(ACTIVITYMYTRACKS.getString(R.string.menu_stop_recording));
|
||||||
|
if (startButton != null || stopButton != null) {
|
||||||
|
HAS_ACTIONBAR = true;
|
||||||
|
} else {
|
||||||
|
SOLO.sendKey(KeyEvent.KEYCODE_MENU);
|
||||||
|
if (SOLO.searchText(ACTIVITYMYTRACKS.getString(R.string.menu_record_track))
|
||||||
|
|| SOLO.searchText(ACTIVITYMYTRACKS.getString(R.string.menu_stop_recording))) {
|
||||||
|
HAS_ACTIONBAR = 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
|
||||||
|
* @param checkActionBar whether this item may on the action bar
|
||||||
|
* @return true if find this menu
|
||||||
|
*/
|
||||||
|
static boolean findMenuItem(String menuName, boolean click, boolean checkActionBar) {
|
||||||
|
boolean findResult = false;
|
||||||
|
|
||||||
|
// Firstly find in action bar.
|
||||||
|
if (checkActionBar) {
|
||||||
|
Button button = getButtonOnScreen(menuName);
|
||||||
|
if (button != null) {
|
||||||
|
findResult = true;
|
||||||
|
if (click) {
|
||||||
|
SOLO.clickOnView(button);
|
||||||
|
}
|
||||||
|
return findResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
return findResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
+144
@@ -0,0 +1,144 @@
|
|||||||
|
/*
|
||||||
|
* 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.app.Instrumentation;
|
||||||
|
import android.test.ActivityInstrumentationTestCase2;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
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.createSimpleTrack(3);
|
||||||
|
EndToEndTestUtils.SOLO.goBack();
|
||||||
|
instrumentation.waitForIdleSync();
|
||||||
|
// Create a empty track.
|
||||||
|
EndToEndTestUtils.createSimpleTrack(0);
|
||||||
|
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.
|
||||||
|
sendKeys(KeyEvent.KEYCODE_MENU);
|
||||||
|
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_import_all), true,
|
||||||
|
false);
|
||||||
|
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.import_no_file,
|
||||||
|
FileUtils.buildExternalDirectoryPath(EndToEndTestUtils.GPX)));
|
||||||
|
EndToEndTestUtils.SOLO.clickOnButton(activityMyTracks.getString(R.string.generic_ok));
|
||||||
|
|
||||||
|
// Click to export tracks(At least one track) to Gpx files.
|
||||||
|
sendKeys(KeyEvent.KEYCODE_MENU);
|
||||||
|
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_export_all), true,
|
||||||
|
false);
|
||||||
|
EndToEndTestUtils.SOLO.clickOnText(String.format(
|
||||||
|
activityMyTracks.getString(R.string.menu_export_all_format),
|
||||||
|
EndToEndTestUtils.GPX.toUpperCase()));
|
||||||
|
EndToEndTestUtils.rotateAllActivities();
|
||||||
|
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.export_success));
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
sendKeys(KeyEvent.KEYCODE_MENU);
|
||||||
|
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_import_all), true,
|
||||||
|
false);
|
||||||
|
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.import_success).split(
|
||||||
|
"%")[0]);
|
||||||
|
// Check import tracks should be equal with the sum of trackNumber and
|
||||||
|
// gpxFilesNumber;
|
||||||
|
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.generic_ok));
|
||||||
|
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();
|
||||||
|
sendKeys(KeyEvent.KEYCODE_MENU);
|
||||||
|
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_export_all), true,
|
||||||
|
false);
|
||||||
|
EndToEndTestUtils.SOLO.clickOnText(String.format(
|
||||||
|
activityMyTracks.getString(R.string.menu_export_all_format),
|
||||||
|
EndToEndTestUtils.KML.toUpperCase()));
|
||||||
|
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.export_success));
|
||||||
|
// 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+64
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* 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.app.Instrumentation;
|
||||||
|
import android.test.ActivityInstrumentationTestCase2;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the function of go to my location.
|
||||||
|
*
|
||||||
|
* @author Youtao Liu
|
||||||
|
*/
|
||||||
|
public class GoToMyLocationTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
||||||
|
|
||||||
|
private Instrumentation instrumentation;
|
||||||
|
private TrackListActivity activityMyTracks;
|
||||||
|
|
||||||
|
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.createSimpleTrack(0);
|
||||||
|
EndToEndTestUtils.SOLO.sendKey(KeyEvent.KEYCODE_MENU);
|
||||||
|
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_my_location), true,
|
||||||
|
false);
|
||||||
|
// 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,88 @@
|
|||||||
|
/*
|
||||||
|
* 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.app.Instrumentation;
|
||||||
|
import android.test.ActivityInstrumentationTestCase2;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests some menu items of MyTracks.
|
||||||
|
*
|
||||||
|
* @author Youtao Liu
|
||||||
|
*/
|
||||||
|
public class MenuItemsTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
||||||
|
|
||||||
|
private Instrumentation instrumentation;
|
||||||
|
private TrackListActivity activityMyTracks;
|
||||||
|
|
||||||
|
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.
|
||||||
|
sendKeys(KeyEvent.KEYCODE_MENU);
|
||||||
|
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_aggregated_statistics),
|
||||||
|
true, false);
|
||||||
|
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.stat_total_distance));
|
||||||
|
EndToEndTestUtils.SOLO.goBack();
|
||||||
|
|
||||||
|
EndToEndTestUtils.startRecording();
|
||||||
|
instrumentation.waitForIdleSync();
|
||||||
|
// Menu in TrackDetailActivity.
|
||||||
|
sendKeys(KeyEvent.KEYCODE_MENU);
|
||||||
|
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_sensor_state), true,
|
||||||
|
false);
|
||||||
|
EndToEndTestUtils.SOLO.waitForText(activityMyTracks
|
||||||
|
.getString(R.string.sensor_state_last_sensor_time));
|
||||||
|
|
||||||
|
EndToEndTestUtils.SOLO.goBack();
|
||||||
|
sendKeys(KeyEvent.KEYCODE_MENU);
|
||||||
|
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_help), true, false);
|
||||||
|
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.help_about));
|
||||||
|
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.generic_ok));
|
||||||
|
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.generic_ok));
|
||||||
|
|
||||||
|
EndToEndTestUtils.stopRecording(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void tearDown() throws Exception {
|
||||||
|
EndToEndTestUtils.SOLO.finishOpenedActivities();
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* 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.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;
|
||||||
|
private static boolean isCreateTrack = true;
|
||||||
|
|
||||||
|
public SaveToSdCardTest() {
|
||||||
|
super(TrackListActivity.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
instrumentation = getInstrumentation();
|
||||||
|
activityMyTracks = getActivity();
|
||||||
|
EndToEndTestUtils.setupForAllTest(instrumentation, activityMyTracks);
|
||||||
|
if (isCreateTrack) {
|
||||||
|
EndToEndTestUtils.createSimpleTrack(0);
|
||||||
|
// Only create one track for this test.
|
||||||
|
isCreateTrack = false;
|
||||||
|
} else {
|
||||||
|
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.TRACK_NAME);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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,115 @@
|
|||||||
|
/*
|
||||||
|
* 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.app.Instrumentation;
|
||||||
|
import android.test.ActivityInstrumentationTestCase2;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
import android.widget.CheckBox;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the setting of MyTracks.
|
||||||
|
*
|
||||||
|
* @author Youtao Liu
|
||||||
|
*/
|
||||||
|
public class SettingTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
||||||
|
|
||||||
|
private Instrumentation instrumentation;
|
||||||
|
private TrackListActivity activityMyTracks;
|
||||||
|
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
public void testSetting() {
|
||||||
|
sendKeys(KeyEvent.KEYCODE_MENU);
|
||||||
|
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true, false);
|
||||||
|
instrumentation.waitForIdleSync();
|
||||||
|
// Rotate on the settings page.
|
||||||
|
EndToEndTestUtils.rotateAllActivities();
|
||||||
|
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.settings_reset));
|
||||||
|
// Reset all settings at first.
|
||||||
|
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_reset));
|
||||||
|
EndToEndTestUtils.SOLO.clickOnButton(activityMyTracks.getString(R.string.generic_ok));
|
||||||
|
// Change a setting of display.
|
||||||
|
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_display));
|
||||||
|
EndToEndTestUtils.SOLO
|
||||||
|
.waitForText(activityMyTracks.getString(R.string.settings_display_metric));
|
||||||
|
// Rotate on a sub setting page.
|
||||||
|
EndToEndTestUtils.rotateAllActivities();
|
||||||
|
EndToEndTestUtils.SOLO
|
||||||
|
.waitForText(activityMyTracks.getString(R.string.settings_display_metric));
|
||||||
|
ArrayList<CheckBox> displayCheckBoxs = EndToEndTestUtils.SOLO.getCurrentCheckBoxes();
|
||||||
|
boolean useMetric = displayCheckBoxs.get(0).isChecked();
|
||||||
|
EndToEndTestUtils.SOLO.clickOnCheckBox(0);
|
||||||
|
EndToEndTestUtils.SOLO.goBack();
|
||||||
|
// Change a setting of sharing.
|
||||||
|
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_sharing));
|
||||||
|
EndToEndTestUtils.SOLO.waitForText(activityMyTracks
|
||||||
|
.getString(R.string.settings_sharing_allow_access));
|
||||||
|
ArrayList<CheckBox> sharingCheckBoxs = EndToEndTestUtils.SOLO.getCurrentCheckBoxes();
|
||||||
|
boolean newMapsPublic = sharingCheckBoxs.get(0).isChecked();
|
||||||
|
EndToEndTestUtils.SOLO.clickOnCheckBox(0);
|
||||||
|
// Rotate on a sub setting page when the value of a checkbox is changed.
|
||||||
|
instrumentation.waitForIdleSync();
|
||||||
|
EndToEndTestUtils.rotateAllActivities();
|
||||||
|
EndToEndTestUtils.SOLO.waitForText(activityMyTracks
|
||||||
|
.getString(R.string.settings_sharing_allow_access));
|
||||||
|
assertEquals(!newMapsPublic, sharingCheckBoxs.get(0).isChecked());
|
||||||
|
EndToEndTestUtils.SOLO.goBack();
|
||||||
|
|
||||||
|
// Reset all settings.
|
||||||
|
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_reset));
|
||||||
|
EndToEndTestUtils.SOLO.clickOnButton(activityMyTracks.getString(R.string.generic_ok));
|
||||||
|
|
||||||
|
// Check settings.
|
||||||
|
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_display));
|
||||||
|
EndToEndTestUtils.SOLO
|
||||||
|
.waitForText(activityMyTracks.getString(R.string.settings_display_metric));
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
@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.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;
|
||||||
|
|
||||||
|
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.SOLO.sendKey(KeyEvent.KEYCODE_MENU);
|
||||||
|
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_delete_all), true,
|
||||||
|
false);
|
||||||
|
EndToEndTestUtils.SOLO.clickOnButton(activityMyTracks.getString(R.string.generic_ok));
|
||||||
|
instrumentation.waitForIdleSync();
|
||||||
|
|
||||||
|
EndToEndTestUtils.createSimpleTrack(3);
|
||||||
|
|
||||||
|
EndToEndTestUtils.SOLO.goBack();
|
||||||
|
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.TRACK_NAME);
|
||||||
|
|
||||||
|
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_chart_tab));
|
||||||
|
EndToEndTestUtils.rotateAllActivities();
|
||||||
|
sendKeys(KeyEvent.KEYCODE_MENU);
|
||||||
|
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_chart_settings), true,
|
||||||
|
false);
|
||||||
|
assertTrue(EndToEndTestUtils.SOLO.searchText(activityMyTracks
|
||||||
|
.getString(R.string.chart_settings_by_distance)));
|
||||||
|
EndToEndTestUtils.SOLO.goBack();
|
||||||
|
|
||||||
|
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_stats_tab));
|
||||||
|
sendKeys(KeyEvent.KEYCODE_MENU);
|
||||||
|
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_satellite_mode), false,
|
||||||
|
false);
|
||||||
|
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_sensor_state), true,
|
||||||
|
false);
|
||||||
|
assertTrue(EndToEndTestUtils.SOLO.searchText(activityMyTracks
|
||||||
|
.getString(R.string.sensor_state_last_sensor_time)));
|
||||||
|
EndToEndTestUtils.SOLO.goBack();
|
||||||
|
|
||||||
|
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_map_tab));
|
||||||
|
sendKeys(KeyEvent.KEYCODE_MENU);
|
||||||
|
assertTrue(EndToEndTestUtils.findMenuItem(
|
||||||
|
activityMyTracks.getString(R.string.menu_my_location), false, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the switch between satellite mode and map mode.
|
||||||
|
*/
|
||||||
|
public void testSatelliteAndMapView() {
|
||||||
|
EndToEndTestUtils.startRecording();
|
||||||
|
instrumentation.waitForIdleSync();
|
||||||
|
// Check current mode.
|
||||||
|
boolean isMapMode = true;
|
||||||
|
sendKeys(KeyEvent.KEYCODE_MENU);
|
||||||
|
// If can not find switch menu in top menu, click More menu.
|
||||||
|
if (!EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_satellite_mode),
|
||||||
|
false, false)) {
|
||||||
|
isMapMode = false;
|
||||||
|
}
|
||||||
|
// 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.SOLO.sendKey(KeyEvent.KEYCODE_MENU);
|
||||||
|
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_help), false, false);
|
||||||
|
instrumentation.waitForIdleSync();
|
||||||
|
EndToEndTestUtils.rotateAllActivities();
|
||||||
|
|
||||||
|
// Switch back.
|
||||||
|
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);
|
||||||
|
EndToEndTestUtils.stopRecording(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void tearDown() throws Exception {
|
||||||
|
EndToEndTestUtils.SOLO.finishOpenedActivities();
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,715 +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.smoketest;
|
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.TrackListActivity;
|
|
||||||
import com.google.android.apps.mytracks.fragments.MapFragment;
|
|
||||||
import com.google.android.apps.mytracks.util.FileUtils;
|
|
||||||
import com.google.android.maps.MapView;
|
|
||||||
import com.google.android.maps.mytracks.R;
|
|
||||||
import com.jayway.android.robotium.solo.Solo;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.Instrumentation;
|
|
||||||
import android.test.ActivityInstrumentationTestCase2;
|
|
||||||
import android.view.KeyEvent;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.CheckBox;
|
|
||||||
import android.widget.ListView;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileFilter;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Makes a smoke test of MyTracks. It's a total end-to-end test.
|
|
||||||
*
|
|
||||||
* @author Youtao Liu
|
|
||||||
*/
|
|
||||||
public class MyTracksSmokeTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
|
||||||
|
|
||||||
private static final String TRACK_NAME_PREFIX = "testTrackName";
|
|
||||||
private static final String WAYPOINT_NAME = "testWaypoint";
|
|
||||||
private static final String STATISTICS_NAME = "testStatistics";
|
|
||||||
private static final String GPX = "gpx";
|
|
||||||
private static final String KML = "kml";
|
|
||||||
private static final String CSV = "csv";
|
|
||||||
private static final String TCX = "tcx";
|
|
||||||
private static final String MENU_MORE = "More";
|
|
||||||
|
|
||||||
private Instrumentation instrumentation;
|
|
||||||
private TrackListActivity activityMyTracks;
|
|
||||||
private Solo solo;
|
|
||||||
private boolean checkedFirstLaunch = false;
|
|
||||||
// Check whether the UI has an action bar which is related with the version of
|
|
||||||
// Android OS.
|
|
||||||
private boolean hasActionBar = false;
|
|
||||||
private String trackName;
|
|
||||||
|
|
||||||
public MyTracksSmokeTest() {
|
|
||||||
super(TrackListActivity.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
instrumentation = getInstrumentation();
|
|
||||||
activityMyTracks = getActivity();
|
|
||||||
solo = new Solo(instrumentation, 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 (!checkedFirstLaunch) {
|
|
||||||
if ((getButtonOnScreen(activityMyTracks.getString(R.string.eula_accept)) != null)) {
|
|
||||||
verifyFirstLaunch();
|
|
||||||
}
|
|
||||||
setHasActionBar();
|
|
||||||
checkedFirstLaunch = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make every track name is unique to make sure every check can be trusted.
|
|
||||||
trackName = TRACK_NAME_PREFIX + System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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() {
|
|
||||||
solo.sendKey(KeyEvent.KEYCODE_MENU);
|
|
||||||
findMenuItem(activityMyTracks.getString(R.string.menu_delete_all), true);
|
|
||||||
solo.clickOnButton(activityMyTracks.getString(R.string.generic_ok));
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
|
|
||||||
createSimpleTrack(3);
|
|
||||||
|
|
||||||
solo.goBack();
|
|
||||||
solo.clickOnText(trackName);
|
|
||||||
|
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.track_detail_chart_tab));
|
|
||||||
rotateAllActivities();
|
|
||||||
sendKeys(KeyEvent.KEYCODE_MENU);
|
|
||||||
findMenuItem(activityMyTracks.getString(R.string.menu_chart_settings), true);
|
|
||||||
assertTrue(solo.searchText(activityMyTracks.getString(R.string.chart_settings_by_distance)));
|
|
||||||
solo.goBack();
|
|
||||||
|
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.track_detail_stats_tab));
|
|
||||||
sendKeys(KeyEvent.KEYCODE_MENU);
|
|
||||||
findMenuItem(activityMyTracks.getString(R.string.menu_satellite_mode), false);
|
|
||||||
findMenuItem(activityMyTracks.getString(R.string.menu_sensor_state), true);
|
|
||||||
assertTrue(solo.searchText(activityMyTracks.getString(R.string.sensor_state_last_sensor_time)));
|
|
||||||
solo.goBack();
|
|
||||||
|
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.track_detail_map_tab));
|
|
||||||
sendKeys(KeyEvent.KEYCODE_MENU);
|
|
||||||
assertTrue(findMenuItem(activityMyTracks.getString(R.string.menu_my_location), false));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a track with markers and the setting to send to google.
|
|
||||||
*/
|
|
||||||
public void testCreateAndSendTrack() {
|
|
||||||
// Create a track at first.
|
|
||||||
createSimpleTrack(1);
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
sendKeys(KeyEvent.KEYCODE_MENU);
|
|
||||||
findMenuItem(activityMyTracks.getString(R.string.menu_send_google), true);
|
|
||||||
solo.waitForText(activityMyTracks.getString(R.string.send_google_title));
|
|
||||||
rotateCurrentActivity();
|
|
||||||
|
|
||||||
ArrayList<CheckBox> checkBoxs = solo.getCurrentCheckBoxes();
|
|
||||||
for (int i = 0; i < checkBoxs.size(); i++) {
|
|
||||||
if (checkBoxs.get(i).isChecked()) {
|
|
||||||
solo.clickOnCheckBox(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.send_google_send_now));
|
|
||||||
assertTrue(solo.waitForText(activityMyTracks
|
|
||||||
.getString(R.string.send_google_no_service_selected)));
|
|
||||||
// Stop here for do not really send.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests saving a track to SD card as a GPX file.
|
|
||||||
*/
|
|
||||||
public void testSaveToSDCard_GPX() {
|
|
||||||
createSimpleTrack(0);
|
|
||||||
saveTrackToSdCard(GPX);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests saving a track to SD card as a KML file.
|
|
||||||
*/
|
|
||||||
public void testSaveToSDCard_KML() {
|
|
||||||
createSimpleTrack(0);
|
|
||||||
saveTrackToSdCard(KML);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests saving a track to SD card as a CSV file.
|
|
||||||
*/
|
|
||||||
public void testSaveToSDCard_CSV() {
|
|
||||||
createSimpleTrack(0);
|
|
||||||
saveTrackToSdCard(CSV);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests saving a track to SD card as a TCX file.
|
|
||||||
*/
|
|
||||||
public void testSaveToSDCard_TCX() {
|
|
||||||
createSimpleTrack(0);
|
|
||||||
saveTrackToSdCard(TCX);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests editing a track.
|
|
||||||
*/
|
|
||||||
public void testEditTrack() {
|
|
||||||
createSimpleTrack(0);
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
sendKeys(KeyEvent.KEYCODE_MENU);
|
|
||||||
findMenuItem(activityMyTracks.getString(R.string.menu_edit), true);
|
|
||||||
|
|
||||||
String newTrackName = TRACK_NAME_PREFIX + "_new" + System.currentTimeMillis();
|
|
||||||
String newType = "type" + newTrackName;
|
|
||||||
String newDesc = "desc" + newTrackName;
|
|
||||||
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
rotateAllActivities();
|
|
||||||
sendKeys(KeyEvent.KEYCODE_DEL);
|
|
||||||
solo.enterText(0, newTrackName);
|
|
||||||
sendKeys(KeyEvent.KEYCODE_TAB);
|
|
||||||
solo.enterText(1, newType);
|
|
||||||
sendKeys(KeyEvent.KEYCODE_TAB);
|
|
||||||
solo.enterText(2, newDesc);
|
|
||||||
|
|
||||||
solo.clickOnButton(activityMyTracks.getString(R.string.generic_save));
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
// Go back to track list.
|
|
||||||
solo.goBack();
|
|
||||||
|
|
||||||
assertTrue(solo.searchText(newTrackName));
|
|
||||||
assertTrue(solo.searchText(newDesc));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests the menu My Location.
|
|
||||||
*/
|
|
||||||
public void testGotoMyLocation() {
|
|
||||||
createSimpleTrack(1);
|
|
||||||
solo.sendKey(KeyEvent.KEYCODE_MENU);
|
|
||||||
findMenuItem(activityMyTracks.getString(R.string.menu_my_location), true);
|
|
||||||
// TODO How to verify the location is shown on the map.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Changes some settings and then reset them.
|
|
||||||
*/
|
|
||||||
public void testSetting() {
|
|
||||||
sendKeys(KeyEvent.KEYCODE_MENU);
|
|
||||||
findMenuItem(activityMyTracks.getString(R.string.menu_settings), true);
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
// Rotate on the settings page.
|
|
||||||
rotateAllActivities();
|
|
||||||
solo.waitForText(activityMyTracks.getString(R.string.settings_reset));
|
|
||||||
// Reset all settings at first.
|
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.settings_reset));
|
|
||||||
solo.clickOnButton(activityMyTracks.getString(R.string.generic_ok));
|
|
||||||
// Change a setting of display.
|
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.settings_display));
|
|
||||||
solo.waitForText(activityMyTracks.getString(R.string.settings_display_metric));
|
|
||||||
// Rotate on a sub setting page.
|
|
||||||
rotateAllActivities();
|
|
||||||
solo.waitForText(activityMyTracks.getString(R.string.settings_display_metric));
|
|
||||||
ArrayList<CheckBox> displayCheckBoxs = solo.getCurrentCheckBoxes();
|
|
||||||
boolean useMetric = displayCheckBoxs.get(0).isChecked();
|
|
||||||
solo.clickOnCheckBox(0);
|
|
||||||
solo.goBack();
|
|
||||||
// Change a setting of sharing.
|
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.settings_sharing));
|
|
||||||
solo.waitForText(activityMyTracks.getString(R.string.settings_sharing_allow_access));
|
|
||||||
ArrayList<CheckBox> sharingCheckBoxs = solo.getCurrentCheckBoxes();
|
|
||||||
boolean newMapsPublic = sharingCheckBoxs.get(0).isChecked();
|
|
||||||
solo.clickOnCheckBox(0);
|
|
||||||
// Rotate on a sub setting page when the value of a checkbox is changed.
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
rotateAllActivities();
|
|
||||||
solo.waitForText(activityMyTracks.getString(R.string.settings_sharing_allow_access));
|
|
||||||
assertEquals(!newMapsPublic, sharingCheckBoxs.get(0).isChecked());
|
|
||||||
solo.goBack();
|
|
||||||
|
|
||||||
// Reset all settings.
|
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.settings_reset));
|
|
||||||
solo.clickOnButton(activityMyTracks.getString(R.string.generic_ok));
|
|
||||||
|
|
||||||
// Check settings.
|
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.settings_display));
|
|
||||||
solo.waitForText(activityMyTracks.getString(R.string.settings_display_metric));
|
|
||||||
displayCheckBoxs = solo.getCurrentCheckBoxes();
|
|
||||||
assertEquals(useMetric, displayCheckBoxs.get(0).isChecked());
|
|
||||||
|
|
||||||
solo.goBack();
|
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.settings_sharing));
|
|
||||||
solo.waitForText(activityMyTracks.getString(R.string.settings_sharing_allow_access));
|
|
||||||
sharingCheckBoxs = solo.getCurrentCheckBoxes();
|
|
||||||
assertEquals(newMapsPublic, sharingCheckBoxs.get(0).isChecked());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates one track with a two locations, a way point and a statistics point.
|
|
||||||
*/
|
|
||||||
public void testCreateTrackWithMarkers() {
|
|
||||||
solo.sendKey(KeyEvent.KEYCODE_MENU);
|
|
||||||
findMenuItem(activityMyTracks.getString(R.string.menu_delete_all), true);
|
|
||||||
solo.clickOnButton(activityMyTracks.getString(R.string.generic_ok));
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
|
|
||||||
startRecording();
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
SmokeTestUtils.sendGps(2);
|
|
||||||
createWaypointAndStatistics();
|
|
||||||
SmokeTestUtils.sendGps(2);
|
|
||||||
// Back to tracks list.
|
|
||||||
solo.goBack();
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
rotateAllActivities();
|
|
||||||
stopRecording(false);
|
|
||||||
solo.enterText(0, trackName);
|
|
||||||
solo.clickOnButton(activityMyTracks.getString(R.string.generic_save));
|
|
||||||
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
// Check the new track
|
|
||||||
assertTrue(solo.waitForText(trackName, 1, 5000, true, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes all tracks.
|
|
||||||
*/
|
|
||||||
public void testDeleteTracks() {
|
|
||||||
createSimpleTrack(0);
|
|
||||||
solo.goBack();
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
// There is at least one track.
|
|
||||||
ArrayList<ListView> trackListView = solo.getCurrentListViews();
|
|
||||||
assertTrue(trackListView.size() > 0);
|
|
||||||
assertTrue(trackListView.get(0).getCount() > 0);
|
|
||||||
|
|
||||||
solo.sendKey(KeyEvent.KEYCODE_MENU);
|
|
||||||
findMenuItem(activityMyTracks.getString(R.string.menu_delete_all), true);
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
rotateAllActivities();
|
|
||||||
solo.clickOnButton(activityMyTracks.getString(R.string.generic_ok));
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
// There is no track now.
|
|
||||||
trackListView = solo.getCurrentListViews();
|
|
||||||
assertEquals(0, trackListView.get(0).getCount());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
createSimpleTrack(3);
|
|
||||||
solo.goBack();
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
// Create a empty track.
|
|
||||||
createSimpleTrack(0);
|
|
||||||
solo.goBack();
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
// Delete all exported gpx and kml tracks.
|
|
||||||
deleteExportedFiles(GPX);
|
|
||||||
deleteExportedFiles(KML);
|
|
||||||
int gpxFilesNumber = 0;
|
|
||||||
File[] allGpxFiles = getExportedFiles(GPX);
|
|
||||||
// For the first export, there is no MyTracks folder.
|
|
||||||
if (allGpxFiles != null) {
|
|
||||||
gpxFilesNumber = getExportedFiles(GPX).length;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get track number in current track list of MyTracks.
|
|
||||||
int trackNumber = solo.getCurrentListViews().get(0).getCount();
|
|
||||||
|
|
||||||
// No file to imported.
|
|
||||||
sendKeys(KeyEvent.KEYCODE_MENU);
|
|
||||||
findMenuItem(activityMyTracks.getString(R.string.menu_import_all), true);
|
|
||||||
solo.waitForText(activityMyTracks.getString(R.string.import_no_file,
|
|
||||||
FileUtils.buildExternalDirectoryPath(GPX)));
|
|
||||||
solo.clickOnButton(activityMyTracks.getString(R.string.generic_ok));
|
|
||||||
|
|
||||||
// Click to export tracks(At least one track) to Gpx files.
|
|
||||||
sendKeys(KeyEvent.KEYCODE_MENU);
|
|
||||||
findMenuItem(activityMyTracks.getString(R.string.menu_export_all), true);
|
|
||||||
solo.clickOnText(String.format(activityMyTracks.getString(R.string.menu_export_all_format),
|
|
||||||
GPX.toUpperCase()));
|
|
||||||
rotateAllActivities();
|
|
||||||
solo.waitForText(activityMyTracks.getString(R.string.export_success));
|
|
||||||
// Check export file.
|
|
||||||
assertEquals(gpxFilesNumber + trackNumber, getExportedFiles(GPX).length);
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
|
|
||||||
// Click to import track.
|
|
||||||
gpxFilesNumber = getExportedFiles(GPX).length;
|
|
||||||
trackNumber = solo.getCurrentListViews().get(0).getCount();
|
|
||||||
|
|
||||||
sendKeys(KeyEvent.KEYCODE_MENU);
|
|
||||||
findMenuItem(activityMyTracks.getString(R.string.menu_import_all), true);
|
|
||||||
rotateAllActivities();
|
|
||||||
// Wait for the prefix of import success string is much faster than wait
|
|
||||||
// the whole string.
|
|
||||||
solo.waitForText(activityMyTracks.getString(R.string.import_success).split("%")[0]);
|
|
||||||
// Check import tracks should be equal with the sum of trackNumber and
|
|
||||||
// gpxFilesNumber;
|
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.generic_ok));
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
assertEquals(trackNumber + gpxFilesNumber, solo.getCurrentListViews().get(0).getCount());
|
|
||||||
|
|
||||||
// Click to export tracks(At least two tracks) to KML files.
|
|
||||||
gpxFilesNumber = getExportedFiles(GPX).length;
|
|
||||||
trackNumber = solo.getCurrentListViews().get(0).getCount();
|
|
||||||
sendKeys(KeyEvent.KEYCODE_MENU);
|
|
||||||
findMenuItem(activityMyTracks.getString(R.string.menu_export_all), true);
|
|
||||||
solo.clickOnText(String.format(activityMyTracks.getString(R.string.menu_export_all_format),
|
|
||||||
KML.toUpperCase()));
|
|
||||||
solo.waitForText(activityMyTracks.getString(R.string.export_success));
|
|
||||||
// Check export files.
|
|
||||||
assertEquals(gpxFilesNumber, getExportedFiles(GPX).length);
|
|
||||||
assertEquals(trackNumber, getExportedFiles(KML).length);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests the switch between satellite mode and map mode.
|
|
||||||
*/
|
|
||||||
public void testSatelliteAndMapView() {
|
|
||||||
startRecording();
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
// Check current mode.
|
|
||||||
boolean isMapMode = true;
|
|
||||||
sendKeys(KeyEvent.KEYCODE_MENU);
|
|
||||||
// If can not find switch menu in top menu, click More menu.
|
|
||||||
if (!findMenuItem(activityMyTracks.getString(R.string.menu_satellite_mode), false)) {
|
|
||||||
isMapMode = false;
|
|
||||||
}
|
|
||||||
// Switch to satellite mode if it's map mode now..
|
|
||||||
solo.clickOnText(activityMyTracks.getString(isMapMode ? R.string.menu_satellite_mode
|
|
||||||
: R.string.menu_map_mode));
|
|
||||||
|
|
||||||
isMapMode = !isMapMode;
|
|
||||||
|
|
||||||
ArrayList<View> allViews = solo.getViews();
|
|
||||||
for (View view : allViews) {
|
|
||||||
if (view instanceof MapView) {
|
|
||||||
assertEquals(isMapMode, !((MapView) view).isSatellite());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
|
|
||||||
solo.sendKey(KeyEvent.KEYCODE_MENU);
|
|
||||||
findMenuItem(activityMyTracks.getString(R.string.menu_help), false);
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
rotateAllActivities();
|
|
||||||
|
|
||||||
// Switch back.
|
|
||||||
solo.clickOnText(activityMyTracks.getString(isMapMode ? R.string.menu_satellite_mode
|
|
||||||
: R.string.menu_map_mode));
|
|
||||||
isMapMode = !isMapMode;
|
|
||||||
allViews = 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.
|
|
||||||
solo.waitForText(activityMyTracks.getString(R.string.track_detail_chart_tab), 0, 1000);
|
|
||||||
stopRecording(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
sendKeys(KeyEvent.KEYCODE_MENU);
|
|
||||||
findMenuItem(activityMyTracks.getString(R.string.menu_aggregated_statistics), true);
|
|
||||||
solo.waitForText(activityMyTracks.getString(R.string.stat_total_distance));
|
|
||||||
solo.goBack();
|
|
||||||
|
|
||||||
startRecording();
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
// Menu in TrackDetailActivity.
|
|
||||||
sendKeys(KeyEvent.KEYCODE_MENU);
|
|
||||||
findMenuItem(activityMyTracks.getString(R.string.menu_sensor_state), true);
|
|
||||||
solo.waitForText(activityMyTracks.getString(R.string.sensor_state_last_sensor_time));
|
|
||||||
|
|
||||||
solo.goBack();
|
|
||||||
sendKeys(KeyEvent.KEYCODE_MENU);
|
|
||||||
findMenuItem(activityMyTracks.getString(R.string.menu_help), true);
|
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.help_about));
|
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.generic_ok));
|
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.generic_ok));
|
|
||||||
|
|
||||||
stopRecording(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a way point and a statistics during track recording.
|
|
||||||
*/
|
|
||||||
private void createWaypointAndStatistics() {
|
|
||||||
sendKeys(KeyEvent.KEYCODE_MENU);
|
|
||||||
findMenuItem(activityMyTracks.getString(R.string.menu_markers), true);
|
|
||||||
|
|
||||||
solo.clickOnButton(activityMyTracks.getString(R.string.marker_list_insert_waypoint));
|
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.marker_detail_marker_name));
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
rotateAllActivities();
|
|
||||||
solo.enterText(0, WAYPOINT_NAME);
|
|
||||||
|
|
||||||
solo.clickOnButton(activityMyTracks.getString(R.string.generic_save));
|
|
||||||
|
|
||||||
solo.clickOnButton(activityMyTracks.getString(R.string.marker_list_insert_statistics));
|
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.marker_detail_marker_name));
|
|
||||||
solo.enterText(0, STATISTICS_NAME);
|
|
||||||
solo.clickOnButton(activityMyTracks.getString(R.string.generic_save));
|
|
||||||
|
|
||||||
assertTrue(solo.searchText(WAYPOINT_NAME));
|
|
||||||
assertTrue(solo.searchText(STATISTICS_NAME));
|
|
||||||
|
|
||||||
solo.goBack();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void tearDown() throws Exception {
|
|
||||||
solo.finishOpenedActivities();
|
|
||||||
super.tearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Accepts terms and configures units.
|
|
||||||
*/
|
|
||||||
private void verifyFirstLaunch() {
|
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.eula_accept));
|
|
||||||
// Click for welcome.
|
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.generic_ok));
|
|
||||||
// Click for choose units.
|
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.generic_ok));
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a simple track which can be used by subsequent test.
|
|
||||||
*
|
|
||||||
* @param numberOfGpsData number of simulated Gps data
|
|
||||||
*/
|
|
||||||
private void createSimpleTrack(int numberOfGpsData) {
|
|
||||||
startRecording();
|
|
||||||
SmokeTestUtils.sendGps(numberOfGpsData);
|
|
||||||
stopRecording(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts recoding track.
|
|
||||||
*/
|
|
||||||
private void startRecording() {
|
|
||||||
if (hasActionBar) {
|
|
||||||
Button startButton =
|
|
||||||
getButtonOnScreen(activityMyTracks.getString(R.string.menu_record_track));
|
|
||||||
// In case a track is recording.
|
|
||||||
if (startButton == null) {
|
|
||||||
stopRecording(true);
|
|
||||||
startButton = getButtonOnScreen(activityMyTracks.getString(R.string.menu_record_track));
|
|
||||||
}
|
|
||||||
solo.clickOnView(startButton);
|
|
||||||
} else {
|
|
||||||
sendKeys(KeyEvent.KEYCODE_MENU);
|
|
||||||
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);
|
|
||||||
sendKeys(KeyEvent.KEYCODE_MENU);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.menu_record_track));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stops recoding track.
|
|
||||||
*
|
|
||||||
* @param isSave ture means should save this track
|
|
||||||
*/
|
|
||||||
private void stopRecording(boolean isSave) {
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
if (hasActionBar) {
|
|
||||||
solo.clickOnView(getButtonOnScreen(activityMyTracks.getString(R.string.menu_stop_recording)));
|
|
||||||
} else {
|
|
||||||
sendKeys(KeyEvent.KEYCODE_MENU);
|
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.menu_stop_recording));
|
|
||||||
}
|
|
||||||
if (isSave) {
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
solo.enterText(0, trackName);
|
|
||||||
solo.clickLongOnText(activityMyTracks.getString(R.string.generic_save));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes a kind of track in MyTracks folder.
|
|
||||||
*
|
|
||||||
* @param trackKind the kind of track
|
|
||||||
*/
|
|
||||||
private 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
|
|
||||||
*/
|
|
||||||
private 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
|
|
||||||
*/
|
|
||||||
private void saveTrackToSdCard(String trackKind) {
|
|
||||||
deleteExportedFiles(trackKind);
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
sendKeys(KeyEvent.KEYCODE_MENU);
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.menu_save));
|
|
||||||
solo.clickOnText(trackKind.toUpperCase());
|
|
||||||
rotateAllActivities();
|
|
||||||
solo.waitForText(activityMyTracks.getString(R.string.generic_success_title));
|
|
||||||
assertEquals(1, getExportedFiles(trackKind).length);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if a button is existed in the screen.
|
|
||||||
*
|
|
||||||
* @param buttonName the name string of the button
|
|
||||||
* @return the button to search, and null means can not find the button
|
|
||||||
*/
|
|
||||||
private Button getButtonOnScreen(String buttonName) {
|
|
||||||
ArrayList<Button> currentButtons = solo.getCurrentButtons();
|
|
||||||
for (Button button : currentButtons) {
|
|
||||||
if (((String) button.getText()).equalsIgnoreCase(buttonName)) {
|
|
||||||
return button;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether an action bar is shown.
|
|
||||||
*/
|
|
||||||
private void setHasActionBar() {
|
|
||||||
// If can find record button without pressing Menu, it should be an action
|
|
||||||
// bar.
|
|
||||||
Button startButton = getButtonOnScreen(activityMyTracks.getString(R.string.menu_record_track));
|
|
||||||
Button stopButton = getButtonOnScreen(activityMyTracks.getString(R.string.menu_stop_recording));
|
|
||||||
if (startButton != null || stopButton != null) {
|
|
||||||
hasActionBar = true;
|
|
||||||
} else {
|
|
||||||
sendKeys(KeyEvent.KEYCODE_MENU);
|
|
||||||
if (solo.searchText(activityMyTracks.getString(R.string.menu_record_track))
|
|
||||||
|| solo.searchText(activityMyTracks.getString(R.string.menu_stop_recording))) {
|
|
||||||
hasActionBar = false;
|
|
||||||
} else {
|
|
||||||
fail();
|
|
||||||
}
|
|
||||||
solo.goBack();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rotates the current activity.
|
|
||||||
*/
|
|
||||||
private void rotateCurrentActivity() {
|
|
||||||
SmokeTestUtils.rotateActivity(solo.getCurrentActivity());
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rotates all activities.
|
|
||||||
*/
|
|
||||||
private void rotateAllActivities() {
|
|
||||||
ArrayList<Activity> allActivities = solo.getAllOpenedActivities();
|
|
||||||
for (Activity activity : allActivities) {
|
|
||||||
SmokeTestUtils.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
|
|
||||||
*/
|
|
||||||
private boolean findMenuItem(String menuName, boolean click) {
|
|
||||||
boolean findResult = false;
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
return findResult;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,90 +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.smoketest;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.res.Configuration;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides utilities to smoke test.
|
|
||||||
*
|
|
||||||
* @author Youtao Liu
|
|
||||||
*/
|
|
||||||
public class SmokeTestUtils {
|
|
||||||
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 SmokeTestUtils() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends Gps data to emulator.
|
|
||||||
*
|
|
||||||
* @param number send times
|
|
||||||
*/
|
|
||||||
public static void sendGps(int number) {
|
|
||||||
if (number < 1) { 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rotates the given activity.
|
|
||||||
*
|
|
||||||
* @param activity a given activity
|
|
||||||
*/
|
|
||||||
public static void rotateActivity(Activity activity) {
|
|
||||||
activity
|
|
||||||
.setRequestedOrientation(activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT ? ORIENTATION_LANDSCAPE
|
|
||||||
: ORIENTATION_PORTRAIT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user