mobile/android/base/tests/testBookmarksPanel.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 package org.mozilla.gecko.tests;
michael@0 2
michael@0 3 import org.json.JSONException;
michael@0 4 import org.json.JSONObject;
michael@0 5 import org.mozilla.gecko.Actions;
michael@0 6 import org.mozilla.gecko.Element;
michael@0 7 import org.mozilla.gecko.R;
michael@0 8
michael@0 9 public class testBookmarksPanel extends AboutHomeTest {
michael@0 10 public void testBookmarksPanel() {
michael@0 11 final String BOOKMARK_URL = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_01_URL);
michael@0 12 JSONObject data = null;
michael@0 13
michael@0 14 // Add a mobile bookmark
michael@0 15 mDatabaseHelper.addOrUpdateMobileBookmark(StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE, BOOKMARK_URL);
michael@0 16
michael@0 17 openAboutHomeTab(AboutHomeTabs.BOOKMARKS);
michael@0 18
michael@0 19 // Check that the default bookmarks are displayed
michael@0 20 for (String url : StringHelper.DEFAULT_BOOKMARKS_URLS) {
michael@0 21 isBookmarkDisplayed(url);
michael@0 22 }
michael@0 23
michael@0 24 // Open the context menu for the first bookmark in the list
michael@0 25 openBookmarkContextMenu(StringHelper.DEFAULT_BOOKMARKS_URLS[0]);
michael@0 26
michael@0 27 // Test that the options are all displayed
michael@0 28 for (String contextMenuOption : StringHelper.BOOKMARK_CONTEXT_MENU_ITEMS) {
michael@0 29 mAsserter.ok(mSolo.searchText(contextMenuOption), "Checking that the context menu option is present", contextMenuOption + " is present");
michael@0 30 }
michael@0 31
michael@0 32 // Test that "Open in New Tab" works
michael@0 33 final Element tabCount = mDriver.findElement(getActivity(), R.id.tabs_counter);
michael@0 34 final int tabCountInt = Integer.parseInt(tabCount.getText());
michael@0 35 Actions.EventExpecter tabEventExpecter = mActions.expectGeckoEvent("Tab:Added");
michael@0 36 mSolo.clickOnText(StringHelper.BOOKMARK_CONTEXT_MENU_ITEMS[0]);
michael@0 37 try {
michael@0 38 data = new JSONObject(tabEventExpecter.blockForEventData());
michael@0 39 } catch (JSONException e) {
michael@0 40 mAsserter.ok(false, "exception getting event data", e.toString());
michael@0 41 }
michael@0 42 tabEventExpecter.unregisterListener();
michael@0 43 mAsserter.ok(mSolo.searchText(StringHelper.TITLE_PLACE_HOLDER), "Checking that the tab is not changed", "The tab was not changed");
michael@0 44 // extra check here on the Tab:Added message to be sure the right tab opened
michael@0 45 int tabID = 0;
michael@0 46 try {
michael@0 47 mAsserter.is(StringHelper.ABOUT_FIREFOX_URL, data.getString("uri"), "Checking tab uri");
michael@0 48 tabID = data.getInt("tabID");
michael@0 49 } catch (JSONException e) {
michael@0 50 mAsserter.ok(false, "exception accessing event data", e.toString());
michael@0 51 }
michael@0 52 // close tab so about:firefox can be selected again
michael@0 53 closeTab(tabID);
michael@0 54
michael@0 55 // Test that "Open in Private Tab" works
michael@0 56 openBookmarkContextMenu(StringHelper.DEFAULT_BOOKMARKS_URLS[0]);
michael@0 57 tabEventExpecter = mActions.expectGeckoEvent("Tab:Added");
michael@0 58 mSolo.clickOnText(StringHelper.BOOKMARK_CONTEXT_MENU_ITEMS[1]);
michael@0 59 try {
michael@0 60 data = new JSONObject(tabEventExpecter.blockForEventData());
michael@0 61 } catch (JSONException e) {
michael@0 62 mAsserter.ok(false, "exception getting event data", e.toString());
michael@0 63 }
michael@0 64 tabEventExpecter.unregisterListener();
michael@0 65 mAsserter.ok(mSolo.searchText(StringHelper.TITLE_PLACE_HOLDER), "Checking that the tab is not changed", "The tab was not changed");
michael@0 66 // extra check here on the Tab:Added message to be sure the right tab opened, again
michael@0 67 try {
michael@0 68 mAsserter.is(StringHelper.ABOUT_FIREFOX_URL, data.getString("uri"), "Checking tab uri");
michael@0 69 } catch (JSONException e) {
michael@0 70 mAsserter.ok(false, "exception accessing event data", e.toString());
michael@0 71 }
michael@0 72
michael@0 73 // Test that "Edit" works
michael@0 74 String[] editedBookmarkValues = new String[] { "New bookmark title", "www.NewBookmark.url", "newBookmarkKeyword" };
michael@0 75 editBookmark(BOOKMARK_URL, editedBookmarkValues);
michael@0 76 checkBookmarkEdit(editedBookmarkValues[1], editedBookmarkValues);
michael@0 77
michael@0 78 // Test that "Remove" works
michael@0 79 openBookmarkContextMenu(editedBookmarkValues[1]);
michael@0 80 mSolo.clickOnText(StringHelper.BOOKMARK_CONTEXT_MENU_ITEMS[3]);
michael@0 81 waitForText("Bookmark removed");
michael@0 82 mAsserter.ok(!mDatabaseHelper.isBookmark(editedBookmarkValues[1]), "Checking that the bookmark was removed", "The bookmark was removed");
michael@0 83 }
michael@0 84
michael@0 85 /**
michael@0 86 * @param bookmarkUrl URL of the bookmark to edit
michael@0 87 * @param values String array with the new values for all fields
michael@0 88 */
michael@0 89 private void editBookmark(String bookmarkUrl, String[] values) {
michael@0 90 openBookmarkContextMenu(bookmarkUrl);
michael@0 91 mSolo.clickOnText("Edit");
michael@0 92 waitForText("Edit Bookmark");
michael@0 93
michael@0 94 // Update the fields with the new values
michael@0 95 for (int i = 0; i < values.length; i++) {
michael@0 96 mSolo.clearEditText(i);
michael@0 97 mSolo.clickOnEditText(i);
michael@0 98 mActions.sendKeys(values[i]);
michael@0 99 }
michael@0 100
michael@0 101 mSolo.clickOnButton("OK");
michael@0 102 waitForText("Bookmark updated");
michael@0 103 }
michael@0 104
michael@0 105 /**
michael@0 106 * @param bookmarkUrl String with the original url
michael@0 107 * @param values String array with the new values for all fields
michael@0 108 */
michael@0 109 private void checkBookmarkEdit(String bookmarkUrl, String[] values) {
michael@0 110 openBookmarkContextMenu(bookmarkUrl);
michael@0 111 mSolo.clickOnText("Edit");
michael@0 112 waitForText("Edit Bookmark");
michael@0 113
michael@0 114 // Check the values of the fields
michael@0 115 for (String value : values) {
michael@0 116 mAsserter.ok(mSolo.searchText(value), "Checking that the value is correct", "The value = " + value + " is correct");
michael@0 117 }
michael@0 118
michael@0 119 mSolo.clickOnButton("Cancel");
michael@0 120 waitForText("BOOKMARKS");
michael@0 121 }
michael@0 122 }

mercurial