diff --git a/mobile/android/base/tests/AboutHomeTest.java.in b/mobile/android/base/tests/AboutHomeTest.java.in index 95a1303e6d6f..574b507d66de 100644 --- a/mobile/android/base/tests/AboutHomeTest.java.in +++ b/mobile/android/base/tests/AboutHomeTest.java.in @@ -20,7 +20,6 @@ import android.widget.TextView; import java.lang.reflect.Method; import java.util.ArrayList; -import java.util.Arrays; /** * This class is an extension of BaseTest that helps with interaction with about:home @@ -98,10 +97,6 @@ abstract class AboutHomeTest extends BaseTest { // @return the View associated with bookmark for the provided url or null if the link is not bookmarked protected View getDisplayedBookmark(String url) { openAboutHomeTab(AboutHomeTabs.BOOKMARKS); - if (!mDevice.type.equals("tablet")) { - toggleVKB(); // dismiss the keyboard to make sure this works on small screen devices - } - getInstrumentation().waitForIdleSync(); ListView bookmarksTabList = findListViewWithTag("bookmarks"); waitForNonEmptyListToLoad(bookmarksTabList); ListAdapter adapter = bookmarksTabList.getAdapter(); @@ -182,30 +177,59 @@ abstract class AboutHomeTest extends BaseTest { } /** - * @param1 a String with the original url - * @param2 a String array with the new values for all fields + * FIXME: rewrite this to work with fig when rewriting the testBookmarksTab test + * This method will edit the bookmark with index = bookmarkIndex from the list of bookmarks + * For the field index: + * fieldIndex = 1 - the Bookmark name + * fieldIndex = 2 - the Bookmark url + * fieldIndex = 3 - the Bookmark keyword */ - protected void editBookmark(String originalUrl, String[] newValues) { - openBookmarkContextMenu(originalUrl); + protected void editBookmark(int bookmarkIndex, int fieldIndex, String addedText, ListView list) { + + // Open the Edit Bookmark context menu + View child; + mSolo.clickOnText("Bookmarks"); + child = list.getChildAt(bookmarkIndex); + mAsserter.ok(child != null, "edit item can be retrieved", child != null ? child.toString() : "null!"); + waitForText("Switch to tab"); + mSolo.clickLongOnView(child); + waitForText("Share"); mSolo.clickOnText("Edit"); waitForText("Edit Bookmark"); - for (String value:newValues) { - mSolo.clearEditText(Arrays.asList(newValues).indexOf(value)); - mSolo.clickOnEditText(Arrays.asList(newValues).indexOf(value)); - mActions.sendKeys(value); - } - mSolo.clickOnButton("OK"); + + // Clear the Field + mSolo.clearEditText(fieldIndex); + + // Enter the new text + mSolo.clickOnEditText(fieldIndex); + mActions.sendKeys(addedText); + mSolo.clickOnText("OK"); waitForText("Bookmark updated"); } - protected void checkBookmarkEdit(String bookmarkUrl, String[] values) { - openBookmarkContextMenu(bookmarkUrl); + // FIXME: rewrite this to work with fig when rewriting the testBookmarksTab test + protected boolean checkBookmarkEdit(int bookmarkIndex, String addedText, ListView list) { + // Open the Edit Bookmark context menu + View child; + mSolo.clickOnText("Bookmarks"); + child = list.getChildAt(bookmarkIndex); + mAsserter.ok(child != null, "check item can be retrieved", child != null ? child.toString() : "null!"); + waitForText("Switch to tab"); + mSolo.clickLongOnView(child); + waitForText("Share"); mSolo.clickOnText("Edit"); - for (String value:values) { - mAsserter.ok(mSolo.searchText(value), "Checking that the value is correct", "The value = " + value + " is correct"); + waitForText("Edit Bookmark"); + + // Check if the new text was added + if (mSolo.searchText(addedText)) { + clickOnButton("Cancel"); + waitForText("about:home"); + return true; + } else { + clickOnButton("Cancel"); + waitForText("about:home"); + return false; } - clickOnButton("Cancel"); - waitForText("BOOKMARKS"); } // A wait in order for the about:home tab to be rendered after drag/tab selection diff --git a/mobile/android/base/tests/StringHelper.java.in b/mobile/android/base/tests/StringHelper.java.in index 6d5cd05fad40..3a8aaaa1b38f 100644 --- a/mobile/android/base/tests/StringHelper.java.in +++ b/mobile/android/base/tests/StringHelper.java.in @@ -45,8 +45,6 @@ class StringHelper { "Add to Home Screen" }; - public static final String[] BOOKMARK_CONTEXT_MENU_ITEMS = {"Open in New Tab", "Open in Private Tab", "Share", "Edit", "Remove", "Add to Home Screen"}; - // Robocop page urls // Note: please use getAbsoluteUrl(String url) on each robocop url to get the correct url public static final String ROBOCOP_BIG_LINK_URL = "/robocop/robocop_big_link.html"; diff --git a/mobile/android/base/tests/robocop.ini b/mobile/android/base/tests/robocop.ini index 236dbd2319b6..83c81790cb8e 100644 --- a/mobile/android/base/tests/robocop.ini +++ b/mobile/android/base/tests/robocop.ini @@ -1,7 +1,6 @@ [testAwesomebar] # [testAwesomebarSwipes] # disabled on fig - bug 880060 [testBookmark] -[testBookmarksPage] # [testBookmarklets] # see bug 915350 # [testBookmarkKeyword] # see bug 915350 [testBrowserSearchVisibility] diff --git a/mobile/android/base/tests/testBookmarksPage.java.in b/mobile/android/base/tests/testBookmarksPage.java.in deleted file mode 100644 index c3557211e7ae..000000000000 --- a/mobile/android/base/tests/testBookmarksPage.java.in +++ /dev/null @@ -1,223 +0,0 @@ -#filter substitution -package @ANDROID_PACKAGE_NAME@.tests; - -import @ANDROID_PACKAGE_NAME@.*; - -import com.jayway.android.robotium.solo.Condition; - -import android.content.ContentResolver; -import android.content.ContentValues; -import android.content.ContentUris; -import android.database.Cursor; -import android.net.Uri; -import android.view.View; -import android.widget.ListAdapter; -import android.widget.ListView; -import android.widget.TextView; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; - -public class testBookmarksPage extends AboutHomeTest { - private static String BOOKMARK_URL; - private static String DESKTOP_BOOKMARK_URL; - - @Override - protected int getTestType() { - return TEST_MOCHITEST; - } - - public void testBookmarksPage() { - BOOKMARK_URL = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_01_URL); - DESKTOP_BOOKMARK_URL = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_02_URL); - - setUpDesktopBookmarks(); - checkBookmarkList(); - checkBookmarkContextMenu(); - } - - private void checkBookmarkList() { - // Check that the default bookmarks are displayed - for (String url:StringHelper.DEFAULT_BOOKMARKS_URLS) { - mAsserter.ok(isBookmarkDisplayed(url), "Checking that default bookmark: " + url + " is displayed in the bookmarks list", url + " is displayed as a bookmark"); - } - mAsserter.ok(isBookmarkDisplayed(BOOKMARK_URL), "Checking that added bookmark: " + BOOKMARK_URL + " is displayed in the bookmarks list", BOOKMARK_URL + " is displayed as a bookmark"); - - waitForText(StringHelper.DESKTOP_FOLDER_LABEL); - clickOnBookmarkFolder(StringHelper.DESKTOP_FOLDER_LABEL); - waitForText(StringHelper.TOOLBAR_FOLDER_LABEL); - - // Verify the number of folders displayed in the Desktop Bookmarks folder is correct - ListView desktopFolderContent = findListViewWithTag("bookmarks"); - ListAdapter adapter = desktopFolderContent.getAdapter(); - if (mDevice.type.equals("tablet")) { // On tablets it's 4 folders and 1 view for top padding - mAsserter.is(adapter.getCount(), 5, "Checking that the correct number of folders is displayed in the Desktop Bookmarks folder"); - } else { // On phones it's just the 4 folders - mAsserter.is(adapter.getCount(), 4, "Checking that the correct number of folders is displayed in the Desktop Bookmarks folder"); - } - - clickOnBookmarkFolder(StringHelper.TOOLBAR_FOLDER_LABEL); - - // Go up in the bookmark folder hierarchy - clickOnBookmarkFolder(StringHelper.TOOLBAR_FOLDER_LABEL); - mAsserter.ok(waitForText(StringHelper.BOOKMARKS_MENU_FOLDER_LABEL), "Going up in the folder hierarchy", "We are back in the Desktop Bookmarks folder"); - - clickOnBookmarkFolder(StringHelper.DESKTOP_FOLDER_LABEL); - mAsserter.ok(waitForText(StringHelper.DESKTOP_FOLDER_LABEL), "Going up in the folder hierarchy", "We are back in the main Bookmarks List View"); - - clickOnBookmarkFolder(StringHelper.DESKTOP_FOLDER_LABEL); - clickOnBookmarkFolder(StringHelper.TOOLBAR_FOLDER_LABEL); - mAsserter.ok(isBookmarkDisplayed(DESKTOP_BOOKMARK_URL), "Checking that added bookmark: " + DESKTOP_BOOKMARK_URL + " is displayed in the bookmarks list", DESKTOP_BOOKMARK_URL + " is displayed as a bookmark"); - - // Open the bookmark from a bookmark folder hierarchy - loadBookmark(DESKTOP_BOOKMARK_URL); - waitForText(StringHelper.ROBOCOP_BLANK_PAGE_02_TITLE); - verifyPageTitle(StringHelper.ROBOCOP_BLANK_PAGE_02_TITLE); - openAboutHomeTab(AboutHomeTabs.BOOKMARKS); - - // Check that folders don't have a context menu - boolean success = waitForCondition(new Condition() { - @Override - public boolean isSatisfied() { - View desktopFolder = getBookmarkFolderView(StringHelper.DESKTOP_FOLDER_LABEL); - if (desktopFolder != null) { - mSolo.clickLongOnView(desktopFolder); - return true; - } - return false; - } - }, MAX_WAIT_MS); - mAsserter.ok(success, "Trying to long click on the Desktop Bookmarks","Desktop Bookmarks folder could not be long clicked"); - mAsserter.ok(!waitForText("Share"), "Folders do not have context menus", "The context menu was not opened"); - - // Even if no context menu is opened long clicking a folder still opens it. We need to close it. - clickOnBookmarkFolder(StringHelper.DESKTOP_FOLDER_LABEL); - } - - private void checkBookmarkContextMenu() { - // Open default bookmarks in a new tab and a new private tab since the url is substituted with "Switch to tab" after opening the link - openBookmarkContextMenu(StringHelper.DEFAULT_BOOKMARKS_URLS[1]); - - // Test that the options are all displayed - for (String contextMenuOption:StringHelper.BOOKMARK_CONTEXT_MENU_ITEMS) { - mAsserter.ok(mSolo.searchText(contextMenuOption), "Checking that the context menu option is present", contextMenuOption + " is present"); - } - - // Test that "Open in New Tab" works - final Element tabCount = mDriver.findElement(getActivity(), "tabs_counter"); - final int tabCountInt = Integer.parseInt(tabCount.getText()); - Actions.EventExpecter tabEventExpecter = mActions.expectGeckoEvent("Tab:Added"); - mSolo.clickOnText(StringHelper.BOOKMARK_CONTEXT_MENU_ITEMS[0]); - tabEventExpecter.blockForEvent(); - tabEventExpecter.unregisterListener(); - - // Test that "Open in Private Tab" works - openBookmarkContextMenu(StringHelper.DEFAULT_BOOKMARKS_URLS[2]); - tabEventExpecter = mActions.expectGeckoEvent("Tab:Added"); - mSolo.clickOnText(StringHelper.BOOKMARK_CONTEXT_MENU_ITEMS[1]); - tabEventExpecter.blockForEvent(); - tabEventExpecter.unregisterListener(); - - // Test that "Share" works - openBookmarkContextMenu(BOOKMARK_URL); - mSolo.clickOnText(StringHelper.BOOKMARK_CONTEXT_MENU_ITEMS[2]); - mAsserter.ok(waitForText("Share via"), "Checking to see if the share menu has been opened","The share menu has been opened"); - mActions.sendSpecialKey(Actions.SpecialKey.BACK); - waitForText(StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE); - - // Test that "Edit" works - String[] editedBookmarkValues = {"New bookmark title", "www.NewBookmark.url", "newBookmarkKeyword"}; - editBookmark(BOOKMARK_URL,editedBookmarkValues); - checkBookmarkEdit(editedBookmarkValues[1],editedBookmarkValues); - - // Test that "Remove" works - openBookmarkContextMenu(editedBookmarkValues[1]); - mSolo.clickOnText(StringHelper.BOOKMARK_CONTEXT_MENU_ITEMS[4]); - waitForText("Bookmark removed"); - mAsserter.ok(!mDatabaseHelper.isBookmark(editedBookmarkValues[1]), "Checking that the bookmark was removed", "The bookmark was removed"); - } - - private void clickOnBookmarkFolder(final String folderName) { - boolean success = waitForCondition(new Condition() { - @Override - public boolean isSatisfied() { - View bookmarksFolder = getBookmarkFolderView(folderName); - if (bookmarksFolder != null) { - mSolo.clickOnView(bookmarksFolder); - return true; - } - return false; - } - }, MAX_WAIT_MS); - mAsserter.ok(success, "Trying to click on the " + folderName + " folder","The " + folderName + " folder was clicked"); - } - - private View getBookmarkFolderView(String folderName) { - ListView bookmarksTabList = findListViewWithTag("bookmarks"); - ListAdapter adapter = bookmarksTabList.getAdapter(); - if (adapter != null) { - for (int i = 0; i < adapter.getCount(); i++ ) { - View bookmarkView = bookmarksTabList.getChildAt(i); - if (bookmarkView instanceof TextView) { - TextView folderTextView = (TextView) bookmarkView; - if (folderTextView.getText().equals(folderName)) { - return bookmarkView; - } - } - } - } - return null; - } - - // Add a bookmark in the Desktop folder so we can check the folder navigation in the bookmarks page - private void setUpDesktopBookmarks() { - // Get the folder id of the StringHelper.DESKTOP_FOLDER_LABEL folder - Long desktopFolderId = mDatabaseHelper.getFolderIdFromGuid("toolbar"); - - // Generate a Guid for the bookmark - String generatedGuid = null; - try { - ClassLoader classLoader = getActivity().getClassLoader(); - Class syncUtilityClass = classLoader.loadClass("org.mozilla.gecko.sync.Utils"); - Method generateGuid = syncUtilityClass.getMethod("generateGuid", (Class[]) null); - generatedGuid = (String)generateGuid.invoke(null); - } catch (Exception e) { - mAsserter.dumpLog("Exception in setUpDesktopBookmarks" + e); - } - mAsserter.ok((generatedGuid != null), "Generating a random Guid for the bookmark", "We could not generate a Guid for the bookmark"); - - // Insert the bookmark - ContentResolver resolver = getActivity().getContentResolver(); - Uri bookmarksUri = mDatabaseHelper.buildUri(DatabaseHelper.BrowserDataType.BOOKMARKS); - ContentValues values = new ContentValues(); - values.put("title", StringHelper.ROBOCOP_BLANK_PAGE_02_TITLE); - values.put("url", DESKTOP_BOOKMARK_URL); - values.put("parent", desktopFolderId); - long now = System.currentTimeMillis(); - values.put("modified", now); - values.put("type", 1); - values.put("guid", generatedGuid); - values.put("position", 10); - values.put("created", now); - int updated = resolver.update(bookmarksUri, - values, - "url = ?", - new String[] { DESKTOP_BOOKMARK_URL }); - if (updated == 0) { - Uri uri = resolver.insert(bookmarksUri, values); - mAsserter.ok(true, "Inserted at: ", uri.toString()); - } else { - mAsserter.ok(false, "Failed to insert the Desktop bookmark", "Something went wrong"); - } - - // Add a mobile bookmark - mDatabaseHelper.addOrUpdateMobileBookmark(StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE, BOOKMARK_URL); - } - - @Override - public void tearDown() throws Exception { - mDatabaseHelper.deleteBookmark(DESKTOP_BOOKMARK_URL); - super.tearDown(); - } -}