From cb8744999b5554176f04b8f8116cd22cee7bf80f Mon Sep 17 00:00:00 2001 From: youtaol Date: Tue, 24 Jul 2012 18:03:09 +0800 Subject: [PATCH] Merge heads --- .../endtoendtest/CreateAndSendTrackTest.java | 73 +++++--- .../mytracks/endtoendtest/DeleteTest.java | 11 +- .../endtoendtest/EndToEndTestUtils.java | 165 +++++++++--------- .../mytracks/endtoendtest/GoogleUtils.java | 41 ++++- .../mytracks/endtoendtest/SettingTest.java | 12 +- 5 files changed, 177 insertions(+), 125 deletions(-) diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/CreateAndSendTrackTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/CreateAndSendTrackTest.java index 0296806bf..e2146c527 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/CreateAndSendTrackTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/CreateAndSendTrackTest.java @@ -113,33 +113,38 @@ public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2 allActivities = SOLO.getAllOpenedActivities(); for (Activity activity : allActivities) { - EndToEndTestUtils.rotateActivity(activity); + rotateActivity(activity); } - - instrumentation.waitForIdleSync(); } + instrumentation.waitForIdleSync(); } /** @@ -536,56 +535,56 @@ public class EndToEndTestUtils { * @param click true means need click this menu * @return true if find this menu */ - static boolean findMenuItem(String menuName, boolean click) { - boolean findResult = false; - boolean isMoreMenuOpened = false; - - // ICS phone. - if(hasActionBar) { - // Firstly find in action bar. - Button button = getButtonOnScreen(menuName, false, false); - if (button != null) { - findResult = true; - if (click) { - SOLO.clickOnView(button); - instrumentation.waitForIdleSync(); - } - return findResult; + static boolean findMenuItem(String menuName, boolean click) {boolean findResult = false; + boolean isMoreMenuOpened = false; + + // ICS phone. + if(hasActionBar) { + // Firstly find in action bar. + Button button = getButtonOnScreen(menuName, false, false); + if (button != null) { + findResult = true; + if (click) { + SOLO.clickOnView(button); + instrumentation.waitForIdleSync(); } - showMenuItem(); + return findResult; + } + showMenuItem(); + findResult = SOLO.searchText(menuName); + } else { + // Non-ICS phone. + SOLO.sendKey(KeyEvent.KEYCODE_MENU); + if (SOLO.searchText(menuName)) { + findResult = true; + } else if (SOLO.searchText(MENU_MORE)) { + SOLO.clickOnText(MENU_MORE); findResult = SOLO.searchText(menuName); - } else { - // Non-ICS phone. - SOLO.sendKey(KeyEvent.KEYCODE_MENU); - if (SOLO.searchText(menuName)) { - findResult = true; - } else if (SOLO.searchText(MENU_MORE)) { - SOLO.clickOnText(MENU_MORE); - findResult = SOLO.searchText(menuName); - isMoreMenuOpened = true; - } + isMoreMenuOpened = true; } - - if (findResult && click) { - SOLO.clickOnText(menuName); - instrumentation.waitForIdleSync(); - } else { - // Quit more menu list if opened. - if (isMoreMenuOpened) { - SOLO.goBack(); - } - // Quit menu list. - SOLO.goBack(); - } - return findResult; } + if (findResult && click) { + SOLO.clickOnText(menuName); + instrumentation.waitForIdleSync(); + } else { + // Quit more menu list if opened. + if (isMoreMenuOpened) { + SOLO.goBack(); + } + // Quit menu list. + SOLO.goBack(); + } + return findResult; +} + /** * Show menu item list. */ public static void showMenuItem() { showMenuItem(0); } + /** * Gets more menu items operation is different for different Android OS. When * get overflow button view on action, it usually be able to click. But in @@ -630,8 +629,8 @@ public class EndToEndTestUtils { private static View getMoreOptionView() { ArrayList allViews = SOLO.getViews(); for (View view : allViews) { - if (view instanceof ImageButton && view.getClass().getName().equals(MOREOPTION_CLASSNAME)) { - return view; + if (view instanceof ImageButton && view.getClass().getName().equals(MOREOPTION_CLASSNAME)) { + return view; } } return null; @@ -645,7 +644,7 @@ public class EndToEndTestUtils { * @return the text view, null means can not find it */ static TextView findTextView(String findText, View parent) { - ArrayList textViews = EndToEndTestUtils.SOLO.getCurrentTextViews(parent); + ArrayList textViews = SOLO.getCurrentTextViews(parent); for (TextView textView : textViews) { String text = (String) textView.getText(); if (textView.isShown() && text.endsWith(findText)) { @@ -661,7 +660,7 @@ public class EndToEndTestUtils { * @return the ChartView or null if not find */ static ChartView getChartView() { - ArrayList views = EndToEndTestUtils.SOLO.getViews(); + ArrayList views = SOLO.getViews(); for (View view : views) { if (view instanceof ChartView) { return (ChartView) view; @@ -677,14 +676,24 @@ public class EndToEndTestUtils { * @param keepInSettingList whether keep in setting list or not */ public static void resetAllSettings(Activity activityMyTracks, boolean keepInSettingList) { - EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true); + findMenuItem(activityMyTracks.getString(R.string.menu_settings), true); SOLO.waitForText(activityMyTracks.getString(R.string.settings_reset)); SOLO.clickOnText(activityMyTracks.getString(R.string.settings_reset)); getButtonOnScreen(activityMytracks.getString(R.string.generic_ok), true, true); instrumentation.waitForIdleSync(); if (!keepInSettingList) { - EndToEndTestUtils.SOLO.goBack(); + SOLO.goBack(); } } + + /** + * Hides soft key board when input text in an exit text. + * @param myEditText + * @param context + */ + public static void hideSoftKeyBoard(EditText myEditText, Context context) { + InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(myEditText.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY); + } -} +} \ No newline at end of file diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/GoogleUtils.java b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/GoogleUtils.java index 61fbe80bc..8ba9f0631 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/GoogleUtils.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/GoogleUtils.java @@ -62,17 +62,20 @@ import java.util.Locale; * @author Youtao Liu */ public class GoogleUtils { - private static Account account; public static final String LOG_TAG = "MyTracksTest"; public static final String DOCUMENT_NAME_PREFIX = "My Tracks"; public static final String SPREADSHEET_NAME = DOCUMENT_NAME_PREFIX + "-" + EndToEndTestUtils.DEFAULTACTIVITY; + /** + * Gets the account to access Google Services. + * + * @param context context used to get account + * @return the first account which is bound with current device + */ private static Account getAccount(Context context) { - return account == null ? account = AccountManager.get(context).getAccountsByType( - Constants.ACCOUNT_TYPE)[0] : account; + return AccountManager.get(context).getAccountsByType(Constants.ACCOUNT_TYPE)[0]; } - /** * Gets Google maps of a user. * @@ -81,7 +84,6 @@ public class GoogleUtils { * @return true means set successfully */ private static ArrayList getMaps(Context context, MapsClient mapsClient) { - // Reset the per request states String authToken = null; ArrayList mapIds = new ArrayList(); ArrayList mapData = new ArrayList(); @@ -176,7 +178,7 @@ public class GoogleUtils { * @param activity to get context * @return the entry of the document, null means can not find the spreadsheet. */ - private static Entry searchSepeadsheetByTitle(String title, Activity activity) { + private static Entry searchSpreadsheetByTitle(String title, Activity activity) { Context context = activity.getApplicationContext(); DocumentsClient documentsClient = new DocumentsClient( GDataClientFactory.getGDataClient(context), @@ -214,8 +216,8 @@ public class GoogleUtils { * @param isDelete whether delete the information of this track in the document * @return true means find the track name in the spreadsheet */ - public static boolean searchTrackTitleInSpreadsheet(String title, Activity activity, String spreadsheetTitle, boolean isDelete) { - String spreadsheetId = searchSepeadsheetByTitle(spreadsheetTitle, activity).getId().replace(SendDocsUtils.SPREADSHEET_ID_PREFIX, ""); + private static boolean searchTrackTitleInSpreadsheet(String title, Activity activity, String spreadsheetTitle, boolean isDelete) { + String spreadsheetId = searchSpreadsheetByTitle(spreadsheetTitle, activity).getId().replace(SendDocsUtils.SPREADSHEET_ID_PREFIX, ""); if(spreadsheetId == null) { Log.d(LOG_TAG, "Unable to find the spreadsheet -- " + spreadsheetTitle); return false; @@ -249,6 +251,28 @@ public class GoogleUtils { } return false; } + + /** + * Searches a track in spreadsheet. + * + * @param title the track name to search + * @param activity to get context + * @return true means find the track name in the spreadsheet + */ + public static boolean searchTrackInSpreadSheet(String title, Activity activity) { + return searchTrackTitleInSpreadsheet(title, activity, GoogleUtils.SPREADSHEET_NAME, false); + } + + /** + * Searches and deletes a track in spreadsheet. + * + * @param title the track name to search + * @param activity to get context + * @return true means find and delete successfully + */ + public static boolean deleteTrackInSpreadSheet(String title, Activity activity) { + return searchTrackTitleInSpreadsheet(title, activity, GoogleUtils.SPREADSHEET_NAME, true); + } /** * Searches a fusion table in user's Google tables. @@ -276,6 +300,7 @@ public class GoogleUtils { * * @param title the title of a track to drop * @param activity to get context + * @return the result of drop */ public static boolean dropFusionTables(String title, Activity activity) { Context context = activity.getApplicationContext(); diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/SettingTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/SettingTest.java index 5c66cdf49..0e88e3de1 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/SettingTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/SettingTest.java @@ -280,13 +280,12 @@ public class SettingTest extends ActivityInstrumentationTestCase2