mobile/android/base/tests/testBookmarksPanel.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/tests/testBookmarksPanel.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,122 @@
     1.4 +package org.mozilla.gecko.tests;
     1.5 +
     1.6 +import org.json.JSONException;
     1.7 +import org.json.JSONObject;
     1.8 +import org.mozilla.gecko.Actions;
     1.9 +import org.mozilla.gecko.Element;
    1.10 +import org.mozilla.gecko.R;
    1.11 +
    1.12 +public class testBookmarksPanel extends AboutHomeTest {
    1.13 +    public void testBookmarksPanel() {
    1.14 +        final String BOOKMARK_URL = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_01_URL);
    1.15 +        JSONObject data = null;
    1.16 +
    1.17 +        // Add a mobile bookmark
    1.18 +        mDatabaseHelper.addOrUpdateMobileBookmark(StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE, BOOKMARK_URL);
    1.19 +
    1.20 +        openAboutHomeTab(AboutHomeTabs.BOOKMARKS);
    1.21 +
    1.22 +        // Check that the default bookmarks are displayed
    1.23 +        for (String url : StringHelper.DEFAULT_BOOKMARKS_URLS) {
    1.24 +            isBookmarkDisplayed(url);
    1.25 +        }
    1.26 +
    1.27 +        // Open the context menu for the first bookmark in the list
    1.28 +        openBookmarkContextMenu(StringHelper.DEFAULT_BOOKMARKS_URLS[0]);
    1.29 +
    1.30 +        // Test that the options are all displayed
    1.31 +        for (String contextMenuOption : StringHelper.BOOKMARK_CONTEXT_MENU_ITEMS) {
    1.32 +            mAsserter.ok(mSolo.searchText(contextMenuOption), "Checking that the context menu option is present", contextMenuOption + " is present");
    1.33 +        }
    1.34 +
    1.35 +        // Test that "Open in New Tab" works
    1.36 +        final Element tabCount = mDriver.findElement(getActivity(), R.id.tabs_counter);
    1.37 +        final int tabCountInt = Integer.parseInt(tabCount.getText());
    1.38 +        Actions.EventExpecter tabEventExpecter = mActions.expectGeckoEvent("Tab:Added");
    1.39 +        mSolo.clickOnText(StringHelper.BOOKMARK_CONTEXT_MENU_ITEMS[0]);
    1.40 +        try {
    1.41 +            data = new JSONObject(tabEventExpecter.blockForEventData());
    1.42 +        } catch (JSONException e) {
    1.43 +            mAsserter.ok(false, "exception getting event data", e.toString());
    1.44 +        }
    1.45 +        tabEventExpecter.unregisterListener();
    1.46 +        mAsserter.ok(mSolo.searchText(StringHelper.TITLE_PLACE_HOLDER), "Checking that the tab is not changed", "The tab was not changed");
    1.47 +        // extra check here on the Tab:Added message to be sure the right tab opened
    1.48 +        int tabID = 0;
    1.49 +        try {
    1.50 +            mAsserter.is(StringHelper.ABOUT_FIREFOX_URL, data.getString("uri"), "Checking tab uri");
    1.51 +            tabID = data.getInt("tabID");
    1.52 +        } catch (JSONException e) {
    1.53 +            mAsserter.ok(false, "exception accessing event data", e.toString());
    1.54 +        }
    1.55 +        // close tab so about:firefox can be selected again
    1.56 +        closeTab(tabID);
    1.57 +
    1.58 +        // Test that "Open in Private Tab" works
    1.59 +        openBookmarkContextMenu(StringHelper.DEFAULT_BOOKMARKS_URLS[0]);
    1.60 +        tabEventExpecter = mActions.expectGeckoEvent("Tab:Added");
    1.61 +        mSolo.clickOnText(StringHelper.BOOKMARK_CONTEXT_MENU_ITEMS[1]);
    1.62 +        try {
    1.63 +            data = new JSONObject(tabEventExpecter.blockForEventData());
    1.64 +        } catch (JSONException e) {
    1.65 +            mAsserter.ok(false, "exception getting event data", e.toString());
    1.66 +        }
    1.67 +        tabEventExpecter.unregisterListener();
    1.68 +        mAsserter.ok(mSolo.searchText(StringHelper.TITLE_PLACE_HOLDER), "Checking that the tab is not changed", "The tab was not changed");
    1.69 +        // extra check here on the Tab:Added message to be sure the right tab opened, again
    1.70 +        try {
    1.71 +            mAsserter.is(StringHelper.ABOUT_FIREFOX_URL, data.getString("uri"), "Checking tab uri");
    1.72 +        } catch (JSONException e) {
    1.73 +            mAsserter.ok(false, "exception accessing event data", e.toString());
    1.74 +        }
    1.75 +
    1.76 +        // Test that "Edit" works
    1.77 +        String[] editedBookmarkValues = new String[] { "New bookmark title", "www.NewBookmark.url", "newBookmarkKeyword" };
    1.78 +        editBookmark(BOOKMARK_URL, editedBookmarkValues);
    1.79 +        checkBookmarkEdit(editedBookmarkValues[1], editedBookmarkValues);
    1.80 +
    1.81 +        // Test that "Remove" works
    1.82 +        openBookmarkContextMenu(editedBookmarkValues[1]);
    1.83 +        mSolo.clickOnText(StringHelper.BOOKMARK_CONTEXT_MENU_ITEMS[3]);
    1.84 +        waitForText("Bookmark removed");
    1.85 +        mAsserter.ok(!mDatabaseHelper.isBookmark(editedBookmarkValues[1]), "Checking that the bookmark was removed", "The bookmark was removed");
    1.86 +    }
    1.87 +
    1.88 +   /**
    1.89 +    * @param bookmarkUrl URL of the bookmark to edit
    1.90 +    * @param values String array with the new values for all fields
    1.91 +    */
    1.92 +    private void editBookmark(String bookmarkUrl, String[] values) {
    1.93 +        openBookmarkContextMenu(bookmarkUrl);
    1.94 +        mSolo.clickOnText("Edit");
    1.95 +        waitForText("Edit Bookmark");
    1.96 +
    1.97 +        // Update the fields with the new values
    1.98 +        for (int i = 0; i < values.length; i++) {
    1.99 +            mSolo.clearEditText(i);
   1.100 +            mSolo.clickOnEditText(i);
   1.101 +            mActions.sendKeys(values[i]);
   1.102 +        }
   1.103 +
   1.104 +        mSolo.clickOnButton("OK");
   1.105 +        waitForText("Bookmark updated");
   1.106 +    }
   1.107 +
   1.108 +   /**
   1.109 +    * @param bookmarkUrl String with the original url
   1.110 +    * @param values String array with the new values for all fields
   1.111 +    */
   1.112 +    private void checkBookmarkEdit(String bookmarkUrl, String[] values) {
   1.113 +        openBookmarkContextMenu(bookmarkUrl);
   1.114 +        mSolo.clickOnText("Edit");
   1.115 +        waitForText("Edit Bookmark");
   1.116 +
   1.117 +        // Check the values of the fields
   1.118 +        for (String value : values) {
   1.119 +            mAsserter.ok(mSolo.searchText(value), "Checking that the value is correct", "The value = " + value + " is correct");
   1.120 +        }
   1.121 +
   1.122 +        mSolo.clickOnButton("Cancel");
   1.123 +        waitForText("BOOKMARKS");
   1.124 +    }
   1.125 +}

mercurial