mobile/android/base/tests/testBookmarkFolders.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/tests/testBookmarkFolders.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,167 @@
     1.4 +package org.mozilla.gecko.tests;
     1.5 +
     1.6 +import org.mozilla.gecko.sync.Utils;
     1.7 +
     1.8 +import android.content.ContentResolver;
     1.9 +import android.content.ContentValues;
    1.10 +import android.net.Uri;
    1.11 +import android.view.View;
    1.12 +import android.widget.ListAdapter;
    1.13 +import android.widget.ListView;
    1.14 +import android.widget.TextView;
    1.15 +
    1.16 +import com.jayway.android.robotium.solo.Condition;
    1.17 +
    1.18 +public class testBookmarkFolders extends AboutHomeTest {
    1.19 +    private static String DESKTOP_BOOKMARK_URL;
    1.20 +
    1.21 +    public void testBookmarkFolders() {
    1.22 +        DESKTOP_BOOKMARK_URL = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_02_URL);
    1.23 +
    1.24 +        setUpDesktopBookmarks();
    1.25 +        checkBookmarkList();
    1.26 +    }
    1.27 +
    1.28 +    private void checkBookmarkList() {
    1.29 +        openAboutHomeTab(AboutHomeTabs.BOOKMARKS);
    1.30 +        waitForText(StringHelper.DESKTOP_FOLDER_LABEL);
    1.31 +        clickOnBookmarkFolder(StringHelper.DESKTOP_FOLDER_LABEL);
    1.32 +        waitForText(StringHelper.TOOLBAR_FOLDER_LABEL);
    1.33 +
    1.34 +        // Verify the number of folders displayed in the Desktop Bookmarks folder is correct
    1.35 +        ListView desktopFolderContent = findListViewWithTag("bookmarks");
    1.36 +        ListAdapter adapter = desktopFolderContent.getAdapter();
    1.37 +        if (mDevice.type.equals("tablet")) { // On tablets it's 4 folders and 1 view for top padding
    1.38 +            mAsserter.is(adapter.getCount(), 5, "Checking that the correct number of folders is displayed in the Desktop Bookmarks folder");
    1.39 +        } else { // On phones it's just the 4 folders
    1.40 +            mAsserter.is(adapter.getCount(), 4, "Checking that the correct number of folders is displayed in the Desktop Bookmarks folder");
    1.41 +        }
    1.42 +
    1.43 +        clickOnBookmarkFolder(StringHelper.TOOLBAR_FOLDER_LABEL);
    1.44 +
    1.45 +        // Go up in the bookmark folder hierarchy
    1.46 +        clickOnBookmarkFolder(StringHelper.TOOLBAR_FOLDER_LABEL);
    1.47 +        mAsserter.ok(waitForText(StringHelper.BOOKMARKS_MENU_FOLDER_LABEL), "Going up in the folder hierarchy", "We are back in the Desktop Bookmarks folder");
    1.48 +
    1.49 +        clickOnBookmarkFolder(StringHelper.DESKTOP_FOLDER_LABEL);
    1.50 +        mAsserter.ok(waitForText(StringHelper.DESKTOP_FOLDER_LABEL), "Going up in the folder hierarchy", "We are back in the main Bookmarks List View");
    1.51 +
    1.52 +        clickOnBookmarkFolder(StringHelper.DESKTOP_FOLDER_LABEL);
    1.53 +        clickOnBookmarkFolder(StringHelper.TOOLBAR_FOLDER_LABEL);
    1.54 +        isBookmarkDisplayed(DESKTOP_BOOKMARK_URL);
    1.55 +
    1.56 +        // Open the bookmark from a bookmark folder hierarchy
    1.57 +        loadBookmark(DESKTOP_BOOKMARK_URL);
    1.58 +        waitForText(StringHelper.ROBOCOP_BLANK_PAGE_02_TITLE);
    1.59 +        verifyPageTitle(StringHelper.ROBOCOP_BLANK_PAGE_02_TITLE);
    1.60 +        openAboutHomeTab(AboutHomeTabs.BOOKMARKS);
    1.61 +
    1.62 +        // Check that folders don't have a context menu
    1.63 +        boolean success = waitForCondition(new Condition() {
    1.64 +            @Override
    1.65 +            public boolean isSatisfied() {
    1.66 +                View desktopFolder = getBookmarkFolderView(StringHelper.DESKTOP_FOLDER_LABEL);
    1.67 +                if (desktopFolder == null) {
    1.68 +                    return false;
    1.69 +                }
    1.70 +                mSolo.clickLongOnView(desktopFolder);
    1.71 +                return true;            }
    1.72 +        }, MAX_WAIT_MS);
    1.73 +
    1.74 +        mAsserter.ok(success, "Trying to long click on the Desktop Bookmarks","Desktop Bookmarks folder could not be long clicked");
    1.75 +
    1.76 +        final String contextMenuString = StringHelper.BOOKMARK_CONTEXT_MENU_ITEMS[0];
    1.77 +        mAsserter.ok(!waitForText(contextMenuString), "Folders do not have context menus", "The context menu was not opened");
    1.78 +
    1.79 +        // Even if no context menu is opened long clicking a folder still opens it. We need to close it.
    1.80 +        clickOnBookmarkFolder(StringHelper.DESKTOP_FOLDER_LABEL);
    1.81 +    }
    1.82 +
    1.83 +    private void clickOnBookmarkFolder(final String folderName) {
    1.84 +        boolean success = waitForCondition(new Condition() {
    1.85 +            @Override
    1.86 +            public boolean isSatisfied() {
    1.87 +                View bookmarksFolder = getBookmarkFolderView(folderName);
    1.88 +                if (bookmarksFolder == null) {
    1.89 +                    return false;
    1.90 +                }
    1.91 +                mSolo.waitForView(bookmarksFolder);
    1.92 +                mSolo.clickOnView(bookmarksFolder);
    1.93 +                return true;
    1.94 +            }
    1.95 +        }, MAX_WAIT_MS);
    1.96 +        mAsserter.ok(success, "Trying to click on the " + folderName + " folder","The " + folderName + " folder was clicked");
    1.97 +    }
    1.98 +
    1.99 +    private View getBookmarkFolderView(String folderName) {
   1.100 +        openAboutHomeTab(AboutHomeTabs.BOOKMARKS);
   1.101 +        mSolo.hideSoftKeyboard();
   1.102 +        getInstrumentation().waitForIdleSync();
   1.103 +
   1.104 +        ListView bookmarksTabList = findListViewWithTag("bookmarks");
   1.105 +        if (!waitForNonEmptyListToLoad(bookmarksTabList)) {
   1.106 +            return null;
   1.107 +        }
   1.108 +
   1.109 +        ListAdapter adapter = bookmarksTabList.getAdapter();
   1.110 +        if (adapter == null) {
   1.111 +            return null;
   1.112 +        }
   1.113 +
   1.114 +        for (int i = 0; i < adapter.getCount(); i++ ) {
   1.115 +            View bookmarkView = bookmarksTabList.getChildAt(i);
   1.116 +            if (bookmarkView instanceof TextView) {
   1.117 +                TextView folderTextView = (TextView) bookmarkView;
   1.118 +                if (folderTextView.getText().equals(folderName)) {
   1.119 +                    return bookmarkView;
   1.120 +                }
   1.121 +            }
   1.122 +        }
   1.123 +
   1.124 +        return null;
   1.125 +    }
   1.126 +
   1.127 +    // Add a bookmark in the Desktop folder so we can check the folder navigation in the bookmarks page
   1.128 +    private void setUpDesktopBookmarks() {
   1.129 +        blockForGeckoReady();
   1.130 +
   1.131 +        // Get the folder id of the StringHelper.DESKTOP_FOLDER_LABEL folder
   1.132 +        Long desktopFolderId = mDatabaseHelper.getFolderIdFromGuid("toolbar");
   1.133 +
   1.134 +        // Generate a Guid for the bookmark
   1.135 +        final String generatedGuid = Utils.generateGuid();
   1.136 +        mAsserter.ok((generatedGuid != null), "Generating a random Guid for the bookmark", "We could not generate a Guid for the bookmark");
   1.137 +
   1.138 +        // Insert the bookmark
   1.139 +        ContentResolver resolver = getActivity().getContentResolver();
   1.140 +        Uri bookmarksUri = mDatabaseHelper.buildUri(DatabaseHelper.BrowserDataType.BOOKMARKS);
   1.141 +
   1.142 +        long now = System.currentTimeMillis();
   1.143 +        ContentValues values = new ContentValues();
   1.144 +        values.put("title", StringHelper.ROBOCOP_BLANK_PAGE_02_TITLE);
   1.145 +        values.put("url", DESKTOP_BOOKMARK_URL);
   1.146 +        values.put("parent", desktopFolderId);
   1.147 +        values.put("modified", now);
   1.148 +        values.put("type", 1);
   1.149 +        values.put("guid", generatedGuid);
   1.150 +        values.put("position", 10);
   1.151 +        values.put("created", now);
   1.152 +
   1.153 +        int updated = resolver.update(bookmarksUri,
   1.154 +                                      values,
   1.155 +                                      "url = ?",
   1.156 +                                      new String[] { DESKTOP_BOOKMARK_URL });
   1.157 +        if (updated == 0) {
   1.158 +            Uri uri = resolver.insert(bookmarksUri, values);
   1.159 +            mAsserter.ok(true, "Inserted at: ", uri.toString());
   1.160 +        } else {
   1.161 +            mAsserter.ok(false, "Failed to insert the Desktop bookmark", "Something went wrong");
   1.162 +        }
   1.163 +    }
   1.164 +
   1.165 +    @Override
   1.166 +    public void tearDown() throws Exception {
   1.167 +        mDatabaseHelper.deleteBookmark(DESKTOP_BOOKMARK_URL);
   1.168 +        super.tearDown();
   1.169 +    }
   1.170 +}

mercurial