diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/smoketest/MyTracksSmokeTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/smoketest/MyTracksSmokeTest.java index 11bc52e26..c0d0e9471 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/smoketest/MyTracksSmokeTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/smoketest/MyTracksSmokeTest.java @@ -1,12 +1,12 @@ /* * 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 @@ -22,6 +22,7 @@ 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; @@ -53,7 +54,7 @@ public class MyTracksSmokeTest extends ActivityInstrumentationTestCase2 checkBoxs = solo.getCurrentCheckBoxes(); for (int i = 0; i < checkBoxs.size(); i++) { @@ -176,10 +179,13 @@ public class MyTracksSmokeTest extends ActivityInstrumentationTestCase2 displayCheckBoxs = solo.getCurrentCheckBoxes(); boolean useMetric = displayCheckBoxs.get(0).isChecked(); solo.clickOnCheckBox(0); solo.goBack(); - // Change a setting of sharing. + // Changes a setting of sharing. solo.clickOnText(activityMyTracks.getString(R.string.settings_sharing)); solo.waitForText(activityMyTracks.getString(R.string.settings_sharing_allow_access)); ArrayList sharingCheckBoxs = solo.getCurrentCheckBoxes(); boolean newMapsPublic = sharingCheckBoxs.get(0).isChecked(); solo.clickOnCheckBox(0); + // Rotates 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. + // Resets all settings. solo.clickOnText(activityMyTracks.getString(R.string.settings_reset)); solo.clickOnButton(activityMyTracks.getString(R.string.generic_ok)); - // Check settings. + // Checks settings. solo.clickOnText(activityMyTracks.getString(R.string.settings_display)); solo.waitForText(activityMyTracks.getString(R.string.settings_display_metric)); displayCheckBoxs = solo.getCurrentCheckBoxes(); @@ -256,20 +273,22 @@ public class MyTracksSmokeTest extends ActivityInstrumentationTestCase2 allViews = solo.getViews(); for (View view : allViews) { if (view instanceof MapView) { - assertFalse(isMapMode ? ((MapView) view).isSatellite() : !(((MapView) view).isSatellite())); + assertEquals(isMapMode, !(((MapView) view).isSatellite())); } } instrumentation.waitForIdleSync(); - // Switches back. - sendKeys(KeyEvent.KEYCODE_MENU); + + solo.sendKey(KeyEvent.KEYCODE_MENU); + findMenuItem(activityMyTracks.getString(R.string.menu_help), false); instrumentation.waitForIdleSync(); + rotateAllActivities(); + + // Switches 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) { - assertFalse(isMapMode ? ((MapView) view).isSatellite() : !(((MapView) view).isSatellite())); + assertEquals(isMapMode, !(((MapView) view).isSatellite())); } } + // Waits 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); } @@ -454,7 +484,10 @@ public class MyTracksSmokeTest extends ActivityInstrumentationTestCase2 currentButtons = solo.getCurrentButtons(); for (Button button : currentButtons) { - if (((String) button.getText()).equalsIgnoreCase(buttonName)) { - return button; + if (((String) button.getText()).equalsIgnoreCase(buttonName)) { + return button; } } return null; @@ -632,6 +667,26 @@ public class MyTracksSmokeTest extends ActivityInstrumentationTestCase2 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. * diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/smoketest/SmokeTestUtils.java b/MyTracksTest/src/com/google/android/apps/mytracks/smoketest/SmokeTestUtils.java index 1749eefdb..28097c69d 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/smoketest/SmokeTestUtils.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/smoketest/SmokeTestUtils.java @@ -1,12 +1,12 @@ /* * 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 @@ -15,6 +15,9 @@ */ 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; @@ -29,6 +32,9 @@ 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; @@ -36,7 +42,8 @@ public class SmokeTestUtils { private static final float DELTA_LONGITUDE = 0.0005f; private static final float DELTA_LADITUDE = 0.0005f; - private SmokeTestUtils() {} + private SmokeTestUtils() { + } /** * Sends Gps data to emulator. @@ -44,10 +51,13 @@ public class SmokeTestUtils { * @param number send times */ public static void sendGps(int number) { - if (number < 1) return; + if (number < 1) { + return; + } PrintStream out = null; + Socket socket = null; try { - Socket socket = new Socket(ANDROID_LOCAL_IP, ANDROID_LOCAL_PORT); + socket = new Socket(ANDROID_LOCAL_IP, ANDROID_LOCAL_PORT); out = new PrintStream(socket.getOutputStream()); float longitude = START_LONGITUDE; float latitude = START_LATITUDE; @@ -57,8 +67,6 @@ public class SmokeTestUtils { longitude += DELTA_LONGITUDE; latitude += DELTA_LADITUDE; } - out.close(); - socket.close(); } catch (UnknownHostException e) { System.exit(-1); } catch (IOException e) { @@ -71,4 +79,19 @@ public class SmokeTestUtils { } } } + + /** + * Rotates the given activity. + * + * @param activity a given activity. + * @return current orientation of the activity. + */ + public static int rotateActivity(Activity activity) { + if (activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { + activity.setRequestedOrientation(ORIENTATION_LANDSCAPE); + } else { + activity.setRequestedOrientation(ORIENTATION_PORTRAIT); + } + return activity.getRequestedOrientation(); + } }