michael@0: package org.mozilla.gecko.tests; michael@0: michael@0: import org.json.JSONException; michael@0: import org.json.JSONObject; michael@0: import org.mozilla.gecko.Actions; michael@0: import org.mozilla.gecko.Element; michael@0: import org.mozilla.gecko.R; michael@0: michael@0: public class testBookmarksPanel extends AboutHomeTest { michael@0: public void testBookmarksPanel() { michael@0: final String BOOKMARK_URL = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_01_URL); michael@0: JSONObject data = null; michael@0: michael@0: // Add a mobile bookmark michael@0: mDatabaseHelper.addOrUpdateMobileBookmark(StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE, BOOKMARK_URL); michael@0: michael@0: openAboutHomeTab(AboutHomeTabs.BOOKMARKS); michael@0: michael@0: // Check that the default bookmarks are displayed michael@0: for (String url : StringHelper.DEFAULT_BOOKMARKS_URLS) { michael@0: isBookmarkDisplayed(url); michael@0: } michael@0: michael@0: // Open the context menu for the first bookmark in the list michael@0: openBookmarkContextMenu(StringHelper.DEFAULT_BOOKMARKS_URLS[0]); michael@0: michael@0: // Test that the options are all displayed michael@0: for (String contextMenuOption : StringHelper.BOOKMARK_CONTEXT_MENU_ITEMS) { michael@0: mAsserter.ok(mSolo.searchText(contextMenuOption), "Checking that the context menu option is present", contextMenuOption + " is present"); michael@0: } michael@0: michael@0: // Test that "Open in New Tab" works michael@0: final Element tabCount = mDriver.findElement(getActivity(), R.id.tabs_counter); michael@0: final int tabCountInt = Integer.parseInt(tabCount.getText()); michael@0: Actions.EventExpecter tabEventExpecter = mActions.expectGeckoEvent("Tab:Added"); michael@0: mSolo.clickOnText(StringHelper.BOOKMARK_CONTEXT_MENU_ITEMS[0]); michael@0: try { michael@0: data = new JSONObject(tabEventExpecter.blockForEventData()); michael@0: } catch (JSONException e) { michael@0: mAsserter.ok(false, "exception getting event data", e.toString()); michael@0: } michael@0: tabEventExpecter.unregisterListener(); michael@0: mAsserter.ok(mSolo.searchText(StringHelper.TITLE_PLACE_HOLDER), "Checking that the tab is not changed", "The tab was not changed"); michael@0: // extra check here on the Tab:Added message to be sure the right tab opened michael@0: int tabID = 0; michael@0: try { michael@0: mAsserter.is(StringHelper.ABOUT_FIREFOX_URL, data.getString("uri"), "Checking tab uri"); michael@0: tabID = data.getInt("tabID"); michael@0: } catch (JSONException e) { michael@0: mAsserter.ok(false, "exception accessing event data", e.toString()); michael@0: } michael@0: // close tab so about:firefox can be selected again michael@0: closeTab(tabID); michael@0: michael@0: // Test that "Open in Private Tab" works michael@0: openBookmarkContextMenu(StringHelper.DEFAULT_BOOKMARKS_URLS[0]); michael@0: tabEventExpecter = mActions.expectGeckoEvent("Tab:Added"); michael@0: mSolo.clickOnText(StringHelper.BOOKMARK_CONTEXT_MENU_ITEMS[1]); michael@0: try { michael@0: data = new JSONObject(tabEventExpecter.blockForEventData()); michael@0: } catch (JSONException e) { michael@0: mAsserter.ok(false, "exception getting event data", e.toString()); michael@0: } michael@0: tabEventExpecter.unregisterListener(); michael@0: mAsserter.ok(mSolo.searchText(StringHelper.TITLE_PLACE_HOLDER), "Checking that the tab is not changed", "The tab was not changed"); michael@0: // extra check here on the Tab:Added message to be sure the right tab opened, again michael@0: try { michael@0: mAsserter.is(StringHelper.ABOUT_FIREFOX_URL, data.getString("uri"), "Checking tab uri"); michael@0: } catch (JSONException e) { michael@0: mAsserter.ok(false, "exception accessing event data", e.toString()); michael@0: } michael@0: michael@0: // Test that "Edit" works michael@0: String[] editedBookmarkValues = new String[] { "New bookmark title", "www.NewBookmark.url", "newBookmarkKeyword" }; michael@0: editBookmark(BOOKMARK_URL, editedBookmarkValues); michael@0: checkBookmarkEdit(editedBookmarkValues[1], editedBookmarkValues); michael@0: michael@0: // Test that "Remove" works michael@0: openBookmarkContextMenu(editedBookmarkValues[1]); michael@0: mSolo.clickOnText(StringHelper.BOOKMARK_CONTEXT_MENU_ITEMS[3]); michael@0: waitForText("Bookmark removed"); michael@0: mAsserter.ok(!mDatabaseHelper.isBookmark(editedBookmarkValues[1]), "Checking that the bookmark was removed", "The bookmark was removed"); michael@0: } michael@0: michael@0: /** michael@0: * @param bookmarkUrl URL of the bookmark to edit michael@0: * @param values String array with the new values for all fields michael@0: */ michael@0: private void editBookmark(String bookmarkUrl, String[] values) { michael@0: openBookmarkContextMenu(bookmarkUrl); michael@0: mSolo.clickOnText("Edit"); michael@0: waitForText("Edit Bookmark"); michael@0: michael@0: // Update the fields with the new values michael@0: for (int i = 0; i < values.length; i++) { michael@0: mSolo.clearEditText(i); michael@0: mSolo.clickOnEditText(i); michael@0: mActions.sendKeys(values[i]); michael@0: } michael@0: michael@0: mSolo.clickOnButton("OK"); michael@0: waitForText("Bookmark updated"); michael@0: } michael@0: michael@0: /** michael@0: * @param bookmarkUrl String with the original url michael@0: * @param values String array with the new values for all fields michael@0: */ michael@0: private void checkBookmarkEdit(String bookmarkUrl, String[] values) { michael@0: openBookmarkContextMenu(bookmarkUrl); michael@0: mSolo.clickOnText("Edit"); michael@0: waitForText("Edit Bookmark"); michael@0: michael@0: // Check the values of the fields michael@0: for (String value : values) { michael@0: mAsserter.ok(mSolo.searchText(value), "Checking that the value is correct", "The value = " + value + " is correct"); michael@0: } michael@0: michael@0: mSolo.clickOnButton("Cancel"); michael@0: waitForText("BOOKMARKS"); michael@0: } michael@0: }