forked from upstream-mirrors/OpenTracks
Code cleanup: ViewTest.java
This commit is contained in:
+126
-133
@@ -13,22 +13,21 @@
|
|||||||
* License for the specific language governing permissions and limitations under
|
* License for the specific language governing permissions and limitations under
|
||||||
* the License.
|
* the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.google.android.apps.mytracks.endtoendtest.common;
|
package com.google.android.apps.mytracks.endtoendtest.common;
|
||||||
|
|
||||||
|
import com.google.android.apps.mytracks.TrackDetailActivity;
|
||||||
import com.google.android.apps.mytracks.TrackListActivity;
|
import com.google.android.apps.mytracks.TrackListActivity;
|
||||||
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils;
|
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils;
|
||||||
|
import com.google.android.apps.mytracks.fragments.ChartFragment;
|
||||||
import com.google.android.apps.mytracks.fragments.MyTracksMapFragment;
|
import com.google.android.apps.mytracks.fragments.MyTracksMapFragment;
|
||||||
|
import com.google.android.apps.mytracks.fragments.StatsFragment;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.app.Instrumentation;
|
import android.app.Instrumentation;
|
||||||
import android.graphics.Point;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.test.ActivityInstrumentationTestCase2;
|
import android.test.ActivityInstrumentationTestCase2;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
@@ -39,9 +38,8 @@ import junit.framework.Assert;
|
|||||||
*/
|
*/
|
||||||
public class ViewsTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
public class ViewsTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
||||||
|
|
||||||
private static final String TAG = ViewsTest.class.getSimpleName();
|
|
||||||
private Instrumentation instrumentation;
|
private Instrumentation instrumentation;
|
||||||
private TrackListActivity activityMyTracks;
|
private TrackListActivity trackListActivity;
|
||||||
|
|
||||||
public ViewsTest() {
|
public ViewsTest() {
|
||||||
super(TrackListActivity.class);
|
super(TrackListActivity.class);
|
||||||
@@ -51,132 +49,8 @@ public class ViewsTest extends ActivityInstrumentationTestCase2<TrackListActivit
|
|||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
instrumentation = getInstrumentation();
|
instrumentation = getInstrumentation();
|
||||||
activityMyTracks = getActivity();
|
trackListActivity = getActivity();
|
||||||
EndToEndTestUtils.setupForAllTest(instrumentation, activityMyTracks);
|
EndToEndTestUtils.setupForAllTest(instrumentation, trackListActivity);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Switches view from {@link MyTracksMapFragment} to @ ChartFragment} , then
|
|
||||||
* changes to @ StatsFragment} . Finally back to {@link MyTracksMapFragment}.
|
|
||||||
* And check some menus in these views. In MapFragment, the menu should
|
|
||||||
* contain satellite/map mode. In ChartFragment and StatsFragment, the menu
|
|
||||||
* should not contain satellite/map mode.
|
|
||||||
*/
|
|
||||||
public void testSwitchViewsAndMenusOfView() {
|
|
||||||
EndToEndTestUtils.createTrackIfEmpty(3, true);
|
|
||||||
|
|
||||||
EndToEndTestUtils.SOLO.scrollUp();
|
|
||||||
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.trackName, 1, true);
|
|
||||||
|
|
||||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_chart_tab));
|
|
||||||
EndToEndTestUtils.rotateCurrentActivity();
|
|
||||||
|
|
||||||
assertTrue(EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings),
|
|
||||||
false));
|
|
||||||
assertFalse(EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_map_layer),
|
|
||||||
false));
|
|
||||||
|
|
||||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_stats_tab));
|
|
||||||
assertTrue(EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings),
|
|
||||||
false));
|
|
||||||
assertFalse(EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_map_layer),
|
|
||||||
false));
|
|
||||||
|
|
||||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_map_tab));
|
|
||||||
EndToEndTestUtils.rotateCurrentActivity();
|
|
||||||
assertTrue(EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings),
|
|
||||||
false));
|
|
||||||
assertTrue(EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_map_layer),
|
|
||||||
false));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests the switch between satellite mode and map mode.
|
|
||||||
*/
|
|
||||||
public void testSatelliteAndMapView() {
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
EndToEndTestUtils.createTrackIfEmpty(1, false);
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.track_detail_chart_tab));
|
|
||||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_map_layer), true);
|
|
||||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.menu_terrain));
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.track_detail_chart_tab));
|
|
||||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_map_layer), true);
|
|
||||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.menu_satellite));
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.track_detail_chart_tab));
|
|
||||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_map_layer), true);
|
|
||||||
// But in some languages only has one match(Such as French).
|
|
||||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.menu_map));
|
|
||||||
// The first match maybe a noise(The title of the radio dialog) for some
|
|
||||||
// language(Such as English), we should click the second one.
|
|
||||||
TextView text = EndToEndTestUtils.findTextViewByIndex(
|
|
||||||
activityMyTracks.getString(R.string.menu_map), 2);
|
|
||||||
if (text != null) {
|
|
||||||
EndToEndTestUtils.SOLO.clickOnView(text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests the position of track controller in landscape view and portrait view
|
|
||||||
* on different activities.
|
|
||||||
*/
|
|
||||||
public void testTrackControllerPostion() {
|
|
||||||
checkTrackController();
|
|
||||||
EndToEndTestUtils.rotateCurrentActivity();
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
checkTrackController();
|
|
||||||
|
|
||||||
EndToEndTestUtils.startRecording();
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
checkTrackController();
|
|
||||||
EndToEndTestUtils.rotateCurrentActivity();
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
checkTrackController();
|
|
||||||
|
|
||||||
EndToEndTestUtils.stopRecording(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks the position of track controller in landscape view and portrait
|
|
||||||
* view.
|
|
||||||
*/
|
|
||||||
@SuppressLint("NewApi")
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
private void checkTrackController() {
|
|
||||||
View controller = EndToEndTestUtils.SOLO.getCurrentActivity().findViewById(
|
|
||||||
R.id.track_controler_container);
|
|
||||||
|
|
||||||
Display display = EndToEndTestUtils.SOLO.getCurrentActivity().getWindowManager()
|
|
||||||
.getDefaultDisplay();
|
|
||||||
Point size = new Point();
|
|
||||||
if (Build.VERSION.SDK_INT >= 13) {
|
|
||||||
display.getSize(size);
|
|
||||||
} else {
|
|
||||||
size.x = display.getWidth();
|
|
||||||
size.y = display.getHeight();
|
|
||||||
}
|
|
||||||
int width = size.x;
|
|
||||||
int height = size.y;
|
|
||||||
|
|
||||||
Log.d(TAG, width + ":" + height);
|
|
||||||
|
|
||||||
// In landscape view
|
|
||||||
if (width > height) {
|
|
||||||
Assert.assertTrue(controller.getWidth() < controller.getHeight());
|
|
||||||
Assert.assertTrue(controller.getTop() < height / 2);
|
|
||||||
Assert.assertTrue(controller.getRight() < width / 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
// In portrait view
|
|
||||||
else {
|
|
||||||
Assert.assertTrue(controller.getWidth() > controller.getHeight());
|
|
||||||
Log.d(TAG, controller.getTop() + ":" + controller.getRight());
|
|
||||||
|
|
||||||
Assert.assertTrue(controller.getTop() > height / 2);
|
|
||||||
Assert.assertTrue(controller.getRight() > width / 2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -185,4 +59,123 @@ public class ViewsTest extends ActivityInstrumentationTestCase2<TrackListActivit
|
|||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Switches tab from {@link MyTracksMapFragment} to {@link ChartFragment},
|
||||||
|
* then to {@link StatsFragment}, and then to {@link MyTracksMapFragment}. In
|
||||||
|
* each tab, checks menu items like settings and map layer.
|
||||||
|
*/
|
||||||
|
public void testSwitchTabAndViewMenu() {
|
||||||
|
EndToEndTestUtils.createTrackIfEmpty(3, true);
|
||||||
|
|
||||||
|
EndToEndTestUtils.SOLO.scrollUp();
|
||||||
|
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.trackName, 1, true);
|
||||||
|
|
||||||
|
// Switch to chart view
|
||||||
|
EndToEndTestUtils.SOLO.clickOnText(
|
||||||
|
trackListActivity.getString(R.string.track_detail_chart_tab));
|
||||||
|
EndToEndTestUtils.rotateCurrentActivity();
|
||||||
|
assertTrue(
|
||||||
|
EndToEndTestUtils.findMenuItem(trackListActivity.getString(R.string.menu_settings), false));
|
||||||
|
assertFalse(EndToEndTestUtils.findMenuItem(
|
||||||
|
trackListActivity.getString(R.string.menu_map_layer), false));
|
||||||
|
|
||||||
|
// Switch to stats view
|
||||||
|
EndToEndTestUtils.SOLO.clickOnText(
|
||||||
|
trackListActivity.getString(R.string.track_detail_stats_tab));
|
||||||
|
assertTrue(
|
||||||
|
EndToEndTestUtils.findMenuItem(trackListActivity.getString(R.string.menu_settings), false));
|
||||||
|
assertFalse(EndToEndTestUtils.findMenuItem(
|
||||||
|
trackListActivity.getString(R.string.menu_map_layer), false));
|
||||||
|
|
||||||
|
// Switch to map view
|
||||||
|
EndToEndTestUtils.SOLO.clickOnText(trackListActivity.getString(R.string.track_detail_map_tab));
|
||||||
|
EndToEndTestUtils.rotateCurrentActivity();
|
||||||
|
assertTrue(
|
||||||
|
EndToEndTestUtils.findMenuItem(trackListActivity.getString(R.string.menu_settings), false));
|
||||||
|
assertTrue(EndToEndTestUtils.findMenuItem(
|
||||||
|
trackListActivity.getString(R.string.menu_map_layer), false));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test selecting map layer.
|
||||||
|
*/
|
||||||
|
public void testMapLayer() {
|
||||||
|
EndToEndTestUtils.createTrackIfEmpty(1, false);
|
||||||
|
|
||||||
|
selectMapLayer(R.string.menu_terrain);
|
||||||
|
selectMapLayer(R.string.menu_satellite_with_streets);
|
||||||
|
selectMapLayer(R.string.menu_satellite);
|
||||||
|
selectMapLayer(R.string.menu_map);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the track controller position in landscape view and portrait view on
|
||||||
|
* {@link TrackListActivity} and {@link TrackDetailActivity}.
|
||||||
|
*/
|
||||||
|
public void testTrackControllerPostion() {
|
||||||
|
checkTrackControllerPosition();
|
||||||
|
|
||||||
|
EndToEndTestUtils.rotateCurrentActivity();
|
||||||
|
instrumentation.waitForIdleSync();
|
||||||
|
checkTrackControllerPosition();
|
||||||
|
|
||||||
|
EndToEndTestUtils.startRecording();
|
||||||
|
instrumentation.waitForIdleSync();
|
||||||
|
checkTrackControllerPosition();
|
||||||
|
|
||||||
|
EndToEndTestUtils.rotateCurrentActivity();
|
||||||
|
instrumentation.waitForIdleSync();
|
||||||
|
checkTrackControllerPosition();
|
||||||
|
|
||||||
|
EndToEndTestUtils.stopRecording(true);
|
||||||
|
EndToEndTestUtils.SOLO.goBack();
|
||||||
|
instrumentation.waitForIdleSync();
|
||||||
|
checkTrackControllerPosition();
|
||||||
|
|
||||||
|
EndToEndTestUtils.rotateCurrentActivity();
|
||||||
|
instrumentation.waitForIdleSync();
|
||||||
|
checkTrackControllerPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Selects a map layer
|
||||||
|
*
|
||||||
|
* @param id the map layer id
|
||||||
|
*/
|
||||||
|
private void selectMapLayer(int id) {
|
||||||
|
|
||||||
|
// Make sure can see the map tab
|
||||||
|
EndToEndTestUtils.SOLO.waitForText(trackListActivity.getString(R.string.track_detail_map_tab));
|
||||||
|
EndToEndTestUtils.findMenuItem(trackListActivity.getString(R.string.menu_map_layer), true);
|
||||||
|
EndToEndTestUtils.SOLO.clickOnText(trackListActivity.getString(id));
|
||||||
|
EndToEndTestUtils.getButtonOnScreen(
|
||||||
|
trackListActivity.getString(R.string.generic_ok), true, true);
|
||||||
|
instrumentation.waitForIdleSync();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks the position of track controller in landscape view and portrait
|
||||||
|
* view.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
private void checkTrackControllerPosition() {
|
||||||
|
View controller = EndToEndTestUtils.SOLO.getCurrentActivity()
|
||||||
|
.findViewById(R.id.track_controler_container);
|
||||||
|
Display display = EndToEndTestUtils.SOLO.getCurrentActivity()
|
||||||
|
.getWindowManager().getDefaultDisplay();
|
||||||
|
int width = display.getWidth();
|
||||||
|
int height = display.getHeight();
|
||||||
|
|
||||||
|
if (width > height) {
|
||||||
|
// In landscape view
|
||||||
|
Assert.assertTrue(controller.getWidth() < controller.getHeight());
|
||||||
|
Assert.assertTrue(controller.getTop() < height / 2);
|
||||||
|
Assert.assertTrue(controller.getRight() < width / 2);
|
||||||
|
} else {
|
||||||
|
// In portrait view
|
||||||
|
Assert.assertTrue(controller.getWidth() > controller.getHeight());
|
||||||
|
Assert.assertTrue(controller.getTop() > height / 2);
|
||||||
|
Assert.assertTrue(controller.getRight() > width / 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user